ds@579: /** ds@579: * vim: set ts=4 : ds@1330: * ============================================================================= dvander@1231: * SourceMod ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= ds@579: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. dvander@1231: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. dvander@1231: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . dvander@1231: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . ds@579: * ds@579: * Version: $Id$ ds@579: */ ds@579: ds@579: #ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ ds@579: #define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ ds@579: ds@579: #include "sm_globals.h" ds@579: #include "sourcemm_api.h" ds@579: #include "ForwardSys.h" ds@579: #include "sm_trie.h" ds@579: #include "sm_memtable.h" ds@579: #include ds@579: #include ds@579: #include ds@579: #include dvander@1584: #include "concmd_cleaner.h" ds@579: ds@579: using namespace SourceHook; ds@579: ds@579: enum CmdType ds@579: { ds@579: Cmd_Server, ds@579: Cmd_Admin, ds@579: }; ds@579: ds@579: struct AdminCmdInfo ds@579: { ds@579: AdminCmdInfo() ds@579: { ds@579: cmdGrpId = -1; ds@579: flags = 0; ds@579: eflags = 0; ds@579: } ds@579: int cmdGrpId; /* index into cmdgroup string table */ ds@579: FlagBits flags; /* default flags */ ds@579: FlagBits eflags; /* effective flags */ ds@579: }; ds@579: ds@579: struct CmdHook ds@579: { ds@579: CmdHook() ds@579: { ds@579: pf = NULL; ds@579: pAdmin = NULL; ds@579: } ds@579: IPluginFunction *pf; /* function hook */ ds@579: String helptext; /* help text */ ds@579: AdminCmdInfo *pAdmin; /* admin requirements, if any */ ds@579: }; ds@579: ds@579: struct ConCmdInfo ds@579: { ds@579: ConCmdInfo() ds@579: { ds@579: sourceMod = false; ds@579: pCmd = NULL; ds@579: } ds@579: bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */ ds@579: ConCommand *pCmd; /**< Pointer to the command itself */ ds@579: List srvhooks; /**< Hooks as a server command */ ds@579: List conhooks; /**< Hooks as a console command */ dvander@1119: AdminCmdInfo admin; /**< Admin info, if any */ ds@579: }; ds@579: dvander@3302: typedef List ConCmdList; dvander@3302: ds@579: class ConCmdManager : ds@579: public SMGlobalClass, ds@579: public IRootConsoleCommand, dvander@1584: public IPluginsListener, dvander@1584: public IConCommandTracker ds@579: { skamonkey@3899: #if SOURCE_ENGINE == SE_DOTA skamonkey@3899: friend void CommandCallback(void *pUnknown, const CCommand &command); skamonkey@3899: #elif SOURCE_ENGINE >= SE_ORANGEBOX faluco@1541: friend void CommandCallback(const CCommand &command); faluco@1541: #else ds@579: friend void CommandCallback(); faluco@1541: #endif ds@579: public: ds@579: ConCmdManager(); ds@579: ~ConCmdManager(); ds@579: public: //SMGlobalClass ds@579: void OnSourceModAllInitialized(); ds@579: void OnSourceModShutdown(); ds@579: public: //IPluginsListener ds@579: void OnPluginDestroyed(IPlugin *plugin); ds@579: public: //IRootConsoleCommand faluco@1541: void OnRootConsoleCommand(const char *cmdname, const CCommand &command); dvander@1584: public: //IConCommandTracker dvander@1584: void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); ds@579: public: ds@579: bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); ds@579: bool AddAdminCommand(IPluginFunction *pFunction, ds@579: const char *name, ds@579: const char *group, ds@579: int adminflags, ds@579: const char *description, ds@579: int flags); dvander@1335: ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type); dvander@1435: void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove); dvander@893: bool LookForSourceModCommand(const char *cmd); dvander@1349: bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags); skamonkey@3389: bool CheckClientCommandAccess(int client, const char *cmd, FlagBits flags); skamonkey@3389: bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags); ds@579: private: faluco@1541: void InternalDispatch(const CCommand &command); ds@579: ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args); ds@579: ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags); ds@579: void SetCommandClient(int client); ds@579: void AddToCmdList(ConCmdInfo *info); dvander@1584: void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack); dvander@1584: void RemoveConCmds(List &cmdlist); ds@579: void RemoveConCmds(List &cmdlist, IPluginContext *pContext); ds@579: bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); dvander@3302: dvander@3302: // Case insensitive dvander@3302: ConCmdList::iterator FindInList(const char *name); dvander@3302: dvander@3302: // Case sensitive dvander@3302: ConCmdInfo *FindInTrie(const char *name); dvander@769: public: dvander@769: inline int GetCommandClient() dvander@769: { dvander@769: return m_CmdClient; dvander@769: } dvander@1119: inline const List & GetCommandList() dvander@1119: { dvander@1119: return m_CmdList; dvander@1119: } ds@579: private: ds@579: Trie *m_pCmds; /* command lookup */ ds@579: Trie *m_pCmdGrps; /* command group lookup */ dvander@3302: ConCmdList m_CmdList; /* command list */ ds@579: int m_CmdClient; /* current client */ ds@579: BaseStringTable m_Strings; /* string table */ ds@579: }; ds@579: ds@579: extern ConCmdManager g_ConCmds; ds@579: ds@579: #endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ dvander@2806: