[Half-Life AMXX] / pausecfg.sma Repository:
ViewVC logotype

Annotation of /pausecfg.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * Pause Plugins Plugin
3 :     *
4 :     * by the AMX Mod X Development Team
5 :     * originally developed by OLO
6 :     *
7 :     * This file is part of AMX Mod X.
8 :     *
9 :     *
10 :     * This program is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by the
12 :     * Free Software Foundation; either version 2 of the License, or (at
13 :     * your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful, but
16 :     * WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 :     * General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software Foundation,
22 :     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * In addition, as a special exception, the author gives permission to
25 :     * link the code of this program with the Half-Life Game Engine ("HL
26 :     * Engine") and Modified Game Libraries ("MODs") developed by Valve,
27 :     * L.L.C ("Valve"). You must obey the GNU General Public License in all
28 :     * respects for all of the code used other than the HL Engine and MODs
29 :     * from Valve. If you modify this file, you may extend this exception
30 :     * to your version of the file, but you are not obligated to do so. If
31 :     * you do not wish to do so, delete this exception statement from your
32 :     * version.
33 :     */
34 :    
35 :     #include <amxmodx>
36 :     #include <amxmisc>
37 :    
38 :     // Uncomment if you want to have two new commands
39 :     // amx_off - pause plugins not marked as unpauseable
40 :     // amx_on - enable plugins not marked as unpauseable
41 :     #define DIRECT_ONOFF
42 :    
43 :     #define MAX_SYSTEM 32
44 :    
45 :     new g_menuPos[33]
46 :     new g_fileToSave[64]
47 :     new g_coloredMenus
48 :     new g_Modified
49 :     new g_addCmd[] = "amx_pausecfg add ^"%s^""
50 :     new g_system[MAX_SYSTEM]
51 :     new g_systemNum
52 :    
53 :     public plugin_init()
54 :     {
55 :     register_plugin("Pause Plugins", AMXX_VERSION_STR, "AMXX Dev Team")
56 :     register_dictionary("pausecfg.txt")
57 :     register_dictionary("common.txt")
58 :     register_dictionary("admincmd.txt")
59 :    
60 :     register_concmd("amx_pausecfg", "cmdPlugin", ADMIN_CFG, "- list commands for pause/unpause management")
61 :     register_clcmd("amx_pausecfgmenu", "cmdMenu", ADMIN_CFG, "- pause/unpause plugins with menu")
62 :     #if defined DIRECT_ONOFF
63 :     register_concmd("amx_off", "cmdOFF", ADMIN_CFG, "- pauses some plugins")
64 :     register_concmd("amx_on", "cmdON", ADMIN_CFG, "- unpauses some plugins")
65 :     #endif
66 :     register_menucmd(register_menuid("Pause/Unpause Plugins"), 1023, "actionMenu")
67 :    
68 :     g_coloredMenus = colored_menus()
69 :     get_configsdir(g_fileToSave, 63);
70 :     format(g_fileToSave, 63, "%s/pausecfg.ini", g_fileToSave);
71 :    
72 :     return PLUGIN_CONTINUE
73 :     }
74 :    
75 :     #if defined DIRECT_ONOFF
76 :     public cmdOFF(id, level, cid)
77 :     {
78 :     if (cmd_access(id, level, cid, 1))
79 :     pausePlugins(id)
80 :    
81 :     return PLUGIN_HANDLED
82 :     }
83 :    
84 :     public cmdON(id, level, cid)
85 :     {
86 :     if (cmd_access(id, level, cid, 1))
87 :     unpausePlugins(id)
88 :    
89 :     return PLUGIN_HANDLED
90 :     }
91 :     #endif
92 :    
93 :     public plugin_cfg()
94 :     {
95 :     loadSettings(g_fileToSave)
96 :    
97 :     // Put here titles of plugins which you don't want to pause
98 :     server_cmd(g_addCmd, "Admin Base")
99 :     server_cmd(g_addCmd, "Admin Base (SQL)")
100 :     server_cmd(g_addCmd, "Pause Plugins")
101 :     server_cmd(g_addCmd, "TimeLeft")
102 :     server_cmd(g_addCmd, "NextMap")
103 :     server_cmd(g_addCmd, "Slots Reservation")
104 :     }
105 :    
106 :     public actionMenu(id, key)
107 :     {
108 :     switch (key)
109 :     {
110 :     case 6:
111 :     {
112 :     if (file_exists(g_fileToSave))
113 :     {
114 :     delete_file(g_fileToSave)
115 :     client_print(id, print_chat, "* %L", id, "PAUSE_CONF_CLEARED")
116 :     }
117 :     else
118 :     client_print(id, print_chat, "* %L", id, "PAUSE_ALR_CLEARED")
119 :    
120 :     displayMenu(id, g_menuPos[id])
121 :     }
122 :     case 7:
123 :     {
124 :     if (saveSettings(g_fileToSave))
125 :     {
126 :     g_Modified = 0
127 :     client_print(id, print_chat, "* %L", id, "PAUSE_CONF_SAVED")
128 :     }
129 :     else
130 :     client_print(id, print_chat, "* %L", id, "PAUSE_SAVE_FAILED")
131 :    
132 :     displayMenu(id, g_menuPos[id])
133 :     }
134 :     case 8: displayMenu(id, ++g_menuPos[id])
135 :     case 9: displayMenu(id, --g_menuPos[id])
136 :     default:
137 :     {
138 :     new option = g_menuPos[id] * 6 + key
139 :     new file[32], status[2]
140 :    
141 :     get_plugin(option, file, 31, status, 0, status, 0, status, 0, status, 1)
142 :    
143 :     switch (status[0])
144 :     {
145 :     case 'r': pause("ac", file)
146 :     case 'p':
147 :     {
148 :     g_Modified = 1
149 :     unpause("ac", file)
150 :     }
151 :     }
152 :    
153 :     displayMenu(id, g_menuPos[id])
154 :     }
155 :     }
156 :    
157 :     return PLUGIN_HANDLED
158 :     }
159 :    
160 :     getStatus(id, code, &statusCode, lStatus[], lLen)
161 :     {
162 :     switch (code)
163 :     {
164 :     case 'r':
165 :     {
166 :     statusCode = 'O'
167 :     format(lStatus, lLen, "%L", id, "ON")
168 :     }
169 :     case 's':
170 :     {
171 :     statusCode = 'S'
172 :     format(lStatus, lLen, "%L", id, "STOPPED")
173 :     }
174 :     case 'p':
175 :     {
176 :     statusCode = 'O'
177 :     format(lStatus, lLen, "%L", id, "OFF")
178 :     }
179 :     case 'b':
180 :     {
181 :     statusCode = 'E'
182 :     format(lStatus, lLen, "%L", id, "ERROR")
183 :     }
184 :     default:
185 :     {
186 :     statusCode = 'L'
187 :     format(lStatus, lLen, "%L", id, "LOCKED")
188 :     }
189 :     }
190 :     }
191 :    
192 :     isSystem(id)
193 :     {
194 :     for (new a = 0; a < g_systemNum; ++a)
195 :     if (g_system[a] == id)
196 :     return 1
197 :     return 0
198 :     }
199 :    
200 :     displayMenu(id, pos)
201 :     {
202 :     if (pos < 0) return
203 :    
204 :     new filename[32], title[32], status[8], statusCode
205 :     new datanum = get_pluginsnum()
206 :     new menu_body[512], start = pos * 6, k = 0
207 :    
208 :     if (start >= datanum)
209 :     start = pos = g_menuPos[id] = 0
210 :    
211 :     new len = format(menu_body, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, "PAUSE_UNPAUSE", pos + 1, ((datanum / 6) + ((datanum % 6) ? 1 : 0)))
212 :     new end = start + 6, keys = MENU_KEY_0|MENU_KEY_8|MENU_KEY_7
213 :    
214 :     if (end > datanum)
215 :     end = datanum
216 :    
217 :     for (new a = start; a < end; ++a)
218 :     {
219 :     get_plugin(a, filename, 31, title, 31, status, 0, status, 0, status, 1)
220 :     getStatus(id, status[0], statusCode, status, 7)
221 :    
222 :     if (isSystem(a) || (statusCode != 'O' && statusCode != 'S'))
223 :     {
224 :     if (g_coloredMenus)
225 :     {
226 :     len += format(menu_body[len], 511-len, "\d%d. %s\R%s^n\w", ++k, title, status)
227 :     } else {
228 :     ++k
229 :     len += format(menu_body[len], 511-len, "#. %s %s^n", title, status)
230 :     }
231 :     } else {
232 :     keys |= (1<<k)
233 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "%d. %s\y\R%s^n\w" : "%d. %s %s^n", ++k, title, status)
234 :     }
235 :     }
236 :    
237 :     len += format(menu_body[len], 511-len, "^n7. %L^n", id, "CLEAR_STOPPED")
238 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "8. %L \y\R%s^n\w" : "8. %L %s^n", id, "SAVE_STOPPED", g_Modified ? "*" : "")
239 :    
240 :     if (end != datanum)
241 :     {
242 :     format(menu_body[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
243 :     keys |= MENU_KEY_9
244 :     }
245 :     else
246 :     format(menu_body[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
247 :    
248 :     show_menu(id, keys, menu_body, -1, "Pause/Unpause Plugins")
249 :     }
250 :    
251 :     public cmdMenu(id, level, cid)
252 :     {
253 :     if (cmd_access(id, level, cid, 1))
254 :     displayMenu(id, g_menuPos[id] = 0)
255 :    
256 :     return PLUGIN_HANDLED
257 :     }
258 :    
259 :     pausePlugins(id)
260 :     {
261 :     new filename[32], title[32], status[2]
262 :     new count = 0, imax = get_pluginsnum()
263 :    
264 :     for (new a = 0; a < imax; ++a)
265 :     {
266 :     get_plugin(a, filename, 31, title, 31, status, 0, status, 0, status, 1)
267 :    
268 :     if (!isSystem(a) && status[0] == 'r' && pause("ac", filename))
269 :     {
270 :     //console_print(id, "Pausing %s (file ^"%s^")", title, filename)
271 :     ++count
272 :     }
273 :     }
274 :    
275 :     console_print(id, "%L", id, (count == 1) ? "PAUSED_PLUGIN" : "PAUSED_PLUGINS", count)
276 :     }
277 :    
278 :     unpausePlugins(id)
279 :     {
280 :     new filename[32], title[32], status[2]
281 :     new count = 0, imax = get_pluginsnum()
282 :    
283 :     for (new a = 0; a < imax; ++a)
284 :     {
285 :     get_plugin(a, filename, 31, title, 31, status, 0, status, 0, status, 1)
286 :    
287 :     if (!isSystem(a) && status[0] == 'p' && unpause("ac", filename))
288 :     {
289 :     //console_print(id, "Unpausing %s (file ^"%s^")", title, filename)
290 :     ++count
291 :     }
292 :     }
293 :    
294 :     console_print(id, "%L", id, (count == 1) ? "UNPAUSED_PLUGIN" : "UNPAUSED_PLUGINS", count)
295 :     }
296 :    
297 :     findPluginByFile(arg[32], &len)
298 :     {
299 :     new name[32], title[32], status[2]
300 :     new inum = get_pluginsnum()
301 :    
302 :     for (new a = 0; a < inum; ++a)
303 :     {
304 :     get_plugin(a, name, 31, title, 31, status, 0, status, 0, status, 1)
305 :    
306 :     if (equali(name, arg, len) && (
307 :     status[0] == 'r' || /*running*/
308 :     status[0] == 'p' || /*paused*/
309 :     status[0] == 's' || /*stopped*/
310 :     status[0] == 'd' )) /*debug*/
311 :     {
312 :     len = copy(arg, 31, name)
313 :     return a
314 :     }
315 :     }
316 :    
317 :     return -1
318 :     }
319 :    
320 :     findPluginByTitle(name[], file[], len)
321 :     {
322 :     new title[32], status[2]
323 :     new inum = get_pluginsnum()
324 :    
325 :     for (new a = 0; a < inum; ++a)
326 :     {
327 :     get_plugin(a, file, len, title, 31, status, 0, status, 0, status, 1)
328 :    
329 :     if (equali(title, name))
330 :     return a
331 :     }
332 :    
333 :     return -1
334 :     }
335 :    
336 :     public cmdPlugin(id, level, cid)
337 :     {
338 :     if (!cmd_access(id, level, cid, 1))
339 :     return PLUGIN_HANDLED
340 :    
341 :     new cmds[32]
342 :     read_argv(1, cmds, 31)
343 :    
344 :     if (equal(cmds, "add") && read_argc() > 2)
345 :     {
346 :     read_argv(2, cmds, 31)
347 :     new file[2]
348 :    
349 :     if ((g_system[g_systemNum] = findPluginByTitle(cmds, file, 0)) != -1)
350 :     {
351 :     if (g_systemNum < MAX_SYSTEM)
352 :     g_systemNum++
353 :     else
354 :     console_print(id, "%L", id, "CANT_MARK_MORE")
355 :     }
356 :     }
357 :     else if (equal(cmds, "off"))
358 :     {
359 :     pausePlugins(id)
360 :     }
361 :     else if (equal(cmds, "on"))
362 :     {
363 :     unpausePlugins(id)
364 :     }
365 :     else if (equal(cmds, "save"))
366 :     {
367 :     if (saveSettings(g_fileToSave))
368 :     {
369 :     g_Modified = 0
370 :     console_print(id, "%L", id, "PAUSE_CONF_SAVED")
371 :     }
372 :     else
373 :     console_print(id, "%L", id, "PAUSE_SAVE_FAILED")
374 :     }
375 :     else if (equal(cmds, "clear"))
376 :     {
377 :     if (file_exists(g_fileToSave))
378 :     {
379 :     delete_file(g_fileToSave)
380 :     console_print(id, "%L", id, "PAUSE_CONF_CLEARED")
381 :     }
382 :     else
383 :     console_print(id, "%L", id, "PAUSE_ALR_CLEARED")
384 :     }
385 :     else if (equal(cmds, "pause"))
386 :     {
387 :     new arg[32], a, len = read_argv(2, arg, 31)
388 :    
389 :     if (len && ((a = findPluginByFile(arg, len)) != -1) && !isSystem(a) && pause("ac", arg))
390 :     console_print(id, "%L %L", id, "PAUSE_PLUGIN_MATCH", arg, id, "PAUSED")
391 :     else
392 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
393 :     }
394 :     else if (equal(cmds, "enable"))
395 :     {
396 :     new arg[32], a, len = read_argv(2, arg, 31)
397 :    
398 :     if (len && (a = findPluginByFile(arg, len)) != -1 && !isSystem(a))
399 :     {
400 :     if (unpause("ac", arg))
401 :     {
402 :     console_print(id, "%L %L", id, "PAUSE_PLUGIN_MATCH", arg, id, "UNPAUSED")
403 :     }
404 :     else
405 :     {
406 :     // TODO: change this to let out an error that the plugin is stopped
407 :     // need language keys for this first! Use old message for now
408 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
409 :     }
410 :     }
411 :     else
412 :     {
413 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
414 :     }
415 :     }
416 :     else if (equal(cmds, "stop"))
417 :     {
418 :     new arg[32], a, len = read_argv(2, arg, 31)
419 :    
420 :     if (len && (a = findPluginByFile(arg, len)) != -1 && !isSystem(a) && pause("dc", arg))
421 :     {
422 :     g_Modified = 1
423 :     console_print(id, "%L %L", id, "PAUSE_PLUGIN_MATCH", arg, id, "STOPPED")
424 :     }
425 :     else
426 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
427 :     }
428 :     else if (equal(cmds, "list"))
429 :     {
430 :     new lName[32], lVersion[32], lAuthor[32], lFile[32], lStatus[32]
431 :    
432 :     format(lName, 31, "%L", id, "NAME")
433 :     format(lVersion, 31, "%L", id, "VERSION")
434 :     format(lAuthor, 31, "%L", id, "AUTHOR")
435 :     format(lFile, 31, "%L", id, "FILE")
436 :     format(lStatus, 31, "%L", id, "STATUS")
437 :    
438 :     new arg1[8], running = 0
439 :     new start = read_argv(2, arg1, 7) ? str_to_num(arg1) : 1
440 :    
441 :     if (--start < 0)
442 :     start = 0
443 :    
444 :     new plgnum = get_pluginsnum()
445 :    
446 :     if (start >= plgnum)
447 :     start = plgnum - 1
448 :    
449 :     console_print(id, "^n----- %L -----", id, "PAUSE_LOADED")
450 :     console_print(id, " %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s", lName, lVersion, lAuthor, lFile, lStatus)
451 :    
452 :     new plugin[32], title[32], version[16], author[32], status[16]
453 :     new end = start + 10
454 :    
455 :     if (end > plgnum) end = plgnum
456 :    
457 :     for (new a = start; a < end; ++a)
458 :     {
459 :     get_plugin(a, plugin, 31, title, 31, version, 15, author, 31, status, 15)
460 :     if (status[0] == 'r') ++running
461 :     console_print(id, " [%3d] %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s", a + 1, title, version, author, plugin, status)
462 :     }
463 :    
464 :     console_print(id, "----- %L -----", id, "PAUSE_ENTRIES", start + 1, end, plgnum, running)
465 :    
466 :     if (end < plgnum)
467 :     console_print(id, "----- %L -----", id, "PAUSE_USE_MORE", end + 1)
468 :     else
469 :     console_print(id, "----- %L -----", id, "PAUSE_USE_BEGIN")
470 :     } else {
471 :     console_print(id, "%L", id, "PAUSE_USAGE")
472 :     console_print(id, "%L:", id, "PAUSE_COMMANDS")
473 :     console_print(id, "%L", id, "COM_PAUSE_OFF")
474 :     console_print(id, "%L", id, "COM_PAUSE_ON")
475 :     console_print(id, "%L", id, "COM_PAUSE_STOP")
476 :     console_print(id, "%L", id, "COM_PAUSE_PAUSE")
477 :     console_print(id, "%L", id, "COM_PAUSE_ENABLE")
478 :     console_print(id, "%L", id, "COM_PAUSE_SAVE")
479 :     console_print(id, "%L", id, "COM_PAUSE_CLEAR")
480 :     console_print(id, "%L", id, "COM_PAUSE_LIST")
481 :     console_print(id, "%L", id, "COM_PAUSE_ADD")
482 :     }
483 :    
484 :     return PLUGIN_HANDLED
485 :     }
486 :    
487 :     saveSettings(filename[])
488 :     {
489 :     if (file_exists(filename))
490 :     delete_file(filename)
491 :    
492 :     new text[256], file[32], title[32], status[2]
493 :     new inum = get_pluginsnum()
494 :    
495 :     if (!write_file(filename, ";Generated by Pause Plugins Plugin. Do not modify!^n;Title Filename"))
496 :     return 0
497 :    
498 :     for (new a = 0; a < inum; ++a)
499 :     {
500 :     get_plugin(a, file, 31, title, 31, status, 0, status, 0, status, 1)
501 :    
502 :     if (status[0] == 's')
503 :     {
504 :     format(text, 255, "^"%s^" ;%s", title, file)
505 :     write_file(filename, text)
506 :     }
507 :     }
508 :    
509 :     return 1
510 :     }
511 :    
512 :     loadSettings(filename[])
513 :     {
514 :     if (!file_exists(filename))
515 :     return 0
516 :    
517 :     new name[256], file[32], i, pos = 0
518 :    
519 :     while (read_file(filename, pos++, name, 255, i))
520 :     {
521 :     if (name[0] != ';' && parse(name, name, 31) && (i = findPluginByTitle(name, file, 31) != -1))
522 :     pause("dc", file)
523 :     }
524 :    
525 :     return 1
526 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4