|
ds@579
|
1 |
/** |
|
dvander@4076
|
2 |
* vim: set ts=4 sw=4 tw=99 noet : |
|
ds@1330
|
3 |
* ============================================================================= |
|
dvander@1231
|
4 |
* SourceMod |
|
ds@1947
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
6 |
* ============================================================================= |
|
ds@579
|
7 |
* |
|
ds@1330
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
10 |
* Free Software Foundation. |
|
dvander@1231
|
11 |
* |
|
ds@1330
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
15 |
* details. |
|
dvander@1231
|
16 |
* |
|
ds@1330
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
dvander@1231
|
19 |
* |
|
ds@1330
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@579
|
28 |
* |
|
ds@579
|
29 |
* Version: $Id$ |
|
ds@579
|
30 |
*/ |
|
ds@579
|
31 |
|
|
ds@579
|
32 |
#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ |
|
ds@579
|
33 |
#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ |
|
ds@579
|
34 |
|
|
ds@579
|
35 |
#include "sm_globals.h" |
|
ds@579
|
36 |
#include "sourcemm_api.h" |
|
ds@579
|
37 |
#include "ForwardSys.h" |
|
ds@579
|
38 |
#include "sm_memtable.h" |
|
ds@579
|
39 |
#include <sh_list.h> |
|
ds@579
|
40 |
#include <sh_string.h> |
|
ds@579
|
41 |
#include <IRootConsoleMenu.h> |
|
ds@579
|
42 |
#include <IAdminSystem.h> |
|
dvander@1584
|
43 |
#include "concmd_cleaner.h" |
|
dvander@4076
|
44 |
#include <sm_stringhashmap.h> |
|
dvander@4076
|
45 |
#include <am-utility.h> |
|
ds@579
|
46 |
|
|
ds@579
|
47 |
using namespace SourceHook; |
|
ds@579
|
48 |
|
|
ds@579
|
49 |
enum CmdType |
|
ds@579
|
50 |
{ |
|
ds@579
|
51 |
Cmd_Server, |
|
ds@579
|
52 |
Cmd_Admin, |
|
ds@579
|
53 |
}; |
|
ds@579
|
54 |
|
|
ds@579
|
55 |
struct AdminCmdInfo |
|
ds@579
|
56 |
{ |
|
ds@579
|
57 |
AdminCmdInfo() |
|
ds@579
|
58 |
{ |
|
ds@579
|
59 |
cmdGrpId = -1; |
|
ds@579
|
60 |
flags = 0; |
|
ds@579
|
61 |
eflags = 0; |
|
ds@579
|
62 |
} |
|
ds@579
|
63 |
int cmdGrpId; /* index into cmdgroup string table */ |
|
ds@579
|
64 |
FlagBits flags; /* default flags */ |
|
ds@579
|
65 |
FlagBits eflags; /* effective flags */ |
|
ds@579
|
66 |
}; |
|
ds@579
|
67 |
|
|
ds@579
|
68 |
struct CmdHook |
|
ds@579
|
69 |
{ |
|
ds@579
|
70 |
CmdHook() |
|
ds@579
|
71 |
{ |
|
ds@579
|
72 |
pf = NULL; |
|
ds@579
|
73 |
pAdmin = NULL; |
|
ds@579
|
74 |
} |
|
ds@579
|
75 |
IPluginFunction *pf; /* function hook */ |
|
ds@579
|
76 |
String helptext; /* help text */ |
|
ds@579
|
77 |
AdminCmdInfo *pAdmin; /* admin requirements, if any */ |
|
ds@579
|
78 |
}; |
|
ds@579
|
79 |
|
|
ds@579
|
80 |
struct ConCmdInfo |
|
ds@579
|
81 |
{ |
|
ds@579
|
82 |
ConCmdInfo() |
|
ds@579
|
83 |
{ |
|
ds@579
|
84 |
sourceMod = false; |
|
ds@579
|
85 |
pCmd = NULL; |
|
ds@579
|
86 |
} |
|
ds@579
|
87 |
bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */ |
|
ds@579
|
88 |
ConCommand *pCmd; /**< Pointer to the command itself */ |
|
ds@579
|
89 |
List<CmdHook *> srvhooks; /**< Hooks as a server command */ |
|
ds@579
|
90 |
List<CmdHook *> conhooks; /**< Hooks as a console command */ |
|
dvander@1119
|
91 |
AdminCmdInfo admin; /**< Admin info, if any */ |
|
ds@579
|
92 |
}; |
|
ds@579
|
93 |
|
|
dvander@3302
|
94 |
typedef List<ConCmdInfo *> ConCmdList; |
|
dvander@3302
|
95 |
|
|
ds@579
|
96 |
class ConCmdManager : |
|
ds@579
|
97 |
public SMGlobalClass, |
|
ds@579
|
98 |
public IRootConsoleCommand, |
|
dvander@1584
|
99 |
public IPluginsListener, |
|
dvander@1584
|
100 |
public IConCommandTracker |
|
ds@579
|
101 |
{ |
|
skamonkey@3899
|
102 |
#if SOURCE_ENGINE == SE_DOTA |
|
skamonkey@3942
|
103 |
friend void CommandCallback(const CCommandContext &context, const CCommand &command); |
|
skamonkey@3899
|
104 |
#elif SOURCE_ENGINE >= SE_ORANGEBOX |
|
faluco@1541
|
105 |
friend void CommandCallback(const CCommand &command); |
|
faluco@1541
|
106 |
#else |
|
ds@579
|
107 |
friend void CommandCallback(); |
|
faluco@1541
|
108 |
#endif |
|
ds@579
|
109 |
public: |
|
ds@579
|
110 |
ConCmdManager(); |
|
ds@579
|
111 |
~ConCmdManager(); |
|
ds@579
|
112 |
public: //SMGlobalClass |
|
ds@579
|
113 |
void OnSourceModAllInitialized(); |
|
ds@579
|
114 |
void OnSourceModShutdown(); |
|
ds@579
|
115 |
public: //IPluginsListener |
|
ds@579
|
116 |
void OnPluginDestroyed(IPlugin *plugin); |
|
ds@579
|
117 |
public: //IRootConsoleCommand |
|
faluco@1541
|
118 |
void OnRootConsoleCommand(const char *cmdname, const CCommand &command); |
|
dvander@1584
|
119 |
public: //IConCommandTracker |
|
dvander@1584
|
120 |
void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); |
|
ds@579
|
121 |
public: |
|
ds@579
|
122 |
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); |
|
ds@579
|
123 |
bool AddAdminCommand(IPluginFunction *pFunction, |
|
ds@579
|
124 |
const char *name, |
|
ds@579
|
125 |
const char *group, |
|
ds@579
|
126 |
int adminflags, |
|
ds@579
|
127 |
const char *description, |
|
ds@579
|
128 |
int flags); |
|
dvander@1335
|
129 |
ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type); |
|
dvander@1435
|
130 |
void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove); |
|
dvander@893
|
131 |
bool LookForSourceModCommand(const char *cmd); |
|
dvander@1349
|
132 |
bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags); |
|
skamonkey@3389
|
133 |
bool CheckClientCommandAccess(int client, const char *cmd, FlagBits flags); |
|
skamonkey@3389
|
134 |
bool CheckAdminCommandAccess(AdminId adm, const char *cmd, FlagBits flags); |
|
ds@579
|
135 |
private: |
|
faluco@1541
|
136 |
void InternalDispatch(const CCommand &command); |
|
ds@579
|
137 |
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args); |
|
ds@579
|
138 |
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags); |
|
ds@579
|
139 |
void SetCommandClient(int client); |
|
ds@579
|
140 |
void AddToCmdList(ConCmdInfo *info); |
|
dvander@1584
|
141 |
void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack); |
|
dvander@1584
|
142 |
void RemoveConCmds(List<CmdHook *> &cmdlist); |
|
ds@579
|
143 |
void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext); |
|
ds@579
|
144 |
bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); |
|
dvander@3302
|
145 |
|
|
dvander@3302
|
146 |
// Case insensitive |
|
dvander@3302
|
147 |
ConCmdList::iterator FindInList(const char *name); |
|
dvander@3302
|
148 |
|
|
dvander@3302
|
149 |
// Case sensitive |
|
dvander@3302
|
150 |
ConCmdInfo *FindInTrie(const char *name); |
|
dvander@769
|
151 |
public: |
|
dvander@769
|
152 |
inline int GetCommandClient() |
|
dvander@769
|
153 |
{ |
|
dvander@769
|
154 |
return m_CmdClient; |
|
dvander@769
|
155 |
} |
|
dvander@1119
|
156 |
inline const List<ConCmdInfo *> & GetCommandList() |
|
dvander@1119
|
157 |
{ |
|
dvander@1119
|
158 |
return m_CmdList; |
|
dvander@1119
|
159 |
} |
|
ds@579
|
160 |
private: |
|
dvander@4076
|
161 |
StringHashMap<ConCmdInfo *> m_Cmds; /* command lookup */ |
|
dvander@4076
|
162 |
StringHashMap<int> m_CmdGrps; /* command group lookup */ |
|
dvander@3302
|
163 |
ConCmdList m_CmdList; /* command list */ |
|
ds@579
|
164 |
int m_CmdClient; /* current client */ |
|
ds@579
|
165 |
BaseStringTable m_Strings; /* string table */ |
|
ds@579
|
166 |
}; |
|
ds@579
|
167 |
|
|
ds@579
|
168 |
extern ConCmdManager g_ConCmds; |
|
ds@579
|
169 |
|
|
ds@579
|
170 |
#endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ |
|
dvander@2806
|
171 |
|