|
darope@0
|
1 |
// vi: set ts=4 sw=4 : |
|
darope@0
|
2 |
// vim: set tw=75 : |
|
darope@0
|
3 |
|
|
darope@0
|
4 |
// commands_meta.cpp - implementation of various console commands |
|
darope@0
|
5 |
|
|
darope@0
|
6 |
/* |
|
darope@236
|
7 |
* Copyright (c) 2001-2004 Will Day <[email protected]> |
|
darope@0
|
8 |
* |
|
darope@0
|
9 |
* This file is part of Metamod. |
|
darope@0
|
10 |
* |
|
darope@0
|
11 |
* Metamod is free software; you can redistribute it and/or modify it |
|
darope@0
|
12 |
* under the terms of the GNU General Public License as published by the |
|
darope@0
|
13 |
* Free Software Foundation; either version 2 of the License, or (at |
|
darope@0
|
14 |
* your option) any later version. |
|
darope@0
|
15 |
* |
|
darope@0
|
16 |
* Metamod is distributed in the hope that it will be useful, but |
|
darope@0
|
17 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
darope@0
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
darope@0
|
19 |
* General Public License for more details. |
|
darope@0
|
20 |
* |
|
darope@0
|
21 |
* You should have received a copy of the GNU General Public License |
|
darope@0
|
22 |
* along with Metamod; if not, write to the Free Software Foundation, |
|
darope@0
|
23 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
darope@0
|
24 |
* |
|
darope@0
|
25 |
* In addition, as a special exception, the author gives permission to |
|
darope@0
|
26 |
* link the code of this program with the Half-Life Game Engine ("HL |
|
darope@0
|
27 |
* Engine") and Modified Game Libraries ("MODs") developed by Valve, |
|
darope@0
|
28 |
* L.L.C ("Valve"). You must obey the GNU General Public License in all |
|
darope@0
|
29 |
* respects for all of the code used other than the HL Engine and MODs |
|
darope@0
|
30 |
* from Valve. If you modify this file, you may extend this exception |
|
darope@0
|
31 |
* to your version of the file, but you are not obligated to do so. If |
|
darope@0
|
32 |
* you do not wish to do so, delete this exception statement from your |
|
darope@0
|
33 |
* version. |
|
darope@0
|
34 |
* |
|
darope@0
|
35 |
*/ |
|
darope@0
|
36 |
|
|
darope@0
|
37 |
#include <ctype.h> // isdigit() |
|
darope@248
|
38 |
#include <stdlib.h> // strtol() |
|
darope@0
|
39 |
|
|
darope@0
|
40 |
#include <extdll.h> // always |
|
darope@0
|
41 |
|
|
darope@0
|
42 |
#include "commands_meta.h" // me |
|
darope@0
|
43 |
#include "metamod.h" // Plugins, etc |
|
darope@0
|
44 |
#include "log_meta.h" // META_CONS, etc |
|
darope@0
|
45 |
#include "info_name.h" // VNAME, etc |
|
darope@236
|
46 |
#include "vdate.h" // COMPILE_TIME, COMPILE_TZONE |
|
darope@0
|
47 |
|
|
darope@0
|
48 |
|
|
darope@0
|
49 |
// Register commands and cvars. |
|
darope@0
|
50 |
void meta_register_cmdcvar() { |
|
darope@0
|
51 |
CVAR_REGISTER(&meta_debug); |
|
darope@0
|
52 |
CVAR_REGISTER(&meta_version); |
|
darope@0
|
53 |
REG_SVR_COMMAND("meta", svr_meta); |
|
darope@0
|
54 |
} |
|
darope@0
|
55 |
|
|
darope@0
|
56 |
// Parse "meta" console command. |
|
darope@0
|
57 |
void svr_meta(void) { |
|
darope@0
|
58 |
const char *cmd; |
|
darope@0
|
59 |
cmd=CMD_ARGV(1); |
|
darope@0
|
60 |
// arguments: none |
|
darope@0
|
61 |
if(!strcasecmp(cmd, "version")) |
|
darope@0
|
62 |
cmd_meta_version(); |
|
darope@0
|
63 |
else if(!strcasecmp(cmd, "gpl")) |
|
darope@0
|
64 |
cmd_meta_gpl(); |
|
darope@0
|
65 |
else if(!strcasecmp(cmd, "refresh")) |
|
darope@0
|
66 |
cmd_meta_refresh(); |
|
darope@0
|
67 |
else if(!strcasecmp(cmd, "list")) |
|
darope@0
|
68 |
cmd_meta_pluginlist(); |
|
darope@0
|
69 |
else if(!strcasecmp(cmd, "cmds")) |
|
darope@0
|
70 |
cmd_meta_cmdlist(); |
|
darope@0
|
71 |
else if(!strcasecmp(cmd, "cvars")) |
|
darope@0
|
72 |
cmd_meta_cvarlist(); |
|
darope@0
|
73 |
else if(!strcasecmp(cmd, "game")) |
|
darope@0
|
74 |
cmd_meta_game(); |
|
darope@0
|
75 |
else if(!strcasecmp(cmd, "config")) |
|
darope@0
|
76 |
cmd_meta_config(); |
|
darope@0
|
77 |
// arguments: existing plugin(s) |
|
darope@0
|
78 |
else if(!strcasecmp(cmd, "pause")) |
|
darope@0
|
79 |
cmd_doplug(PC_PAUSE); |
|
darope@0
|
80 |
else if(!strcasecmp(cmd, "unpause")) |
|
darope@0
|
81 |
cmd_doplug(PC_UNPAUSE); |
|
darope@0
|
82 |
else if(!strcasecmp(cmd, "unload")) |
|
darope@0
|
83 |
cmd_doplug(PC_UNLOAD); |
|
darope@0
|
84 |
else if(!strcasecmp(cmd, "force_unload")) |
|
darope@0
|
85 |
cmd_doplug(PC_FORCE_UNLOAD); |
|
darope@0
|
86 |
else if(!strcasecmp(cmd, "reload")) |
|
darope@0
|
87 |
cmd_doplug(PC_RELOAD); |
|
darope@0
|
88 |
else if(!strcasecmp(cmd, "retry")) |
|
darope@0
|
89 |
cmd_doplug(PC_RETRY); |
|
darope@0
|
90 |
else if(!strcasecmp(cmd, "clear")) |
|
darope@0
|
91 |
cmd_doplug(PC_CLEAR); |
|
darope@0
|
92 |
else if(!strcasecmp(cmd, "info")) |
|
darope@0
|
93 |
cmd_doplug(PC_INFO); |
|
darope@0
|
94 |
else if(!strcasecmp(cmd, "require")) |
|
darope@0
|
95 |
cmd_doplug(PC_REQUIRE); |
|
darope@0
|
96 |
// arguments: filename, description |
|
darope@0
|
97 |
else if(!strcasecmp(cmd, "load")) |
|
darope@0
|
98 |
cmd_meta_load(); |
|
darope@0
|
99 |
// unrecognized |
|
darope@0
|
100 |
else { |
|
darope@0
|
101 |
META_CONS("Unrecognized meta command: %s", cmd); |
|
darope@0
|
102 |
cmd_meta_usage(); |
|
darope@0
|
103 |
return; |
|
darope@0
|
104 |
} |
|
darope@0
|
105 |
} |
|
darope@0
|
106 |
|
|
darope@0
|
107 |
// Parse "meta" client command. |
|
darope@0
|
108 |
void client_meta(edict_t *pEntity) { |
|
darope@0
|
109 |
const char *cmd; |
|
darope@0
|
110 |
cmd=CMD_ARGV(1); |
|
darope@0
|
111 |
META_LOG("ClientCommand 'meta %s' from player '%s'", |
|
darope@0
|
112 |
CMD_ARGS(), STRING(pEntity->v.netname)); |
|
darope@0
|
113 |
// arguments: none |
|
darope@0
|
114 |
if(strmatch(cmd, "version")) |
|
darope@0
|
115 |
client_meta_version(pEntity); |
|
darope@0
|
116 |
else if(strmatch(cmd, "list")) |
|
darope@0
|
117 |
client_meta_pluginlist(pEntity); |
|
darope@0
|
118 |
// unrecognized |
|
darope@0
|
119 |
else { |
|
darope@0
|
120 |
META_CLIENT(pEntity, "Unrecognized meta command: %s", cmd); |
|
darope@0
|
121 |
client_meta_usage(pEntity); |
|
darope@0
|
122 |
return; |
|
darope@0
|
123 |
} |
|
darope@0
|
124 |
} |
|
darope@0
|
125 |
|
|
darope@0
|
126 |
// Print usage for "meta" console command. |
|
darope@0
|
127 |
void cmd_meta_usage(void) { |
|
darope@0
|
128 |
META_CONS("usage: meta <command> [<arguments>]"); |
|
darope@0
|
129 |
META_CONS("valid commands are:"); |
|
darope@0
|
130 |
META_CONS(" version - display metamod version info"); |
|
darope@0
|
131 |
META_CONS(" game - display gamedll info"); |
|
darope@0
|
132 |
META_CONS(" list - list plugins currently loaded"); |
|
darope@0
|
133 |
META_CONS(" cmds - list console cmds registered by plugins"); |
|
darope@0
|
134 |
META_CONS(" cvars - list cvars registered by plugins"); |
|
darope@0
|
135 |
META_CONS(" refresh - load/unload any new/deleted/updated plugins"); |
|
darope@0
|
136 |
META_CONS(" config - show config info loaded from config.ini"); |
|
darope@0
|
137 |
META_CONS(" load <name> - find and load a plugin with the given name"); |
|
darope@0
|
138 |
META_CONS(" unload <plugin> - unload a loaded plugin"); |
|
darope@0
|
139 |
META_CONS(" reload <plugin> - unload a plugin and load it again"); |
|
darope@0
|
140 |
META_CONS(" info <plugin> - show all information about a plugin"); |
|
darope@0
|
141 |
META_CONS(" pause <plugin> - pause a loaded, running plugin"); |
|
darope@0
|
142 |
META_CONS(" unpause <plugin> - unpause a previously paused plugin"); |
|
darope@0
|
143 |
META_CONS(" retry <plugin> - retry a plugin that previously failed its action"); |
|
darope@0
|
144 |
META_CONS(" clear <plugin> - clear a failed plugin from the list"); |
|
darope@0
|
145 |
META_CONS(" force_unload <plugin> - forcibly unload a loaded plugin"); |
|
darope@0
|
146 |
META_CONS(" require <plugin> - exit server if plugin not loaded/running"); |
|
darope@0
|
147 |
} |
|
darope@0
|
148 |
|
|
darope@0
|
149 |
// Print usage for "meta" client command. |
|
darope@0
|
150 |
void client_meta_usage(edict_t *pEntity) { |
|
darope@0
|
151 |
META_CLIENT(pEntity, "usage: meta <command> [<arguments>]"); |
|
darope@0
|
152 |
META_CLIENT(pEntity, "valid commands are:"); |
|
darope@0
|
153 |
META_CLIENT(pEntity, " version - display metamod version info"); |
|
darope@0
|
154 |
META_CLIENT(pEntity, " list - list plugins currently loaded"); |
|
darope@0
|
155 |
} |
|
darope@0
|
156 |
|
|
darope@0
|
157 |
// "meta version" console command. |
|
darope@0
|
158 |
void cmd_meta_version(void) { |
|
darope@0
|
159 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
160 |
META_CONS("usage: meta version"); |
|
darope@0
|
161 |
return; |
|
darope@0
|
162 |
} |
|
darope@248
|
163 |
META_CONS("%s v%s %s (%s)", VNAME, VVERSION, VDATE, META_INTERFACE_VERSION); |
|
darope@0
|
164 |
META_CONS("by %s", VAUTHOR); |
|
darope@0
|
165 |
META_CONS(" %s", VURL); |
|
darope@236
|
166 |
META_CONS("compiled: %s %s (%s)", COMPILE_TIME, COMPILE_TZONE, OPT_TYPE); |
|
darope@0
|
167 |
} |
|
darope@0
|
168 |
|
|
darope@0
|
169 |
// "meta version" client command. |
|
darope@0
|
170 |
void client_meta_version(edict_t *pEntity) { |
|
darope@0
|
171 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
172 |
META_CLIENT(pEntity, "usage: meta version"); |
|
darope@0
|
173 |
return; |
|
darope@0
|
174 |
} |
|
darope@248
|
175 |
META_CLIENT(pEntity, "%s v%s %s (%s)", VNAME, VVERSION, VDATE, META_INTERFACE_VERSION); |
|
darope@0
|
176 |
META_CLIENT(pEntity, "by %s", VAUTHOR); |
|
darope@0
|
177 |
META_CLIENT(pEntity, " %s", VURL); |
|
darope@236
|
178 |
META_CLIENT(pEntity, "compiled: %s %s (%s)", COMPILE_TIME, COMPILE_TZONE, OPT_TYPE); |
|
darope@248
|
179 |
META_CLIENT(pEntity, "ifvers: %s", META_INTERFACE_VERSION); |
|
darope@0
|
180 |
} |
|
darope@0
|
181 |
|
|
darope@0
|
182 |
// "meta gpl" console command. |
|
darope@0
|
183 |
void cmd_meta_gpl(void) { |
|
darope@0
|
184 |
META_CONS("%s version %s %s", VNAME, VVERSION, VDATE); |
|
darope@236
|
185 |
META_CONS("Copyright (c) 2001-%s Will Day <[email protected]>", COPYRIGHT_YEAR); |
|
darope@0
|
186 |
META_CONS(""); |
|
darope@0
|
187 |
META_CONS(" Metamod is free software; you can redistribute it and/or"); |
|
darope@0
|
188 |
META_CONS(" modify it under the terms of the GNU General Public License"); |
|
darope@0
|
189 |
META_CONS(" as published by the Free Software Foundation; either"); |
|
darope@0
|
190 |
META_CONS(" version 2 of the License, or (at your option) any later"); |
|
darope@0
|
191 |
META_CONS(" version."); |
|
darope@0
|
192 |
META_CONS(" "); |
|
darope@0
|
193 |
META_CONS(" Metamod is distributed in the hope that it will be useful,"); |
|
darope@0
|
194 |
META_CONS(" but WITHOUT ANY WARRANTY; without even the implied warranty"); |
|
darope@0
|
195 |
META_CONS(" of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); |
|
darope@0
|
196 |
META_CONS(" See the GNU General Public License for more details."); |
|
darope@0
|
197 |
META_CONS(" "); |
|
darope@0
|
198 |
META_CONS(" You should have received a copy of the GNU General Public"); |
|
darope@0
|
199 |
META_CONS(" License along with Metamod; if not, write to the Free"); |
|
darope@0
|
200 |
META_CONS(" Software Foundation, Inc., 59 Temple Place, Suite 330,"); |
|
darope@0
|
201 |
META_CONS(" Boston, MA 02111-1307 USA"); |
|
darope@0
|
202 |
META_CONS(" "); |
|
darope@0
|
203 |
META_CONS(" In addition, as a special exception, the author gives"); |
|
darope@0
|
204 |
META_CONS(" permission to link the code of this program with the"); |
|
darope@0
|
205 |
META_CONS(" Half-Life Game Engine (\"HL Engine\") and Modified Game"); |
|
darope@0
|
206 |
META_CONS(" Libraries (\"MODs\") developed by Valve, L.L.C (\"Valve\")."); |
|
darope@0
|
207 |
META_CONS(" You must obey the GNU General Public License in all"); |
|
darope@0
|
208 |
META_CONS(" respects for all of the code used other than the HL Engine"); |
|
darope@0
|
209 |
META_CONS(" and MODs from Valve. If you modify this file, you may"); |
|
darope@0
|
210 |
META_CONS(" extend this exception to your version of the file, but you"); |
|
darope@0
|
211 |
META_CONS(" are not obligated to do so. If you do not wish to do so,"); |
|
darope@0
|
212 |
META_CONS(" delete this exception statement from your version."); |
|
darope@0
|
213 |
} |
|
darope@0
|
214 |
|
|
darope@0
|
215 |
// "meta game" console command. |
|
darope@0
|
216 |
void cmd_meta_game(void) { |
|
darope@0
|
217 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
218 |
META_CONS("usage: meta game"); |
|
darope@0
|
219 |
return; |
|
darope@0
|
220 |
} |
|
darope@0
|
221 |
META_CONS("GameDLL info:"); |
|
darope@0
|
222 |
META_CONS(" name: %s", GameDLL.name); |
|
darope@0
|
223 |
META_CONS(" desc: %s", GameDLL.desc); |
|
darope@0
|
224 |
META_CONS(" gamedir: %s", GameDLL.gamedir); |
|
darope@0
|
225 |
META_CONS(" dll file: %s", GameDLL.file); |
|
darope@0
|
226 |
META_CONS("dll pathname: %s", GameDLL.pathname); |
|
darope@0
|
227 |
RegMsgs->show(); |
|
darope@0
|
228 |
} |
|
darope@0
|
229 |
|
|
darope@0
|
230 |
// "meta refresh" console command. |
|
darope@0
|
231 |
void cmd_meta_refresh(void) { |
|
darope@0
|
232 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
233 |
META_CONS("usage: meta refresh"); |
|
darope@0
|
234 |
return; |
|
darope@0
|
235 |
} |
|
darope@0
|
236 |
META_LOG("Refreshing the plugins on demand..."); |
|
darope@0
|
237 |
if(Plugins->refresh(PT_ANYTIME) != mTRUE) { |
|
darope@0
|
238 |
META_LOG("Refresh failed."); |
|
darope@0
|
239 |
} |
|
darope@0
|
240 |
} |
|
darope@0
|
241 |
|
|
darope@0
|
242 |
// "meta list" console command. |
|
darope@0
|
243 |
void cmd_meta_pluginlist(void) { |
|
darope@0
|
244 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
245 |
META_CONS("usage: meta list"); |
|
darope@0
|
246 |
return; |
|
darope@0
|
247 |
} |
|
darope@248
|
248 |
Plugins->show(0); |
|
darope@0
|
249 |
} |
|
darope@0
|
250 |
|
|
darope@0
|
251 |
// "meta list" client command. |
|
darope@0
|
252 |
void client_meta_pluginlist(edict_t *pEntity) { |
|
darope@0
|
253 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
254 |
META_CLIENT(pEntity, "usage: meta list"); |
|
darope@0
|
255 |
return; |
|
darope@0
|
256 |
} |
|
darope@0
|
257 |
Plugins->show_client(pEntity); |
|
darope@0
|
258 |
} |
|
darope@0
|
259 |
|
|
darope@0
|
260 |
// "meta cmds" console command. |
|
darope@0
|
261 |
void cmd_meta_cmdlist(void) { |
|
darope@0
|
262 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
263 |
META_CONS("usage: meta cmds"); |
|
darope@0
|
264 |
return; |
|
darope@0
|
265 |
} |
|
darope@0
|
266 |
RegCmds->show(); |
|
darope@0
|
267 |
} |
|
darope@0
|
268 |
|
|
darope@0
|
269 |
// "meta cvars" console command. |
|
darope@0
|
270 |
void cmd_meta_cvarlist(void) { |
|
darope@0
|
271 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
272 |
META_CONS("usage: meta cvars"); |
|
darope@0
|
273 |
return; |
|
darope@0
|
274 |
} |
|
darope@0
|
275 |
RegCvars->show(); |
|
darope@0
|
276 |
} |
|
darope@0
|
277 |
|
|
darope@0
|
278 |
// "meta config" console command. |
|
darope@0
|
279 |
void cmd_meta_config(void) { |
|
darope@0
|
280 |
if(CMD_ARGC() != 2) { |
|
darope@0
|
281 |
META_CONS("usage: meta cvars"); |
|
darope@0
|
282 |
return; |
|
darope@0
|
283 |
} |
|
darope@0
|
284 |
Config->show(); |
|
darope@0
|
285 |
} |
|
darope@0
|
286 |
|
|
darope@0
|
287 |
// gamedir/filename |
|
darope@0
|
288 |
// gamedir/dlls/filename |
|
darope@0
|
289 |
// |
|
darope@0
|
290 |
// dir/mm_file |
|
darope@0
|
291 |
// dir/file |
|
darope@0
|
292 |
// |
|
darope@0
|
293 |
// path |
|
darope@0
|
294 |
// path_mm |
|
darope@0
|
295 |
// path_MM |
|
darope@0
|
296 |
// path.so, path.dll |
|
darope@0
|
297 |
// path_i386.so, path_i486.so, etc |
|
darope@0
|
298 |
|
|
darope@0
|
299 |
// "meta load" console command. |
|
darope@0
|
300 |
void cmd_meta_load(void) { |
|
darope@0
|
301 |
int argc; |
|
darope@0
|
302 |
const char *args; |
|
darope@0
|
303 |
argc=CMD_ARGC(); |
|
darope@0
|
304 |
if(argc < 3) { |
|
darope@0
|
305 |
META_CONS("usage: meta load <name> [<description>]"); |
|
darope@0
|
306 |
META_CONS(" where <name> is an identifier used to locate the plugin file."); |
|
darope@0
|
307 |
META_CONS(" The system will look for a number of files based on this name, including:"); |
|
darope@0
|
308 |
META_CONS(" name"); |
|
darope@0
|
309 |
#ifdef linux |
|
darope@0
|
310 |
META_CONS(" name.so"); |
|
darope@0
|
311 |
META_CONS(" name_mm.so"); |
|
darope@0
|
312 |
META_CONS(" name_MM.so"); |
|
darope@0
|
313 |
META_CONS(" mm_name.so"); |
|
darope@0
|
314 |
META_CONS(" name_i386.so"); |
|
darope@0
|
315 |
META_CONS(" name_i686.so"); |
|
darope@0
|
316 |
#elif defined(_WIN32) |
|
darope@0
|
317 |
META_CONS(" name.dll"); |
|
darope@0
|
318 |
META_CONS(" name_mm.dll"); |
|
darope@0
|
319 |
META_CONS(" mm_name.dll"); |
|
darope@0
|
320 |
#endif /* linux */ |
|
darope@0
|
321 |
META_CONS(" in a number of directories, including:"); |
|
darope@0
|
322 |
META_CONS(" <gamedir>"); |
|
darope@0
|
323 |
META_CONS(" <gamedir>/dlls"); |
|
darope@0
|
324 |
META_CONS(" <given path, if absolute>"); |
|
darope@0
|
325 |
return; |
|
darope@0
|
326 |
} |
|
darope@0
|
327 |
args=CMD_ARGS(); |
|
darope@0
|
328 |
// cmd_addload() handles all the feedback to the console.. |
|
darope@0
|
329 |
Plugins->cmd_addload(args); |
|
darope@0
|
330 |
} |
|
darope@0
|
331 |
|
|
darope@0
|
332 |
// Handle various console commands that refer to a known/loaded plugin. |
|
darope@0
|
333 |
void cmd_doplug(PLUG_CMD pcmd) { |
|
darope@0
|
334 |
int i=0, argc; |
|
darope@0
|
335 |
const char *cmd, *arg; |
|
darope@0
|
336 |
MPlugin *findp; |
|
darope@0
|
337 |
|
|
darope@0
|
338 |
argc=CMD_ARGC(); |
|
darope@0
|
339 |
cmd=CMD_ARGV(1); |
|
darope@0
|
340 |
if(argc < 3) { |
|
darope@0
|
341 |
META_CONS("usage: meta %s <plugin> [<plugin> ...]", cmd); |
|
darope@0
|
342 |
META_CONS(" where <plugin> can be either the plugin index #"); |
|
darope@0
|
343 |
META_CONS(" or a non-ambiguous prefix string matching name, desc, file, or logtag"); |
|
darope@0
|
344 |
return; |
|
darope@0
|
345 |
} |
|
darope@0
|
346 |
// i=2 to skip first arg, as that's the "cmd" |
|
darope@0
|
347 |
for(i=2; i < argc; i++) { |
|
darope@248
|
348 |
int pindex; |
|
darope@248
|
349 |
char *endptr; |
|
darope@0
|
350 |
arg=CMD_ARGV(i); |
|
darope@0
|
351 |
|
|
darope@0
|
352 |
// try to match plugin id first |
|
darope@248
|
353 |
pindex = strtol(arg, &endptr, 10); |
|
darope@248
|
354 |
if (*arg != '\0' && *endptr == '\0') |
|
darope@248
|
355 |
findp=Plugins->find(pindex); |
|
darope@0
|
356 |
// else try to match some string (prefix) |
|
darope@0
|
357 |
else |
|
darope@0
|
358 |
findp=Plugins->find_match(arg); |
|
darope@0
|
359 |
|
|
darope@0
|
360 |
// Require that: |
|
darope@0
|
361 |
// - specified plugin was found in the list of current plugins |
|
darope@0
|
362 |
// - plugin successfully loaded and began running |
|
darope@0
|
363 |
// Otherwise, print error and exit. |
|
darope@0
|
364 |
if(pcmd==PC_REQUIRE) { |
|
darope@0
|
365 |
if(findp && findp->status >= PL_RUNNING) { |
|
darope@0
|
366 |
META_DEBUG(3, ("Required plugin '%s' found loaded and running.", |
|
darope@0
|
367 |
arg)); |
|
darope@0
|
368 |
return; |
|
darope@0
|
369 |
} |
|
darope@0
|
370 |
// Output to both places, because we don't want the admin |
|
darope@0
|
371 |
// to miss this.. |
|
darope@0
|
372 |
if(!findp && meta_errno == ME_NOTUNIQ) { |
|
darope@0
|
373 |
META_ERROR("Unique match for required plugin '%s' was not found! Exiting.", arg); |
|
darope@0
|
374 |
META_CONS("\nERROR: Unique match for required plugin '%s' was not found! Exiting.\n", arg); |
|
darope@0
|
375 |
} |
|
darope@0
|
376 |
else if (!findp) { |
|
darope@0
|
377 |
META_ERROR("Required plugin '%s' was not found! Exiting.", |
|
darope@0
|
378 |
arg); |
|
darope@0
|
379 |
META_CONS("\nERROR: Required plugin '%s' was not found! Exiting.\n", |
|
darope@0
|
380 |
arg); |
|
darope@0
|
381 |
} |
|
darope@0
|
382 |
else { |
|
darope@0
|
383 |
META_ERROR("Required plugin '%s' did not load successfully! (status=%s) Exiting.", arg, findp->str_status(ST_SIMPLE)); |
|
darope@0
|
384 |
META_CONS("\nERROR: Required plugin '%s' did not load successfully! (status=%s) Exiting.\n", arg, findp->str_status(ST_SIMPLE)); |
|
darope@0
|
385 |
} |
|
darope@0
|
386 |
// Allow chance to read the message, before any window closes. |
|
darope@0
|
387 |
sleep(1); |
|
darope@0
|
388 |
#ifdef linux |
|
darope@0
|
389 |
// Argh, "quit" appears to segfault the server under linux; I |
|
darope@0
|
390 |
// was unable to determine why. |
|
darope@0
|
391 |
exit(1); |
|
darope@0
|
392 |
#else |
|
darope@0
|
393 |
// Argh, and exit() appears to generate an "Application Error" |
|
darope@0
|
394 |
// under MSVC. Interestingly, both seem to work fine with |
|
darope@0
|
395 |
// mingw32. |
|
darope@0
|
396 |
SERVER_COMMAND("quit\n"); |
|
darope@0
|
397 |
#endif /* not linux */ |
|
darope@0
|
398 |
} |
|
darope@0
|
399 |
|
|
darope@0
|
400 |
if(!findp) { |
|
darope@0
|
401 |
if(meta_errno == ME_NOTUNIQ) |
|
darope@0
|
402 |
META_CONS("Couldn't find unique plugin matching '%s'", arg); |
|
darope@0
|
403 |
else |
|
darope@0
|
404 |
META_CONS("Couldn't find plugin matching '%s'", arg); |
|
darope@0
|
405 |
return; |
|
darope@0
|
406 |
} |
|
darope@0
|
407 |
|
|
darope@0
|
408 |
if(pcmd==PC_PAUSE) { |
|
darope@0
|
409 |
if(findp->pause()) |
|
darope@0
|
410 |
META_CONS("Paused plugin '%s'", findp->desc); |
|
darope@0
|
411 |
else |
|
darope@0
|
412 |
META_CONS("Pause failed for plugin '%s'", findp->desc); |
|
darope@0
|
413 |
} |
|
darope@0
|
414 |
else if(pcmd==PC_UNPAUSE) { |
|
darope@0
|
415 |
if(findp->unpause()) |
|
darope@0
|
416 |
META_CONS("Unpaused plugin '%s'", findp->desc); |
|
darope@0
|
417 |
else |
|
darope@0
|
418 |
META_CONS("Unpause failed for plugin '%s'", findp->desc); |
|
darope@0
|
419 |
} |
|
darope@0
|
420 |
else if(pcmd==PC_UNLOAD) { |
|
darope@0
|
421 |
findp->action=PA_UNLOAD; |
|
darope@248
|
422 |
if(findp->unload(PT_ANYTIME, PNL_COMMAND, PNL_COMMAND)) { |
|
darope@0
|
423 |
META_CONS("Unloaded plugin '%s'", findp->desc); |
|
darope@248
|
424 |
Plugins->show(0); |
|
darope@0
|
425 |
} |
|
darope@0
|
426 |
else if(meta_errno == ME_DELAYED) |
|
darope@0
|
427 |
META_CONS("Unload delayed for plugin '%s'", findp->desc); |
|
darope@0
|
428 |
else |
|
darope@0
|
429 |
META_CONS("Unload failed for plugin '%s'", findp->desc); |
|
darope@0
|
430 |
} |
|
darope@0
|
431 |
else if(pcmd==PC_FORCE_UNLOAD) { |
|
darope@0
|
432 |
findp->action=PA_UNLOAD; |
|
darope@248
|
433 |
if(findp->unload(PT_ANYTIME, PNL_CMD_FORCED, PNL_CMD_FORCED)) { |
|
darope@0
|
434 |
META_CONS("Forced unload plugin '%s'", findp->desc); |
|
darope@248
|
435 |
Plugins->show(0); |
|
darope@0
|
436 |
} |
|
darope@0
|
437 |
else |
|
darope@0
|
438 |
META_CONS("Forced unload failed for plugin '%s'", findp->desc); |
|
darope@0
|
439 |
} |
|
darope@0
|
440 |
else if(pcmd==PC_RELOAD) { |
|
darope@0
|
441 |
findp->action=PA_RELOAD; |
|
darope@0
|
442 |
if(findp->reload(PT_ANYTIME, PNL_COMMAND)) |
|
darope@0
|
443 |
META_CONS("Reloaded plugin '%s'", findp->desc); |
|
darope@0
|
444 |
else if(meta_errno == ME_DELAYED) |
|
darope@0
|
445 |
META_CONS("Reload delayed for plugin '%s'", findp->desc); |
|
darope@246
|
446 |
else if(meta_errno == ME_NOTALLOWED) |
|
darope@246
|
447 |
META_CONS("Reload not allowed for plugin '%s' now, only allowed %s", findp->desc, findp->str_loadable(SL_ALLOWED)); |
|
darope@0
|
448 |
else |
|
darope@0
|
449 |
META_CONS("Reload failed for plugin '%s'", findp->desc); |
|
darope@0
|
450 |
} |
|
darope@0
|
451 |
else if(pcmd==PC_RETRY) { |
|
darope@0
|
452 |
if(findp->retry(PT_ANYTIME, PNL_COMMAND)) |
|
darope@0
|
453 |
META_CONS("Retry succeeded for plugin '%s'", findp->desc); |
|
darope@0
|
454 |
else |
|
darope@0
|
455 |
META_CONS("Retry failed for plugin '%s'", findp->desc); |
|
darope@0
|
456 |
} |
|
darope@0
|
457 |
else if(pcmd==PC_CLEAR) { |
|
darope@0
|
458 |
if(findp->clear()) { |
|
darope@0
|
459 |
META_CONS("Cleared failed plugin '%s' from list", findp->desc); |
|
darope@248
|
460 |
Plugins->show(0); |
|
darope@0
|
461 |
} |
|
darope@0
|
462 |
else |
|
darope@0
|
463 |
META_CONS("Clear failed for plugin '%s'", findp->desc); |
|
darope@0
|
464 |
} |
|
darope@0
|
465 |
else if(pcmd==PC_INFO) |
|
darope@0
|
466 |
findp->show(); |
|
darope@0
|
467 |
else { |
|
darope@0
|
468 |
META_ERROR("Unexpected plug_cmd: %d", pcmd); |
|
darope@0
|
469 |
META_CONS("Command failed; see log"); |
|
darope@0
|
470 |
} |
|
darope@0
|
471 |
} |
|
darope@0
|
472 |
} |