Move adminsys and more natives from core to logic.

This commit is contained in:
Nicholas Hastings 2014-05-29 13:31:12 -04:00
parent dc4c3f2f1a
commit 35784c018d
22 changed files with 2880 additions and 2769 deletions

View File

@ -52,7 +52,6 @@ for sdk_name in SM.sdks:
compiler.linkflags.insert(0, binary.Dep(lib_path)) compiler.linkflags.insert(0, binary.Dep(lib_path))
binary.sources += [ binary.sources += [
'AdminCache.cpp',
'MenuStyle_Valve.cpp', 'MenuStyle_Valve.cpp',
'logic_bridge.cpp', 'logic_bridge.cpp',
'smn_entities.cpp', 'smn_entities.cpp',
@ -60,7 +59,6 @@ for sdk_name in SM.sdks:
'MenuVoting.cpp', 'MenuVoting.cpp',
'smn_events.cpp', 'smn_events.cpp',
'smn_menus.cpp', 'smn_menus.cpp',
'sm_trie.cpp',
'CDataPack.cpp', 'CDataPack.cpp',
'frame_hooks.cpp', 'frame_hooks.cpp',
'smn_nextmap.cpp', 'smn_nextmap.cpp',

View File

@ -31,7 +31,6 @@
#include "ConCmdManager.h" #include "ConCmdManager.h"
#include "sm_srvcmds.h" #include "sm_srvcmds.h"
#include "AdminCache.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "HalfLife2.h" #include "HalfLife2.h"
@ -330,85 +329,9 @@ void ConCmdManager::InternalDispatch(const CCommand &command)
} }
} }
bool ConCmdManager::CheckClientCommandAccess(int client, const char *cmd, FlagBits cmdflags)
{
if (cmdflags == 0 || client == 0)
{
return true;
}
/* If running listen server, then client 1 is the server host and should have 'root' access */
if (client == 1 && !engine->IsDedicatedServer())
{
return true;
}
CPlayer *player = g_Players.GetPlayerByIndex(client);
if (!player
|| player->GetEdict() == NULL
|| player->IsFakeClient())
{
return false;
}
return CheckAdminCommandAccess(player->GetAdminId(), cmd, cmdflags);
}
bool ConCmdManager::CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits cmdflags)
{
if (adm != INVALID_ADMIN_ID)
{
FlagBits bits = g_Admins.GetAdminFlags(adm, Access_Effective);
/* root knows all, WHOA */
if ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT)
{
return true;
}
/* Check for overrides
* :TODO: is it worth optimizing this?
*/
unsigned int groups = g_Admins.GetAdminGroupCount(adm);
GroupId gid;
OverrideRule rule;
bool override = false;
for (unsigned int i=0; i<groups; i++)
{
gid = g_Admins.GetAdminGroup(adm, i, NULL);
/* First get group-level override */
override = g_Admins.GetGroupCommandOverride(gid, cmd, Override_CommandGroup, &rule);
/* Now get the specific command override */
if (g_Admins.GetGroupCommandOverride(gid, cmd, Override_Command, &rule))
{
override = true;
}
if (override)
{
if (rule == Command_Allow)
{
return true;
}
else if (rule == Command_Deny)
{
return false;
}
}
}
/* See if our other flags match */
if ((bits & cmdflags) == cmdflags)
{
return true;
}
}
return false;
}
bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin) bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin)
{ {
if (CheckClientCommandAccess(client, cmd, pAdmin->eflags)) if (adminsys->CheckClientCommandAccess(client, cmd, pAdmin->eflags))
{ {
return true; return true;
} }
@ -468,12 +391,12 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
pHook->admin = new AdminCmdInfo(cmdgroup, adminflags); pHook->admin = new AdminCmdInfo(cmdgroup, adminflags);
/* First get the command group override, if any */ /* First get the command group override, if any */
bool override = g_Admins.GetCommandOverride(group, bool override = adminsys->GetCommandOverride(group,
Override_CommandGroup, Override_CommandGroup,
&(pHook->admin->eflags)); &(pHook->admin->eflags));
/* Next get the command override, if any */ /* Next get the command override, if any */
if (g_Admins.GetCommandOverride(name, if (adminsys->GetCommandOverride(name,
Override_Command, Override_Command,
&(pHook->admin->eflags))) &(pHook->admin->eflags)))
{ {

View File

@ -146,8 +146,6 @@ public:
void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove); void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove);
bool LookForSourceModCommand(const char *cmd); bool LookForSourceModCommand(const char *cmd);
bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags); bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
bool CheckClientCommandAccess(int client, const char *cmd, FlagBits flags);
bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags);
private: private:
void InternalDispatch(const CCommand &command); void InternalDispatch(const CCommand &command);
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args); ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);

View File

@ -30,7 +30,7 @@
*/ */
#include "PlayerManager.h" #include "PlayerManager.h"
#include "AdminCache.h" #include "IAdminSystem.h"
#include "ConCmdManager.h" #include "ConCmdManager.h"
#include "MenuStyle_Valve.h" #include "MenuStyle_Valve.h"
#include "MenuStyle_Radio.h" #include "MenuStyle_Radio.h"
@ -333,7 +333,7 @@ bool PlayerManager::IsServerActivated()
bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id) bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
{ {
const char *password = g_Admins.GetAdminPassword(id); const char *password = adminsys->GetAdminPassword(id);
if (password != NULL) if (password != NULL)
{ {
if (m_PassInfoVar.size() < 1) if (m_PassInfoVar.size() < 1)
@ -356,7 +356,7 @@ bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
bool PlayerManager::CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id) bool PlayerManager::CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id)
{ {
const char *password = g_Admins.GetAdminPassword(id); const char *password = adminsys->GetAdminPassword(id);
if (password == NULL) if (password == NULL)
{ {
return false; return false;
@ -1183,7 +1183,7 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity)
if (strcmp(old_name, new_name) != 0) if (strcmp(old_name, new_name) != 0)
{ {
AdminId id = g_Admins.FindAdminByIdentity("name", new_name); AdminId id = adminsys->FindAdminByIdentity("name", new_name);
if (id != INVALID_ADMIN_ID && pPlayer->GetAdminId() != id) if (id != INVALID_ADMIN_ID && pPlayer->GetAdminId() != id)
{ {
if (!CheckSetAdminName(client, pPlayer, id)) if (!CheckSetAdminName(client, pPlayer, id))
@ -1193,7 +1193,7 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity)
pPlayer->Kick(kickMsg); pPlayer->Kick(kickMsg);
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
} else if ((id = g_Admins.FindAdminByIdentity("name", old_name)) != INVALID_ADMIN_ID) { } else if ((id = adminsys->FindAdminByIdentity("name", old_name)) != INVALID_ADMIN_ID) {
if (id == pPlayer->GetAdminId()) if (id == pPlayer->GetAdminId())
{ {
/* This player is changing their name; force them to drop admin privileges! */ /* This player is changing their name; force them to drop admin privileges! */
@ -1327,14 +1327,6 @@ void PlayerManager::ClearAdminId(AdminId id)
} }
} }
void PlayerManager::ClearAllAdmins()
{
for (int i=1; i<=m_maxClients; i++)
{
m_Players[i].DumpAdmin(true);
}
}
const char *PlayerManager::GetPassInfoVar() const char *PlayerManager::GetPassInfoVar()
{ {
return m_PassInfoVar.c_str(); return m_PassInfoVar.c_str();
@ -1425,7 +1417,7 @@ int PlayerManager::InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget
if (pAdmin != NULL) if (pAdmin != NULL)
{ {
if ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY if ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY
&& !g_Admins.CanAdminTarget(pAdmin->GetAdminId(), pTarget->GetAdminId())) && !adminsys->CanAdminTarget(pAdmin->GetAdminId(), pTarget->GetAdminId()))
{ {
return COMMAND_TARGET_IMMUNE; return COMMAND_TARGET_IMMUNE;
} }
@ -2076,13 +2068,18 @@ AdminId CPlayer::GetAdminId()
return m_Admin; return m_Admin;
} }
void CPlayer::ClearAdmin()
{
DumpAdmin(true);
}
void CPlayer::DumpAdmin(bool deleting) void CPlayer::DumpAdmin(bool deleting)
{ {
if (m_Admin != INVALID_ADMIN_ID) if (m_Admin != INVALID_ADMIN_ID)
{ {
if (m_TempAdmin && !deleting) if (m_TempAdmin && !deleting)
{ {
g_Admins.InvalidateAdmin(m_Admin); adminsys->InvalidateAdmin(m_Admin);
} }
m_Admin = INVALID_ADMIN_ID; m_Admin = INVALID_ADMIN_ID;
m_TempAdmin = false; m_TempAdmin = false;
@ -2225,7 +2222,7 @@ void CPlayer::DoBasicAdminChecks()
AdminId id; AdminId id;
int client = IndexOfEdict(m_pEdict); int client = IndexOfEdict(m_pEdict);
if ((id = g_Admins.FindAdminByIdentity("name", GetName())) != INVALID_ADMIN_ID) if ((id = adminsys->FindAdminByIdentity("name", GetName())) != INVALID_ADMIN_ID)
{ {
if (!g_Players.CheckSetAdminName(client, this, id)) if (!g_Players.CheckSetAdminName(client, this, id))
{ {
@ -2236,7 +2233,7 @@ void CPlayer::DoBasicAdminChecks()
} }
/* Check IP */ /* Check IP */
if ((id = g_Admins.FindAdminByIdentity("ip", m_IpNoPort.c_str())) != INVALID_ADMIN_ID) if ((id = adminsys->FindAdminByIdentity("ip", m_IpNoPort.c_str())) != INVALID_ADMIN_ID)
{ {
if (g_Players.CheckSetAdmin(client, this, id)) if (g_Players.CheckSetAdmin(client, this, id))
{ {
@ -2245,7 +2242,7 @@ void CPlayer::DoBasicAdminChecks()
} }
/* Check steam id */ /* Check steam id */
if ((id = g_Admins.FindAdminByIdentity("steam", m_AuthID.c_str())) != INVALID_ADMIN_ID) if ((id = adminsys->FindAdminByIdentity("steam", m_AuthID.c_str())) != INVALID_ADMIN_ID)
{ {
if (g_Players.CheckSetAdmin(client, this, id)) if (g_Players.CheckSetAdmin(client, this, id))
{ {

View File

@ -92,6 +92,7 @@ public:
unsigned int GetSerial(); unsigned int GetSerial();
int GetIndex() const; int GetIndex() const;
void PrintToConsole(const char *pMsg); void PrintToConsole(const char *pMsg);
void ClearAdmin();
public: public:
void DoBasicAdminChecks(); void DoBasicAdminChecks();
void MarkAsBeingKicked(); void MarkAsBeingKicked();
@ -149,8 +150,6 @@ public: //SMGlobalClass
public: public:
CPlayer *GetPlayerByIndex(int client) const; CPlayer *GetPlayerByIndex(int client) const;
void RunAuthChecks(); void RunAuthChecks();
void ClearAdminId(AdminId id);
void ClearAllAdmins();
public: public:
#if SOURCE_ENGINE == SE_DOTA #if SOURCE_ENGINE == SE_DOTA
bool OnClientConnect(CEntityIndex index, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); bool OnClientConnect(CEntityIndex index, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
@ -190,6 +189,8 @@ public: //IPlayerManager
void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler); void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
void ProcessCommandTarget(cmd_target_info_t *info); void ProcessCommandTarget(cmd_target_info_t *info);
int GetClientFromSerial(unsigned int serial); int GetClientFromSerial(unsigned int serial);
void ClearAdminId(AdminId id);
void RecheckAnyAdmins();
public: public:
inline int MaxClients() inline int MaxClients()
{ {
@ -206,7 +207,6 @@ public:
bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id); bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id); bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
const char *GetPassInfoVar(); const char *GetPassInfoVar();
void RecheckAnyAdmins();
unsigned int GetReplyTo(); unsigned int GetReplyTo();
unsigned int SetReplyTo(unsigned int reply); unsigned int SetReplyTo(unsigned int reply);
void MaxPlayersChanged(int newvalue = -1); void MaxPlayersChanged(int newvalue = -1);

View File

@ -63,6 +63,9 @@ binary.sources += [
'Database.cpp', 'Database.cpp',
'smn_database.cpp', 'smn_database.cpp',
'ForwardSys.cpp', 'ForwardSys.cpp',
'AdminCache.cpp',
'sm_trie.cpp',
'smn_console.cpp',
] ]
if builder.target_platform == 'windows': if builder.target_platform == 'windows':
binary.sources += ['thread/WinThreads.cpp'] binary.sources += ['thread/WinThreads.cpp']

File diff suppressed because it is too large Load Diff

View File

@ -1,224 +1,226 @@
/** /**
* vim: set ts=4 sw=4 tw=99 noet : * vim: set ts=4 sw=4 tw=99 noet :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_ #ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_ #define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
#include "sm_memtable.h" #include "common_logic.h"
#include <sm_trie.h> #include <IAdminSystem.h>
#include <sh_list.h> #include "sm_memtable.h"
#include <sh_string.h> #include <sm_trie.h>
#include <IAdminSystem.h> #include <sh_list.h>
#include "sm_globals.h" #include <sh_string.h>
#include <IForwardSys.h> #include <IForwardSys.h>
#include <sm_stringhashmap.h> #include <sm_stringhashmap.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
using namespace SourceHook; using namespace SourceHook;
#define GRP_MAGIC_SET 0xDEADFADE #define GRP_MAGIC_SET 0xDEADFADE
#define GRP_MAGIC_UNSET 0xFACEFACE #define GRP_MAGIC_UNSET 0xFACEFACE
#define USR_MAGIC_SET 0xDEADFACE #define USR_MAGIC_SET 0xDEADFACE
#define USR_MAGIC_UNSET 0xFADEDEAD #define USR_MAGIC_UNSET 0xFADEDEAD
typedef StringHashMap<OverrideRule> OverrideMap; typedef StringHashMap<OverrideRule> OverrideMap;
struct AdminGroup struct AdminGroup
{ {
uint32_t magic; /* Magic flag, for memory validation (ugh) */ uint32_t magic; /* Magic flag, for memory validation (ugh) */
unsigned int immunity_level; /* Immunity level */ unsigned int immunity_level; /* Immunity level */
/* Immune from target table (-1 = nonexistent) /* Immune from target table (-1 = nonexistent)
* [0] = number of entries * [0] = number of entries
* [1...N] = immune targets * [1...N] = immune targets
*/ */
int immune_table; int immune_table;
OverrideMap *pCmdTable; /* Command override table (can be NULL) */ OverrideMap *pCmdTable; /* Command override table (can be NULL) */
OverrideMap *pCmdGrpTable; /* Command group override table (can be NULL) */ OverrideMap *pCmdGrpTable; /* Command group override table (can be NULL) */
int next_grp; /* Next group in the chain */ int next_grp; /* Next group in the chain */
int prev_grp; /* Previous group in the chain */ int prev_grp; /* Previous group in the chain */
int nameidx; /* Name */ int nameidx; /* Name */
FlagBits addflags; /* Additive flags */ FlagBits addflags; /* Additive flags */
}; };
struct AuthMethod struct AuthMethod
{ {
String name; String name;
StringHashMap<AdminId> identities; StringHashMap<AdminId> identities;
AuthMethod(const char *name) AuthMethod(const char *name)
: name(name) : name(name)
{ {
} }
static inline bool matches(const char *name, const AuthMethod *method) static inline bool matches(const char *name, const AuthMethod *method)
{ {
return strcmp(name, method->name.c_str()) == 0; return strcmp(name, method->name.c_str()) == 0;
} }
}; };
struct UserAuth struct UserAuth
{ {
unsigned int index; /* Index into auth table */ unsigned int index; /* Index into auth table */
int identidx; /* Index into the string table */ int identidx; /* Index into the string table */
}; };
struct AdminUser struct AdminUser
{ {
uint32_t magic; /* Magic flag, for memory validation */ uint32_t magic; /* Magic flag, for memory validation */
FlagBits flags; /* Flags */ FlagBits flags; /* Flags */
FlagBits eflags; /* Effective flags */ FlagBits eflags; /* Effective flags */
int nameidx; /* Name index */ int nameidx; /* Name index */
int password; /* Password index */ int password; /* Password index */
unsigned int grp_count; /* Number of groups */ unsigned int grp_count; /* Number of groups */
unsigned int grp_size; /* Size of groups table */ unsigned int grp_size; /* Size of groups table */
int grp_table; /* Group table itself */ int grp_table; /* Group table itself */
int next_user; /* Next user in the list */ int next_user; /* Next user in the list */
int prev_user; /* Previous user in the list */ int prev_user; /* Previous user in the list */
UserAuth auth; /* Auth method for this user */ UserAuth auth; /* Auth method for this user */
unsigned int immunity_level; /* Immunity level */ unsigned int immunity_level; /* Immunity level */
unsigned int serialchange; /* Serial # for changes */ unsigned int serialchange; /* Serial # for changes */
}; };
class AdminCache : class AdminCache :
public IAdminSystem, public IAdminSystem,
public SMGlobalClass public SMGlobalClass
{ {
public: public:
AdminCache(); AdminCache();
~AdminCache(); ~AdminCache();
public: //SMGlobalClass public: //SMGlobalClass
void OnSourceModStartup(bool late); void OnSourceModStartup(bool late);
void OnSourceModAllInitialized(); void OnSourceModAllInitialized();
void OnSourceModLevelChange(const char *mapName); void OnSourceModLevelChange(const char *mapName);
void OnSourceModShutdown(); void OnSourceModShutdown();
void OnSourceModPluginsLoaded(); void OnSourceModPluginsLoaded();
public: //IAdminSystem public: //IAdminSystem
/** Command cache stuff */ /** Command cache stuff */
void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags); void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags); bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
void UnsetCommandOverride(const char *cmd, OverrideType type); void UnsetCommandOverride(const char *cmd, OverrideType type);
/** Group cache stuff */ /** Group cache stuff */
GroupId AddGroup(const char *group_name); GroupId AddGroup(const char *group_name);
GroupId FindGroupByName(const char *group_name); GroupId FindGroupByName(const char *group_name);
void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled); void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
bool GetGroupAddFlag(GroupId id, AdminFlag flag); bool GetGroupAddFlag(GroupId id, AdminFlag flag);
FlagBits GetGroupAddFlags(GroupId id); FlagBits GetGroupAddFlags(GroupId id);
void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled); void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
bool GetGroupGenericImmunity(GroupId id, ImmunityType type); bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
void InvalidateGroup(GroupId id); void InvalidateGroup(GroupId id);
void AddGroupImmunity(GroupId id, GroupId other_id); void AddGroupImmunity(GroupId id, GroupId other_id);
unsigned int GetGroupImmunityCount(GroupId id); unsigned int GetGroupImmunityCount(GroupId id);
GroupId GetGroupImmunity(GroupId id, unsigned int number); GroupId GetGroupImmunity(GroupId id, unsigned int number);
void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule); void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule); bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
void DumpAdminCache(AdminCachePart part, bool rebuild); void DumpAdminCache(AdminCachePart part, bool rebuild);
void AddAdminListener(IAdminListener *pListener); void AddAdminListener(IAdminListener *pListener);
void RemoveAdminListener(IAdminListener *pListener); void RemoveAdminListener(IAdminListener *pListener);
/** User stuff */ /** User stuff */
void RegisterAuthIdentType(const char *name); void RegisterAuthIdentType(const char *name);
AdminId CreateAdmin(const char *name); AdminId CreateAdmin(const char *name);
const char *GetAdminName(AdminId id); const char *GetAdminName(AdminId id);
bool BindAdminIdentity(AdminId id, const char *auth, const char *ident); bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled); virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode); bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
FlagBits GetAdminFlags(AdminId id, AccessMode mode); FlagBits GetAdminFlags(AdminId id, AccessMode mode);
bool AdminInheritGroup(AdminId id, GroupId gid); bool AdminInheritGroup(AdminId id, GroupId gid);
unsigned int GetAdminGroupCount(AdminId id); unsigned int GetAdminGroupCount(AdminId id);
GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name); GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
void SetAdminPassword(AdminId id, const char *password); void SetAdminPassword(AdminId id, const char *password);
const char *GetAdminPassword(AdminId id); const char *GetAdminPassword(AdminId id);
AdminId FindAdminByIdentity(const char *auth, const char *identity); AdminId FindAdminByIdentity(const char *auth, const char *identity);
bool InvalidateAdmin(AdminId id); bool InvalidateAdmin(AdminId id);
unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize); unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize); FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags); FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize); unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
bool CheckAdminFlags(AdminId id, FlagBits bits); bool CheckAdminFlags(AdminId id, FlagBits bits);
bool CanAdminTarget(AdminId id, AdminId target); bool CanAdminTarget(AdminId id, AdminId target);
void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits); void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
bool FindFlag(const char *str, AdminFlag *pFlag); bool FindFlag(const char *str, AdminFlag *pFlag);
bool FindFlag(char c, AdminFlag *pAdmFlag); bool FindFlag(char c, AdminFlag *pAdmFlag);
FlagBits ReadFlagString(const char *flags, const char **end); FlagBits ReadFlagString(const char *flags, const char **end);
size_t FillFlagString(FlagBits bits, char *buffer, size_t maxlen); size_t FillFlagString(FlagBits bits, char *buffer, size_t maxlen);
unsigned int GetAdminSerialChange(AdminId id); unsigned int GetAdminSerialChange(AdminId id);
bool CanAdminUseCommand(int client, const char *cmd); bool CanAdminUseCommand(int client, const char *cmd);
const char *GetGroupName(GroupId gid); const char *GetGroupName(GroupId gid);
unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level); unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level);
unsigned int GetGroupImmunityLevel(GroupId gid); unsigned int GetGroupImmunityLevel(GroupId gid);
unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level); unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level);
unsigned int GetAdminImmunityLevel(AdminId id); unsigned int GetAdminImmunityLevel(AdminId id);
bool CheckAccess(int client, bool CheckAccess(int client,
const char *cmd, const char *cmd,
FlagBits flags, FlagBits flags,
bool override_only); bool override_only);
bool FindFlagChar(AdminFlag flag, char *c); bool FindFlagChar(AdminFlag flag, char *c);
bool IsValidAdmin(AdminId id); bool IsValidAdmin(AdminId id);
public: bool CheckClientCommandAccess(int client, const char *cmd, FlagBits cmdflags);
void DumpCache(FILE *fp); public:
AdminGroup *GetGroup(GroupId gid); void DumpCache(FILE *fp);
AdminUser *GetUser(AdminId id); AdminGroup *GetGroup(GroupId gid);
const char *GetString(int idx); AdminUser *GetUser(AdminId id);
private: const char *GetString(int idx);
void _UnsetCommandOverride(const char *cmd); bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags);
void _UnsetCommandGroupOverride(const char *group); private:
void InvalidateGroupCache(); void _UnsetCommandOverride(const char *cmd);
void InvalidateAdminCache(bool unlink_admins); void _UnsetCommandGroupOverride(const char *group);
void DumpCommandOverrideCache(OverrideType type); void InvalidateGroupCache();
AuthMethod *GetMethodByIndex(unsigned int index); void InvalidateAdminCache(bool unlink_admins);
bool GetMethodIndex(const char *name, unsigned int *_index); void DumpCommandOverrideCache(OverrideType type);
const char *GetMethodName(unsigned int index); AuthMethod *GetMethodByIndex(unsigned int index);
void NameFlag(const char *str, AdminFlag flag); bool GetMethodIndex(const char *name, unsigned int *_index);
public: const char *GetMethodName(unsigned int index);
typedef StringHashMap<FlagBits> FlagMap; void NameFlag(const char *str, AdminFlag flag);
public:
BaseStringTable *m_pStrings; typedef StringHashMap<FlagBits> FlagMap;
BaseMemTable *m_pMemory;
FlagMap m_CmdOverrides; BaseStringTable *m_pStrings;
FlagMap m_CmdGrpOverrides; BaseMemTable *m_pMemory;
int m_FirstGroup; FlagMap m_CmdOverrides;
int m_LastGroup; FlagMap m_CmdGrpOverrides;
int m_FreeGroupList; int m_FirstGroup;
StringHashMap<GroupId> m_Groups; int m_LastGroup;
List<IAdminListener *> m_hooks; int m_FreeGroupList;
List<AuthMethod *> m_AuthMethods; StringHashMap<GroupId> m_Groups;
NameHashSet<AuthMethod *> m_AuthTables; List<IAdminListener *> m_hooks;
IForward *m_pCacheFwd; List<AuthMethod *> m_AuthMethods;
int m_FirstUser; NameHashSet<AuthMethod *> m_AuthTables;
int m_LastUser; IForward *m_pCacheFwd;
int m_FreeUserList; int m_FirstUser;
bool m_InvalidatingAdmins; int m_LastUser;
bool m_destroying; int m_FreeUserList;
StringHashMap<AdminFlag> m_LevelNames; bool m_InvalidatingAdmins;
}; bool m_destroying;
StringHashMap<AdminFlag> m_LevelNames;
extern AdminCache g_Admins; };
#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_ extern AdminCache g_Admins;
#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_

