ds@579: /** ds@579: * vim: set ts=4 : ds@579: * =============================================================== ds@579: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@579: * =============================================================== ds@579: * ds@579: * This file is not open source and may not be copied without explicit ds@579: * written permission of AlliedModders LLC. This file may not be redistributed ds@579: * in whole or significant part. ds@579: * For information, see LICENSE.txt or http://www.sourcemod.net/license.php 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 ds@579: ds@579: using namespace SourceHook; ds@579: ds@579: enum CmdType ds@579: { ds@579: Cmd_Server, ds@579: Cmd_Console, 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 */ ds@579: }; ds@579: ds@579: class ConCmdManager : ds@579: public SMGlobalClass, ds@579: public IRootConsoleCommand, ds@579: public IPluginsListener ds@579: { ds@579: friend void CommandCallback(); ds@579: public: ds@579: ConCmdManager(); ds@579: ~ConCmdManager(); ds@579: public: //SMGlobalClass ds@579: void OnSourceModAllInitialized(); ds@579: void OnSourceModShutdown(); dvander@848: void OnSourceModLevelChange(const char *mapName); ds@579: public: //IPluginsListener ds@579: void OnPluginDestroyed(IPlugin *plugin); ds@579: public: //IRootConsoleCommand ds@579: void OnRootConsoleCommand(const char *command, unsigned int argcount); ds@579: public: ds@579: bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); ds@579: bool AddConsoleCommand(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); ds@579: ResultType DispatchClientCommand(int client, ResultType type); ds@579: void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits); dvander@723: void NotifyExecDone(const char *file); dvander@893: bool LookForSourceModCommand(const char *cmd); ds@579: private: ds@579: void InternalDispatch(); 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); ds@579: void RemoveConCmd(ConCmdInfo *info); ds@579: void RemoveConCmds(List &cmdlist, IPluginContext *pContext); ds@579: bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); dvander@723: void OnExecCmd(); dvander@769: public: dvander@769: inline int GetCommandClient() dvander@769: { dvander@769: return m_CmdClient; dvander@769: } dvander@848: inline bool IsServerCfgDone() dvander@848: { dvander@848: return m_bServerCfgDone; dvander@848: } ds@579: private: ds@579: Trie *m_pCmds; /* command lookup */ ds@579: Trie *m_pCmdGrps; /* command group lookup */ ds@579: List m_CmdList; /* command list */ ds@579: int m_CmdClient; /* current client */ ds@579: BaseStringTable m_Strings; /* string table */ dvander@723: ConVar *m_pServerCfgFile; /* servercfgfile cvar */ dvander@723: ConCommand *m_pExecCmd; /* "exec" command */ dvander@723: IForward *m_pServerCfgFwd; /* server config forward */ dvander@723: bool m_bServerCfgDone; /* marks whether a servercfg was detected */ ds@579: }; ds@579: ds@579: extern ConCmdManager g_ConCmds; ds@579: ds@579: #endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_