From 2e3c61c849ee0fab3fc1f3b0e817ac5990e88af5 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 8 Jun 2007 07:54:45 +0000 Subject: [PATCH] SourceMod now does authentication in core; admin-auth gets removed. this has an added bonus that OnClientAuthorized reliably has whether an admin is validated --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40936 --- core/PlayerManager.cpp | 48 +++++++++++++++++++++++++++++++ plugins/admin-auth.sp | 61 ---------------------------------------- plugins/basecommands.sp | 4 +-- tools/builder/PkgCore.cs | 9 +++--- 4 files changed, 54 insertions(+), 68 deletions(-) delete mode 100644 plugins/admin-auth.sp diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 26e5f98c..b01af11d 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -19,6 +19,7 @@ #include "ConCmdManager.h" #include "MenuStyle_Valve.h" #include "MenuStyle_Radio.h" +#include "sm_stringutil.h" PlayerManager g_Players; bool g_OnMapStarted = false; @@ -115,6 +116,24 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl g_OnMapStarted = true; } +bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id) +{ + const char *password = g_Admins.GetAdminPassword(id); + if (password != NULL) + { + /* Whoa... the user needs a password! */ + const char *given = engine->GetClientConVarValue(index, "_password"); + if (!given || strcmp(given, password) != 0) + { + return false; + } + } + + pPlayer->SetAdminId(id, false); + + return true; +} + void PlayerManager::RunAuthChecks() { CPlayer *pPlayer; @@ -136,6 +155,13 @@ void PlayerManager::RunAuthChecks() m_AuthQueue[i] = 0; removed++; + /* Do admin lookups */ + AdminId id = g_Admins.FindAdminByIdentity("steam", authstr); + if (id != INVALID_ADMIN_ID) + { + CheckSetAdmin(client, pPlayer, id); + } + /* Send to extensions */ List::iterator iter; IClientListener *pListener; @@ -233,6 +259,7 @@ bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, { int client = engine->IndexOfEdict(pEntity); bool orig_value = META_RESULT_ORIG_RET(bool); + CPlayer *pPlayer = GetPlayerByIndex(client); if (orig_value) { List::iterator iter; @@ -241,6 +268,27 @@ bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, { pListener = (*iter); pListener->OnClientConnected(client); + if (!pPlayer->IsConnected()) + { + break; + } + } + } + + if (pPlayer->IsConnected()) + { + /* Do an ip based lookup */ + char ip[24], *ptr; + strncopy(ip, pszAddress, sizeof(ip)); + if ((ptr = strchr(ip, ':')) != NULL) + { + *ptr = '\0'; + } + + AdminId id = g_Admins.FindAdminByIdentity("ip", pPlayer->GetIPAddress()); + if (id != INVALID_ADMIN_ID) + { + CheckSetAdmin(client, pPlayer, id); } } diff --git a/plugins/admin-auth.sp b/plugins/admin-auth.sp deleted file mode 100644 index 00ea519d..00000000 --- a/plugins/admin-auth.sp +++ /dev/null @@ -1,61 +0,0 @@ -/** - * admin-auth.sp - * Authenticates admins. - * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Version: $Id$ - */ - - -#include - -public Plugin:myinfo = -{ - name = "Admin Auth", - author = "AlliedModders LLC", - description = "Authenticates Admins", - version = SOURCEMOD_VERSION, - url = "http://www.sourcemod.net/" -}; - -public OnClientAuthorized(client, const String:auth[]) -{ - if (StrEqual(auth, "BOT") - || StrEqual(auth, "STEAM_ID_LAN")) - { - return; - } - - new AdminId:id - if ((id = FindAdminByIdentity("steam", auth)) == INVALID_ADMIN_ID) - { - return; - } - - decl String:buffer[256], String:account[64]; - - FormatUserLogText(client, buffer, sizeof(buffer)); - - if (GetAdminUsername(id, account, sizeof(account))) - { - LogMessage("%s authenticated to account \"%s\"", buffer, account); - } else { - LogMessage("%s authenticated to an anonymous account", buffer); - } - - SetUserAdmin(client, id); -} diff --git a/plugins/basecommands.sp b/plugins/basecommands.sp index 7185c7d7..611c8f71 100644 --- a/plugins/basecommands.sp +++ b/plugins/basecommands.sp @@ -49,8 +49,8 @@ public OnPluginStart() RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]"); RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> [reason]"); RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban "); - RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_ROOT, "sm_addban