added logout command for econ

This commit is contained in:
oy 2011-12-30 19:12:31 +01:00
parent 1bb64d7534
commit ec4bb94537
8 changed files with 43 additions and 15 deletions

View file

@ -78,6 +78,7 @@ public:
virtual bool LineIsValid(const char *pStr) = 0;
virtual void ExecuteLine(const char *Sptr) = 0;
virtual void ExecuteLineFlag(const char *Sptr, int FlasgMask) = 0;
virtual void ExecuteLineStroked(int Stroke, const char *pStr) = 0;
virtual void ExecuteFile(const char *pFilename) = 0;

View file

@ -961,7 +961,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
m_RconClientID = ClientID;
m_RconAuthLevel = m_aClients[ClientID].m_Authed;
Console()->SetAccessLevel(m_aClients[ClientID].m_Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD);
Console()->ExecuteLine(pCmd);
Console()->ExecuteLineFlag(pCmd, CFGFLAG_SERVER);
Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_ADMIN);
m_RconClientID = -1;
m_RconAuthLevel = AUTHED_ADMIN;
@ -1649,7 +1649,7 @@ int main(int argc, const char **argv) // ignore_convention
IEngine *pEngine = CreateEngine("Teeworlds");
IEngineMap *pEngineMap = CreateEngineMap();
IGameServer *pGameServer = CreateGameServer();
IConsole *pConsole = CreateConsole(CFGFLAG_SERVER);
IConsole *pConsole = CreateConsole(CFGFLAG_SERVER|CFGFLAG_ECON);
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention
IConfig *pConfig = CreateConfig();

View file

@ -20,7 +20,8 @@ enum
CFGFLAG_CLIENT=2,
CFGFLAG_SERVER=4,
CFGFLAG_STORE=8,
CFGFLAG_MASTER=16
CFGFLAG_MASTER=16,
CFGFLAG_ECON=32,
};
#endif

View file

