From 50b8d93d6d3a3af88fdd96948cf2d8b965d36b03 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Sun, 7 Nov 2010 17:35:11 +0100 Subject: [PATCH] finished system to generalize rcon commands, sorry for last commit's description --- src/engine/shared/config.h | 5 ++++- src/engine/shared/console.cpp | 10 +++++----- src/engine/shared/console.h | 7 ------- src/game/server/gamecontext.cpp | 10 ++++------ src/game/server/gamecontext.h | 2 -- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/engine/shared/config.h b/src/engine/shared/config.h index 100a52fc5..75da73fb2 100644 --- a/src/engine/shared/config.h +++ b/src/engine/shared/config.h @@ -23,7 +23,10 @@ enum CFGFLAG_SAVE=1, CFGFLAG_CLIENT=2, CFGFLAG_SERVER=4, - CFGFLAG_STORE=8 + CFGFLAG_STORE=8, + CMDFLAG_CHEAT=16, + CMDFLAG_TIMER=32, + CMDFLAG_HELPERCMD=64, }; #endif diff --git a/src/engine/shared/console.cpp b/src/engine/shared/console.cpp index cc240cd93..b4b881d61 100644 --- a/src/engine/shared/console.cpp +++ b/src/engine/shared/console.cpp @@ -405,7 +405,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client if(pResult->GetVictim() == -2) pResult->SetVictim(ClientId); - if((ClientLevel < pCommand->m_Level && !(pCommand->m_Flags & CCommand::CMDFLAG_HELPERCMD)) || (ClientLevel < 1 && (pCommand->m_Flags & CCommand::CMDFLAG_HELPERCMD))) + if((ClientLevel < pCommand->m_Level && !(pCommand->m_Flags & CMDFLAG_HELPERCMD)) || (ClientLevel < 1 && (pCommand->m_Flags & CMDFLAG_HELPERCMD))) { RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData); @@ -423,21 +423,21 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client ReleaseAlternativePrintResponseCallback(); } - else if(ClientLevel == 1 && (pCommand->m_Flags & CCommand::CMDFLAG_HELPERCMD) && pResult->GetVictim() != ClientId) + else if(ClientLevel == 1 && (pCommand->m_Flags & CMDFLAG_HELPERCMD) && pResult->GetVictim() != ClientId) { RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData); PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "As a helper you can't use commands on others."); dbg_msg("server", "helper tried rcon command ('%s') on others without permission. ClientId=%d", pCommand->m_pName, ClientId); ReleaseAlternativePrintResponseCallback(); } - else if(!g_Config.m_SvCheats && (pCommand->m_Flags & CCommand::CMDFLAG_CHEAT)) + else if(!g_Config.m_SvCheats && (pCommand->m_Flags & CMDFLAG_CHEAT)) { RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData); PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "Cheats are not available on this server"); dbg_msg("server", "client tried rcon cheat ('%s') with cheats off. ClientId=%d", pCommand->m_pName, ClientId); ReleaseAlternativePrintResponseCallback(); } - else if(!g_Config.m_SvTimer && (pCommand->m_Flags & CCommand::CMDFLAG_TIMER)) + else if(!g_Config.m_SvTimer && (pCommand->m_Flags & CMDFLAG_TIMER)) { RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData); PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "Timer commands are not available on this server"); @@ -473,7 +473,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, const int Client PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "client is offline"); ReleaseAlternativePrintResponseCallback(); } - else if (!CompareClients(ClientLevel, pResult->GetVictim())) + else if (!CompareClients(ClientLevel, pResult->GetVictim()) && ClientId != pResult->GetVictim()) { RegisterAlternativePrintResponseCallback(pfnAlternativePrintResponseCallback, pResponseUserData); PrintResponse(OUTPUT_LEVEL_STANDARD, "Console", "you can not use commands on players with the same or higher level than you"); diff --git a/src/engine/shared/console.h b/src/engine/shared/console.h index 688898fbb..316e57cea 100644 --- a/src/engine/shared/console.h +++ b/src/engine/shared/console.h @@ -13,13 +13,6 @@ class CConsole : public IConsole int m_Flags; FCommandCallback m_pfnCallback; void *m_pUserData; - - enum - { - CMDFLAG_CHEAT = 16, - CMDFLAG_TIMER = 32, - CMDFLAG_HELPERCMD = 64, - }; }; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 4588c6995..932fae02f 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -618,7 +618,7 @@ void CGameContext::OnClientEnter(int ClientId) m_VoteUpdate = true; } -bool compare_players(CPlayer *pl1, CPlayer *pl2) +bool ComparePlayers(CPlayer *pl1, CPlayer *pl2) { if(((pl1->m_Authed >= 0) ? pl1->m_Authed : 0) > ((pl2->m_Authed >= 0) ? pl2->m_Authed : 0)) return true; @@ -862,7 +862,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) SendChatTarget(ClientId, "You can't kick yourself"); return; } - if(compare_players(m_apPlayers[KickId], pPlayer)) + if(ComparePlayers(m_apPlayers[KickId], pPlayer)) { SendChatTarget(ClientId, "You can't kick admins"); m_apPlayers[ClientId]->m_Last_KickVote = time_get(); @@ -1326,7 +1326,7 @@ void CGameContext::MoveCharacter(int ClientId, int Victim, int X, int Y, bool Ra void CGameContext::ConMute(IConsole::IResult *pResult, void *pUserData, int ClientId) { CGameContext *pSelf = (CGameContext *)pUserData; - int Victim = pResult->GetVictim()); + int Victim = pResult->GetVictim(); int Seconds = pResult->GetInteger(0); char buf[512]; if(Seconds < 10) @@ -1342,7 +1342,6 @@ void CGameContext::ConMute(IConsole::IResult *pResult, void *pUserData, int Clie str_format(buf, sizeof(buf), "%s muted by %s for %d seconds", pSelf->Server()->ClientName(Victim), pSelf->Server()->ClientName(ClientId), Seconds); pSelf->SendChat(-1, CGameContext::CHAT_ALL, buf); } -} void CGameContext::ConSetlvl3(IConsole::IResult *pResult, void *pUserData, int ClientId) { @@ -1585,7 +1584,6 @@ void CGameContext::ModifyWeapons(int ClientId, int Victim, int Weapon, bool Remo void CGameContext::ConTeleport(IConsole::IResult *pResult, void *pUserData, int ClientId) { CGameContext *pSelf = (CGameContext *)pUserData; - if(!pSelf->CheatsAvailable()) return; int Victim = pResult->GetVictim(); int TeleTo = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); if(pSelf->m_apPlayers[TeleTo]) @@ -1669,7 +1667,7 @@ void CGameContext::ConTimerReStart(IConsole::IResult *pResult, void *pUserData, CCharacter* chr = pSelf->GetPlayerChar(Victim); if(!chr) return; - if(pSelf->m_apPlayers[Victim] && compare_players(pSelf->m_apPlayers[ClientId],pSelf->m_apPlayers[Victim])) + if(pSelf->m_apPlayers[Victim]) { chr->m_StartTime = pSelf->Server()->Tick(); chr->m_RefreshTime = pSelf->Server()->Tick(); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 76065e7c4..0f60c1ffd 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -186,8 +186,6 @@ public: void SendVoteStatus(int ClientId, int Total, int Yes, int No); void AbortVoteKickOnDisconnect(int ClientId); - bool CheatsAvailable(); - bool m_VoteKick; int m_VoteCreator; int64 m_VoteCloseTime;