Add user level access and use this level for /cmds if player is not authed.

This commit is contained in:
Ravomavain 2011-08-26 09:19:00 +02:00 committed by GreYFoX
parent 5912395554
commit 15d0a40825
4 changed files with 15 additions and 3 deletions

View file

@ -19,6 +19,7 @@ public:
ACCESS_LEVEL_ADMIN=0,
ACCESS_LEVEL_MOD,
ACCESS_LEVEL_USER,
TEMPCMD_NAME_LENGTH=32,
TEMPCMD_HELP_LENGTH=96,

View file

@ -442,9 +442,15 @@ void CConsole::ConModCommandAccess(IResult *pResult, void *pUser)
{
pCommand->SetAccessLevel(pResult->GetInteger(1));
str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() ? "enabled" : "disabled");
pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
str_format(aBuf, sizeof(aBuf), "user access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_USER ? "enabled" : "disabled");
}
else
{
str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() ? "enabled" : "disabled");
pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
str_format(aBuf, sizeof(aBuf), "user access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_USER ? "enabled" : "disabled");
}
}
else
str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0));
@ -461,7 +467,7 @@ void CConsole::ConModCommandStatus(IResult *pResult, void *pUser)
for(CCommand *pCommand = pConsole->m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext)
{
if(pCommand->m_Flags&pConsole->m_FlagMask && pCommand->GetAccessLevel() == ACCESS_LEVEL_MOD)
if(pCommand->m_Flags&pConsole->m_FlagMask && pCommand->GetAccessLevel() >= ACCESS_LEVEL_MOD)
{
int Length = str_length(pCommand->m_pName);
if(Used + Length + 2 < (int)(sizeof(aBuf)))

View file

@ -19,7 +19,7 @@ class CConsole : public IConsole
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)); }
void SetAccessLevel(int AccessLevel) { m_AccessLevel = clamp(AccessLevel, (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_USER)); }
};
@ -176,7 +176,7 @@ public:
virtual void SetPrintOutputLevel(int Index, int OutputLevel);
virtual void Print(int Level, const char *pFrom, const char *pStr);
void SetAccessLevel(int AccessLevel) { m_AccessLevel = clamp(AccessLevel, (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_MOD)); }
void SetAccessLevel(int AccessLevel) { m_AccessLevel = clamp(AccessLevel, (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_USER)); }
// DDRace

View file

@ -747,8 +747,13 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
Info.m_GameContext = this;
Info.m_To = ClientID;
if (pPlayer->m_Authed)
Console()->SetAccessLevel(pPlayer->m_Authed == CServer::AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : IConsole::ACCESS_LEVEL_MOD);
else
Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_USER);
// Todo(Shereef Marzouk): Follow up on the RCON/Chat redirection
Console()->ExecuteLine(pMsg->m_pMessage + 1);
Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_ADMIN);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "chat",
pMsg->m_pMessage);
}