@ -89,12 +89,12 @@ MACRO_CONFIG_INT(SvRconBantime, sv_rcon_bantime, 5, 0, 1440, CFGFLAG_SERVER, "Th
MACRO_CONFIG_INT(SvAutoDemoRecord, sv_auto_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos")
MACRO_CONFIG_INT(SvAutoDemoMax, sv_auto_demo_max, 10, 0, 1000, CFGFLAG_SERVER, "Maximum number of automatically recorded demos (0 = no limit)")
MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_SERVER, "Address to bind the external console to. Anything but 'localhost' is dangerous")
MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_SERVER, "Port to use for the external console")
MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_SERVER, "External console password")
MACRO_CONFIG_INT(EcBantime, ec_bantime, 0, 0, 1440, CFGFLAG_SERVER, "The time a client gets banned if econ authentication fails. 0 just closes the connection")
MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_SERVER, "Time in seconds before the the econ authentification times out")
MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 1, 0, 2, CFGFLAG_SERVER, "Adjusts the amount of information in the external console")
MACRO_CONFIG_STR(EcBindaddr, ec_bindaddr, 128, "localhost", CFGFLAG_ECON, "Address to bind the external console to. Anything but 'localhost' is dangerous")
MACRO_CONFIG_INT(EcPort, ec_port, 0, 0, 0, CFGFLAG_ECON, "Port to use for the external console")
MACRO_CONFIG_STR(EcPassword, ec_password, 32, "", CFGFLAG_ECON, "External console password")
MACRO_CONFIG_INT(EcBantime, ec_bantime, 0, 0, 1440, CFGFLAG_ECON, "The time a client gets banned if econ authentication fails. 0 just closes the connection")
MACRO_CONFIG_INT(EcAuthTimeout, ec_auth_timeout, 30, 1, 120, CFGFLAG_ECON, "Time in seconds before the the econ authentification times out")
MACRO_CONFIG_INT(EcOutputLevel, ec_output_level, 1, 0, 2, CFGFLAG_ECON, "Adjusts the amount of information in the external console")
MACRO_CONFIG_INT(Debug, debug, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Debug mode")
MACRO_CONFIG_INT(DbgStress, dbg_stress, 0, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SERVER, "Stress systems")

View file

@ -12,6 +12,8 @@
#include "console.h"
#include "linereader.h"
// todo: rework this
const char *CConsole::CResult::GetString(unsigned Index)
{
if (Index < 0 || Index >= m_NumArgs)
@ -374,6 +376,14 @@ void CConsole::ExecuteLine(const char *pStr)
CConsole::ExecuteLineStroked(0, pStr); // then release it
}
void CConsole::ExecuteLineFlag(const char *pStr, int FlagMask)
{
int Temp = m_FlagMask;
m_FlagMask = FlagMask;
ExecuteLine(pStr);
m_FlagMask = Temp;
}
void CConsole::ExecuteFile(const char *pFilename)
{
@ -633,7 +643,7 @@ void CConsole::ParseArguments(int NumArgs, const char **ppArguments)
void CConsole::AddCommandSorted(CCommand *pCommand)
{
if(!m_pFirstCommand || str_comp(pCommand->m_pName, m_pFirstCommand->m_pName) < 0)
if(!m_pFirstCommand || str_comp(pCommand->m_pName, m_pFirstCommand->m_pName) <= 0)
{
if(m_pFirstCommand && m_pFirstCommand->m_pNext)
pCommand->m_pNext = m_pFirstCommand;
@ -645,7 +655,7 @@ void CConsole::AddCommandSorted(CCommand *pCommand)
{
for(CCommand *p = m_pFirstCommand; p; p = p->m_pNext)
{
if(!p->m_pNext || str_comp(pCommand->m_pName, p->m_pNext->m_pName) < 0)
if(!p->m_pNext || str_comp(pCommand->m_pName, p->m_pNext->m_pName) <= 0)
{
pCommand->m_pNext = p->m_pNext;
p->m_pNext = pCommand;

View file

@ -156,7 +156,7 @@ class CConsole : public IConsole
public:
CConsole(int FlagMask);
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const;
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int FlagMask) const;
virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp);
virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser);
@ -170,6 +170,7 @@ public:
virtual bool LineIsValid(const char *pStr);
virtual void ExecuteLine(const char *pStr);
virtual void ExecuteLineFlag(const char *pStr, int FlagMask);
virtual void ExecuteFile(const char *pFilename);
virtual int RegisterPrintCallback(int OutputLevel, FPrintCallback pfnPrintCallback, void *pUserData);

View file

@ -52,6 +52,14 @@ void CEcon::ConchainEconOutputLevelUpdate(IConsole::IResult *pResult, void *pUse
}
}
void CEcon::ConLogout(IConsole::IResult *pResult, void *pUserData)
{
CEcon *pThis = static_cast<CEcon *>(pUserData);
if(pThis->m_UserClientID >= 0 && pThis->m_UserClientID < NET_MAX_CONSOLE_CLIENTS && pThis->m_aClients[pThis->m_UserClientID].m_State != CClient::STATE_EMPTY)
pThis->m_NetConsole.Drop(pThis->m_UserClientID, "Logout");
}
void CEcon::Init(IConsole *pConsole, CNetBan *pNetBan)
{
m_pConsole = pConsole;
@ -60,6 +68,7 @@ void CEcon::Init(IConsole *pConsole, CNetBan *pNetBan)
m_aClients[i].m_State = CClient::STATE_EMPTY;
m_Ready = false;
m_UserClientID = -1;
if(g_Config.m_EcPort == 0 || g_Config.m_EcPassword[0] == 0)
return;
@ -84,6 +93,8 @@ void CEcon::Init(IConsole *pConsole, CNetBan *pNetBan)
Console()->Chain("ec_output_level", ConchainEconOutputLevelUpdate, this);
m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_EcOutputLevel, SendLineCB, this);
Console()->Register("logout", "", CFGFLAG_ECON, ConLogout, this, "Logout of econ");
}
else
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD,"econ", "couldn't open socket. port might already be in use");
@ -115,9 +126,9 @@ void CEcon::Update()
else
{
m_aClients[ClientID].m_AuthTries++;
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "Wrong password %d/%d.", m_aClients[ClientID].m_AuthTries, MAX_AUTH_TRIES);
m_NetConsole.Send(ClientID, aBuf);
char aMsg[128];
str_format(aMsg, sizeof(aMsg), "Wrong password %d/%d.", m_aClients[ClientID].m_AuthTries, MAX_AUTH_TRIES);
m_NetConsole.Send(ClientID, aMsg);
if(m_aClients[ClientID].m_AuthTries >= MAX_AUTH_TRIES)
{
if(!g_Config.m_EcBantime)
@ -132,7 +143,9 @@ void CEcon::Update()
char aFormatted[256];
str_format(aFormatted, sizeof(aBuf), "cid=%d cmd='%s'", ClientID, aBuf);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aFormatted);
m_UserClientID = ClientID;
Console()->ExecuteLine(aBuf);
m_UserClientID = -1;
}
}

View file

@ -32,9 +32,11 @@ class CEcon
bool m_Ready;
int m_PrintCBIndex;
int m_UserClientID;
static void SendLineCB(const char *pLine, void *pUserData);
static void ConchainEconOutputLevelUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConLogout(IConsole::IResult *pResult, void *pUserData);
static int NewClientCallback(int ClientID, void *pUser);
static int DelClientCallback(int ClientID, const char *pReason, void *pUser);