|
ds@579
|
1 |
/** |
|
ds@579
|
2 |
* vim: set ts=4 : |
|
ds@579
|
3 |
* =============================================================== |
|
ds@579
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@579
|
5 |
* =============================================================== |
|
ds@579
|
6 |
* |
|
ds@579
|
7 |
* This file is not open source and may not be copied without explicit |
|
ds@579
|
8 |
* written permission of AlliedModders LLC. This file may not be redistributed |
|
ds@579
|
9 |
* in whole or significant part. |
|
ds@579
|
10 |
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php |
|
ds@579
|
11 |
* |
|
ds@579
|
12 |
* Version: $Id$ |
|
ds@579
|
13 |
*/ |
|
ds@579
|
14 |
|
|
ds@579
|
15 |
#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ |
|
ds@579
|
16 |
#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ |
|
ds@579
|
17 |
|
|
ds@579
|
18 |
#include "sm_globals.h" |
|
ds@579
|
19 |
#include "sourcemm_api.h" |
|
ds@579
|
20 |
#include "ForwardSys.h" |
|
ds@579
|
21 |
#include "sm_trie.h" |
|
ds@579
|
22 |
#include "sm_memtable.h" |
|
ds@579
|
23 |
#include <sh_list.h> |
|
ds@579
|
24 |
#include <sh_string.h> |
|
ds@579
|
25 |
#include <IRootConsoleMenu.h> |
|
ds@579
|
26 |
#include <IAdminSystem.h> |
|
ds@579
|
27 |
|
|
ds@579
|
28 |
using namespace SourceHook; |
|
ds@579
|
29 |
|
|
ds@579
|
30 |
enum CmdType |
|
ds@579
|
31 |
{ |
|
ds@579
|
32 |
Cmd_Server, |
|
ds@579
|
33 |
Cmd_Console, |
|
ds@579
|
34 |
Cmd_Admin, |
|
ds@579
|
35 |
}; |
|
ds@579
|
36 |
|
|
ds@579
|
37 |
struct AdminCmdInfo |
|
ds@579
|
38 |
{ |
|
ds@579
|
39 |
AdminCmdInfo() |
|
ds@579
|
40 |
{ |
|
ds@579
|
41 |
cmdGrpId = -1; |
|
ds@579
|
42 |
flags = 0; |
|
ds@579
|
43 |
eflags = 0; |
|
ds@579
|
44 |
} |
|
ds@579
|
45 |
int cmdGrpId; /* index into cmdgroup string table */ |
|
ds@579
|
46 |
FlagBits flags; /* default flags */ |
|
ds@579
|
47 |
FlagBits eflags; /* effective flags */ |
|
ds@579
|
48 |
}; |
|
ds@579
|
49 |
|
|
ds@579
|
50 |
struct CmdHook |
|
ds@579
|
51 |
{ |
|
ds@579
|
52 |
CmdHook() |
|
ds@579
|
53 |
{ |
|
ds@579
|
54 |
pf = NULL; |
|
ds@579
|
55 |
pAdmin = NULL; |
|
ds@579
|
56 |
} |
|
ds@579
|
57 |
IPluginFunction *pf; /* function hook */ |
|
ds@579
|
58 |
String helptext; /* help text */ |
|
ds@579
|
59 |
AdminCmdInfo *pAdmin; /* admin requirements, if any */ |
|
ds@579
|
60 |
}; |
|
ds@579
|
61 |
|
|
ds@579
|
62 |
struct ConCmdInfo |
|
ds@579
|
63 |
{ |
|
ds@579
|
64 |
ConCmdInfo() |
|
ds@579
|
65 |
{ |
|
ds@579
|
66 |
sourceMod = false; |
|
ds@579
|
67 |
pCmd = NULL; |
|
ds@579
|
68 |
} |
|
ds@579
|
69 |
bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */ |
|
ds@579
|
70 |
ConCommand *pCmd; /**< Pointer to the command itself */ |
|
ds@579
|
71 |
List<CmdHook *> srvhooks; /**< Hooks as a server command */ |
|
ds@579
|
72 |
List<CmdHook *> conhooks; /**< Hooks as a console command */ |
|
dvander@1119
|
73 |
AdminCmdInfo admin; /**< Admin info, if any */ |
|
ds@579
|
74 |
}; |
|
ds@579
|
75 |
|
|
ds@579
|
76 |
class ConCmdManager : |
|
ds@579
|
77 |
public SMGlobalClass, |
|
ds@579
|
78 |
public IRootConsoleCommand, |
|
ds@579
|
79 |
public IPluginsListener |
|
ds@579
|
80 |
{ |
|
ds@579
|
81 |
friend void CommandCallback(); |
|
ds@579
|
82 |
public: |
|
ds@579
|
83 |
ConCmdManager(); |
|
ds@579
|
84 |
~ConCmdManager(); |
|
ds@579
|
85 |
public: //SMGlobalClass |
|
ds@579
|
86 |
void OnSourceModAllInitialized(); |
|
ds@579
|
87 |
void OnSourceModShutdown(); |
|
ds@579
|
88 |
public: //IPluginsListener |
|
ds@579
|
89 |
void OnPluginDestroyed(IPlugin *plugin); |
|
ds@579
|
90 |
public: //IRootConsoleCommand |
|
ds@579
|
91 |
void OnRootConsoleCommand(const char *command, unsigned int argcount); |
|
ds@579
|
92 |
public: |
|
ds@579
|
93 |
bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); |
|
ds@579
|
94 |
bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); |
|
ds@579
|
95 |
bool AddAdminCommand(IPluginFunction *pFunction, |
|
ds@579
|
96 |
const char *name, |
|
ds@579
|
97 |
const char *group, |
|
ds@579
|
98 |
int adminflags, |
|
ds@579
|
99 |
const char *description, |
|
ds@579
|
100 |
int flags); |
|
ds@579
|
101 |
ResultType DispatchClientCommand(int client, ResultType type); |
|
ds@579
|
102 |
void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits); |
|
dvander@893
|
103 |
bool LookForSourceModCommand(const char *cmd); |
|
dvander@1119
|
104 |
bool CheckCommandAccess(int client, const char *cmd, FlagBits flags); |
|
ds@579
|
105 |
private: |
|
ds@579
|
106 |
void InternalDispatch(); |
|
ds@579
|
107 |
ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args); |
|
ds@579
|
108 |
ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags); |
|
ds@579
|
109 |
void SetCommandClient(int client); |
|
ds@579
|
110 |
void AddToCmdList(ConCmdInfo *info); |
|
ds@579
|
111 |
void RemoveConCmd(ConCmdInfo *info); |
|
ds@579
|
112 |
void RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext); |
|
ds@579
|
113 |
bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); |
|
dvander@769
|
114 |
public: |
|
dvander@769
|
115 |
inline int GetCommandClient() |
|
dvander@769
|
116 |
{ |
|
dvander@769
|
117 |
return m_CmdClient; |
|
dvander@769
|
118 |
} |
|
dvander@1119
|
119 |
inline const List<ConCmdInfo *> & GetCommandList() |
|
dvander@1119
|
120 |
{ |
|
dvander@1119
|
121 |
return m_CmdList; |
|
dvander@1119
|
122 |
} |
|
ds@579
|
123 |
private: |
|
ds@579
|
124 |
Trie *m_pCmds; /* command lookup */ |
|
ds@579
|
125 |
Trie *m_pCmdGrps; /* command group lookup */ |
|
ds@579
|
126 |
List<ConCmdInfo *> m_CmdList; /* command list */ |
|
ds@579
|
127 |
int m_CmdClient; /* current client */ |
|
ds@579
|
128 |
BaseStringTable m_Strings; /* string table */ |
|
ds@579
|
129 |
}; |
|
ds@579
|
130 |
|
|
ds@579
|
131 |
extern ConCmdManager g_ConCmds; |
|
ds@579
|
132 |
|
|
ds@579
|
133 |
#endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ |