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

Annotation of /pausecfg.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (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 : ian 17 // "running"
146 : ian 1 case 'r': pause("ac", file)
147 : ian 17
148 :     // "debug"
149 :     case 'd': pause("ac", file)
150 :    
151 :     // "paused"
152 : ian 1 case 'p':
153 :     {
154 :     g_Modified = 1
155 :     unpause("ac", file)
156 :     }
157 : ian 17
158 :     // "stopped"
159 :     case 's':
160 :     {
161 :     client_print(id, print_chat, "%L", id, "CANT_UNPAUSE_PLUGIN", file);
162 :     }
163 : ian 1 }
164 :    
165 :     displayMenu(id, g_menuPos[id])
166 :     }
167 :     }
168 :    
169 :     return PLUGIN_HANDLED
170 :     }
171 :    
172 :     getStatus(id, code, &statusCode, lStatus[], lLen)
173 :     {
174 :     switch (code)
175 :     {
176 : ian 17 // "running"
177 : ian 1 case 'r':
178 :     {
179 :     statusCode = 'O'
180 :     format(lStatus, lLen, "%L", id, "ON")
181 :     }
182 : ian 17
183 :     // "debug"
184 :     case 'd':
185 :     {
186 :     statusCode = 'O'
187 :     format(lStatus, lLen, "%L", id, "ON")
188 :     }
189 :    
190 :     // "stopped"
191 : ian 1 case 's':
192 :     {
193 :     statusCode = 'S'
194 :     format(lStatus, lLen, "%L", id, "STOPPED")
195 :     }
196 : ian 17
197 :     // "paused"
198 : ian 1 case 'p':
199 :     {
200 :     statusCode = 'O'
201 :     format(lStatus, lLen, "%L", id, "OFF")
202 :     }
203 : ian 17
204 :     // "bad load"
205 : ian 1 case 'b':
206 :     {
207 :     statusCode = 'E'
208 :     format(lStatus, lLen, "%L", id, "ERROR")
209 :     }
210 :     default:
211 :     {
212 :     statusCode = 'L'
213 :     format(lStatus, lLen, "%L", id, "LOCKED")
214 :     }
215 :     }
216 :     }
217 :    
218 :     isSystem(id)
219 :     {
220 :     for (new a = 0; a < g_systemNum; ++a)
221 :     if (g_system[a] == id)
222 :     return 1
223 :     return 0
224 :     }
225 :    
226 :     displayMenu(id, pos)
227 :     {
228 :     if (pos < 0) return
229 :    
230 :     new filename[32], title[32], status[8], statusCode
231 :     new datanum = get_pluginsnum()
232 :     new menu_body[512], start = pos * 6, k = 0
233 :    
234 :     if (start >= datanum)
235 :     start = pos = g_menuPos[id] = 0
236 :    
237 :     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)))
238 :     new end = start + 6, keys = MENU_KEY_0|MENU_KEY_8|MENU_KEY_7
239 :    
240 :     if (end > datanum)
241 :     end = datanum
242 :    
243 :     for (new a = start; a < end; ++a)
244 :     {
245 :     get_plugin(a, filename, 31, title, 31, status, 0, status, 0, status, 1)
246 :     getStatus(id, status[0], statusCode, status, 7)
247 :    
248 :     if (isSystem(a) || (statusCode != 'O' && statusCode != 'S'))
249 :     {
250 :     if (g_coloredMenus)
251 :     {
252 :     len += format(menu_body[len], 511-len, "\d%d. %s\R%s^n\w", ++k, title, status)
253 :     } else {
254 :     ++k
255 :     len += format(menu_body[len], 511-len, "#. %s %s^n", title, status)
256 :     }
257 :     } else {
258 :     keys |= (1<<k)
259 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "%d. %s\y\R%s^n\w" : "%d. %s %s^n", ++k, title, status)
260 :     }
261 :     }
262 :    
263 : ian 17 len += format(menu_body[len], 511-len, "^n7. %L^n", id, "CLEAR_PAUSED")
264 :     len += format(menu_body[len], 511-len, g_coloredMenus ? "8. %L \y\R%s^n\w" : "8. %L %s^n", id, "SAVE_PAUSED", g_Modified ? "*" : "")
265 : ian 1
266 :     if (end != datanum)
267 :     {
268 :     format(menu_body[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
269 :     keys |= MENU_KEY_9
270 :     }
271 :     else
272 :     format(menu_body[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
273 :    
274 :     show_menu(id, keys, menu_body, -1, "Pause/Unpause Plugins")
275 :     }
276 :    
277 :     public cmdMenu(id, level, cid)
278 :     {
279 :     if (cmd_access(id, level, cid, 1))
280 :     displayMenu(id, g_menuPos[id] = 0)
281 :    
282 :     return PLUGIN_HANDLED
283 :     }
284 :    
285 :     pausePlugins(id)
286 :     {
287 :     new filename[32], title[32], status[2]
288 :     new count = 0, imax = get_pluginsnum()
289 :    
290 :     for (new a = 0; a < imax; ++a)
291 :     {
292 :     get_plugin(a, filename, 31, title, 31, status, 0, status, 0, status, 1)
293 :    
294 :     if (!isSystem(a) && status[0] == 'r' && pause("ac", filename))
295 :     {
296 :     //console_print(id, "Pausing %s (file ^"%s^")", title, filename)
297 :     ++count
298 :     }
299 :     }
300 :    
301 :     console_print(id, "%L", id, (count == 1) ? "PAUSED_PLUGIN" : "PAUSED_PLUGINS", count)
302 :     }
303 :    
304 :     unpausePlugins(id)
305 :     {
306 :     new filename[32], title[32], status[2]
307 :     new count = 0, imax = get_pluginsnum()
308 :    
309 :     for (new a = 0; a < imax; ++a)
310 :     {
311 :     get_plugin(a, filename, 31, title, 31, status, 0, status, 0, status, 1)
312 :    
313 :     if (!isSystem(a) && status[0] == 'p' && unpause("ac", filename))
314 :     {
315 :     //console_print(id, "Unpausing %s (file ^"%s^")", title, filename)
316 :     ++count
317 :     }
318 :     }
319 :    
320 :     console_print(id, "%L", id, (count == 1) ? "UNPAUSED_PLUGIN" : "UNPAUSED_PLUGINS", count)
321 :     }
322 :    
323 :     findPluginByFile(arg[32], &len)
324 :     {
325 :     new name[32], title[32], status[2]
326 :     new inum = get_pluginsnum()
327 :    
328 :     for (new a = 0; a < inum; ++a)
329 :     {
330 :     get_plugin(a, name, 31, title, 31, status, 0, status, 0, status, 1)
331 :    
332 :     if (equali(name, arg, len) && (
333 :     status[0] == 'r' || /*running*/
334 :     status[0] == 'p' || /*paused*/
335 :     status[0] == 's' || /*stopped*/
336 :     status[0] == 'd' )) /*debug*/
337 :     {
338 :     len = copy(arg, 31, name)
339 :     return a
340 :     }
341 :     }
342 :    
343 :     return -1
344 :     }
345 :    
346 :     findPluginByTitle(name[], file[], len)
347 :     {
348 :     new title[32], status[2]
349 :     new inum = get_pluginsnum()
350 :    
351 :     for (new a = 0; a < inum; ++a)
352 :     {
353 :     get_plugin(a, file, len, title, 31, status, 0, status, 0, status, 1)
354 :    
355 :     if (equali(title, name))
356 :     return a
357 :     }
358 :    
359 :     return -1
360 :     }
361 :    
362 :     public cmdPlugin(id, level, cid)
363 :     {
364 :     if (!cmd_access(id, level, cid, 1))
365 :     return PLUGIN_HANDLED
366 :    
367 :     new cmds[32]
368 :     read_argv(1, cmds, 31)
369 :    
370 :     if (equal(cmds, "add") && read_argc() > 2)
371 :     {
372 :     read_argv(2, cmds, 31)
373 :     new file[2]
374 :    
375 :     if ((g_system[g_systemNum] = findPluginByTitle(cmds, file, 0)) != -1)
376 :     {
377 :     if (g_systemNum < MAX_SYSTEM)
378 :     g_systemNum++
379 :     else
380 :     console_print(id, "%L", id, "CANT_MARK_MORE")
381 :     }
382 :     }
383 :     else if (equal(cmds, "off"))
384 :     {
385 :     pausePlugins(id)
386 :     }
387 :     else if (equal(cmds, "on"))
388 :     {
389 :     unpausePlugins(id)
390 :     }
391 :     else if (equal(cmds, "save"))
392 :     {
393 :     if (saveSettings(g_fileToSave))
394 :     {
395 :     g_Modified = 0
396 :     console_print(id, "%L", id, "PAUSE_CONF_SAVED")
397 :     }
398 :     else
399 :     console_print(id, "%L", id, "PAUSE_SAVE_FAILED")
400 :     }
401 :     else if (equal(cmds, "clear"))
402 :     {
403 :     if (file_exists(g_fileToSave))
404 :     {
405 :     delete_file(g_fileToSave)
406 :     console_print(id, "%L", id, "PAUSE_CONF_CLEARED")
407 :     }
408 :     else
409 :     console_print(id, "%L", id, "PAUSE_ALR_CLEARED")
410 :     }
411 :     else if (equal(cmds, "pause"))
412 :     {
413 :     new arg[32], a, len = read_argv(2, arg, 31)
414 :    
415 :     if (len && ((a = findPluginByFile(arg, len)) != -1) && !isSystem(a) && pause("ac", arg))
416 :     console_print(id, "%L %L", id, "PAUSE_PLUGIN_MATCH", arg, id, "PAUSED")
417 :     else
418 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
419 :     }
420 :     else if (equal(cmds, "enable"))
421 :     {
422 :     new arg[32], a, len = read_argv(2, arg, 31)
423 :    
424 :     if (len && (a = findPluginByFile(arg, len)) != -1 && !isSystem(a))
425 :     {
426 :     if (unpause("ac", arg))
427 :     {
428 :     console_print(id, "%L %L", id, "PAUSE_PLUGIN_MATCH", arg, id, "UNPAUSED")
429 :     }
430 :     else
431 :     {
432 : ian 17 console_print(id, "%L", id, "CANT_UNPAUSE_PLUGIN", arg)
433 : ian 1 }
434 :     }
435 :     else
436 :     {
437 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
438 :     }
439 :     }
440 :     else if (equal(cmds, "stop"))
441 :     {
442 :     new arg[32], a, len = read_argv(2, arg, 31)
443 :    
444 :     if (len && (a = findPluginByFile(arg, len)) != -1 && !isSystem(a) && pause("dc", arg))
445 :     {
446 :     g_Modified = 1
447 :     console_print(id, "%L %L", id, "PAUSE_PLUGIN_MATCH", arg, id, "STOPPED")
448 :     }
449 :     else
450 :     console_print(id, "%L", id, "PAUSE_COULDNT_FIND", arg)
451 :     }
452 :     else if (equal(cmds, "list"))
453 :     {
454 :     new lName[32], lVersion[32], lAuthor[32], lFile[32], lStatus[32]
455 :    
456 :     format(lName, 31, "%L", id, "NAME")
457 :     format(lVersion, 31, "%L", id, "VERSION")
458 :     format(lAuthor, 31, "%L", id, "AUTHOR")
459 :     format(lFile, 31, "%L", id, "FILE")
460 :     format(lStatus, 31, "%L", id, "STATUS")
461 :    
462 :     new arg1[8], running = 0
463 :     new start = read_argv(2, arg1, 7) ? str_to_num(arg1) : 1
464 :    
465 :     if (--start < 0)
466 :     start = 0
467 :    
468 :     new plgnum = get_pluginsnum()
469 :    
470 :     if (start >= plgnum)
471 :     start = plgnum - 1
472 :    
473 :     console_print(id, "^n----- %L -----", id, "PAUSE_LOADED")
474 :     console_print(id, " %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s", lName, lVersion, lAuthor, lFile, lStatus)
475 :    
476 :     new plugin[32], title[32], version[16], author[32], status[16]
477 :     new end = start + 10
478 :    
479 :     if (end > plgnum) end = plgnum
480 :    
481 :     for (new a = start; a < end; ++a)
482 :     {
483 :     get_plugin(a, plugin, 31, title, 31, version, 15, author, 31, status, 15)
484 :     if (status[0] == 'r') ++running
485 :     console_print(id, " [%3d] %-18.17s %-8.7s %-17.16s %-16.15s %-9.8s", a + 1, title, version, author, plugin, status)
486 :     }
487 :    
488 :     console_print(id, "----- %L -----", id, "PAUSE_ENTRIES", start + 1, end, plgnum, running)
489 :    
490 :     if (end < plgnum)
491 :     console_print(id, "----- %L -----", id, "PAUSE_USE_MORE", end + 1)
492 :     else
493 :     console_print(id, "----- %L -----", id, "PAUSE_USE_BEGIN")
494 :     } else {
495 :     console_print(id, "%L", id, "PAUSE_USAGE")
496 :     console_print(id, "%L:", id, "PAUSE_COMMANDS")
497 :     console_print(id, "%L", id, "COM_PAUSE_OFF")
498 :     console_print(id, "%L", id, "COM_PAUSE_ON")
499 :     console_print(id, "%L", id, "COM_PAUSE_STOP")
500 :     console_print(id, "%L", id, "COM_PAUSE_PAUSE")
501 :     console_print(id, "%L", id, "COM_PAUSE_ENABLE")
502 : ian 17 console_print(id, "%L", id, "COM_PAUSE_SAVE_PAUSED")
503 :     console_print(id, "%L", id, "COM_PAUSE_CLEAR_PAUSED")
504 : ian 1 console_print(id, "%L", id, "COM_PAUSE_LIST")
505 :     console_print(id, "%L", id, "COM_PAUSE_ADD")
506 :     }
507 :    
508 :     return PLUGIN_HANDLED
509 :     }
510 :    
511 :     saveSettings(filename[])
512 :     {
513 :     if (file_exists(filename))
514 :     delete_file(filename)
515 :    
516 :     new text[256], file[32], title[32], status[2]
517 :     new inum = get_pluginsnum()
518 :    
519 :     if (!write_file(filename, ";Generated by Pause Plugins Plugin. Do not modify!^n;Title Filename"))
520 :     return 0
521 :    
522 :     for (new a = 0; a < inum; ++a)
523 :     {
524 :     get_plugin(a, file, 31, title, 31, status, 0, status, 0, status, 1)
525 :    
526 : ian 17 // "paused"
527 :     if (status[0] == 'p')
528 : ian 1 {
529 :     format(text, 255, "^"%s^" ;%s", title, file)
530 :     write_file(filename, text)
531 :     }
532 :     }
533 :    
534 :     return 1
535 :     }
536 :    
537 :     loadSettings(filename[])
538 :     {
539 :     if (!file_exists(filename))
540 :     return 0
541 :    
542 :     new name[256], file[32], i, pos = 0
543 :    
544 :     while (read_file(filename, pos++, name, 255, i))
545 :     {
546 :     if (name[0] != ';' && parse(name, name, 31) && (i = findPluginByTitle(name, file, 31) != -1))
547 : ian 17 pause("ac", file)
548 : ian 1 }
549 :    
550 :     return 1
551 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4