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:
Tekaoh
2020-04-14 17:17:17 -04:00
committed by GitHub
parent 7a837945da
commit 3942353e62
3 changed files with 35 additions and 4 deletions

View File

@@ -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;

View File

@@ -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()
}
//-----------------------------------------------------------------------

View File

@@ -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();