mirror of
https://bitbucket.org/seefoe/src.git
synced 2026-07-30 00:15:46 -04:00
add skeleton of auth system based on previous work by parz1val, you need to install libcurl4-gnutls-dev (libcurl4-gnutls-dev:i386 if a 64 bit host)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "sharedNetworkMessages/LoginEnumCluster.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <curl/curl.h>
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user