mirror of
https://github.com/SWG-Source/src.git
synced 2026-01-17 00:04:25 -05:00
Feature/external admin levels (#9)
* Add cfg to enable external admin levels * Add cfg for external admin levels url * Check if enabled * Get admin level with webAPI
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ConfigServerUtility.h"
|
||||
|
||||
#include "serverUtility/FirstServerUtility.h"
|
||||
#include "serverUtility/AdminAccountManager.h"
|
||||
|
||||
@@ -10,6 +12,8 @@
|
||||
#include "sharedUtility/DataTable.h"
|
||||
#include "sharedUtility/DataTableManager.h"
|
||||
|
||||
#include "../../../../../../external/3rd/library/webAPI/webAPI.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -69,6 +73,14 @@ int AdminAccountManager::getAdminLevel(const std::string & account)
|
||||
int level = 0;
|
||||
DEBUG_FATAL(!ms_installed, ("AdminAccountManager not installed"));
|
||||
|
||||
if(ConfigServerUtility::isExternalAdminLevelsEnabled()){
|
||||
std::ostringstream postBuffer;
|
||||
postBuffer << "user_name=" << account;
|
||||
std::string response = webAPI::simplePost(ConfigServerUtility::getExternalAdminLevelsURL(), std::string(postBuffer.str()), "");
|
||||
level = std::stoi(response);
|
||||
return level;
|
||||
}
|
||||
|
||||
int columnNumber = ms_adminTable->findColumnNumber("AdminAccounts");
|
||||
DEBUG_FATAL(columnNumber == -1, ("Error loading admin table...no account column"));
|
||||
int row = ms_adminTable->searchColumnString( columnNumber, account);
|
||||
@@ -113,8 +125,8 @@ bool AdminAccountManager::isInternalIp(const std::string & addr)
|
||||
size_t xpos = ipAddr.find ('x');
|
||||
|
||||
//if no X is found, do a straight compare
|
||||
if ( (xpos == 0 || xpos == std::string::npos)
|
||||
&& ipAddr.compare(addr) == 0
|
||||
if ( (xpos == 0 || xpos == std::string::npos)
|
||||
&& ipAddr.compare(addr) == 0
|
||||
)
|
||||
{
|
||||
retval = true;
|
||||
@@ -125,7 +137,7 @@ bool AdminAccountManager::isInternalIp(const std::string & addr)
|
||||
else if (xpos - 1 > addr.size())
|
||||
retval = false;
|
||||
|
||||
//compare substring
|
||||
//compare substring
|
||||
else if (ipAddr.compare(0, xpos - 1, addr, 0, xpos - 1) == 0)
|
||||
{
|
||||
retval = true;
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace ConfigServerUtilityNamespace
|
||||
int serverMaxChatLogLines;
|
||||
int playerMaxChatLogLines;
|
||||
bool chatLogManagerLoggingEnabled;
|
||||
bool externalAdminLevelsEnabled;
|
||||
const char * externalAdminLevelsURL;
|
||||
}
|
||||
|
||||
using namespace ConfigServerUtilityNamespace;
|
||||
@@ -75,6 +77,20 @@ bool ConfigServerUtility::isChatLogManagerLoggingEnabled()
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool ConfigServerUtility::isExternalAdminLevelsEnabled()
|
||||
{
|
||||
return externalAdminLevelsEnabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const char * ConfigServerUtility::getExternalAdminLevelsURL()
|
||||
{
|
||||
return externalAdminLevelsURL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigServerUtility::install()
|
||||
{
|
||||
KEY_INT(spawnCookie, 0);
|
||||
@@ -82,6 +98,8 @@ void ConfigServerUtility::install()
|
||||
KEY_INT(serverMaxChatLogLines, 5000);
|
||||
KEY_INT(playerMaxChatLogLines, 200);
|
||||
KEY_BOOL(chatLogManagerLoggingEnabled, false);
|
||||
KEY_BOOL(externalAdminLevelsEnabled, false);
|
||||
KEY_STRING(externalAdminLevelsURL, "http://localhost/");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -91,4 +109,3 @@ void ConfigServerUtility::remove()
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
static int getServerMaxChatLogLines();
|
||||
static int getPlayerMaxChatLogLines();
|
||||
static bool isChatLogManagerLoggingEnabled();
|
||||
static bool isExternalAdminLevelsEnabled();
|
||||
static const char * getExternalAdminLevelsURL();
|
||||
|
||||
static void install();
|
||||
static void remove();
|
||||
|
||||
Reference in New Issue
Block a user