2 * vim: set ts=4 sw=4 tw=99 noet :
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
33 #define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
35 #include "sm_globals.h"
36 #include "sourcemm_api.h"
37 #include "ForwardSys.h"
38 #include "sm_memtable.h"
40 #include <sh_string.h>
41 #include <IRootConsoleMenu.h>
42 #include <IAdminSystem.h>
43 #include "concmd_cleaner.h"
44 #include <sm_stringhashmap.h>
45 #include <am-utility.h>
47 using namespace SourceHook;
63 int cmdGrpId; /* index into cmdgroup string table */
64 FlagBits flags; /* default flags */
65 FlagBits eflags; /* effective flags */
75 IPluginFunction *pf; /* function hook */
76 String helptext; /* help text */
77 AdminCmdInfo *pAdmin; /* admin requirements, if any */
87 bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */
88 ConCommand *pCmd; /**< Pointer to the command itself */
89 List<CmdHook *> srvhooks; /**< Hooks as a server command */
90 List<CmdHook *> conhooks; /**< Hooks as a console command */
91 AdminCmdInfo admin; /**< Admin info, if any */
94 typedef List<ConCmdInfo *> ConCmdList;
98 public IRootConsoleCommand,
99 public IPluginsListener,
100 public IConCommandTracker
102 #if SOURCE_ENGINE == SE_DOTA
103 friend void CommandCallback(const CCommandContext &context, const CCommand &command);
104 #elif SOURCE_ENGINE >= SE_ORANGEBOX
105 friend void CommandCallback(const CCommand &command);
107 friend void CommandCallback();
112 public: //SMGlobalClass
113 void OnSourceModAllInitialized();
114 void OnSourceModShutdown();
115 public: //IPluginsListener
116 void OnPluginDestroyed(IPlugin *plugin);
117 public: //IRootConsoleCommand
118 void OnRootConsoleCommand(const char *cmdname, const CCommand &command);
119 public: //IConCommandTracker
120 void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe);
122 bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags);
123 bool AddAdminCommand(IPluginFunction *pFunction,
127 const char *description,
129 ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type);
130 void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove);
131 bool LookForSourceModCommand(const char *cmd);
132 bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags);
133 bool CheckClientCommandAccess(int client, const char *cmd, FlagBits flags);
134 bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags);
136 void InternalDispatch(const CCommand &command);
137 ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args);
138 ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags);
139 void SetCommandClient(int client);
140 void AddToCmdList(ConCmdInfo *info);
141 void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack);
142 void RemoveConCmds(List<CmdHook *> &cmdlist);
143 void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext);
144 bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin);
147 ConCmdList::iterator FindInList(const char *name);
150 ConCmdInfo *FindInTrie(const char *name);
152 inline int GetCommandClient()
156 inline const List<ConCmdInfo *> & GetCommandList()
161 StringHashMap<ConCmdInfo *> m_Cmds; /* command lookup */
162 StringHashMap<int> m_CmdGrps; /* command group lookup */
163 ConCmdList m_CmdList; /* command list */
164 int m_CmdClient; /* current client */
165 BaseStringTable m_Strings; /* string table */
168 extern ConCmdManager g_ConCmds;
170 #endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_