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:
parent
18aabecfd3
commit
57c1f0dd4d
@ -59,7 +59,7 @@ void CPlayerManager::OnSourceModAllInitialized()
|
|||||||
m_cldisconnect_post = g_Forwards.CreateForward("OnClientDisconnect_Post", ET_Ignore, 1, p2);
|
m_cldisconnect_post = g_Forwards.CreateForward("OnClientDisconnect_Post", ET_Ignore, 1, p2);
|
||||||
m_clcommand = g_Forwards.CreateForward("OnClientCommand", ET_Hook, 1, p2);
|
m_clcommand = g_Forwards.CreateForward("OnClientCommand", ET_Hook, 1, p2);
|
||||||
m_clinfochanged = g_Forwards.CreateForward("OnClientSettingsChanged", ET_Ignore, 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()
|
void CPlayerManager::OnSourceModShutdown()
|
||||||
|
@ -375,6 +375,22 @@ static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
|
|||||||
return g_Admins.GetAdminFlags(id, Access_Effective);
|
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)
|
REGISTER_NATIVES(playernatives)
|
||||||
{
|
{
|
||||||
{"GetMaxClients", sm_GetMaxClients},
|
{"GetMaxClients", sm_GetMaxClients},
|
||||||
@ -394,6 +410,7 @@ REGISTER_NATIVES(playernatives)
|
|||||||
{"RemoveUserFlags", RemoveUserFlags},
|
{"RemoveUserFlags", RemoveUserFlags},
|
||||||
{"SetUserFlagBits", SetUserFlagBits},
|
{"SetUserFlagBits", SetUserFlagBits},
|
||||||
{"GetUserFlagBits", GetUserFlagBits},
|
{"GetUserFlagBits", GetUserFlagBits},
|
||||||
|
{"GetClientUserId", GetClientUserId},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
59
plugins/admin-auth.sp
Normal file
59
plugins/admin-auth.sp
Normal 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);
|
||||||
|
}
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
public Plugin:myinfo =
|
public Plugin:myinfo =
|
||||||
{
|
{
|
||||||
name = "Admin Base",
|
name = "Admin File Reader",
|
||||||
author = "AlliedModders LLC",
|
author = "AlliedModders LLC",
|
||||||
description = "Reads admin files",
|
description = "Reads admin files",
|
||||||
version = "1.0.0.0",
|
version = "1.0.0.0",
|
||||||
|
@ -76,7 +76,7 @@ public SMCResult:ReadUsers_KeyValue(Handle:smc,
|
|||||||
{
|
{
|
||||||
auth = true;
|
auth = true;
|
||||||
StrCopy(g_CurAuth, sizeof(g_CurAuth), value);
|
StrCopy(g_CurAuth, sizeof(g_CurAuth), value);
|
||||||
} else if (StrEqual(key, "ident")) {
|
} else if (StrEqual(key, "identity")) {
|
||||||
auth = true;
|
auth = true;
|
||||||
StrCopy(g_CurIdent, sizeof(g_CurIdent), value);
|
StrCopy(g_CurIdent, sizeof(g_CurIdent), value);
|
||||||
} else if (StrEqual(key, "password")) {
|
} else if (StrEqual(key, "password")) {
|
||||||
|
45
plugins/include/helpers.inc
Normal file
45
plugins/include/helpers.inc
Normal 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);
|
||||||
|
}
|
@ -180,7 +180,7 @@ native bool:GetClientName(client, String:name[], maxlen);
|
|||||||
* @param maxlen Maximum length of string buffer (includes NULL terminator).
|
* @param maxlen Maximum length of string buffer (includes NULL terminator).
|
||||||
* @param remport Remove client's port from the ip string (true by default).
|
* @param remport Remove client's port from the ip string (true by default).
|
||||||
* @return True on success, false otherwise.
|
* @return True on success, false otherwise.
|
||||||
* @error If the client is not connected an error will be thrown.
|
* @error If the client is not connected or the index is invalid.
|
||||||
*/
|
*/
|
||||||
native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
|
native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
|
||||||
|
|
||||||
@ -191,10 +191,20 @@ native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
|
|||||||
* @param auth Buffer to store the client's auth string.
|
* @param auth Buffer to store the client's auth string.
|
||||||
* @param maxlen Maximum length of string buffer (includes NULL terminator).
|
* @param maxlen Maximum length of string buffer (includes NULL terminator).
|
||||||
* @return True on success, false otherwise.
|
* @return True on success, false otherwise.
|
||||||
* @error If the client is not connected an error will be thrown.
|
* @error If the client is not connected or the index is invalid.
|
||||||
*/
|
*/
|
||||||
native bool:GetClientAuthString(client, String:auth[], maxlen);
|
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.
|
* Returns if a certain player is connected.
|
||||||
*
|
*
|
||||||
@ -347,3 +357,5 @@ native LogMessage(const String:format[], {Handle,Float,String,_}:...);
|
|||||||
* @noreturn
|
* @noreturn
|
||||||
*/
|
*/
|
||||||
native LogError(const String:format[], {Handle,Float,String,_}:...);
|
native LogError(const String:format[], {Handle,Float,String,_}:...);
|
||||||
|
|
||||||
|
#include <helpers>
|
||||||
|
Loading…
Reference in New Issue
Block a user