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