diff --git a/CMakeLists.txt b/CMakeLists.txt index cfe0cbfa..44a929d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ find_package(PCRE REQUIRED) find_package(Perl REQUIRED) find_package(Threads) find_package(ZLIB REQUIRED) +find_package(CURL REQUIRED) if(WIN32) find_package(Iconv REQUIRED) diff --git a/engine/server/application/LoginServer/src/CMakeLists.txt b/engine/server/application/LoginServer/src/CMakeLists.txt index 94910cb3..ef517f2f 100644 --- a/engine/server/application/LoginServer/src/CMakeLists.txt +++ b/engine/server/application/LoginServer/src/CMakeLists.txt @@ -101,7 +101,7 @@ include_directories( ${SWG_ENGINE_SOURCE_DIR}/server/library/serverKeyShare/include/public ${SWG_ENGINE_SOURCE_DIR}/server/library/serverNetworkMessages/include/public ${SWG_ENGINE_SOURCE_DIR}/server/library/serverUtility/include/public - ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include + ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localization/include ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localizationArchive/include/public ${SWG_EXTERNALS_SOURCE_DIR}/ours/library/singleton/include @@ -110,6 +110,7 @@ include_directories( ${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/platform/projects ${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/platform/utils ${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/udplibrary + ${CURL_INCLUDE_DIRS} ) add_executable(LoginServer @@ -150,5 +151,6 @@ target_link_libraries(LoginServer CommonAPI LoginAPI MonAPI2 + ${CURL_LIBRARIES} ${CMAKE_DL_LIBS} ) diff --git a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp index 6fe81a51..32ffaa9f 100755 --- a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp @@ -24,6 +24,7 @@ #include "sharedNetworkMessages/LoginEnumCluster.h" #include +#include //----------------------------------------------------------------------- @@ -168,6 +169,14 @@ void ClientConnection::onReceive(const Archive::ByteStream & message) } //----------------------------------------------------------------------- + +static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) +{ + ((std::string*)userp)->append((char*)contents, size * nmemb); + return size * nmemb; +} + + //----------------------------------------------------------------------- // Stub routine for station API account validation. // Grab a challenge key from the list and send it back to the client. @@ -202,7 +211,45 @@ void ClientConnection::validateClient(const std::string & id, const std::string LOG("LoginClientConnection", ("validateClient() for stationId (%lu) at IP (%s), id (%s) key (%s), skipping validating session", m_stationId, getRemoteAddress().c_str(), id.c_str(), key.c_str())); - LoginServer::getInstance().onValidateClient(suid, id, this, true, nullptr, 0xFFFFFFFF, 0xFFFFFFFF); + if (ConfigLoginServer::getUseExternalAuth() == true) + { + CURL *curl; + std::string readBuffer; + + curl = curl_easy_init(); + if (curl) + { + std::string username(curl_easy_escape(curl, id.c_str(), id.length())); + std::string password(curl_easy_escape(curl, key.c_str(), key.length())); + + curl_easy_setopt(curl, CURLOPT_URL, ("phpauthurl" + username + "&pw=" + password).c_str()); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); + + curl_easy_cleanup(curl); + curl_global_cleanup(); + + // where possible we'll use http status codes - later this will become json and this nonsense isn't necessary + if (readBuffer == "1") + { + LoginServer::getInstance().onValidateClient(suid, id, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF); + } + else if (readBuffer == "2") + { + ErrorMessage err("Login Failed", "You have been banned."); + this->send(err, true); + } + else + { + ErrorMessage err("Login Failed", "Invalid username or password."); + this->send(err, true); + } + } + } + else + { + LoginServer::getInstance().onValidateClient(suid, id, this, true, NULL, 0xFFFFFFFF, 0xFFFFFFFF); + } } } diff --git a/engine/server/application/LoginServer/src/shared/ConfigLoginServer.cpp b/engine/server/application/LoginServer/src/shared/ConfigLoginServer.cpp index 2de2a2fa..8cbaaccc 100755 --- a/engine/server/application/LoginServer/src/shared/ConfigLoginServer.cpp +++ b/engine/server/application/LoginServer/src/shared/ConfigLoginServer.cpp @@ -114,6 +114,7 @@ void ConfigLoginServer::install(void) KEY_INT (populationLightThresholdPercent, 8); KEY_INT (csToolPort, 10666); KEY_BOOL(requireSecureLoginForCsTool, true); + KEY_BOOL(useExternalAuth, false); int index = 0; char const * result = 0; diff --git a/engine/server/application/LoginServer/src/shared/ConfigLoginServer.h b/engine/server/application/LoginServer/src/shared/ConfigLoginServer.h index 7bd94880..3badbf0a 100755 --- a/engine/server/application/LoginServer/src/shared/ConfigLoginServer.h +++ b/engine/server/application/LoginServer/src/shared/ConfigLoginServer.h @@ -65,6 +65,7 @@ class ConfigLoginServer int csToolPort; bool requireSecureLoginForCsTool; + bool useExternalAuth; }; static const uint16 getCentralServicePort(); @@ -126,6 +127,8 @@ class ConfigLoginServer static int getPopulationHeavyThresholdPercent(); static int getPopulationMediumThresholdPercent(); static int getPopulationLightThresholdPercent(); + + static bool getUseExternalAuth(); // has character creation for this cluster been disabled through config option static bool isCharacterCreationDisabled(std::string const & cluster); @@ -467,6 +470,11 @@ inline const int ConfigLoginServer::getCSToolPort() { return data->csToolPort; } + +inline bool ConfigLoginServer::getUseExternalAuth() +{ + return data->useExternalAuth; +} // ====================================================================== #endif // _ConfigLoginServer_H