View File

@ -49,6 +49,7 @@
#include "HandleSys.h" #include "HandleSys.h"
#include "ExtensionSys.h" #include "ExtensionSys.h"
#include "ForwardSys.h" #include "ForwardSys.h"
#include "AdminCache.h"
sm_core_t smcore; sm_core_t smcore;
IHandleSys *handlesys = &g_HandleSys; IHandleSys *handlesys = &g_HandleSys;
@ -65,7 +66,7 @@ IForwardManager *forwardsys = &g_Forwards;
ITimerSystem *timersys; ITimerSystem *timersys;
ServerGlobals serverGlobals; ServerGlobals serverGlobals;
IPlayerManager *playerhelpers; IPlayerManager *playerhelpers;
IAdminSystem *adminsys; IAdminSystem *adminsys = &g_Admins;
IGameHelpers *gamehelpers; IGameHelpers *gamehelpers;
ISourcePawnEngine *g_pSourcePawn; ISourcePawnEngine *g_pSourcePawn;
ISourcePawnEngine2 *g_pSourcePawn2; ISourcePawnEngine2 *g_pSourcePawn2;
@ -103,6 +104,11 @@ static void DumpHandles(void (*dumpfn)(const char *fmt, ...))
g_HandleSys.Dump(dumpfn); g_HandleSys.Dump(dumpfn);
} }
static void DumpAdminCache(FILE *f)
{
g_Admins.DumpCache(f);
}
static sm_logic_t logic = static sm_logic_t logic =
{ {
NULL, NULL,
@ -121,11 +127,13 @@ static sm_logic_t logic =
GenerateError, GenerateError,
AddNatives, AddNatives,
DumpHandles, DumpHandles,
DumpAdminCache,
&g_PluginSys, &g_PluginSys,
&g_ShareSys, &g_ShareSys,
&g_Extensions, &g_Extensions,
&g_HandleSys, &g_HandleSys,
&g_Forwards, &g_Forwards,
&g_Admins,
NULL, NULL,
-1.0f -1.0f
}; };
@ -144,7 +152,6 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
rootmenu = core->rootmenu; rootmenu = core->rootmenu;
timersys = core->timersys; timersys = core->timersys;
playerhelpers = core->playerhelpers; playerhelpers = core->playerhelpers;
adminsys = core->adminsys;
gamehelpers = core->gamehelpers; gamehelpers = core->gamehelpers;
g_pSourcePawn = *core->spe1; g_pSourcePawn = *core->spe1;
g_pSourcePawn2 = *core->spe2; g_pSourcePawn2 = *core->spe2;

View File

@ -42,6 +42,7 @@
#include <sh_vector.h> #include <sh_vector.h>
#include <IExtensionSys.h> #include <IExtensionSys.h>
#include <IForwardSys.h> #include <IForwardSys.h>
#include <IAdminSystem.h>
using namespace SourceMod; using namespace SourceMod;
using namespace SourcePawn; using namespace SourcePawn;
@ -51,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 27) #define SM_LOGIC_MAGIC (0x0F47C0DE - 28)
#if defined SM_LOGIC #if defined SM_LOGIC
class IVEngineServer class IVEngineServer
@ -61,8 +62,13 @@ class IVEngineServer_Logic
{ {
public: public:
virtual bool IsMapValid(const char *map) = 0; virtual bool IsMapValid(const char *map) = 0;
virtual bool IsDedicatedServer() = 0;
virtual void InsertServerCommand(const char *cmd) = 0;
virtual void ServerCommand(const char *cmd) = 0; virtual void ServerCommand(const char *cmd) = 0;
virtual void ServerExecute() = 0;
virtual const char *GetClientConVarValue(int clientIndex, const char *name) = 0; virtual const char *GetClientConVarValue(int clientIndex, const char *name) = 0;
virtual void ClientCommand(edict_t *pEdict, const char *szCommand) = 0;
virtual void FakeClientCommand(edict_t *pEdict, const char *szCommand) = 0;
}; };
typedef void * FileHandle_t; typedef void * FileHandle_t;
@ -260,7 +266,6 @@ struct sm_core_t
IRootConsole *rootmenu; IRootConsole *rootmenu;
ITimerSystem *timersys; ITimerSystem *timersys;
IPlayerManager *playerhelpers; IPlayerManager *playerhelpers;
IAdminSystem *adminsys;
IGameHelpers *gamehelpers; IGameHelpers *gamehelpers;
ISourcePawnEngine **spe1; ISourcePawnEngine **spe1;
ISourcePawnEngine2 **spe2; ISourcePawnEngine2 **spe2;
@ -296,6 +301,9 @@ struct sm_core_t
void (*ExecuteConfigs)(IPluginContext *ctx); void (*ExecuteConfigs)(IPluginContext *ctx);
DatabaseInfo (*GetDBInfoFromKeyValues)(KeyValues *); DatabaseInfo (*GetDBInfoFromKeyValues)(KeyValues *);
int (*GetActivityFlags)(); int (*GetActivityFlags)();
int (*GetImmunityMode)();
void (*UpdateAdminCmdFlags)(const char *cmd, OverrideType type, FlagBits bits, bool remove);
bool (*LookForCommandAdminFlags)(const char *cmd, FlagBits *pFlags);
const char *gamesuffix; const char *gamesuffix;
/* Data */ /* Data */
ServerGlobals *serverGlobals; ServerGlobals *serverGlobals;
@ -323,11 +331,13 @@ struct sm_logic_t
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...); void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
void (*AddNatives)(sp_nativeinfo_t *natives); void (*AddNatives)(sp_nativeinfo_t *natives);
void (*DumpHandles)(void (*dumpfn)(const char *fmt, ...)); void (*DumpHandles)(void (*dumpfn)(const char *fmt, ...));
void (*DumpAdminCache)(FILE *);
IScriptManager *scripts; IScriptManager *scripts;
IShareSys *sharesys; IShareSys *sharesys;
IExtensionSys *extsys; IExtensionSys *extsys;
IHandleSys *handlesys; IHandleSys *handlesys;
IForwardManager *forwardsys; IForwardManager *forwardsys;
IAdminSystem *adminsys;
IdentityToken_t *core_ident; IdentityToken_t *core_ident;
float sentinel; float sentinel;
}; };

View File

@ -1,121 +1,121 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <sm_trie_tpl.h> #include <sm_trie_tpl.h>
#include "sm_trie.h" #include "sm_trie.h"
struct Trie struct Trie
{ {
KTrie<void *> k; KTrie<void *> k;
}; };
Trie *sm_trie_create() Trie *sm_trie_create()
{ {
return new Trie; return new Trie;
} }
void sm_trie_destroy(Trie *trie) void sm_trie_destroy(Trie *trie)
{ {
delete trie; delete trie;
} }
bool sm_trie_insert(Trie *trie, const char *key, void *value) bool sm_trie_insert(Trie *trie, const char *key, void *value)
{ {
return trie->k.insert(key, value); return trie->k.insert(key, value);
} }
bool sm_trie_replace(Trie *trie, const char *key, void *value) bool sm_trie_replace(Trie *trie, const char *key, void *value)
{ {
return trie->k.replace(key, value); return trie->k.replace(key, value);
} }
bool sm_trie_retrieve(Trie *trie, const char *key, void **value) bool sm_trie_retrieve(Trie *trie, const char *key, void **value)
{ {
void **pValue = trie->k.retrieve(key); void **pValue = trie->k.retrieve(key);
if (!pValue) if (!pValue)
{ {
return false; return false;
} }
if (value) if (value)
{ {
*value = *pValue; *value = *pValue;
} }
return true; return true;
} }
bool sm_trie_delete(Trie *trie, const char *key) bool sm_trie_delete(Trie *trie, const char *key)
{ {
return trie->k.remove(key); return trie->k.remove(key);
} }
void sm_trie_clear(Trie *trie) void sm_trie_clear(Trie *trie)
{ {
trie->k.clear(); trie->k.clear();
} }
size_t sm_trie_mem_usage(Trie *trie) size_t sm_trie_mem_usage(Trie *trie)
{ {
return trie->k.mem_usage(); return trie->k.mem_usage();
} }
struct trie_iter_data struct trie_iter_data
{ {
SM_TRIE_BAD_ITERATOR iter; SM_TRIE_BAD_ITERATOR iter;
void *ptr; void *ptr;
Trie *pTrie; Trie *pTrie;
}; };
void our_trie_iterator(KTrie<void *> *pTrie, const char *name, void *& obj, void *data) void our_trie_iterator(KTrie<void *> *pTrie, const char *name, void *& obj, void *data)
{ {
trie_iter_data *our_iter; trie_iter_data *our_iter;
our_iter = (trie_iter_data *)data; our_iter = (trie_iter_data *)data;
our_iter->iter(our_iter->pTrie, name, &obj, our_iter->ptr); our_iter->iter(our_iter->pTrie, name, &obj, our_iter->ptr);
} }
void sm_trie_bad_iterator(Trie *trie, void sm_trie_bad_iterator(Trie *trie,
char *buffer, char *buffer,
size_t maxlength, size_t maxlength,
SM_TRIE_BAD_ITERATOR iter, SM_TRIE_BAD_ITERATOR iter,
void *data) void *data)
{ {
trie_iter_data our_iter; trie_iter_data our_iter;
our_iter.iter = iter; our_iter.iter = iter;
our_iter.ptr = data; our_iter.ptr = data;
our_iter.pTrie = trie; our_iter.pTrie = trie;
trie->k.bad_iterator(buffer, maxlength, &our_iter, our_trie_iterator); trie->k.bad_iterator(buffer, maxlength, &our_iter, our_trie_iterator);
} }

View File

@ -1,53 +1,53 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 :
* ============================================================================= * =============================================================================
* SourceMod * SourceMod
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#ifndef _INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_ #ifndef _INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_
#define _INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_ #define _INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_
struct Trie; struct Trie;
typedef void (*SM_TRIE_BAD_ITERATOR)(Trie *pTrie, const char *key, void **value, void *data); typedef void (*SM_TRIE_BAD_ITERATOR)(Trie *pTrie, const char *key, void **value, void *data);
Trie *sm_trie_create(); Trie *sm_trie_create();
void sm_trie_destroy(Trie *trie); void sm_trie_destroy(Trie *trie);
bool sm_trie_insert(Trie *trie, const char *key, void *value); bool sm_trie_insert(Trie *trie, const char *key, void *value);
bool sm_trie_replace(Trie *trie, const char *key, void *value); bool sm_trie_replace(Trie *trie, const char *key, void *value);
bool sm_trie_retrieve(Trie *trie, const char *key, void **value); bool sm_trie_retrieve(Trie *trie, const char *key, void **value);
bool sm_trie_delete(Trie *trie, const char *key); bool sm_trie_delete(Trie *trie, const char *key);
void sm_trie_clear(Trie *trie); void sm_trie_clear(Trie *trie);
size_t sm_trie_mem_usage(Trie *trie); size_t sm_trie_mem_usage(Trie *trie);
void sm_trie_bad_iterator(Trie *trie, void sm_trie_bad_iterator(Trie *trie,
char *buffer, char *buffer,
size_t maxlength, size_t maxlength,
SM_TRIE_BAD_ITERATOR iter, SM_TRIE_BAD_ITERATOR iter,
void *data); void *data);
#endif //_INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_ #endif //_INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_

347
core/logic/smn_console.cpp Normal file
View File

@ -0,0 +1,347 @@
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include "common_logic.h"
#include "AdminCache.h"
#include <IGameHelpers.h>
#include <IPlayerHelpers.h>
#include <ISourceMod.h>
#include <ITranslator.h>
static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
{
if (params[1] == 0)
{
return 1;
}
char *cmd;
pContext->LocalToString(params[2], &cmd);
/* Match up with an admin command if possible */
FlagBits bits = params[3];
bool found_command = false;
if (params[0] < 4 || !params[4])
{
found_command = smcore.LookForCommandAdminFlags(cmd, &bits);
}
if (!found_command)
{
adminsys->GetCommandOverride(cmd, Override_Command, &bits);
}
return adminsys->CheckClientCommandAccess(params[1], cmd, bits) ? 1 : 0;
}
static cell_t CheckAccess(IPluginContext *pContext, const cell_t *params)
{
char *cmd;
pContext->LocalToString(params[2], &cmd);
/* Match up with an admin command if possible */
FlagBits bits = params[3];
bool found_command = false;
if (params[0] < 4 || !params[4])
{
found_command = smcore.LookForCommandAdminFlags(cmd, &bits);
}
if (!found_command)
{
adminsys->GetCommandOverride(cmd, Override_Command, &bits);
}
return g_Admins.CheckAdminCommandAccess(params[1], cmd, bits) ? 1 : 0;
}
static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
{
char buffer[1024];
char *fmt;
int arg = 2;
pCtx->LocalToString(params[1], &fmt);
size_t res = smcore.atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
buffer[res++] = '\n';
buffer[res] = '\0';
smcore.ConPrint(buffer);
return 1;
}
static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
{
int index = params[1];
if ((index < 0) || (index > playerhelpers->GetMaxClients()))
{
return pCtx->ThrowNativeError("Client index %d is invalid", index);
}
IGamePlayer *pPlayer = NULL;
if (index != 0)
{
pPlayer = playerhelpers->GetGamePlayer(index);
if (!pPlayer->IsInGame())
{
return pCtx->ThrowNativeError("Client %d is not in game", index);
}
/* Silent fail on bots, engine will crash */
if (pPlayer->IsFakeClient())
{
return 0;
}
}
char buffer[1024];
char *fmt;
int arg = 3;
pCtx->LocalToString(params[2], &fmt);
size_t res = smcore.atcprintf(buffer, sizeof(buffer) - 2, fmt, pCtx, params, &arg);
buffer[res++] = '\n';
buffer[res] = '\0';
if (index != 0)
{
pPlayer->PrintToConsole(buffer);
}
else {
smcore.ConPrint(buffer);
}
return 1;
}
static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params)
{
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
char buffer[1024];
size_t len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 1);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
/* One byte for null terminator, one for newline */
buffer[len++] = '\n';
buffer[len] = '\0';
engine->ServerCommand(buffer);
return 1;
}
static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params)
{
g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
char buffer[1024];
size_t len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 1);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
/* One byte for null terminator, one for newline */
buffer[len++] = '\n';
buffer[len] = '\0';
engine->InsertServerCommand(buffer);
return 1;
}
static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
{
engine->ServerExecute();
return 1;
}
static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
{
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
g_pSM->SetGlobalTarget(params[1]);
char buffer[256];
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
engine->ClientCommand(pPlayer->GetEdict(), buffer);
return 1;
}
static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
{
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
g_pSM->SetGlobalTarget(params[1]);
char buffer[256];
g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
engine->FakeClientCommand(pPlayer->GetEdict(), buffer);
return 1;
}
static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params)
{
g_pSM->SetGlobalTarget(params[1]);
/* Build the format string */
char buffer[1024];
size_t len = g_pSM->FormatString(buffer, sizeof(buffer) - 2, pContext, params, 2);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
/* If we're printing to the server, shortcut out */
if (params[1] == 0)
{
/* Print */
buffer[len++] = '\n';
buffer[len] = '\0';
smcore.ConPrint(buffer);
return 1;
}
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
unsigned int replyto = playerhelpers->GetReplyTo();
if (replyto == SM_REPLY_CONSOLE)
{
buffer[len++] = '\n';
buffer[len] = '\0';
pPlayer->PrintToConsole(buffer);
}
else if (replyto == SM_REPLY_CHAT) {
if (len >= 191)
{
len = 191;
}
buffer[len] = '\0';
gamehelpers->TextMsg(params[1], TEXTMSG_DEST_CHAT, buffer);
}
return 1;
}
static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
{
return playerhelpers->GetReplyTo();
}
static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
{
return playerhelpers->SetReplyTo(params[1]);
}
static cell_t AddServerTag(IPluginContext *pContext, const cell_t *params)
{
return 0;
}
static cell_t RemoveServerTag(IPluginContext *pContext, const cell_t *params)
{
return 0;
}
REGISTER_NATIVES(consoleNatives)
{
{"CheckCommandAccess", CheckCommandAccess},
{"CheckAccess", CheckAccess},
{"PrintToServer", sm_PrintToServer},
{"PrintToConsole", sm_PrintToConsole},
{"ServerCommand", sm_ServerCommand},
{"InsertServerCommand", sm_InsertServerCommand},
{"ServerExecute", sm_ServerExecute},
{"ClientCommand", sm_ClientCommand},
{"FakeClientCommand", FakeClientCommand},
{"ReplyToCommand", ReplyToCommand},
{"GetCmdReplySource", GetCmdReplyTarget},
{"SetCmdReplySource", SetCmdReplyTarget},
{"AddServerTag", AddServerTag},
{"RemoveServerTag", RemoveServerTag},
{NULL, NULL}
};

View File

@ -42,9 +42,9 @@
#include "TimerSys.h" #include "TimerSys.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "AdminCache.h"
#include "HalfLife2.h" #include "HalfLife2.h"
#include "CoreConfig.h" #include "CoreConfig.h"
#include "ConCmdManager.h"
#include "IDBDriver.h" #include "IDBDriver.h"
#if SOURCE_ENGINE == SE_DOTA #if SOURCE_ENGINE == SE_DOTA
#include "convar_sm_dota.h" #include "convar_sm_dota.h"
@ -85,6 +85,7 @@ IShareSys *sharesys;
IExtensionSys *extsys; IExtensionSys *extsys;
IHandleSys *handlesys; IHandleSys *handlesys;
IForwardManager *forwardsys; IForwardManager *forwardsys;
IAdminSystem *adminsys;
class VEngineServer_Logic : public IVEngineServer_Logic class VEngineServer_Logic : public IVEngineServer_Logic
{ {
@ -93,16 +94,42 @@ public:
{ {
return !!engine->IsMapValid(map); return !!engine->IsMapValid(map);
} }
virtual bool IsDedicatedServer()
{
return engine->IsDedicatedServer();
}
virtual void InsertServerCommand(const char *cmd)
{
engine->InsertServerCommand(cmd);
}
virtual void ServerCommand(const char *cmd) virtual void ServerCommand(const char *cmd)
{ {
engine->ServerCommand(cmd); engine->ServerCommand(cmd);
} }
virtual void ServerExecute()
{
engine->ServerExecute();
}
virtual const char *GetClientConVarValue(int clientIndex, const char *name) virtual const char *GetClientConVarValue(int clientIndex, const char *name)
{ {
return engine->GetClientConVarValue(clientIndex, name); return engine->GetClientConVarValue(clientIndex, name);
} }
virtual void ClientCommand(edict_t *pEdict, const char *szCommand)
{
#if SOURCE_ENGINE == SE_DOTA
engine->ClientCommand(IndexOfEdict(pEdict), "%s", szCommand);
#else
engine->ClientCommand(pEdict, "%s", szCommand);
#endif
}
virtual void FakeClientCommand(edict_t *pEdict, const char *szCommand)
{
#if SOURCE_ENGINE == SE_DOTA
engine->ClientCommand(IndexOfEdict(pEdict), "%s", szCommand);
#else
serverpluginhelpers->ClientCommand(pEdict, szCommand);
#endif
}
}; };
static VEngineServer_Logic logic_engine; static VEngineServer_Logic logic_engine;
@ -223,6 +250,7 @@ public:
static VPlayerInfo_Logic logic_playerinfo; static VPlayerInfo_Logic logic_playerinfo;
static ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)"); static ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)");
static ConVar sm_immunity_mode("sm_immunity_mode", "1", FCVAR_SPONLY, "Mode for deciding immunity protection");
static ConVar *find_convar(const char *name) static ConVar *find_convar(const char *name)
{ {
@ -401,6 +429,21 @@ static int get_activity_flags()
return sm_show_activity.GetInt(); return sm_show_activity.GetInt();
} }
static int get_immunity_mode()
{
return sm_immunity_mode.GetInt();
}
static void update_admin_cmd_flags(const char *cmd, OverrideType type, FlagBits bits, bool remove)
{
g_ConCmds.UpdateAdminCmdFlags(cmd, type, bits, remove);
}
static bool look_for_cmd_admin_flags(const char *cmd, FlagBits *pFlags)
{
return g_ConCmds.LookForCommandAdminFlags(cmd, pFlags);
}
int read_cmd_argc(const CCommand &args) int read_cmd_argc(const CCommand &args)
{ {
return args.ArgC(); return args.ArgC();
@ -511,7 +554,6 @@ static sm_core_t core_bridge =
&g_RootMenu, &g_RootMenu,
&g_Timers, &g_Timers,
&g_Players, &g_Players,
&g_Admins,
&g_HL2, &g_HL2,
&g_pSourcePawn, &g_pSourcePawn,
&g_pSourcePawn2, &g_pSourcePawn2,
@ -546,6 +588,9 @@ static sm_core_t core_bridge =
SM_ExecuteForPlugin, SM_ExecuteForPlugin,
keyvalues_to_dbinfo, keyvalues_to_dbinfo,
get_activity_flags, get_activity_flags,
get_immunity_mode,
update_admin_cmd_flags,
look_for_cmd_admin_flags,
GAMEFIX, GAMEFIX,
&serverGlobals, &serverGlobals,
}; };
@ -591,6 +636,7 @@ void InitLogicBridge()
g_pCoreIdent = logicore.core_ident; g_pCoreIdent = logicore.core_ident;
handlesys = logicore.handlesys; handlesys = logicore.handlesys;
forwardsys = logicore.forwardsys; forwardsys = logicore.forwardsys;
adminsys = logicore.adminsys;
} }
bool StartLogicBridge(char *error, size_t maxlength) bool StartLogicBridge(char *error, size_t maxlength)

View File

@ -47,5 +47,6 @@ extern IShareSys *sharesys;
extern IExtensionSys *extsys; extern IExtensionSys *extsys;
extern IHandleSys *handlesys; extern IHandleSys *handlesys;
extern IForwardManager *forwardsys; extern IForwardManager *forwardsys;
extern IAdminSystem *adminsys;
#endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */ #endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */

View File

@ -422,3 +422,23 @@ CON_COMMAND(sm_reload_translations, "Reparses all loaded translation files")
translator->RebuildLanguageDatabase(); translator->RebuildLanguageDatabase();
} }
CON_COMMAND(sm_dump_admcache, "Dumps the admin cache for debugging")
{
FILE *fp;
char buffer[PLATFORM_MAX_PATH];
g_SourceMod.BuildPath(Path_SM, buffer, sizeof(buffer), "data/admin_cache_dump.txt");
if ((fp = fopen(buffer, "wt")) == NULL)
{
g_RootMenu.ConsolePrint("Could not open file for writing: %s", buffer);
return;
}
logicore.DumpAdminCache(fp);
g_RootMenu.ConsolePrint("Admin cache dumped to: %s", buffer);
fclose(fp);
}

View File

@ -38,7 +38,6 @@
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "ChatTriggers.h" #include "ChatTriggers.h"
#include "AdminCache.h"
#include <inetchannel.h> #include <inetchannel.h>
#include <bitbuf.h> #include <bitbuf.h>
#include <tier0/dbg.h> #include <tier0/dbg.h>
@ -831,88 +830,6 @@ static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
return (cell_t)length; return (cell_t)length;
} }
static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params)
{
char buffer[1024];
char *fmt;
int arg = 2;
pCtx->LocalToString(params[1], &fmt);
size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
buffer[res++] = '\n';
buffer[res] = '\0';
META_CONPRINT(buffer);
return 1;
}
static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params)
{
int index = params[1];
if ((index < 0) || (index > g_Players.GetMaxClients()))
{
return pCtx->ThrowNativeError("Client index %d is invalid", index);
}
CPlayer *pPlayer = NULL;
if (index != 0)
{
pPlayer = g_Players.GetPlayerByIndex(index);
if (!pPlayer->IsInGame())
{
return pCtx->ThrowNativeError("Client %d is not in game", index);
}
/* Silent fail on bots, engine will crash */
if (pPlayer->IsFakeClient())
{
return 0;
}
}
char buffer[1024];
char *fmt;
int arg = 3;
pCtx->LocalToString(params[2], &fmt);
size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg);
buffer[res++] = '\n';
buffer[res] = '\0';
if (index != 0)
{
pPlayer->PrintToConsole(buffer);
} else {
META_CONPRINT(buffer);
}
return 1;
}
static cell_t sm_ServerCommand(IPluginContext *pContext, const cell_t *params)
{
g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
char buffer[1024];
size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
/* One byte for null terminator, one for newline */
buffer[len++] = '\n';
buffer[len] = '\0';
engine->ServerCommand(buffer);
return 1;
}
char *g_ServerCommandBuffer = NULL; char *g_ServerCommandBuffer = NULL;
cell_t g_ServerCommandBufferLength; cell_t g_ServerCommandBufferLength;
@ -1031,102 +948,6 @@ static cell_t sm_ServerCommandEx(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
static cell_t sm_InsertServerCommand(IPluginContext *pContext, const cell_t *params)
{
g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
char buffer[1024];
size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 1);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
/* One byte for null terminator, one for newline */
buffer[len++] = '\n';
buffer[len] = '\0';
InsertServerCommand(buffer);
return 1;
}
static cell_t sm_ServerExecute(IPluginContext *pContext, const cell_t *params)
{
engine->ServerExecute();
return 1;
}
static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
{
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
g_SourceMod.SetGlobalTarget(params[1]);
char buffer[256];
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
engine->ClientCommand(
#if SOURCE_ENGINE == SE_DOTA
pPlayer->GetIndex(),
#else
pPlayer->GetEdict(),
#endif
"%s", buffer);
return 1;
}
static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
{
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
g_SourceMod.SetGlobalTarget(params[1]);
char buffer[256];
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
#if SOURCE_ENGINE == SE_DOTA
engine->ClientCommand(pPlayer->GetIndex(), "%s", buffer);
#else
serverpluginhelpers->ClientCommand(pPlayer->GetEdict(), buffer);
#endif
return 1;
}
static cell_t FakeClientCommandEx(IPluginContext *pContext, const cell_t *params) static cell_t FakeClientCommandEx(IPluginContext *pContext, const cell_t *params)
{ {
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]); CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
@ -1156,69 +977,6 @@ static cell_t FakeClientCommandEx(IPluginContext *pContext, const cell_t *params
return 1; return 1;
} }
static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params)
{
g_SourceMod.SetGlobalTarget(params[1]);
/* Build the format string */
char buffer[1024];
size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer)-2, pContext, params, 2);
if (pContext->GetLastNativeError() != SP_ERROR_NONE)
{
return 0;
}
/* If we're printing to the server, shortcut out */
if (params[1] == 0)
{
/* Print */
buffer[len++] = '\n';
buffer[len] = '\0';
META_CONPRINT(buffer);
return 1;
}
CPlayer *pPlayer = g_Players.GetPlayerByIndex(params[1]);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}
unsigned int replyto = g_ChatTriggers.GetReplyTo();
if (replyto == SM_REPLY_CONSOLE)
{
buffer[len++] = '\n';
buffer[len] = '\0';
pPlayer->PrintToConsole(buffer);
} else if (replyto == SM_REPLY_CHAT) {
if (len >= 191)
{
len = 191;
}
buffer[len] = '\0';
g_HL2.TextMsg(params[1], HUD_PRINTTALK, buffer);
}
return 1;
}
static cell_t GetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
{
return g_ChatTriggers.GetReplyTo();
}
static cell_t SetCmdReplyTarget(IPluginContext *pContext, const cell_t *params)
{
return g_ChatTriggers.SetReplyTo(params[1]);
}
static cell_t GetCommandIterator(IPluginContext *pContext, const cell_t *params) static cell_t GetCommandIterator(IPluginContext *pContext, const cell_t *params)
{ {
GlobCmdIter *iter = new GlobCmdIter; GlobCmdIter *iter = new GlobCmdIter;
@ -1278,53 +1036,6 @@ static cell_t ReadCommandIterator(IPluginContext *pContext, const cell_t *params
return 1; return 1;
} }
static cell_t CheckCommandAccess(IPluginContext *pContext, const cell_t *params)
{
if (params[1] == 0)
{
return 1;
}
char *cmd;
pContext->LocalToString(params[2], &cmd);
/* Match up with an admin command if possible */
FlagBits bits = params[3];
bool found_command = false;
if (params[0] < 4 || !params[4])
{
found_command = g_ConCmds.LookForCommandAdminFlags(cmd, &bits);
}
if (!found_command)
{
g_Admins.GetCommandOverride(cmd, Override_Command, &bits);
}
return g_ConCmds.CheckClientCommandAccess(params[1], cmd, bits) ? 1 : 0;
}
static cell_t CheckAccess(IPluginContext *pContext, const cell_t *params)
{
char *cmd;
pContext->LocalToString(params[2], &cmd);
/* Match up with an admin command if possible */
FlagBits bits = params[3];
bool found_command = false;
if (params[0] < 4 || !params[4])
{
found_command = g_ConCmds.LookForCommandAdminFlags(cmd, &bits);
}
if (!found_command)
{
g_Admins.GetCommandOverride(cmd, Override_Command, &bits);
}
return g_ConCmds.CheckAdminCommandAccess(params[1], cmd, bits) ? 1 : 0;
}
static cell_t IsChatTrigger(IPluginContext *pContext, const cell_t *params) static cell_t IsChatTrigger(IPluginContext *pContext, const cell_t *params)
{ {
return g_ChatTriggers.IsChatTrigger() ? 1 : 0; return g_ChatTriggers.IsChatTrigger() ? 1 : 0;
@ -1496,16 +1207,6 @@ static cell_t SendConVarValue(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
static cell_t AddServerTag(IPluginContext *pContext, const cell_t *params)
{
return 0;
}
static cell_t RemoveServerTag(IPluginContext *pContext, const cell_t *params)
{
return 0;
}
static cell_t AddCommandListener(IPluginContext *pContext, const cell_t *params) static cell_t AddCommandListener(IPluginContext *pContext, const cell_t *params)
{ {
char *name; char *name;
@ -1573,22 +1274,10 @@ REGISTER_NATIVES(consoleNatives)
{"GetCmdArgString", sm_GetCmdArgString}, {"GetCmdArgString", sm_GetCmdArgString},
{"GetCmdArgs", sm_GetCmdArgs}, {"GetCmdArgs", sm_GetCmdArgs},
{"GetCmdArg", sm_GetCmdArg}, {"GetCmdArg", sm_GetCmdArg},
{"PrintToServer", sm_PrintToServer},
{"PrintToConsole", sm_PrintToConsole},
{"RegAdminCmd", sm_RegAdminCmd}, {"RegAdminCmd", sm_RegAdminCmd},
{"ServerCommand", sm_ServerCommand},
{"ServerCommandEx", sm_ServerCommandEx}, {"ServerCommandEx", sm_ServerCommandEx},
{"InsertServerCommand", sm_InsertServerCommand},
{"ServerExecute", sm_ServerExecute},
{"ClientCommand", sm_ClientCommand},
{"FakeClientCommand", FakeClientCommand},
{"ReplyToCommand", ReplyToCommand},
{"GetCmdReplySource", GetCmdReplyTarget},
{"SetCmdReplySource", SetCmdReplyTarget},
{"GetCommandIterator", GetCommandIterator}, {"GetCommandIterator", GetCommandIterator},
{"ReadCommandIterator", ReadCommandIterator}, {"ReadCommandIterator", ReadCommandIterator},
{"CheckCommandAccess", CheckCommandAccess},
{"CheckAccess", CheckAccess},
{"FakeClientCommandEx", FakeClientCommandEx}, {"FakeClientCommandEx", FakeClientCommandEx},
{"IsChatTrigger", IsChatTrigger}, {"IsChatTrigger", IsChatTrigger},
{"SetCommandFlags", SetCommandFlags}, {"SetCommandFlags", SetCommandFlags},
@ -1596,8 +1285,6 @@ REGISTER_NATIVES(consoleNatives)
{"FindFirstConCommand", FindFirstConCommand}, {"FindFirstConCommand", FindFirstConCommand},
{"FindNextConCommand", FindNextConCommand}, {"FindNextConCommand", FindNextConCommand},
{"SendConVarValue", SendConVarValue}, {"SendConVarValue", SendConVarValue},
{"AddServerTag", AddServerTag},
{"RemoveServerTag", RemoveServerTag},
{"AddCommandListener", AddCommandListener}, {"AddCommandListener", AddCommandListener},
{"RemoveCommandListener", RemoveCommandListener}, {"RemoveCommandListener", RemoveCommandListener},
{NULL, NULL} {NULL, NULL}

View File

@ -30,7 +30,6 @@
*/ */
#include "PlayerManager.h" #include "PlayerManager.h"
#include "AdminCache.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "HalfLife2.h" #include "HalfLife2.h"
#include "sourcemod.h" #include "sourcemod.h"

View File

@ -36,7 +36,6 @@
#include <sh_string.h> #include <sh_string.h>
#include "CoreConfig.h" #include "CoreConfig.h"
#include "Logger.h" #include "Logger.h"
#include "AdminCache.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "TimerSys.h" #include "TimerSys.h"

View File

@ -35,7 +35,7 @@
#include <IShareSys.h> #include <IShareSys.h>
#define SMINTERFACE_ADMINSYS_NAME "IAdminSys" #define SMINTERFACE_ADMINSYS_NAME "IAdminSys"
#define SMINTERFACE_ADMINSYS_VERSION 7 #define SMINTERFACE_ADMINSYS_VERSION 8
/** /**
* @file IAdminSystem.h * @file IAdminSystem.h
@ -728,12 +728,22 @@ namespace SourceMod
virtual bool FindFlagChar(AdminFlag flag, char *c) =0; virtual bool FindFlagChar(AdminFlag flag, char *c) =0;
/** /**
* brief Returns whether or not an admin id is valid. * @brief Returns whether or not an admin id is valid.
* *
* @param id Admin id to check. * @param id Admin id to check.
* @return True if valid, otherwise false. * @return True if valid, otherwise false.
*/ */
virtual bool IsValidAdmin(AdminId id) =0; virtual bool IsValidAdmin(AdminId id) =0;
/**
* @brief Returns whether or not a client has access to a given command.
*
* @param client Client index.
* @param cmd Command name.
* @param flags Command admin flags.
* @return True if allowed access, otherwise false;
*/
virtual bool CheckClientCommandAccess(int client, const char *cmd, FlagBits cmdflags) =0;
}; };
} }

View File

@ -41,7 +41,7 @@
#include <IAdminSystem.h> #include <IAdminSystem.h>
#define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager" #define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager"
#define SMINTERFACE_PLAYERMANAGER_VERSION 19 #define SMINTERFACE_PLAYERMANAGER_VERSION 20
struct edict_t; struct edict_t;
class IPlayerInfo; class IPlayerInfo;
@ -262,6 +262,11 @@ namespace SourceMod
* @param pMsg String to print. * @param pMsg String to print.
*/ */
virtual void PrintToConsole(const char *pMsg) =0; virtual void PrintToConsole(const char *pMsg) =0;
/**
* @brief Removes admin access from the client.
*/
virtual void ClearAdmin() =0;
}; };
/** /**
@ -584,6 +589,18 @@ namespace SourceMod
* @param info Pointer to the cmd_target_info_t structure to process. * @param info Pointer to the cmd_target_info_t structure to process.
*/ */
virtual void ProcessCommandTarget(cmd_target_info_t *info) =0; virtual void ProcessCommandTarget(cmd_target_info_t *info) =0;
/**
* @brief Removes all access for the given admin id.
*
* @param id Admin id.
*/
virtual void ClearAdminId(AdminId id) =0;
/**
* @brief Reruns admin checks on all players.
*/
virtual void RecheckAnyAdmins() =0;
}; };
} }

View File

@ -41,10 +41,6 @@
{ {
return cmd->IsFlagSet(flag); return cmd->IsFlagSet(flag);
} }
inline void InsertServerCommand(const char *buf)
{
engine->InsertServerCommand(buf);
}
inline ConCommandBase *FindCommandBase(const char *name) inline ConCommandBase *FindCommandBase(const char *name)
{ {
return icvar->FindCommandBase(name); return icvar->FindCommandBase(name);
@ -77,10 +73,6 @@
{ {
return cmd->IsBitSet(flag); return cmd->IsBitSet(flag);
} }
inline void InsertServerCommand(const char *buf)
{
engine->InsertServerCommand(buf);
}
inline ConCommandBase *FindCommandBase(const char *name) inline ConCommandBase *FindCommandBase(const char *name)
{ {
ConCommandBase *pBase = icvar->GetCommands(); ConCommandBase *pBase = icvar->GetCommands();