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
This commit is contained in:
David Anderson 2007-06-08 07:54:45 +00:00
parent e85a6d280f
commit 2e3c61c849
4 changed files with 54 additions and 68 deletions

View File

@ -19,6 +19,7 @@
#include "ConCmdManager.h" #include "ConCmdManager.h"
#include "MenuStyle_Valve.h" #include "MenuStyle_Valve.h"
#include "MenuStyle_Radio.h" #include "MenuStyle_Radio.h"
#include "sm_stringutil.h"
PlayerManager g_Players; PlayerManager g_Players;
bool g_OnMapStarted = false; bool g_OnMapStarted = false;
@ -115,6 +116,24 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl
g_OnMapStarted = true; 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() void PlayerManager::RunAuthChecks()
{ {
CPlayer *pPlayer; CPlayer *pPlayer;
@ -136,6 +155,13 @@ void PlayerManager::RunAuthChecks()
m_AuthQueue[i] = 0; m_AuthQueue[i] = 0;
removed++; removed++;
/* Do admin lookups */
AdminId id = g_Admins.FindAdminByIdentity("steam", authstr);
if (id != INVALID_ADMIN_ID)
{
CheckSetAdmin(client, pPlayer, id);
}
/* Send to extensions */ /* Send to extensions */
List<IClientListener *>::iterator iter; List<IClientListener *>::iterator iter;
IClientListener *pListener; IClientListener *pListener;
@ -233,6 +259,7 @@ bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName,
{ {
int client = engine->IndexOfEdict(pEntity); int client = engine->IndexOfEdict(pEntity);
bool orig_value = META_RESULT_ORIG_RET(bool); bool orig_value = META_RESULT_ORIG_RET(bool);
CPlayer *pPlayer = GetPlayerByIndex(client);
if (orig_value) if (orig_value)
{ {
List<IClientListener *>::iterator iter; List<IClientListener *>::iterator iter;
@ -241,6 +268,27 @@ bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName,
{ {
pListener = (*iter); pListener = (*iter);
pListener->OnClientConnected(client); 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);
} }
} }

View File

@ -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 <sourcemod>
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);
}

View File

@ -49,8 +49,8 @@ public OnPluginStart()
RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]"); RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]");
RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]"); RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>"); RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_ROOT, "sm_addban <time> <steamid> [reason]"); RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_ROOT, "sm_banip <time> <ip> [reason]"); RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_RCON, "sm_banip <time> <ip> [reason]");
hBanForward = CreateGlobalForward("OnClientBanned", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String); hBanForward = CreateGlobalForward("OnClientBanned", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String);
hAddBanForward = CreateGlobalForward("OnBanAdded", ET_Ignore, Param_Cell, Param_String, Param_Cell, Param_String); hAddBanForward = CreateGlobalForward("OnBanAdded", ET_Ignore, Param_Cell, Param_String, Param_Cell, Param_String);

View File

@ -126,12 +126,11 @@ namespace builder
*/ */
public override Plugin [] GetPlugins() public override Plugin [] GetPlugins()
{ {
Plugin [] plugins = new Plugin[4]; Plugin [] plugins = new Plugin[3];
plugins[0] = new Plugin("admin-auth"); plugins[0] = new Plugin("admin-flatfile", "admin-flatfile");
plugins[1] = new Plugin("admin-flatfile", "admin-flatfile"); plugins[1] = new Plugin("basecommands");
plugins[2] = new Plugin("basecommands"); plugins[2] = new Plugin("antiflood");
plugins[3] = new Plugin("antiflood");
return plugins; return plugins;
} }