From 9a5a19e7c7b0d4364f32540b012bce970807f9b6 Mon Sep 17 00:00:00 2001 From: NoxNebula Date: Wed, 2 Jun 2010 04:42:17 +0200 Subject: [PATCH] Admin-Kick-Protection Add IsAuthed(int ClientID); function. Add kickprotection for admins (Remote Console logged in players) Add Anti-Self-Kick (minor) --- src/engine/server.h | 2 ++ src/engine/server/server.cpp | 7 +++++++ src/engine/server/server.h | 1 + src/game/server/gamecontext.cpp | 13 +++++++++++++ 4 files changed, 23 insertions(+) diff --git a/src/engine/server.h b/src/engine/server.h index 52e6ec6a4..fa5d24981 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -49,6 +49,8 @@ public: virtual void *SnapNewItem(int Type, int Id, int Size) = 0; virtual void SnapSetStaticsize(int ItemType, int Size) = 0; + + virtual bool IsAuthed(int ClientID) = 0; }; class IGameServer : public IInterface diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 05e56a742..b5a01a99a 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -293,6 +293,13 @@ int CServer::Init() return 0; } +bool CServer::IsAuthed(int ClientID) +{ + if(m_aClients[ClientID].m_Authed) + return true; + return false; +} + int CServer::GetClientInfo(int ClientID, CClientInfo *pInfo) { dbg_assert(ClientID >= 0 && ClientID < MAX_CLIENTS, "client_id is not valid"); diff --git a/src/engine/server/server.h b/src/engine/server/server.h index 7d56bd333..895a4bd1e 100644 --- a/src/engine/server/server.h +++ b/src/engine/server/server.h @@ -138,6 +138,7 @@ public: int Init(); + bool IsAuthed(int ClientID); int GetClientInfo(int ClientID, CClientInfo *pInfo); void GetClientIP(int ClientID, char *pIPString, int Size); const char *ClientName(int ClientId); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 795bb65fe..c04dd9457 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -647,6 +647,19 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) SendChatTarget(ClientId, "Invalid client id to kick"); return; } + if(KickId == ClientId) + { + SendChatTarget(ClientId, "You cant kick yourself"); + return; + } + if(Server()->IsAuthed(KickId)) + { + SendChatTarget(ClientId, "You cant kick admins"); + char aBufKick[128]; + str_format(aBufKick, sizeof(aBufKick), "%s called for vote to kick you", Server()->ClientName(ClientId)); + SendChatTarget(KickId, aBufKick); + return; + } str_format(aChatmsg, sizeof(aChatmsg), "%s called for vote to kick '%s'", Server()->ClientName(ClientId), Server()->ClientName(KickId)); str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickId));