Move adminsys and more natives from core to logic.
This commit is contained in:
@@ -63,6 +63,9 @@ binary.sources += [
|
||||
'Database.cpp',
|
||||
'smn_database.cpp',
|
||||
'ForwardSys.cpp',
|
||||
'AdminCache.cpp',
|
||||
'sm_trie.cpp',
|
||||
'smn_console.cpp',
|
||||
]
|
||||
if builder.target_platform == 'windows':
|
||||
binary.sources += ['thread/WinThreads.cpp']
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
* vim: set ts=4 sw=4 tw=99 noet :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 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$
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
||||
#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
||||
|
||||
#include "common_logic.h"
|
||||
#include <IAdminSystem.h>
|
||||
#include "sm_memtable.h"
|
||||
#include <sm_trie.h>
|
||||
#include <sh_list.h>
|
||||
#include <sh_string.h>
|
||||
#include <IForwardSys.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sm_namehashset.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
#define GRP_MAGIC_SET 0xDEADFADE
|
||||
#define GRP_MAGIC_UNSET 0xFACEFACE
|
||||
#define USR_MAGIC_SET 0xDEADFACE
|
||||
#define USR_MAGIC_UNSET 0xFADEDEAD
|
||||
|
||||
typedef StringHashMap<OverrideRule> OverrideMap;
|
||||
|
||||
struct AdminGroup
|
||||
{
|
||||
uint32_t magic; /* Magic flag, for memory validation (ugh) */
|
||||
unsigned int immunity_level; /* Immunity level */
|
||||
/* Immune from target table (-1 = nonexistent)
|
||||
* [0] = number of entries
|
||||
* [1...N] = immune targets
|
||||
*/
|
||||
int immune_table;
|
||||
OverrideMap *pCmdTable; /* Command override table (can be NULL) */
|
||||
OverrideMap *pCmdGrpTable; /* Command group override table (can be NULL) */
|
||||
int next_grp; /* Next group in the chain */
|
||||
int prev_grp; /* Previous group in the chain */
|
||||
int nameidx; /* Name */
|
||||
FlagBits addflags; /* Additive flags */
|
||||
};
|
||||
|
||||
struct AuthMethod
|
||||
{
|
||||
String name;
|
||||
StringHashMap<AdminId> identities;
|
||||
|
||||
AuthMethod(const char *name)
|
||||
: name(name)
|
||||
{
|
||||
}
|
||||
|
||||
static inline bool matches(const char *name, const AuthMethod *method)
|
||||
{
|
||||
return strcmp(name, method->name.c_str()) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct UserAuth
|
||||
{
|
||||
unsigned int index; /* Index into auth table */
|
||||
int identidx; /* Index into the string table */
|
||||
};
|
||||
|
||||
struct AdminUser
|
||||
{
|
||||
uint32_t magic; /* Magic flag, for memory validation */
|
||||
FlagBits flags; /* Flags */
|
||||
FlagBits eflags; /* Effective flags */
|
||||
int nameidx; /* Name index */
|
||||
int password; /* Password index */
|
||||
unsigned int grp_count; /* Number of groups */
|
||||
unsigned int grp_size; /* Size of groups table */
|
||||
int grp_table; /* Group table itself */
|
||||
int next_user; /* Next user in the list */
|
||||
int prev_user; /* Previous user in the list */
|
||||
UserAuth auth; /* Auth method for this user */
|
||||
unsigned int immunity_level; /* Immunity level */
|
||||
unsigned int serialchange; /* Serial # for changes */
|
||||
};
|
||||
|
||||
class AdminCache :
|
||||
public IAdminSystem,
|
||||
public SMGlobalClass
|
||||
{
|
||||
public:
|
||||
AdminCache();
|
||||
~AdminCache();
|
||||
public: //SMGlobalClass
|
||||
void OnSourceModStartup(bool late);
|
||||
void OnSourceModAllInitialized();
|
||||
void OnSourceModLevelChange(const char *mapName);
|
||||
void OnSourceModShutdown();
|
||||
void OnSourceModPluginsLoaded();
|
||||
public: //IAdminSystem
|
||||
/** Command cache stuff */
|
||||
void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags);
|
||||
bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags);
|
||||
void UnsetCommandOverride(const char *cmd, OverrideType type);
|
||||
/** Group cache stuff */
|
||||
GroupId AddGroup(const char *group_name);
|
||||
GroupId FindGroupByName(const char *group_name);
|
||||
void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled);
|
||||
bool GetGroupAddFlag(GroupId id, AdminFlag flag);
|
||||
FlagBits GetGroupAddFlags(GroupId id);
|
||||
void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled);
|
||||
bool GetGroupGenericImmunity(GroupId id, ImmunityType type);
|
||||
void InvalidateGroup(GroupId id);
|
||||
void AddGroupImmunity(GroupId id, GroupId other_id);
|
||||
unsigned int GetGroupImmunityCount(GroupId id);
|
||||
GroupId GetGroupImmunity(GroupId id, unsigned int number);
|
||||
void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule);
|
||||
bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule);
|
||||
void DumpAdminCache(AdminCachePart part, bool rebuild);
|
||||
void AddAdminListener(IAdminListener *pListener);
|
||||
void RemoveAdminListener(IAdminListener *pListener);
|
||||
/** User stuff */
|
||||
void RegisterAuthIdentType(const char *name);
|
||||
AdminId CreateAdmin(const char *name);
|
||||
const char *GetAdminName(AdminId id);
|
||||
bool BindAdminIdentity(AdminId id, const char *auth, const char *ident);
|
||||
virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled);
|
||||
bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode);
|
||||
FlagBits GetAdminFlags(AdminId id, AccessMode mode);
|
||||
bool AdminInheritGroup(AdminId id, GroupId gid);
|
||||
unsigned int GetAdminGroupCount(AdminId id);
|
||||
GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name);
|
||||
void SetAdminPassword(AdminId id, const char *password);
|
||||
const char *GetAdminPassword(AdminId id);
|
||||
AdminId FindAdminByIdentity(const char *auth, const char *identity);
|
||||
bool InvalidateAdmin(AdminId id);
|
||||
unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize);
|
||||
FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize);
|
||||
FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags);
|
||||
unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize);
|
||||
bool CheckAdminFlags(AdminId id, FlagBits bits);
|
||||
bool CanAdminTarget(AdminId id, AdminId target);
|
||||
void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits);
|
||||
bool FindFlag(const char *str, AdminFlag *pFlag);
|
||||
bool FindFlag(char c, AdminFlag *pAdmFlag);
|
||||
FlagBits ReadFlagString(const char *flags, const char **end);
|
||||
size_t FillFlagString(FlagBits bits, char *buffer, size_t maxlen);
|
||||
unsigned int GetAdminSerialChange(AdminId id);
|
||||
bool CanAdminUseCommand(int client, const char *cmd);
|
||||
const char *GetGroupName(GroupId gid);
|
||||
unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level);
|
||||
unsigned int GetGroupImmunityLevel(GroupId gid);
|
||||
unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level);
|
||||
unsigned int GetAdminImmunityLevel(AdminId id);
|
||||
bool CheckAccess(int client,
|
||||
const char *cmd,
|
||||
FlagBits flags,
|
||||
bool override_only);
|
||||
bool FindFlagChar(AdminFlag flag, char *c);
|
||||
bool IsValidAdmin(AdminId id);
|
||||
bool CheckClientCommandAccess(int client, const char *cmd, FlagBits cmdflags);
|
||||
public:
|
||||
void DumpCache(FILE *fp);
|
||||
AdminGroup *GetGroup(GroupId gid);
|
||||
AdminUser *GetUser(AdminId id);
|
||||
const char *GetString(int idx);
|
||||
bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags);
|
||||
private:
|
||||
void _UnsetCommandOverride(const char *cmd);
|
||||
void _UnsetCommandGroupOverride(const char *group);
|
||||
void InvalidateGroupCache();
|
||||
void InvalidateAdminCache(bool unlink_admins);
|
||||
void DumpCommandOverrideCache(OverrideType type);
|
||||
AuthMethod *GetMethodByIndex(unsigned int index);
|
||||
bool GetMethodIndex(const char *name, unsigned int *_index);
|
||||
const char *GetMethodName(unsigned int index);
|
||||
void NameFlag(const char *str, AdminFlag flag);
|
||||
public:
|
||||
typedef StringHashMap<FlagBits> FlagMap;
|
||||
|
||||
BaseStringTable *m_pStrings;
|
||||
BaseMemTable *m_pMemory;
|
||||
FlagMap m_CmdOverrides;
|
||||
FlagMap m_CmdGrpOverrides;
|
||||
int m_FirstGroup;
|
||||
int m_LastGroup;
|
||||
int m_FreeGroupList;
|
||||
StringHashMap<GroupId> m_Groups;
|
||||
List<IAdminListener *> m_hooks;
|
||||
List<AuthMethod *> m_AuthMethods;
|
||||
NameHashSet<AuthMethod *> m_AuthTables;
|
||||
IForward *m_pCacheFwd;
|
||||
int m_FirstUser;
|
||||
int m_LastUser;
|
||||
int m_FreeUserList;
|
||||
bool m_InvalidatingAdmins;
|
||||
bool m_destroying;
|
||||
StringHashMap<AdminFlag> m_LevelNames;
|
||||
};
|
||||
|
||||
extern AdminCache g_Admins;
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "HandleSys.h"
|
||||
#include "ExtensionSys.h"
|
||||
#include "ForwardSys.h"
|
||||
#include "AdminCache.h"
|
||||
|
||||
sm_core_t smcore;
|
||||
IHandleSys *handlesys = &g_HandleSys;
|
||||
@@ -65,7 +66,7 @@ IForwardManager *forwardsys = &g_Forwards;
|
||||
ITimerSystem *timersys;
|
||||
ServerGlobals serverGlobals;
|
||||
IPlayerManager *playerhelpers;
|
||||
IAdminSystem *adminsys;
|
||||
IAdminSystem *adminsys = &g_Admins;
|
||||
IGameHelpers *gamehelpers;
|
||||
ISourcePawnEngine *g_pSourcePawn;
|
||||
ISourcePawnEngine2 *g_pSourcePawn2;
|
||||
@@ -103,6 +104,11 @@ static void DumpHandles(void (*dumpfn)(const char *fmt, ...))
|
||||
g_HandleSys.Dump(dumpfn);
|
||||
}
|
||||
|
||||
static void DumpAdminCache(FILE *f)
|
||||
{
|
||||
g_Admins.DumpCache(f);
|
||||
}
|
||||
|
||||
static sm_logic_t logic =
|
||||
{
|
||||
NULL,
|
||||
@@ -121,11 +127,13 @@ static sm_logic_t logic =
|
||||
GenerateError,
|
||||
AddNatives,
|
||||
DumpHandles,
|
||||
DumpAdminCache,
|
||||
&g_PluginSys,
|
||||
&g_ShareSys,
|
||||
&g_Extensions,
|
||||
&g_HandleSys,
|
||||
&g_Forwards,
|
||||
&g_Admins,
|
||||
NULL,
|
||||
-1.0f
|
||||
};
|
||||
@@ -144,7 +152,6 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
|
||||
rootmenu = core->rootmenu;
|
||||
timersys = core->timersys;
|
||||
playerhelpers = core->playerhelpers;
|
||||
adminsys = core->adminsys;
|
||||
gamehelpers = core->gamehelpers;
|
||||
g_pSourcePawn = *core->spe1;
|
||||
g_pSourcePawn2 = *core->spe2;
|
||||
|
||||
+12
-2
@@ -42,6 +42,7 @@
|
||||
#include <sh_vector.h>
|
||||
#include <IExtensionSys.h>
|
||||
#include <IForwardSys.h>
|
||||
#include <IAdminSystem.h>
|
||||
|
||||
using namespace SourceMod;
|
||||
using namespace SourcePawn;
|
||||
@@ -51,7 +52,7 @@ using namespace SourceHook;
|
||||
* Add 1 to the RHS of this expression to bump the intercom file
|
||||
* This is to prevent mismatching core/logic binaries
|
||||
*/
|
||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 27)
|
||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 28)
|
||||
|
||||
#if defined SM_LOGIC
|
||||
class IVEngineServer
|
||||
@@ -61,8 +62,13 @@ class IVEngineServer_Logic
|
||||
{
|
||||
public:
|
||||
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 ServerExecute() = 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;
|
||||
@@ -260,7 +266,6 @@ struct sm_core_t
|
||||
IRootConsole *rootmenu;
|
||||
ITimerSystem *timersys;
|
||||
IPlayerManager *playerhelpers;
|
||||
IAdminSystem *adminsys;
|
||||
IGameHelpers *gamehelpers;
|
||||
ISourcePawnEngine **spe1;
|
||||
ISourcePawnEngine2 **spe2;
|
||||
@@ -296,6 +301,9 @@ struct sm_core_t
|
||||
void (*ExecuteConfigs)(IPluginContext *ctx);
|
||||
DatabaseInfo (*GetDBInfoFromKeyValues)(KeyValues *);
|
||||
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;
|
||||
/* Data */
|
||||
ServerGlobals *serverGlobals;
|
||||
@@ -323,11 +331,13 @@ struct sm_logic_t
|
||||
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
|
||||
void (*AddNatives)(sp_nativeinfo_t *natives);
|
||||
void (*DumpHandles)(void (*dumpfn)(const char *fmt, ...));
|
||||
void (*DumpAdminCache)(FILE *);
|
||||
IScriptManager *scripts;
|
||||
IShareSys *sharesys;
|
||||
IExtensionSys *extsys;
|
||||
IHandleSys *handlesys;
|
||||
IForwardManager *forwardsys;
|
||||
IAdminSystem *adminsys;
|
||||
IdentityToken_t *core_ident;
|
||||
float sentinel;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 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 <string.h>
|
||||
#include <assert.h>
|
||||
#include <sm_trie_tpl.h>
|
||||
#include "sm_trie.h"
|
||||
|
||||
struct Trie
|
||||
{
|
||||
KTrie<void *> k;
|
||||
};
|
||||
|
||||
Trie *sm_trie_create()
|
||||
{
|
||||
return new Trie;
|
||||
}
|
||||
|
||||
void sm_trie_destroy(Trie *trie)
|
||||
{
|
||||
delete trie;
|
||||
}
|
||||
|
||||
bool sm_trie_insert(Trie *trie, const char *key, void *value)
|
||||
{
|
||||
return trie->k.insert(key, value);
|
||||
}
|
||||
|
||||
bool sm_trie_replace(Trie *trie, const char *key, void *value)
|
||||
{
|
||||
return trie->k.replace(key, value);
|
||||
}
|
||||
|
||||
bool sm_trie_retrieve(Trie *trie, const char *key, void **value)
|
||||
{
|
||||
void **pValue = trie->k.retrieve(key);
|
||||
|
||||
if (!pValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
*value = *pValue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sm_trie_delete(Trie *trie, const char *key)
|
||||
{
|
||||
return trie->k.remove(key);
|
||||
}
|
||||
|
||||
void sm_trie_clear(Trie *trie)
|
||||
{
|
||||
trie->k.clear();
|
||||
}
|
||||
|
||||
size_t sm_trie_mem_usage(Trie *trie)
|
||||
{
|
||||
return trie->k.mem_usage();
|
||||
}
|
||||
|
||||
struct trie_iter_data
|
||||
{
|
||||
SM_TRIE_BAD_ITERATOR iter;
|
||||
void *ptr;
|
||||
Trie *pTrie;
|
||||
};
|
||||
|
||||
void our_trie_iterator(KTrie<void *> *pTrie, const char *name, void *& obj, void *data)
|
||||
{
|
||||
trie_iter_data *our_iter;
|
||||
|
||||
our_iter = (trie_iter_data *)data;
|
||||
our_iter->iter(our_iter->pTrie, name, &obj, our_iter->ptr);
|
||||
}
|
||||
|
||||
void sm_trie_bad_iterator(Trie *trie,
|
||||
char *buffer,
|
||||
size_t maxlength,
|
||||
SM_TRIE_BAD_ITERATOR iter,
|
||||
void *data)
|
||||
{
|
||||
trie_iter_data our_iter;
|
||||
|
||||
our_iter.iter = iter;
|
||||
our_iter.ptr = data;
|
||||
our_iter.pTrie = trie;
|
||||
trie->k.bad_iterator(buffer, maxlength, &our_iter, our_trie_iterator);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 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$
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_
|
||||
#define _INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_
|
||||
|
||||
struct Trie;
|
||||
|
||||
typedef void (*SM_TRIE_BAD_ITERATOR)(Trie *pTrie, const char *key, void **value, void *data);
|
||||
|
||||
Trie *sm_trie_create();
|
||||
void sm_trie_destroy(Trie *trie);
|
||||
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_retrieve(Trie *trie, const char *key, void **value);
|
||||
bool sm_trie_delete(Trie *trie, const char *key);
|
||||
void sm_trie_clear(Trie *trie);
|
||||
size_t sm_trie_mem_usage(Trie *trie);
|
||||
void sm_trie_bad_iterator(Trie *trie,
|
||||
char *buffer,
|
||||
size_t maxlength,
|
||||
SM_TRIE_BAD_ITERATOR iter,
|
||||
void *data);
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_SIMPLE_TRIE_H_
|
||||
@@ -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}
|
||||
};
|
||||
Reference in New Issue
Block a user