Take in API requests via json payload instead of params

This commit is contained in:
Akkadius 2019-07-07 19:57:05 -05:00
parent 5473457c0c
commit c2917a9004
8 changed files with 40 additions and 166 deletions

View File

@ -6,16 +6,8 @@
#EQEMU_DISABLE_SAFESEH #EQEMU_DISABLE_SAFESEH
#EQEMU_BUILD_MSVC_MP #EQEMU_BUILD_MSVC_MP
#EQEMU_DEBUG_LEVEL #EQEMU_DEBUG_LEVEL
#EQEMU_LOG_LEVEL_STATUS
#EQEMU_LOG_LEVEL_NORMAL
#EQEMU_LOG_LEVEL_ERROR
#EQEMU_LOG_LEVEL_DEBUG #EQEMU_LOG_LEVEL_DEBUG
#EQEMU_LOG_LEVEL_QUEST
#EQEMU_LOG_LEVEL_COMMANDS
#EQEMU_LOG_LEVEL_CRASH
#EQEMU_DEPOP_INVALIDATES_CACHE
#EQEMU_ENABLE_BOTS #EQEMU_ENABLE_BOTS
#EQEMU_DISABLE_LOGSYS
#EQEMU_COMMANDS_LOGGING #EQEMU_COMMANDS_LOGGING
#EQEMU_BUILD_SERVER #EQEMU_BUILD_SERVER
#EQEMU_BUILD_LOGIN #EQEMU_BUILD_LOGIN
@ -144,36 +136,6 @@ SET(EQEMU_DEBUG_LEVEL 5 CACHE STRING "EQEmu debug level:
10 - More errors than you ever wanted to see" 10 - More errors than you ever wanted to see"
) )
SET(EQEMU_LOG_LEVEL_STATUS 2 CACHE STRING "EQEmu logging level for [Status]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
SET(EQEMU_LOG_LEVEL_NORMAL 3 CACHE STRING "EQEmu logging level for [Normal]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
SET(EQEMU_LOG_LEVEL_ERROR 2 CACHE STRING "EQEmu logging level for [Error]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
SET(EQEMU_LOG_LEVEL_DEBUG 3 CACHE STRING "EQEmu logging level for [Debug]: SET(EQEMU_LOG_LEVEL_DEBUG 3 CACHE STRING "EQEmu logging level for [Debug]:
0 - Disabled 0 - Disabled
1 - Ouput to File Enabled 1 - Ouput to File Enabled
@ -184,47 +146,17 @@ SET(EQEMU_LOG_LEVEL_DEBUG 3 CACHE STRING "EQEmu logging level for [Debug]:
11 - Output to File, stdout and stderr Enabled" 11 - Output to File, stdout and stderr Enabled"
) )
SET(EQEMU_LOG_LEVEL_QUEST 2 CACHE STRING "EQEmu logging level for [Quest]: OPTION(EQEMU_LSPX "" OFF)
0 - Disabled IF(EQEMU_LSPX)
1 - Ouput to File Enabled ADD_DEFINITIONS(-DLSPX=ON)
2 - Output to stdout Enabled ENDIF(EQEMU_LSPX)
3 - Output to File and stdout Enabled MARK_AS_ADVANCED(EQEMU_LSPX)
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
SET(EQEMU_LOG_LEVEL_COMMANDS 1 CACHE STRING "EQEmu logging level for [Commands]: MARK_AS_ADVANCED(EQEMU_LOG_LEVEL_DEBUG)
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
SET(EQEMU_LOG_LEVEL_CRASH 3 CACHE STRING "EQEmu logging level for [Crash]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
MARK_AS_ADVANCED(EQEMU_LOG_LEVEL_STATUS EQEMU_LOG_LEVEL_NORMAL EQEMU_LOG_LEVEL_ERROR EQEMU_LOG_LEVEL_DEBUG EQEMU_LOG_LEVEL_QUEST EQEMU_LOG_LEVEL_COMMANDS EQEMU_LOG_LEVEL_CRASH)
#NPC Types Cache Behavior
OPTION(EQEMU_DEPOP_INVALIDATES_CACHE "#repop invalidates the npc_types cache (will cause a larger database hit on #repop but is more convienent)." ON)
#Bots are a compile time option so on/off #Bots are a compile time option so on/off
OPTION(EQEMU_ENABLE_BOTS "Enable Bots" OFF) OPTION(EQEMU_ENABLE_BOTS "Enable Bots" OFF)
#Disable entire _mlog system (excludes trade/command logs)
OPTION(EQEMU_DISABLE_LOGSYS "Disable Logging INI System" ON)
#Enable GM Command log system #Enable GM Command log system
OPTION(EQEMU_COMMANDS_LOGGING "Enable GM Command logs" ON) OPTION(EQEMU_COMMANDS_LOGGING "Enable GM Command logs" ON)
@ -232,10 +164,6 @@ IF(EQEMU_COMMANDS_LOGGING)
ADD_DEFINITIONS(-DCOMMANDS_LOGGING) ADD_DEFINITIONS(-DCOMMANDS_LOGGING)
ENDIF(EQEMU_COMMANDS_LOGGING) ENDIF(EQEMU_COMMANDS_LOGGING)
IF(EQEMU_DISABLE_LOGSYS)
ADD_DEFINITIONS(-DDISABLE_LOGSYS)
ENDIF(EQEMU_DISABLE_LOGSYS)
IF(EQEMU_ENABLE_BOTS) IF(EQEMU_ENABLE_BOTS)
ADD_DEFINITIONS(-DBOTS) ADD_DEFINITIONS(-DBOTS)
ENDIF(EQEMU_ENABLE_BOTS) ENDIF(EQEMU_ENABLE_BOTS)
@ -278,13 +206,7 @@ ADD_DEFINITIONS(-DEQDEBUG=${EQEMU_DEBUG_LEVEL})
ADD_DEFINITIONS(-DINVERSEXY) ADD_DEFINITIONS(-DINVERSEXY)
ADD_DEFINITIONS(-DFIELD_ITEMS) ADD_DEFINITIONS(-DFIELD_ITEMS)
ADD_DEFINITIONS(-DMAP_DIR="${EQEMU_MAP_DIR}") ADD_DEFINITIONS(-DMAP_DIR="${EQEMU_MAP_DIR}")
ADD_DEFINITIONS(-DLOG_LEVEL_STATUS=${EQEMU_LOG_LEVEL_STATUS})
ADD_DEFINITIONS(-DLOG_LEVEL_NORMAL=${EQEMU_LOG_LEVEL_NORMAL})
ADD_DEFINITIONS(-DLOG_LEVEL_ERROR=${EQEMU_LOG_LEVEL_ERROR})
ADD_DEFINITIONS(-DLOG_LEVEL_DEBUG=${EQEMU_LOG_LEVEL_DEBUG}) ADD_DEFINITIONS(-DLOG_LEVEL_DEBUG=${EQEMU_LOG_LEVEL_DEBUG})
ADD_DEFINITIONS(-DLOG_LEVEL_QUEST=${EQEMU_LOG_LEVEL_QUEST})
ADD_DEFINITIONS(-DLOG_LEVEL_COMMANDS=${EQEMU_LOG_LEVEL_COMMANDS})
ADD_DEFINITIONS(-DLOG_LEVEL_CRASH=${EQEMU_LOG_LEVEL_CRASH})
ADD_DEFINITIONS(-DGLM_FORCE_RADIANS) ADD_DEFINITIONS(-DGLM_FORCE_RADIANS)
ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT) ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT)
ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL) ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL)

View File

@ -385,8 +385,9 @@ void Client::AttemptLoginAccountCreation(
{ {
LogInfo("Attempting login account creation via '{0}'", loginserver); LogInfo("Attempting login account creation via '{0}'", loginserver);
if (loginserver == "eqemu") { #ifdef LSPX
if (loginserver == "eqemu") {
if (!server.options.CanAutoLinkAccounts()) { if (!server.options.CanAutoLinkAccounts()) {
LogInfo("CanAutoLinkAccounts disabled - sending failed login"); LogInfo("CanAutoLinkAccounts disabled - sending failed login");
DoFailedLogin(); DoFailedLogin();
@ -445,16 +446,17 @@ void Client::AttemptLoginAccountCreation(
login_connection_manager->Connect(addr, port); login_connection_manager->Connect(addr, port);
} }
); );
}
else {
if (!server.options.CanAutoCreateAccounts()) { return;
DoFailedLogin(); }
#endif
if (server.options.CanAutoCreateAccounts() && loginserver == "local") {
CreateLocalAccount(user, pass);
return; return;
} }
CreateLocalAccount(user, pass); DoFailedLogin();
}
} }
void Client::DoFailedLogin() void Client::DoFailedLogin()

View File

@ -277,7 +277,7 @@ bool Database::DoesLoginServerAccountExist(
} }
auto query = fmt::format( auto query = fmt::format(
"SELECT AccountName FROM login_accounts WHERE account_name = '{0}' AND source_loginserver = '{1}'", "SELECT account_name FROM login_accounts WHERE account_name = '{0}' AND source_loginserver = '{1}'",
EscapeString(name), EscapeString(name),
EscapeString(loginserver) EscapeString(loginserver)
); );

View File

@ -64,13 +64,18 @@ namespace LoginserverWebserver {
api.Post( api.Post(
"/account/create", [](const httplib::Request &request, httplib::Response &res) { "/account/create", [](const httplib::Request &request, httplib::Response &res) {
LoginserverWebserver::TokenManager::AuthCanWrite(request, res); LoginserverWebserver::TokenManager::AuthCanWrite(request, res);
Json::Value request_body = LoginserverWebserver::ParseRequestBody(request);
std::string username = request_body.get("username", "").asString();
std::string password = request_body.get("password", "").asString();
Json::Value response; Json::Value response;
bool account_created = AccountManagement::CreateLocalLoginServerAccount( if (username.empty() || password.empty()) {
request.get_param_value("username"), response["message"] = "Username or password not set";
request.get_param_value("password") LoginserverWebserver::SendResponse(response, res);
); return;
}
bool account_created = AccountManagement::CreateLocalLoginServerAccount(username, password);
if (account_created) { if (account_created) {
response["message"] = "Account created successfully!"; response["message"] = "Account created successfully!";
} }
@ -108,6 +113,20 @@ namespace LoginserverWebserver {
res.set_content(response_payload.str(), "application/json"); res.set_content(response_payload.str(), "application/json");
} }
/**
* @param payload
* @param res
*/
Json::Value ParseRequestBody(const httplib::Request &request)
{
std::stringstream ss;
ss.str(request.body);
Json::Value request_body;
ss >> request_body;
return request_body;
}
/** /**
* @param request * @param request
* @param res * @param res

View File

@ -52,6 +52,7 @@ namespace LoginserverWebserver {
void RegisterRoutes(httplib::Server &api); void RegisterRoutes(httplib::Server &api);
void SendResponse(const Json::Value &payload, httplib::Response &res); void SendResponse(const Json::Value &payload, httplib::Response &res);
static Json::Value ParseRequestBody(const httplib::Request &request);
}; };
#endif //EQEMU_LOGINSERVER_WEBSERVER_H #endif //EQEMU_LOGINSERVER_WEBSERVER_H

View File

@ -96,28 +96,6 @@ int main(int argc, char** argv)
true true
) )
); );
server.options.AccountTable(server.config.GetVariableString("schema", "account_table", "tblLoginServerAccounts"));
server.options.WorldRegistrationTable(
server.config.GetVariableString(
"schema",
"world_registration_table",
"tblWorldServerRegistration"
)
);
server.options.WorldAdminRegistrationTable(
server.config.GetVariableString(
"schema",
"world_admin_registration_table",
"tblServerAdminRegistration"
)
);
server.options.WorldServerTypeTable(
server.config.GetVariableString(
"schema",
"world_server_type_table",
"tblServerListType"
)
);
/** /**
* mysql connect * mysql connect

View File

@ -102,46 +102,6 @@ public:
*/ */
inline int GetEncryptionMode() const { return encryption_mode; } inline int GetEncryptionMode() const { return encryption_mode; }
/**
* Sets account table.
*/
inline void AccountTable(std::string t) { account_table = t; }
/**
* Return the value of world account table.
*/
inline std::string GetAccountTable() const { return account_table; }
/**
* Sets world registration table.
*/
inline void WorldRegistrationTable(std::string t) { world_registration_table = t; }
/**
* Return the value of world registration table.
*/
inline std::string GetWorldRegistrationTable() const { return world_registration_table; }
/**
* Sets world admin account table.
*/
inline void WorldAdminRegistrationTable(std::string t) { world_admin_registration_table = t; }
/**
* Return the value of world admin account table.
*/
inline std::string GetWorldAdminRegistrationTable() const { return world_admin_registration_table; }
/**
* Sets world server type table.
*/
inline void WorldServerTypeTable(std::string t) { world_server_type_table = t; }
/**
* Return the value of world server type table.
*/
inline std::string GetWorldServerTypeTable() const { return world_server_type_table; }
/** /**
* Sets whether we are rejecting duplicate servers or not. * Sets whether we are rejecting duplicate servers or not.
*/ */
@ -186,10 +146,6 @@ private:
bool auto_link_accounts; bool auto_link_accounts;
bool update_insecure_passwords; bool update_insecure_passwords;
int encryption_mode; int encryption_mode;
std::string account_table;
std::string world_registration_table;
std::string world_admin_registration_table;
std::string world_server_type_table;
std::string eqemu_loginserver_address; std::string eqemu_loginserver_address;
std::string default_loginserver_name; std::string default_loginserver_name;
}; };

View File

@ -250,10 +250,6 @@ SET(zone_headers
zonedb.h zonedb.h
zonedump.h) zonedump.h)
IF(EQEMU_DEPOP_INVALIDATES_CACHE)
ADD_DEFINITIONS(-DDEPOP_INVALIDATES_NPC_TYPES_CACHE)
ENDIF(EQEMU_DEPOP_INVALIDATES_CACHE)
ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers}) ADD_EXECUTABLE(zone ${zone_sources} ${zone_headers})
INSTALL(TARGETS zone RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) INSTALL(TARGETS zone RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)