mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
made rcon auto completion serverside. Closes #97
This commit is contained in:
parent
7a129caf8d
commit
571dff6216
|
@ -30,6 +30,6 @@ for filename in sys.argv[1:]:
|
||||||
|
|
||||||
hash = hashlib.md5(f).hexdigest().lower()[16:]
|
hash = hashlib.md5(f).hexdigest().lower()[16:]
|
||||||
#TODO 0.7: improve nethash creation
|
#TODO 0.7: improve nethash creation
|
||||||
if hash == "5c1e637ffddf3a37":
|
if hash == "71de0f4d82688970":
|
||||||
hash = "626fce9a778df4d4"
|
hash = "626fce9a778df4d4"
|
||||||
print('#define GAME_NETVERSION_HASH "%s"' % hash)
|
print('#define GAME_NETVERSION_HASH "%s"' % hash)
|
||||||
|
|
|
@ -95,6 +95,7 @@ public:
|
||||||
// remote console
|
// remote console
|
||||||
virtual void RconAuth(const char *pUsername, const char *pPassword) = 0;
|
virtual void RconAuth(const char *pUsername, const char *pPassword) = 0;
|
||||||
virtual bool RconAuthed() = 0;
|
virtual bool RconAuthed() = 0;
|
||||||
|
virtual bool UseTempRconCommands() = 0;
|
||||||
virtual void Rcon(const char *pLine) = 0;
|
virtual void Rcon(const char *pLine) = 0;
|
||||||
|
|
||||||
// server info
|
// server info
|
||||||
|
|
|
@ -536,11 +536,6 @@ void CClient::SendReady()
|
||||||
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH);
|
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CClient::RconAuthed()
|
|
||||||
{
|
|
||||||
return m_RconAuthed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CClient::RconAuth(const char *pName, const char *pPassword)
|
void CClient::RconAuth(const char *pName, const char *pPassword)
|
||||||
{
|
{
|
||||||
if(RconAuthed())
|
if(RconAuthed())
|
||||||
|
@ -549,6 +544,7 @@ void CClient::RconAuth(const char *pName, const char *pPassword)
|
||||||
CMsgPacker Msg(NETMSG_RCON_AUTH);
|
CMsgPacker Msg(NETMSG_RCON_AUTH);
|
||||||
Msg.AddString(pName, 32);
|
Msg.AddString(pName, 32);
|
||||||
Msg.AddString(pPassword, 32);
|
Msg.AddString(pPassword, 32);
|
||||||
|
Msg.AddInt(1);
|
||||||
SendMsgEx(&Msg, MSGFLAG_VITAL);
|
SendMsgEx(&Msg, MSGFLAG_VITAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,6 +722,7 @@ void CClient::DisconnectWithReason(const char *pReason)
|
||||||
|
|
||||||
//
|
//
|
||||||
m_RconAuthed = 0;
|
m_RconAuthed = 0;
|
||||||
|
m_pConsole->DeregisterTempAll();
|
||||||
m_NetClient.Disconnect(pReason);
|
m_NetClient.Disconnect(pReason);
|
||||||
SetState(IClient::STATE_OFFLINE);
|
SetState(IClient::STATE_OFFLINE);
|
||||||
m_pMap->Unload();
|
m_pMap->Unload();
|
||||||
|
@ -1313,11 +1310,28 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
|
||||||
CMsgPacker Msg(NETMSG_PING_REPLY);
|
CMsgPacker Msg(NETMSG_PING_REPLY);
|
||||||
SendMsgEx(&Msg, 0);
|
SendMsgEx(&Msg, 0);
|
||||||
}
|
}
|
||||||
|
else if(Msg == NETMSG_RCON_CMD_ADD)
|
||||||
|
{
|
||||||
|
const char *pName = Unpacker.GetString(CUnpacker::SANITIZE_CC);
|
||||||
|
const char *pHelp = Unpacker.GetString(CUnpacker::SANITIZE_CC);
|
||||||
|
const char *pParams = Unpacker.GetString(CUnpacker::SANITIZE_CC);
|
||||||
|
if(Unpacker.Error() == 0)
|
||||||
|
m_pConsole->RegisterTemp(pName, pParams, CFGFLAG_SERVER, pHelp);
|
||||||
|
}
|
||||||
|
else if(Msg == NETMSG_RCON_CMD_REM)
|
||||||
|
{
|
||||||
|
const char *pName = Unpacker.GetString(CUnpacker::SANITIZE_CC);
|
||||||
|
if(Unpacker.Error() == 0)
|
||||||
|
m_pConsole->DeregisterTemp(pName);
|
||||||
|
}
|
||||||
else if(Msg == NETMSG_RCON_AUTH_STATUS)
|
else if(Msg == NETMSG_RCON_AUTH_STATUS)
|
||||||
{
|
{
|
||||||
int Result = Unpacker.GetInt();
|
int Result = Unpacker.GetInt();
|
||||||
if(Unpacker.Error() == 0)
|
if(Unpacker.Error() == 0)
|
||||||
m_RconAuthed = Result;
|
m_RconAuthed = Result;
|
||||||
|
m_UseTempRconCommands = Unpacker.GetInt();
|
||||||
|
if(Unpacker.Error() != 0)
|
||||||
|
m_UseTempRconCommands = 0;
|
||||||
}
|
}
|
||||||
else if(Msg == NETMSG_RCON_LINE)
|
else if(Msg == NETMSG_RCON_LINE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -128,6 +128,7 @@ class CClient : public IClient, public CDemoPlayer::IListner
|
||||||
int m_AckGameTick;
|
int m_AckGameTick;
|
||||||
int m_CurrentRecvTick;
|
int m_CurrentRecvTick;
|
||||||
int m_RconAuthed;
|
int m_RconAuthed;
|
||||||
|
int m_UseTempRconCommands;
|
||||||
|
|
||||||
// version-checking
|
// version-checking
|
||||||
char m_aVersionStr[10];
|
char m_aVersionStr[10];
|
||||||
|
@ -220,7 +221,8 @@ public:
|
||||||
void SendEnterGame();
|
void SendEnterGame();
|
||||||
void SendReady();
|
void SendReady();
|
||||||
|
|
||||||
virtual bool RconAuthed();
|
virtual bool RconAuthed() { return m_RconAuthed != 0; }
|
||||||
|
virtual bool UseTempRconCommands() { return m_UseTempRconCommands != 0; }
|
||||||
void RconAuth(const char *pName, const char *pPassword);
|
void RconAuth(const char *pName, const char *pPassword);
|
||||||
virtual void Rcon(const char *pCmd);
|
virtual void Rcon(const char *pCmd);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ class IConsole : public IInterface
|
||||||
MACRO_INTERFACE("console", 0)
|
MACRO_INTERFACE("console", 0)
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// TODO: rework/cleanup
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
OUTPUT_LEVEL_STANDARD=0,
|
OUTPUT_LEVEL_STANDARD=0,
|
||||||
|
@ -18,6 +19,10 @@ public:
|
||||||
|
|
||||||
ACCESS_LEVEL_ADMIN=0,
|
ACCESS_LEVEL_ADMIN=0,
|
||||||
ACCESS_LEVEL_MOD,
|
ACCESS_LEVEL_MOD,
|
||||||
|
|
||||||
|
TEMPCMD_NAME_LENGTH=32,
|
||||||
|
TEMPCMD_HELP_LENGTH=64,
|
||||||
|
TEMPCMD_PARAMS_LENGTH=16,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: rework this interface to reduce the amount of virtual calls
|
// TODO: rework this interface to reduce the amount of virtual calls
|
||||||
|
@ -38,10 +43,18 @@ public:
|
||||||
|
|
||||||
class CCommandInfo
|
class CCommandInfo
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
int m_AccessLevel;
|
||||||
public:
|
public:
|
||||||
|
CCommandInfo() { m_AccessLevel = ACCESS_LEVEL_ADMIN; }
|
||||||
|
virtual ~CCommandInfo() {}
|
||||||
const char *m_pName;
|
const char *m_pName;
|
||||||
const char *m_pHelp;
|
const char *m_pHelp;
|
||||||
const char *m_pParams;
|
const char *m_pParams;
|
||||||
|
|
||||||
|
virtual const CCommandInfo *NextCommandInfo(int AccessLevel, int FlagMask) const = 0;
|
||||||
|
|
||||||
|
int GetAccessLevel() const { return m_AccessLevel; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*FPrintCallback)(const char *pStr, void *pUser);
|
typedef void (*FPrintCallback)(const char *pStr, void *pUser);
|
||||||
|
@ -49,12 +62,15 @@ public:
|
||||||
typedef void (*FCommandCallback)(IResult *pResult, void *pUserData);
|
typedef void (*FCommandCallback)(IResult *pResult, void *pUserData);
|
||||||
typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData);
|
typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||||
|
|
||||||
virtual CCommandInfo *GetCommandInfo(const char *pName, int FlagMask) = 0;
|
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const = 0;
|
||||||
virtual void PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser) = 0;
|
virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) = 0;
|
||||||
|
virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) = 0;
|
||||||
virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0;
|
virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0;
|
||||||
|
|
||||||
virtual void Register(const char *pName, const char *pParams,
|
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) = 0;
|
||||||
int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp) = 0;
|
virtual void RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp) = 0;
|
||||||
|
virtual void DeregisterTemp(const char *pName) = 0;
|
||||||
|
virtual void DeregisterTempAll() = 0;
|
||||||
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser) = 0;
|
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser) = 0;
|
||||||
virtual void StoreCommands(bool Store) = 0;
|
virtual void StoreCommands(bool Store) = 0;
|
||||||
|
|
||||||
|
|
|
@ -580,6 +580,7 @@ int CServer::NewClientCallback(int ClientID, void *pUser)
|
||||||
pThis->m_aClients[ClientID].m_Country = -1;
|
pThis->m_aClients[ClientID].m_Country = -1;
|
||||||
pThis->m_aClients[ClientID].m_Authed = AUTHED_NO;
|
pThis->m_aClients[ClientID].m_Authed = AUTHED_NO;
|
||||||
pThis->m_aClients[ClientID].m_AuthTries = 0;
|
pThis->m_aClients[ClientID].m_AuthTries = 0;
|
||||||
|
pThis->m_aClients[ClientID].m_pRconCmdToSend = 0;
|
||||||
pThis->m_aClients[ClientID].Reset();
|
pThis->m_aClients[ClientID].Reset();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -605,6 +606,7 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser)
|
||||||
pThis->m_aClients[ClientID].m_Country = -1;
|
pThis->m_aClients[ClientID].m_Country = -1;
|
||||||
pThis->m_aClients[ClientID].m_Authed = AUTHED_NO;
|
pThis->m_aClients[ClientID].m_Authed = AUTHED_NO;
|
||||||
pThis->m_aClients[ClientID].m_AuthTries = 0;
|
pThis->m_aClients[ClientID].m_AuthTries = 0;
|
||||||
|
pThis->m_aClients[ClientID].m_pRconCmdToSend = 0;
|
||||||
pThis->m_aClients[ClientID].m_Snapshots.PurgeAll();
|
pThis->m_aClients[ClientID].m_Snapshots.PurgeAll();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -649,6 +651,37 @@ void CServer::SendRconLineAuthed(const char *pLine, void *pUser)
|
||||||
ReentryGuard--;
|
ReentryGuard--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CServer::SendRconCmdAdd(const IConsole::CCommandInfo *pCommandInfo, int ClientID)
|
||||||
|
{
|
||||||
|
CMsgPacker Msg(NETMSG_RCON_CMD_ADD);
|
||||||
|
Msg.AddString(pCommandInfo->m_pName, 32);
|
||||||
|
Msg.AddString(pCommandInfo->m_pHelp, 64);
|
||||||
|
Msg.AddString(pCommandInfo->m_pParams, 16);
|
||||||
|
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServer::SendRconCmdRem(const IConsole::CCommandInfo *pCommandInfo, int ClientID)
|
||||||
|
{
|
||||||
|
CMsgPacker Msg(NETMSG_RCON_CMD_REM);
|
||||||
|
Msg.AddString(pCommandInfo->m_pName, 256);
|
||||||
|
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServer::UpdateClientRconCommands()
|
||||||
|
{
|
||||||
|
int ClientID = Tick() % MAX_CLIENTS;
|
||||||
|
|
||||||
|
if(m_aClients[ClientID].m_State != CClient::STATE_EMPTY && m_aClients[ClientID].m_Authed)
|
||||||
|
{
|
||||||
|
int ConsoleAccessLevel = m_aClients[ClientID].m_Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD;
|
||||||
|
for(int i = 0; i < MAX_RCONCMD_SEND && m_aClients[ClientID].m_pRconCmdToSend; ++i)
|
||||||
|
{
|
||||||
|
SendRconCmdAdd(m_aClients[ClientID].m_pRconCmdToSend, ClientID);
|
||||||
|
m_aClients[ClientID].m_pRconCmdToSend = m_aClients[ClientID].m_pRconCmdToSend->NextCommandInfo(ConsoleAccessLevel, CFGFLAG_SERVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
||||||
{
|
{
|
||||||
int ClientID = pPacket->m_ClientID;
|
int ClientID = pPacket->m_ClientID;
|
||||||
|
@ -843,10 +876,14 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
||||||
else if(g_Config.m_SvRconPassword[0] && str_comp(pPw, g_Config.m_SvRconPassword) == 0)
|
else if(g_Config.m_SvRconPassword[0] && str_comp(pPw, g_Config.m_SvRconPassword) == 0)
|
||||||
{
|
{
|
||||||
CMsgPacker Msg(NETMSG_RCON_AUTH_STATUS);
|
CMsgPacker Msg(NETMSG_RCON_AUTH_STATUS);
|
||||||
Msg.AddInt(1);
|
Msg.AddInt(1); //authed
|
||||||
|
Msg.AddInt(1); //cmdlist
|
||||||
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
||||||
|
|
||||||
m_aClients[ClientID].m_Authed = AUTHED_ADMIN;
|
m_aClients[ClientID].m_Authed = AUTHED_ADMIN;
|
||||||
|
int SendRconCmds = Unpacker.GetInt();
|
||||||
|
if(Unpacker.Error() == 0 && SendRconCmds)
|
||||||
|
m_aClients[ClientID].m_pRconCmdToSend = Console()->FirstCommandInfo(IConsole::ACCESS_LEVEL_ADMIN, CFGFLAG_SERVER);
|
||||||
SendRconLine(ClientID, "Admin authentication successful. Full remote console access granted.");
|
SendRconLine(ClientID, "Admin authentication successful. Full remote console access granted.");
|
||||||
char aBuf[256];
|
char aBuf[256];
|
||||||
str_format(aBuf, sizeof(aBuf), "ClientID=%d authed (admin)", ClientID);
|
str_format(aBuf, sizeof(aBuf), "ClientID=%d authed (admin)", ClientID);
|
||||||
|
@ -855,10 +892,14 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
||||||
else if(g_Config.m_SvRconModPassword[0] && str_comp(pPw, g_Config.m_SvRconModPassword) == 0)
|
else if(g_Config.m_SvRconModPassword[0] && str_comp(pPw, g_Config.m_SvRconModPassword) == 0)
|
||||||
{
|
{
|
||||||
CMsgPacker Msg(NETMSG_RCON_AUTH_STATUS);
|
CMsgPacker Msg(NETMSG_RCON_AUTH_STATUS);
|
||||||
Msg.AddInt(1);
|
Msg.AddInt(1); //authed
|
||||||
|
Msg.AddInt(1); //cmdlist
|
||||||
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
||||||
|
|
||||||
m_aClients[ClientID].m_Authed = AUTHED_MOD;
|
m_aClients[ClientID].m_Authed = AUTHED_MOD;
|
||||||
|
int SendRconCmds = Unpacker.GetInt();
|
||||||
|
if(Unpacker.Error() == 0 && SendRconCmds)
|
||||||
|
m_aClients[ClientID].m_pRconCmdToSend = Console()->FirstCommandInfo(IConsole::ACCESS_LEVEL_MOD, CFGFLAG_SERVER);
|
||||||
SendRconLine(ClientID, "Moderator authentication successful. Limited remote console access granted.");
|
SendRconLine(ClientID, "Moderator authentication successful. Limited remote console access granted.");
|
||||||
char aBuf[256];
|
char aBuf[256];
|
||||||
str_format(aBuf, sizeof(aBuf), "ClientID=%d authed (moderator)", ClientID);
|
str_format(aBuf, sizeof(aBuf), "ClientID=%d authed (moderator)", ClientID);
|
||||||
|
@ -1243,6 +1284,8 @@ int CServer::Run()
|
||||||
{
|
{
|
||||||
if(g_Config.m_SvHighBandwidth || (m_CurrentGameTick%2) == 0)
|
if(g_Config.m_SvHighBandwidth || (m_CurrentGameTick%2) == 0)
|
||||||
DoSnapshot();
|
DoSnapshot();
|
||||||
|
|
||||||
|
UpdateClientRconCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
// master server stuff
|
// master server stuff
|
||||||
|
@ -1512,26 +1555,56 @@ void CServer::ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pU
|
||||||
((CServer *)pUserData)->m_NetServer.SetMaxClientsPerIP(pResult->GetInteger(0));
|
((CServer *)pUserData)->m_NetServer.SetMaxClientsPerIP(pResult->GetInteger(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CServer::ConchainModCommandUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||||
|
{
|
||||||
|
if(pResult->NumArguments() == 2)
|
||||||
|
{
|
||||||
|
CServer *pThis = static_cast<CServer *>(pUserData);
|
||||||
|
const IConsole::CCommandInfo *pInfo = pThis->Console()->GetCommandInfo(pResult->GetString(0), CFGFLAG_SERVER, false);
|
||||||
|
int OldAccessLevel;
|
||||||
|
if(pInfo)
|
||||||
|
OldAccessLevel = pInfo->GetAccessLevel();
|
||||||
|
pfnCallback(pResult, pCallbackUserData);
|
||||||
|
if(pInfo && OldAccessLevel != pInfo->GetAccessLevel())
|
||||||
|
{
|
||||||
|
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||||
|
{
|
||||||
|
if(pThis->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY || pThis->m_aClients[i].m_Authed != CServer::AUTHED_MOD ||
|
||||||
|
(pThis->m_aClients[i].m_pRconCmdToSend && str_comp(pResult->GetString(0), pThis->m_aClients[i].m_pRconCmdToSend->m_pName) >= 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(OldAccessLevel == IConsole::ACCESS_LEVEL_ADMIN)
|
||||||
|
pThis->SendRconCmdAdd(pInfo, i);
|
||||||
|
else
|
||||||
|
pThis->SendRconCmdRem(pInfo, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pfnCallback(pResult, pCallbackUserData);
|
||||||
|
}
|
||||||
|
|
||||||
void CServer::RegisterCommands()
|
void CServer::RegisterCommands()
|
||||||
{
|
{
|
||||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||||
|
|
||||||
Console()->Register("kick", "i?r", CFGFLAG_SERVER, ConKick, this, "");
|
Console()->Register("kick", "i?r", CFGFLAG_SERVER, ConKick, this, "Kick player with specified id for any reason");
|
||||||
Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBan, this, "");
|
Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBan, this, "Ban player with ip/id for x minutes for any reason");
|
||||||
Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnban, this, "");
|
Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnban, this, "Unban ip");
|
||||||
Console()->Register("bans", "", CFGFLAG_SERVER|CFGFLAG_STORE, ConBans, this, "");
|
Console()->Register("bans", "", CFGFLAG_SERVER|CFGFLAG_STORE, ConBans, this, "Show banlist");
|
||||||
Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "");
|
Console()->Register("status", "", CFGFLAG_SERVER, ConStatus, this, "List players");
|
||||||
Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "");
|
Console()->Register("shutdown", "", CFGFLAG_SERVER, ConShutdown, this, "Shut down");
|
||||||
|
|
||||||
Console()->Register("record", "?s", CFGFLAG_SERVER|CFGFLAG_STORE, ConRecord, this, "");
|
Console()->Register("record", "?s", CFGFLAG_SERVER|CFGFLAG_STORE, ConRecord, this, "Record to a file");
|
||||||
Console()->Register("stoprecord", "", CFGFLAG_SERVER, ConStopRecord, this, "");
|
Console()->Register("stoprecord", "", CFGFLAG_SERVER, ConStopRecord, this, "Stop recording");
|
||||||
|
|
||||||
Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, "");
|
Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, "Reload the map");
|
||||||
|
|
||||||
Console()->Chain("sv_name", ConchainSpecialInfoupdate, this);
|
Console()->Chain("sv_name", ConchainSpecialInfoupdate, this);
|
||||||
Console()->Chain("password", ConchainSpecialInfoupdate, this);
|
Console()->Chain("password", ConchainSpecialInfoupdate, this);
|
||||||
|
|
||||||
Console()->Chain("sv_max_clients_per_ip", ConchainMaxclientsperipUpdate, this);
|
Console()->Chain("sv_max_clients_per_ip", ConchainMaxclientsperipUpdate, this);
|
||||||
|
Console()->Chain("mod_command", ConchainModCommandUpdate, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
AUTHED_NO=0,
|
AUTHED_NO=0,
|
||||||
AUTHED_MOD,
|
AUTHED_MOD,
|
||||||
AUTHED_ADMIN,
|
AUTHED_ADMIN,
|
||||||
|
|
||||||
|
MAX_RCONCMD_SEND=16,
|
||||||
};
|
};
|
||||||
|
|
||||||
class CClient
|
class CClient
|
||||||
|
@ -100,6 +102,8 @@ public:
|
||||||
int m_Authed;
|
int m_Authed;
|
||||||
int m_AuthTries;
|
int m_AuthTries;
|
||||||
|
|
||||||
|
const IConsole::CCommandInfo *m_pRconCmdToSend;
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -169,6 +173,10 @@ public:
|
||||||
void SendRconLine(int ClientID, const char *pLine);
|
void SendRconLine(int ClientID, const char *pLine);
|
||||||
static void SendRconLineAuthed(const char *pLine, void *pUser);
|
static void SendRconLineAuthed(const char *pLine, void *pUser);
|
||||||
|
|
||||||
|
void SendRconCmdAdd(const IConsole::CCommandInfo *pCommandInfo, int ClientID);
|
||||||
|
void SendRconCmdRem(const IConsole::CCommandInfo *pCommandInfo, int ClientID);
|
||||||
|
void UpdateClientRconCommands();
|
||||||
|
|
||||||
void ProcessClientPacket(CNetChunk *pPacket);
|
void ProcessClientPacket(CNetChunk *pPacket);
|
||||||
|
|
||||||
void SendServerInfo(NETADDR *pAddr, int Token);
|
void SendServerInfo(NETADDR *pAddr, int Token);
|
||||||
|
@ -197,6 +205,7 @@ public:
|
||||||
static void ConMapReload(IConsole::IResult *pResult, void *pUser);
|
static void ConMapReload(IConsole::IResult *pResult, void *pUser);
|
||||||
static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||||
static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||||
|
static void ConchainModCommandUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||||
|
|
||||||
void RegisterCommands();
|
void RegisterCommands();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,29 @@ float CConsole::CResult::GetFloat(unsigned Index)
|
||||||
return str_tofloat(m_apArgs[Index]);
|
return str_tofloat(m_apArgs[Index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const IConsole::CCommandInfo *CConsole::CCommand::NextCommandInfo(int AccessLevel, int FlagMask) const
|
||||||
|
{
|
||||||
|
const CCommand *pInfo = m_pNext;
|
||||||
|
while(pInfo)
|
||||||
|
{
|
||||||
|
if(pInfo->m_Flags&FlagMask && pInfo->m_AccessLevel >= AccessLevel)
|
||||||
|
break;
|
||||||
|
pInfo = pInfo->m_pNext;
|
||||||
|
}
|
||||||
|
return pInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IConsole::CCommandInfo *CConsole::FirstCommandInfo(int AccessLevel, int FlagMask) const
|
||||||
|
{
|
||||||
|
for(const CCommand *pCommand = m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
|
||||||
|
{
|
||||||
|
if(pCommand->m_Flags&FlagMask && pCommand->GetAccessLevel() >= AccessLevel)
|
||||||
|
return pCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// the maximum number of tokens occurs in a string of length CONSOLE_MAX_STR_LENGTH with tokens size 1 separated by single spaces
|
// the maximum number of tokens occurs in a string of length CONSOLE_MAX_STR_LENGTH with tokens size 1 separated by single spaces
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,7 +281,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr)
|
||||||
|
|
||||||
if(pCommand)
|
if(pCommand)
|
||||||
{
|
{
|
||||||
if(pCommand->m_AccessLevel >= m_AccessLevel)
|
if(pCommand->GetAccessLevel() >= m_AccessLevel)
|
||||||
{
|
{
|
||||||
int IsStrokeCommand = 0;
|
int IsStrokeCommand = 0;
|
||||||
if(Result.m_pCommand[0] == '+')
|
if(Result.m_pCommand[0] == '+')
|
||||||
|
@ -305,11 +328,11 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConsole::PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser)
|
void CConsole::PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser)
|
||||||
{
|
{
|
||||||
for(CCommand *pCommand = m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
|
for(CCommand *pCommand = m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
|
||||||
{
|
{
|
||||||
if(pCommand->m_Flags&FlagMask)
|
if(pCommand->m_Flags&FlagMask && pCommand->m_Temp == Temp)
|
||||||
{
|
{
|
||||||
if(str_find_nocase(pCommand->m_pName, pStr))
|
if(str_find_nocase(pCommand->m_pName, pStr))
|
||||||
pfnCallback(pCommand->m_pName, pUser);
|
pfnCallback(pCommand->m_pName, pUser);
|
||||||
|
@ -403,11 +426,11 @@ void CConsole::ConModCommandAccess(IResult *pResult, void *pUser)
|
||||||
{
|
{
|
||||||
if(pResult->NumArguments() == 2)
|
if(pResult->NumArguments() == 2)
|
||||||
{
|
{
|
||||||
pCommand->m_AccessLevel = clamp(pResult->GetInteger(1), (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_MOD));
|
pCommand->SetAccessLevel(pResult->GetInteger(1));
|
||||||
str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is now %s", pResult->GetString(0), pCommand->m_AccessLevel ? "enabled" : "disabled");
|
str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is %s", pResult->GetString(0), pCommand->m_AccessLevel ? "enabled" : "disabled");
|
str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0));
|
str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0));
|
||||||
|
@ -424,7 +447,7 @@ void CConsole::ConModCommandStatus(IResult *pResult, void *pUser)
|
||||||
|
|
||||||
for(CCommand *pCommand = pConsole->m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
|
for(CCommand *pCommand = pConsole->m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
|
||||||
{
|
{
|
||||||
if(pCommand->m_Flags&pConsole->m_FlagMask && pCommand->m_AccessLevel == ACCESS_LEVEL_MOD)
|
if(pCommand->m_Flags&pConsole->m_FlagMask && pCommand->GetAccessLevel() == ACCESS_LEVEL_MOD)
|
||||||
{
|
{
|
||||||
int Length = str_length(pCommand->m_pName);
|
int Length = str_length(pCommand->m_pName);
|
||||||
if(Used + Length + 2 < (int)(sizeof(aBuf)))
|
if(Used + Length + 2 < (int)(sizeof(aBuf)))
|
||||||
|
@ -531,6 +554,8 @@ CConsole::CConsole(int FlagMask)
|
||||||
{
|
{
|
||||||
m_FlagMask = FlagMask;
|
m_FlagMask = FlagMask;
|
||||||
m_AccessLevel = ACCESS_LEVEL_ADMIN;
|
m_AccessLevel = ACCESS_LEVEL_ADMIN;
|
||||||
|
m_pRecycleList = 0;
|
||||||
|
m_TempCommands.Reset();
|
||||||
m_StoreCommands = true;
|
m_StoreCommands = true;
|
||||||
m_paStrokeStr[0] = "0";
|
m_paStrokeStr[0] = "0";
|
||||||
m_paStrokeStr[1] = "1";
|
m_paStrokeStr[1] = "1";
|
||||||
|
@ -592,20 +617,131 @@ 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 && m_pFirstCommand->m_pNext)
|
||||||
|
pCommand->m_pNext = m_pFirstCommand;
|
||||||
|
else
|
||||||
|
pCommand->m_pNext = 0;
|
||||||
|
m_pFirstCommand = pCommand;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
pCommand->m_pNext = p->m_pNext;
|
||||||
|
p->m_pNext = pCommand;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CConsole::Register(const char *pName, const char *pParams,
|
void CConsole::Register(const char *pName, const char *pParams,
|
||||||
int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp)
|
int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp)
|
||||||
{
|
{
|
||||||
CCommand *pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand;
|
CCommand *pCommand = new(mem_alloc(sizeof(CCommand), sizeof(void*))) CCommand;
|
||||||
pCommand->m_pfnCallback = pfnFunc;
|
pCommand->m_pfnCallback = pfnFunc;
|
||||||
pCommand->m_pUserData = pUser;
|
pCommand->m_pUserData = pUser;
|
||||||
pCommand->m_pHelp = pHelp;
|
|
||||||
pCommand->m_pName = pName;
|
|
||||||
pCommand->m_pParams = pParams;
|
|
||||||
pCommand->m_Flags = Flags;
|
|
||||||
pCommand->m_AccessLevel = ACCESS_LEVEL_ADMIN;
|
|
||||||
|
|
||||||
pCommand->m_pNext = m_pFirstCommand;
|
pCommand->m_pName = pName;
|
||||||
m_pFirstCommand = pCommand;
|
pCommand->m_pHelp = pHelp;
|
||||||
|
pCommand->m_pParams = pParams;
|
||||||
|
|
||||||
|
pCommand->m_Flags = Flags;
|
||||||
|
pCommand->m_Temp = false;
|
||||||
|
|
||||||
|
AddCommandSorted(pCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConsole::RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp)
|
||||||
|
{
|
||||||
|
CCommand *pCommand;
|
||||||
|
if(m_pRecycleList)
|
||||||
|
{
|
||||||
|
pCommand = m_pRecycleList;
|
||||||
|
str_copy(const_cast<char *>(pCommand->m_pName), pName, TEMPCMD_NAME_LENGTH);
|
||||||
|
str_copy(const_cast<char *>(pCommand->m_pHelp), pHelp, TEMPCMD_HELP_LENGTH);
|
||||||
|
str_copy(const_cast<char *>(pCommand->m_pParams), pParams, TEMPCMD_PARAMS_LENGTH);
|
||||||
|
|
||||||
|
m_pRecycleList = m_pRecycleList->m_pNext;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pCommand = new(m_TempCommands.Allocate(sizeof(CCommand))) CCommand;
|
||||||
|
char *pMem = static_cast<char *>(m_TempCommands.Allocate(TEMPCMD_NAME_LENGTH));
|
||||||
|
str_copy(pMem, pName, TEMPCMD_NAME_LENGTH);
|
||||||
|
pCommand->m_pName = pMem;
|
||||||
|
pMem = static_cast<char *>(m_TempCommands.Allocate(TEMPCMD_HELP_LENGTH));
|
||||||
|
str_copy(pMem, pHelp, TEMPCMD_HELP_LENGTH);
|
||||||
|
pCommand->m_pHelp = pMem;
|
||||||
|
pMem = static_cast<char *>(m_TempCommands.Allocate(TEMPCMD_PARAMS_LENGTH));
|
||||||
|
str_copy(pMem, pParams, TEMPCMD_PARAMS_LENGTH);
|
||||||
|
pCommand->m_pParams = pMem;
|
||||||
|
}
|
||||||
|
|
||||||
|
pCommand->m_pfnCallback = 0;
|
||||||
|
pCommand->m_pUserData = 0;
|
||||||
|
pCommand->m_Flags = Flags;
|
||||||
|
pCommand->m_Temp = true;
|
||||||
|
|
||||||
|
AddCommandSorted(pCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConsole::DeregisterTemp(const char *pName)
|
||||||
|
{
|
||||||
|
if(!m_pFirstCommand)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CCommand *pRemoved = 0;
|
||||||
|
|
||||||
|
// remove temp entry from command list
|
||||||
|
if(m_pFirstCommand->m_Temp && str_comp(m_pFirstCommand->m_pName, pName) == 0)
|
||||||
|
{
|
||||||
|
pRemoved = m_pFirstCommand;
|
||||||
|
m_pFirstCommand = m_pFirstCommand->m_pNext;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(CCommand *pCommand = m_pFirstCommand; pCommand->m_pNext; pCommand = pCommand->m_pNext)
|
||||||
|
if(pCommand->m_pNext->m_Temp && str_comp(pCommand->m_pNext->m_pName, pName) == 0)
|
||||||
|
{
|
||||||
|
pRemoved = pCommand->m_pNext;
|
||||||
|
pCommand->m_pNext = pCommand->m_pNext->m_pNext;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to recycle list
|
||||||
|
if(pRemoved)
|
||||||
|
{
|
||||||
|
pRemoved->m_pNext = m_pRecycleList;
|
||||||
|
m_pRecycleList = pRemoved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CConsole::DeregisterTempAll()
|
||||||
|
{
|
||||||
|
// set non temp as first one
|
||||||
|
for(; m_pFirstCommand && m_pFirstCommand->m_Temp; m_pFirstCommand = m_pFirstCommand->m_pNext);
|
||||||
|
|
||||||
|
// remove temp entries from command list
|
||||||
|
for(CCommand *pCommand = m_pFirstCommand; pCommand && pCommand->m_pNext; pCommand = pCommand->m_pNext)
|
||||||
|
{
|
||||||
|
CCommand *pNext = pCommand->m_pNext;
|
||||||
|
if(pNext->m_Temp)
|
||||||
|
{
|
||||||
|
for(; pNext && pNext->m_Temp; pNext = pNext->m_pNext);
|
||||||
|
pCommand->m_pNext = pNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_TempCommands.Reset();
|
||||||
|
m_pRecycleList = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConsole::Con_Chain(IResult *pResult, void *pUserData)
|
void CConsole::Con_Chain(IResult *pResult, void *pUserData)
|
||||||
|
@ -651,9 +787,18 @@ void CConsole::StoreCommands(bool Store)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IConsole::CCommandInfo *CConsole::GetCommandInfo(const char *pName, int FlagMask)
|
const IConsole::CCommandInfo *CConsole::GetCommandInfo(const char *pName, int FlagMask, bool Temp)
|
||||||
{
|
{
|
||||||
return FindCommand(pName, FlagMask);
|
for(CCommand *pCommand = m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
|
||||||
|
{
|
||||||
|
if(pCommand->m_Flags&FlagMask && pCommand->m_Temp == Temp)
|
||||||
|
{
|
||||||
|
if(str_comp_nocase(pCommand->m_pName, pName) == 0)
|
||||||
|
return pCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,13 @@ class CConsole : public IConsole
|
||||||
public:
|
public:
|
||||||
CCommand *m_pNext;
|
CCommand *m_pNext;
|
||||||
int m_Flags;
|
int m_Flags;
|
||||||
int m_AccessLevel;
|
bool m_Temp;
|
||||||
FCommandCallback m_pfnCallback;
|
FCommandCallback m_pfnCallback;
|
||||||
void *m_pUserData;
|
void *m_pUserData;
|
||||||
|
|
||||||
|
virtual const CCommandInfo *NextCommandInfo(int AccessLevel, int FlagMask) const;
|
||||||
|
|
||||||
|
void SetAccessLevel(int AccessLevel) { m_AccessLevel = clamp(AccessLevel, (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_MOD)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +48,9 @@ class CConsole : public IConsole
|
||||||
class IStorage *m_pStorage;
|
class IStorage *m_pStorage;
|
||||||
int m_AccessLevel;
|
int m_AccessLevel;
|
||||||
|
|
||||||
|
CCommand *m_pRecycleList;
|
||||||
|
CHeap m_TempCommands;
|
||||||
|
|
||||||
static void Con_Chain(IResult *pResult, void *pUserData);
|
static void Con_Chain(IResult *pResult, void *pUserData);
|
||||||
static void Con_Echo(IResult *pResult, void *pUserData);
|
static void Con_Echo(IResult *pResult, void *pUserData);
|
||||||
static void Con_Exec(IResult *pResult, void *pUserData);
|
static void Con_Exec(IResult *pResult, void *pUserData);
|
||||||
|
@ -138,16 +145,21 @@ class CConsole : public IConsole
|
||||||
}
|
}
|
||||||
} m_ExecutionQueue;
|
} m_ExecutionQueue;
|
||||||
|
|
||||||
|
void AddCommandSorted(CCommand *pCommand);
|
||||||
CCommand *FindCommand(const char *pName, int FlagMask);
|
CCommand *FindCommand(const char *pName, int FlagMask);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CConsole(int FlagMask);
|
CConsole(int FlagMask);
|
||||||
|
|
||||||
virtual CCommandInfo *GetCommandInfo(const char *pName, int FlagMask);
|
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const;
|
||||||
virtual void PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser) ;
|
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);
|
||||||
|
|
||||||
virtual void ParseArguments(int NumArgs, const char **ppArguments);
|
virtual void ParseArguments(int NumArgs, const char **ppArguments);
|
||||||
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp);
|
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp);
|
||||||
|
virtual void RegisterTemp(const char *pName, const char *pParams, int Flags, const char *pHelp);
|
||||||
|
virtual void DeregisterTemp(const char *pName);
|
||||||
|
virtual void DeregisterTempAll();
|
||||||
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser);
|
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser);
|
||||||
virtual void StoreCommands(bool Store);
|
virtual void StoreCommands(bool Store);
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,11 @@ enum
|
||||||
// sent by both
|
// sent by both
|
||||||
NETMSG_PING,
|
NETMSG_PING,
|
||||||
NETMSG_PING_REPLY,
|
NETMSG_PING_REPLY,
|
||||||
NETMSG_ERROR
|
NETMSG_ERROR,
|
||||||
|
|
||||||
|
// sent by server (todo: move it up)
|
||||||
|
NETMSG_RCON_CMD_ADD,
|
||||||
|
NETMSG_RCON_CMD_REM,
|
||||||
};
|
};
|
||||||
|
|
||||||
// this should be revised
|
// this should be revised
|
||||||
|
|
|
@ -51,7 +51,7 @@ CGameConsole::CInstance::CInstance(int Type)
|
||||||
m_CompletionChosen = -1;
|
m_CompletionChosen = -1;
|
||||||
m_CompletionRenderOffset = 0.0f;
|
m_CompletionRenderOffset = 0.0f;
|
||||||
|
|
||||||
m_pCommand = 0x0;
|
m_IsCommand = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGameConsole::CInstance::Init(CGameConsole *pGameConsole)
|
void CGameConsole::CInstance::Init(CGameConsole *pGameConsole)
|
||||||
|
@ -147,14 +147,16 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
|
||||||
{
|
{
|
||||||
m_CompletionChosen++;
|
m_CompletionChosen++;
|
||||||
m_CompletionEnumerationCount = 0;
|
m_CompletionEnumerationCount = 0;
|
||||||
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, PossibleCommandsCompleteCallback, this);
|
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL &&
|
||||||
|
m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
|
||||||
|
|
||||||
// handle wrapping
|
// handle wrapping
|
||||||
if(m_CompletionEnumerationCount && m_CompletionChosen >= m_CompletionEnumerationCount)
|
if(m_CompletionEnumerationCount && m_CompletionChosen >= m_CompletionEnumerationCount)
|
||||||
{
|
{
|
||||||
m_CompletionChosen %= m_CompletionEnumerationCount;
|
m_CompletionChosen %= m_CompletionEnumerationCount;
|
||||||
m_CompletionEnumerationCount = 0;
|
m_CompletionEnumerationCount = 0;
|
||||||
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, PossibleCommandsCompleteCallback, this);
|
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL &&
|
||||||
|
m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +192,17 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
|
||||||
aBuf[i] = *pSrc;
|
aBuf[i] = *pSrc;
|
||||||
aBuf[i] = 0;
|
aBuf[i] = 0;
|
||||||
|
|
||||||
m_pCommand = m_pGameConsole->m_pConsole->GetCommandInfo(aBuf, m_CompletionFlagmask);
|
const IConsole::CCommandInfo *pCommand = m_pGameConsole->m_pConsole->GetCommandInfo(aBuf, m_CompletionFlagmask,
|
||||||
|
m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands());
|
||||||
|
if(pCommand)
|
||||||
|
{
|
||||||
|
m_IsCommand = true;
|
||||||
|
str_copy(m_aCommandName, pCommand->m_pName, IConsole::TEMPCMD_NAME_LENGTH);
|
||||||
|
str_copy(m_aCommandHelp, pCommand->m_pHelp, IConsole::TEMPCMD_HELP_LENGTH);
|
||||||
|
str_copy(m_aCommandParams, pCommand->m_pParams, IConsole::TEMPCMD_PARAMS_LENGTH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_IsCommand = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,19 +461,19 @@ void CGameConsole::OnRender()
|
||||||
{
|
{
|
||||||
if(pConsole->m_Input.GetString()[0] != 0)
|
if(pConsole->m_Input.GetString()[0] != 0)
|
||||||
{
|
{
|
||||||
m_pConsole->PossibleCommands(pConsole->m_aCompletionBuffer, pConsole->m_CompletionFlagmask, PossibleCommandsRenderCallback, &Info);
|
m_pConsole->PossibleCommands(pConsole->m_aCompletionBuffer, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL &&
|
||||||
|
Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info);
|
||||||
pConsole->m_CompletionRenderOffset = Info.m_Offset;
|
pConsole->m_CompletionRenderOffset = Info.m_Offset;
|
||||||
|
|
||||||
if(Info.m_EnumCount <= 0)
|
if(Info.m_EnumCount <= 0)
|
||||||
{
|
{
|
||||||
if(pConsole->m_pCommand)
|
if(pConsole->m_IsCommand)
|
||||||
{
|
{
|
||||||
|
|
||||||
char aBuf[512];
|
char aBuf[512];
|
||||||
str_format(aBuf, sizeof(aBuf), "Help: %s ", pConsole->m_pCommand->m_pHelp);
|
str_format(aBuf, sizeof(aBuf), "Help: %s ", pConsole->m_aCommandHelp);
|
||||||
TextRender()->TextEx(&Info.m_Cursor, aBuf, -1);
|
TextRender()->TextEx(&Info.m_Cursor, aBuf, -1);
|
||||||
TextRender()->TextColor(0.75f, 0.75f, 0.75f, 1);
|
TextRender()->TextColor(0.75f, 0.75f, 0.75f, 1);
|
||||||
str_format(aBuf, sizeof(aBuf), "Syntax: %s %s", pConsole->m_pCommand->m_pName, pConsole->m_pCommand->m_pParams);
|
str_format(aBuf, sizeof(aBuf), "Syntax: %s %s", pConsole->m_aCommandName, pConsole->m_aCommandParams);
|
||||||
TextRender()->TextEx(&Info.m_Cursor, aBuf, -1);
|
TextRender()->TextEx(&Info.m_Cursor, aBuf, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,10 @@ class CGameConsole : public CComponent
|
||||||
int m_CompletionFlagmask;
|
int m_CompletionFlagmask;
|
||||||
float m_CompletionRenderOffset;
|
float m_CompletionRenderOffset;
|
||||||
|
|
||||||
IConsole::CCommandInfo *m_pCommand;
|
bool m_IsCommand;
|
||||||
|
char m_aCommandName[IConsole::TEMPCMD_NAME_LENGTH];
|
||||||
|
char m_aCommandHelp[IConsole::TEMPCMD_HELP_LENGTH];
|
||||||
|
char m_aCommandParams[IConsole::TEMPCMD_PARAMS_LENGTH];
|
||||||
|
|
||||||
CInstance(int t);
|
CInstance(int t);
|
||||||
void Init(CGameConsole *pGameConsole);
|
void Init(CGameConsole *pGameConsole);
|
||||||
|
|
|
@ -1317,22 +1317,22 @@ void CGameContext::OnConsoleInit()
|
||||||
m_pServer = Kernel()->RequestInterface<IServer>();
|
m_pServer = Kernel()->RequestInterface<IServer>();
|
||||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||||
|
|
||||||
Console()->Register("tune", "si", CFGFLAG_SERVER, ConTuneParam, this, "");
|
Console()->Register("tune", "si", CFGFLAG_SERVER, ConTuneParam, this, "Tune variable to value");
|
||||||
Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "");
|
Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "Reset tuning");
|
||||||
Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "");
|
Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "Dump tuning");
|
||||||
|
|
||||||
Console()->Register("change_map", "?r", CFGFLAG_SERVER|CFGFLAG_STORE, ConChangeMap, this, "");
|
Console()->Register("change_map", "?r", CFGFLAG_SERVER|CFGFLAG_STORE, ConChangeMap, this, "Change map");
|
||||||
Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, "");
|
Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, "Restart in x seconds");
|
||||||
Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "");
|
Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "Broadcast message");
|
||||||
Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "");
|
Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Say in chat");
|
||||||
Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, "");
|
Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, "Set team of player to team");
|
||||||
Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, "");
|
Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team");
|
||||||
|
|
||||||
Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, "");
|
Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, "Add a voting option");
|
||||||
Console()->Register("remove_vote", "s", CFGFLAG_SERVER, ConRemoveVote, this, "");
|
Console()->Register("remove_vote", "s", CFGFLAG_SERVER, ConRemoveVote, this, "remove a voting option");
|
||||||
Console()->Register("force_vote", "ss?r", CFGFLAG_SERVER, ConForceVote, this, "");
|
Console()->Register("force_vote", "ss?r", CFGFLAG_SERVER, ConForceVote, this, "Force a voting option");
|
||||||
Console()->Register("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, "");
|
Console()->Register("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, "Clears the voting options");
|
||||||
Console()->Register("vote", "r", CFGFLAG_SERVER, ConVote, this, "");
|
Console()->Register("vote", "r", CFGFLAG_SERVER, ConVote, this, "Force a vote to yes/no");
|
||||||
|
|
||||||
Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this);
|
Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue