added and tested admin authentication. WOOT. only steam-based works for now.

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40466
This commit is contained in:
David Anderson 2007-02-09 04:41:03 +00:00
parent 18aabecfd3
commit 57c1f0dd4d
7 changed files with 144 additions and 11 deletions

View File

@ -59,7 +59,7 @@ void CPlayerManager::OnSourceModAllInitialized()
m_cldisconnect_post = g_Forwards.CreateForward("OnClientDisconnect_Post", ET_Ignore, 1, p2);
m_clcommand = g_Forwards.CreateForward("OnClientCommand", ET_Hook, 1, p2);
m_clinfochanged = g_Forwards.CreateForward("OnClientSettingsChanged", ET_Ignore, 1, p2);
m_clauth = g_Forwards.CreateForward("OnClientAuthorized", ET_Ignore, 2, p2);
m_clauth = g_Forwards.CreateForward("OnClientAuthorized", ET_Ignore, 2, p3);
}
void CPlayerManager::OnSourceModShutdown()

View File

@ -375,6 +375,22 @@ static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
return g_Admins.GetAdminFlags(id, Access_Effective);
}
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Invalid client index %d.", client);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected.", client);
}
return engine->GetPlayerUserId(pPlayer->GetEdict());
}
REGISTER_NATIVES(playernatives)
{
{"GetMaxClients", sm_GetMaxClients},
@ -394,6 +410,7 @@ REGISTER_NATIVES(playernatives)
{"RemoveUserFlags", RemoveUserFlags},
{"SetUserFlagBits", SetUserFlagBits},
{"GetUserFlagBits", GetUserFlagBits},
{"GetClientUserId", GetClientUserId},
{NULL, NULL}
};

59
plugins/admin-auth.sp Normal file
View File

@ -0,0 +1,59 @@
/**
* admin-flatfile.sp
* Manages the standard flat files for admins. This is the file to compile.
* 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.
*/
#include <sourcemod>
public Plugin:myinfo =
{
name = "Admin Auth",
author = "AlliedModders LLC",
description = "Authenticates Admins",
version = "1.0.0.0",
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

@ -24,7 +24,7 @@
public Plugin:myinfo =
{
name = "Admin Base",
name = "Admin File Reader",
author = "AlliedModders LLC",
description = "Reads admin files",
version = "1.0.0.0",

View File

@ -76,7 +76,7 @@ public SMCResult:ReadUsers_KeyValue(Handle:smc,
{
auth = true;
StrCopy(g_CurAuth, sizeof(g_CurAuth), value);
} else if (StrEqual(key, "ident")) {
} else if (StrEqual(key, "identity")) {
auth = true;
StrCopy(g_CurIdent, sizeof(g_CurIdent), value);
} else if (StrEqual(key, "password")) {

View File

@ -0,0 +1,45 @@
/**
* ===============================================================
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* ===============================================================
*
* This file is part of the SourceMod/SourcePawn SDK. This file may only be used
* or modified under the Terms and Conditions of its License Agreement, which is found
* in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
* may change at any time. To view the latest information, see:
* http://www.sourcemod.net/license.php
*
* Version: $Id$
*/
#if defined _helpers_included
#endinput
#endif
#define _helpers_included
/**
* Formats a user's info as log text.
*
* @param client Client index.
* @param buffer Buffer for text.
* @param maxlength Maximum length of text.
*/
stock FormatUserLogText(client, String:buffer[], maxlength)
{
decl String:auth[32];
decl String:name[40];
new userid = GetClientUserId(client);
if (!GetClientAuthString(client, auth, sizeof(auth)))
{
StrCopy(auth, sizeof(auth), "UNKNOWN");
}
if (!GetClientName(client, name, sizeof(name)))
{
StrCopy(name, sizeof(name), "UNKNOWN");
}
/** Currently, no team stuff ... */
Format(buffer, maxlength, "\"%s<%d><%s><>\"", name, userid, auth);
}

View File

@ -164,9 +164,9 @@ native GetClientCount(bool:inGameOnly=true);
/**
* Returns the client's name.
*
* @param client Player index.
* @param name Buffer to store the client's name.
* @param maxlen Maximum length of string buffer (includes NULL terminator).
* @param client Player index.
* @param name Buffer to store the client's name.
* @param maxlen Maximum length of string buffer (includes NULL terminator).
* @return True on success, false otherwise.
* @error If the client is not connected an error will be thrown.
*/
@ -179,8 +179,8 @@ native bool:GetClientName(client, String:name[], maxlen);
* @param name Buffer to store the client's ip address.
* @param maxlen Maximum length of string buffer (includes NULL terminator).
* @param remport Remove client's port from the ip string (true by default).
* @return True on success, false otherwise.
* @error If the client is not connected an error will be thrown.
* @return True on success, false otherwise.
* @error If the client is not connected or the index is invalid.
*/
native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
@ -190,11 +190,21 @@ native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
* @param client Player index.
* @param auth Buffer to store the client's auth string.
* @param maxlen Maximum length of string buffer (includes NULL terminator).
* @return True on success, false otherwise.
* @error If the client is not connected an error will be thrown.
* @return True on success, false otherwise.
* @error If the client is not connected or the index is invalid.
*/
native bool:GetClientAuthString(client, String:auth[], maxlen);
/**
* Retrieves a client's user id, which is an index incremented for every client
* that joins the server.
*
* @param client Player index.
* @return User id of the client.
* @error If the client is not connected or the index is invalid.
*/
native GetClientUserId(client);
/**
* Returns if a certain player is connected.
*
@ -346,4 +356,6 @@ native LogMessage(const String:format[], {Handle,Float,String,_}:...);
* @param ... Format arguments.
* @noreturn
*/
native LogError(const String:format[], {Handle,Float,String,_}:...);
native LogError(const String:format[], {Handle,Float,String,_}:...);
#include <helpers>