/[cvs]/eggdrop1.9/src/core_party.c
ViewVC logotype

Annotation of /eggdrop1.9/src/core_party.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.43 - (hide annotations) (download) (as text)
Wed Oct 6 14:59:09 2004 UTC (14 years, 6 months ago) by stdarg
Branch: MAIN
Changes since 1.42: +16 -1 lines
File MIME type: text/x-chdr
* added .timers command to view active timers

1 wcc 1.15 /* core_party.c: core partyline commands
2     *
3     * Copyright (C) 2003, 2004 Eggheads Development Team
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19 wcc 1.14
20 wcc 1.15 #ifndef lint
21 stdarg 1.43 static const char rcsid[] = "$Id: core_party.c,v 1.42 2004/09/29 18:03:53 stdarg Exp $";
22 wcc 1.15 #endif
23 wcc 1.14
24     #ifdef HAVE_CONFIG_H
25     # include <config.h>
26     #endif
27    
28 wcc 1.15 #include <ctype.h>
29     #include <unistd.h>
30 wcc 1.17 #include <string.h>
31     #include <stdlib.h>
32 wcc 1.15
33 wcc 1.14 #ifdef HAVE_UNAME
34     # include <sys/utsname.h>
35     #endif
36    
37 wcc 1.24 #include <eggdrop/eggdrop.h>
38    
39     #include "core_config.h"
40     #include "core_binds.h"
41     #include "logfile.h"
42 wingman 1.33 #include "terminal.h" /* TERMINAL_NICK */
43 wingman 1.32 #include "main.h" /* SHUTDOWN_*, core_shutdown, core_restart */
44 wcc 1.24
45 stdarg 1.41 static int party_help(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
46     {
47     help_summary_t *entry;
48     help_search_t *search;
49     int hits = 0;
50 stdarg 1.42 xml_node_t *node, *arg, *desc, *see;
51     char *argname, *argdesc;
52     int optional;
53    
54 stdarg 1.41
55     if (!text || !*text) {
56     partymember_printf(p, "Syntax: help <command|variable|*search*>");
57     return(0);
58     }
59     /* First try to look up an exact match. */
60     entry = help_lookup_summary(text);
61     if (entry) {
62 stdarg 1.42 node = help_lookup_entry(entry);
63     partymember_printf(p, "Syntax:");
64     partymember_printf(p, " %s", entry->syntax);
65     partymember_printf(p, "");
66     partymember_printf(p, "Summary:");
67     partymember_printf(p, " %s", entry->summary);
68     partymember_printf(p, "");
69     xml_node_get_vars(node, "nnn", "desc.line", &desc, "args.arg", &arg, "seealso.see", &see);
70     if (arg) {
71     partymember_printf(p, "Arguments:");
72     for (; arg; arg = arg->next_sibling) {
73     xml_node_get_vars(arg, "sis", "name", &argname, "optional", &optional, "desc", &argdesc);
74     partymember_printf(p, " %s%s - %s", argname, optional ? " (optional)" : "", argdesc);
75     }
76     partymember_printf(p, "");
77     }
78     partymember_printf(p, "Description:");
79     for (; desc; desc = desc->next_sibling) {
80     partymember_printf(p, " %s", xml_node_str(desc, ""));
81     }
82     partymember_printf(p, "");
83     if (see) {
84     partymember_printf(p, "See also:");
85     for (; see; see = see->next_sibling) {
86     partymember_printf(p, " %s", xml_node_str(see, ""));
87     }
88     }
89     xml_node_delete(node);
90 stdarg 1.41 return(0);
91     }
92    
93     /* No, do a search. */
94 stdarg 1.42 if (!strchr(text, '*') && !strchr(text, '?')) {
95     partymember_printf(p, "No help was found! Try searching with wildcards, e.g. *%s*", text);
96     return(0);
97     }
98    
99 stdarg 1.41 search = help_search_new(text);
100     while ((entry = help_search_result(search))) {
101     partymember_printf(p, "%s - %s", entry->syntax, entry->summary);
102     hits++;
103     }
104     if (hits == 0) {
105     partymember_printf(p, "No help was found! Try more wildcards...");
106     }
107     help_search_end(search);
108     return(0);
109     }
110 stdarg 1.1
111 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
112     {
113 wcc 1.12 if (!text || !*text) {
114 wcc 1.16 partymember_printf(p, _("Syntax: join <channel>"));
115 stdarg 1.4 return(0);
116     }
117     partychan_join_name(text, p);
118     return(0);
119     }
120    
121     static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
122     {
123     partychan_t *chan;
124    
125 wcc 1.12 if (!text || !*text) chan = partychan_get_default(p);
126 stdarg 1.4 else chan = partychan_lookup_name(text);
127     partychan_part(chan, p, "parting");
128     return(0);
129     }
130    
131 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
132 stdarg 1.1 {
133 wingman 1.33 if (0 == strcmp (p->nick, TERMINAL_NICK)) {
134 wingman 1.27 partymember_printf (p, "You can't leave the partyline in terminal mode.");
135     return -1;
136     }
137 darko 1.37
138 wcc 1.18 partymember_printf(p, "Goodbye!");
139     if (!text || !*text) partymember_delete(p, "Quit");
140 wcc 1.12 else partymember_delete(p, text);
141 stdarg 1.1 return(0);
142     }
143    
144 wcc 1.12 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
145 stdarg 1.1 {
146 stdarg 1.13 char *who;
147     const char *next;
148     partymember_t *dest;
149    
150 stdarg 1.21 egg_get_arg(text, &next, &who);
151 stdarg 1.13 if (!who || !next || !*who || !*next) {
152 wcc 1.16 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
153 stdarg 1.13 goto done;
154     }
155    
156     dest = partymember_lookup_nick(who);
157     if (!dest) {
158 wcc 1.16 partymember_printf(p, _("No such user '%s'."), who);
159 stdarg 1.13 goto done;
160     }
161    
162     partymember_msg(dest, p, next, -1);
163     done:
164     if (who) free(who);
165 stdarg 1.1 return(0);
166     }
167    
168 stdarg 1.22 static void *lookup_setting(partymember_t *p, const char *path)
169 stdarg 1.11 {
170     void *root;
171    
172     root = config_get_root("eggdrop");
173     root = config_exists(root, path, 0, NULL);
174 stdarg 1.22 if (!root) partymember_printf(p, _("That setting does not exist."));
175 stdarg 1.11 return(root);
176     }
177    
178     static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
179     {
180     void *root;
181     char *str = NULL;
182    
183     if (!text || !*text) {
184 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
185 stdarg 1.11 return(0);
186     }
187    
188 stdarg 1.22 root = lookup_setting(p, text);
189 stdarg 1.11 if (!root) return(0);
190    
191     config_get_str(&str, root, NULL);
192 wcc 1.24 if (str) partymember_printf(p, "Current value: '%s'", str);
193     else partymember_printf(p, _("Current value: null (unset)"));
194 stdarg 1.11 return(0);
195     }
196    
197 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
198 stdarg 1.2 {
199 stdarg 1.11 void *root;
200     char *path, *str;
201     const char *next;
202    
203 stdarg 1.21 egg_get_arg(text, &next, &path);
204 stdarg 1.22 if (!path) {
205     partymember_printf(p, _("Syntax: set <path> [new value]"));
206 stdarg 1.11 return(0);
207     }
208 stdarg 1.22 if (!next) {
209     free(path);
210     return party_get(p, nick, u, cmd, text);
211     }
212 wcc 1.14
213 stdarg 1.22 root = lookup_setting(p, path);
214 stdarg 1.11 free(path);
215     if (!root) return(0);
216    
217     config_get_str(&str, root, NULL);
218 wcc 1.16 partymember_printf(p, _("Old value: '%s'"), str);
219 stdarg 1.11 config_set_str(next, root, NULL);
220     config_get_str(&str, root, NULL);
221 stdarg 1.20 if (str) partymember_printf(p, _("New value: '%s'"), str);
222     else partymember_printf(p, _("New value: null (unset)"));
223     return(0);
224     }
225    
226     static int party_unset(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
227     {
228     void *root;
229     char *str;
230    
231     if (!text || !*text) {
232     partymember_printf(p, _("Syntax: unset <path>"));
233     return(0);
234     }
235    
236 stdarg 1.22 root = lookup_setting(p, text);
237 stdarg 1.20 if (!root) return(0);
238    
239     config_get_str(&str, root, NULL);
240     if (str) partymember_printf(p, _("Old value: '%s'"), str);
241     else partymember_printf(p, _("Old value: null (unset)"));
242     config_set_str(NULL, root, NULL);
243     config_get_str(&str, root, NULL);
244     if (str) partymember_printf(p, _("New value: '%s'"), str);
245     else partymember_printf(p, _("New value: null (unset)"));
246 wcc 1.14 return(0);
247     }
248    
249     static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
250     {
251     #ifdef HAVE_UNAME
252     struct utsname un;
253     #endif
254    
255 stdarg 1.20 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
256 wcc 1.16 partymember_printf(p, _("Owner: %s"), core_config.owner);
257     if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
258 wcc 1.14 #ifdef HAVE_UNAME
259 stdarg 1.20 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
260 wcc 1.14 #endif
261 stdarg 1.35 partymember_printf(p, _("Help path: %s (%d entries, %d sections)"),
262 stdarg 1.40 core_config.help_path, 0, 0);
263 stdarg 1.20 partymember_printf(p, "");
264     check_bind_status(p, text);
265 stdarg 1.2 return(0);
266     }
267    
268 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
269 stdarg 1.2 {
270 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
271 stdarg 1.5 user_save(core_config.userfile);
272 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
273 stdarg 1.2 core_config_save();
274     return(1);
275     }
276    
277 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
278     {
279     if (!text || strlen(text) < 6) {
280 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
281 stdarg 1.5 return(0);
282     }
283     user_set_pass(p->user, text);
284 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
285 stdarg 1.5 return(0);
286     }
287    
288 stdarg 1.7 static int intsorter(const void *left, const void *right)
289     {
290     return(*(int *)left - *(int *)right);
291     }
292    
293     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
294     {
295     partymember_t *who;
296 stdarg 1.20 int *pids, len, i, width = 0;
297 stdarg 1.7
298 wcc 1.16 partymember_printf(p, _("Partyline members:"));
299 stdarg 1.7 partymember_who(&pids, &len);
300     qsort(pids, len, sizeof(int), intsorter);
301 stdarg 1.20 if (len > 0) {
302     i = pids[len-1];
303     if (!i) i++;
304     while (i != 0) {
305     i /= 10;
306     width++;
307     }
308     }
309 stdarg 1.7 for (i = 0; i < len; i++) {
310     who = partymember_lookup_pid(pids[i]);
311 stdarg 1.20 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
312 stdarg 1.7 }
313     free(pids);
314     return(0);
315     }
316    
317 stdarg 1.23 static int party_whois(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
318     {
319     user_t *who;
320     flags_t flags;
321     char *item, *chan, *setting, *value, flagstr[64];
322     const char *next;
323     int i;
324    
325     if (text && *text) who = user_lookup_by_handle(text);
326     else who = u;
327    
328     if (!who) {
329     partymember_printf(p, "No such user.");
330     return(0);
331     }
332    
333     next = core_config.whois_items;
334     while (next && *next) {
335     egg_get_arg(next, &next, &item);
336     if (!strcasecmp(item, "handle")) {
337     partymember_printf(p, "%s: '%s'", item, who->handle);
338     }
339     else if (!strcasecmp(item, "uid")) {
340     partymember_printf(p, "%s: '%d'", item, who->uid);
341     }
342     else if (!strcasecmp(item, "ircmasks")) {
343     partymember_printf(p, "%s:", item);
344     for (i = 0; i < who->nircmasks; i++) {
345     partymember_printf(p, " %d. '%s'", i+1, who->ircmasks[i]);
346     }
347     }
348     else {
349 stdarg 1.25 if ((setting = strchr(item, '.'))) {
350 stdarg 1.23 chan = item;
351     *setting = 0;
352     setting++;
353     }
354     else {
355     chan = NULL;
356     setting = item;
357     }
358     if (!strcasecmp(setting, "flags")) {
359     user_get_flags(who, chan, &flags);
360     flag_to_str(&flags, flagstr);
361     value = flagstr;
362     }
363     else {
364     user_get_setting(who, chan, setting, &value);
365     }
366    
367     if (chan) partymember_printf(p, "%s.%s: %s", chan, setting, value);
368     else partymember_printf(p, "%s: %s", setting, value);
369     }
370     free(item);
371     }
372     return(0);
373     }
374    
375 stdarg 1.7 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
376     {
377 darko 1.37 /* XXX: should we really enable hard shutdowns?
378 wingman 1.32 if (*text && 0 == strcmp(text, "force")) {
379     return core_shutdown(SHUTDOWN_HARD, nick, text);
380     } else
381     */
382     return core_shutdown(SHUTDOWN_GRACEFULL, nick, text);
383 stdarg 1.7 }
384    
385     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
386     {
387     user_t *newuser;
388    
389     if (!text || !*text) {
390 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
391 stdarg 1.7 return(0);
392     }
393     if (user_lookup_by_handle(text)) {
394 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
395 stdarg 1.7 return(0);
396     }
397     newuser = user_new(text);
398 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
399     else partymember_printf(p, _("Could not create user '%s'."), text);
400 stdarg 1.7 return(0);
401     }
402    
403     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
404     {
405     user_t *who;
406    
407     if (!text || !*text) {
408 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
409 stdarg 1.7 return(0);
410     }
411     who = user_lookup_by_handle(text);
412 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
413 stdarg 1.7 else {
414 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
415 stdarg 1.7 user_delete(who);
416     }
417     return(0);
418     }
419    
420     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
421     {
422 stdarg 1.25 user_t *who;
423     char *target, *newhost;
424    
425     egg_get_args(text, NULL, &target, &newhost, NULL);
426     if (!target) {
427     partymember_printf(p, _("Syntax: +host [handle] <host>"));
428     return(0);
429     }
430     if (!newhost) {
431     newhost = target;
432     target = NULL;
433     }
434     if (target) {
435     who = user_lookup_by_handle(target);
436     if (!who) {
437     partymember_printf(p, _("User '%s' not found."), target);
438     goto done;
439     }
440     }
441     else {
442     who = u;
443     if (!who) {
444     partymember_printf(p, _("Only valid users can add hosts."));
445     goto done;
446     }
447     }
448     user_add_ircmask(who, newhost);
449     partymember_printf(p, _("Added '%1$s' to user '%2$s'."), newhost, who->handle);
450    
451     done:
452     if (target) free(target);
453     free(newhost);
454    
455 stdarg 1.7 return(0);
456     }
457    
458 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
459     {
460 stdarg 1.25 user_t *who;
461     char *target, *host;
462    
463     egg_get_args(text, NULL, &target, &host, NULL);
464     if (!target) {
465     partymember_printf(p, _("Syntax: -host [handle] <host>"));
466     return(0);
467     }
468     if (!host) {
469     host = target;
470     target = NULL;
471     }
472     if (target) {
473     who = user_lookup_by_handle(target);
474     if (!who) {
475     partymember_printf(p, _("User '%s' not found."), target);
476     goto done;
477     }
478     }
479     else {
480     who = u;
481     if (!who) {
482     partymember_printf(p, _("Only valid users can remove hosts."));
483     goto done;
484     }
485     }
486     if (user_del_ircmask(who, host)) {
487     partymember_printf(p, _("Mask '%1$s' not found for user '%2$s'."), host, who->handle);
488     }
489     else {
490     partymember_printf(p, _("Removed '%1$s' from user '%2$s'."), host, who->handle);
491     }
492    
493     done:
494     if (target) free(target);
495     free(host);
496    
497 stdarg 1.9 return(0);
498     }
499    
500 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
501 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
502     {
503     const char *next;
504     char *who, *flags, *chan;
505     user_t *dest;
506     flags_t flagstruct;
507     char flagstr[64];
508     int n;
509    
510 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
511 wcc 1.14 if (!chan || !*chan) {
512 stdarg 1.10 if (who) free(who);
513 wcc 1.24 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
514 stdarg 1.9 return(0);
515     }
516 wcc 1.14 if (!flags || !*flags) {
517 stdarg 1.9 flags = chan;
518     chan = NULL;
519     }
520     dest = user_lookup_by_handle(who);
521     if (dest) {
522 wingman 1.30 user_set_flags_str(dest, chan, flags);
523 stdarg 1.9 user_get_flags(dest, chan, &flagstruct);
524     flag_to_str(&flagstruct, flagstr);
525 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
526 stdarg 1.9 }
527 wcc 1.24 else partymember_printf(p, _("'%s' is not a valid user."), who);
528 stdarg 1.9 free(who);
529     free(flags);
530     if (chan) free(chan);
531     return(0);
532     }
533    
534 stdarg 1.26 static int party_addlog(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
535     {
536     putlog(LOG_MISC, "*", "%s: %s", nick, text);
537 wingman 1.30
538     return BIND_RET_LOG;
539 stdarg 1.26 }
540    
541 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
542     {
543 stdarg 1.19 const char **modules;
544 wcc 1.12 int nummods, ctr;
545    
546 stdarg 1.19 nummods = module_list(&modules);
547 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
548 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
549     free(modules);
550 wingman 1.30
551     return BIND_RET_LOG;
552 wcc 1.12 }
553    
554 stdarg 1.26 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
555 wcc 1.24 {
556     if (!text || !*text) {
557 stdarg 1.26 partymember_printf(p, _("Syntax: loadmod <module name>"));
558 wingman 1.30 return BIND_RET_BREAK;
559 wcc 1.24 }
560 stdarg 1.26 switch (module_load(text)) {
561     case 0:
562     partymember_printf(p, _("Module '%s' loaded successfully."), text);
563     break;
564     case -1:
565     partymember_printf(p, _("Module '%s' is already loaded."), text);
566     break;
567     case -2:
568     partymember_printf(p, _("Module '%s' could not be loaded."), text);
569     break;
570     case -3:
571     partymember_printf(p, _("Module '%s' does not have a valid initialization function. Perhaps it is not an eggdrop module?"), text);
572     break;
573     }
574 wingman 1.30 return BIND_RET_LOG;
575 stdarg 1.26 }
576 wcc 1.24
577 stdarg 1.26 static int party_unloadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
578     {
579     if (!text || !*text) {
580     partymember_printf(p, _("Syntax: unloadmod <module name>"));
581 wingman 1.30 return BIND_RET_BREAK;
582 wcc 1.24 }
583 wingman 1.34 switch (module_unload(text, MODULE_USER)) {
584 stdarg 1.26 case 0:
585     partymember_printf(p, _("Module '%s' unloaded successfully."), text);
586     break;
587     case -1:
588     partymember_printf(p, _("Module '%s' is not loaded."), text);
589     break;
590     case -2:
591     partymember_printf(p, _("Module '%s' has dependencies that are still loaded. You must unload them first."), text);
592     break;
593     case -3:
594     partymember_printf(p, _("Module '%s' refuses to be unloaded by you!"), text);
595     break;
596     }
597 wingman 1.30 return BIND_RET_LOG;
598 wcc 1.24 }
599    
600 wingman 1.32 static int party_binds(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
601     {
602     bind_table_t *table;
603     bind_entry_t *entry;
604     char flags[64];
605    
606     partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %s", _("TABLE"), _("SYNTAX"),
607     _("FUNCTION"), _("MASK"), _("FLAGS"), _("HITS"));
608     for (table = bind_table_list(); table; table = table->next) {
609     for (entry = table->entries; entry; entry = entry->next) {
610     flag_to_str(&entry->user_flags, flags);
611     partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %i", table->name, table->syntax,
612     entry->function_name, entry->mask, flags, entry->nhits);
613     }
614     }
615    
616     return BIND_RET_LOG;
617     }
618    
619 stdarg 1.43 static int party_timers(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
620     {
621     egg_timer_t *timer;
622     int remain, now;
623    
624     now = timer_get_now_sec(NULL);
625     partymember_printf(p, "ID SEC LEFT NAME");
626     for (timer = timer_list(); timer; timer = timer->next) {
627     remain = timer->trigger_time.sec - now;
628     partymember_printf(p, "%-5d %-8d %s", timer->id, remain, timer->name);
629     }
630     return(BIND_RET_LOG);
631     }
632    
633 wingman 1.33 static int party_restart(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
634     {
635     core_restart (nick);
636 darko 1.37
637 wingman 1.33 return BIND_RET_LOG;
638     }
639    
640 darko 1.36 /* Syntax: chhandle <old_handle> <new_handle> */
641     static int party_chhandle(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
642     {
643 stdarg 1.40 char *old = NULL, *newh = NULL;
644 darko 1.36 user_t *dest;
645    
646 stdarg 1.40 egg_get_args(text, NULL, &old, &newh, NULL);
647     if (!old || !newh || !*old || !*newh) {
648     if (old) free(old);
649     if (newh) free(newh);
650 darko 1.36 partymember_printf(p, _("Syntax: chhandle <old_handle> <new_handle>"));
651 darko 1.39 goto chhandleend;
652 darko 1.36 }
653    
654     dest = user_lookup_by_handle(old);
655     if (!dest) {
656 stdarg 1.40 free(old);
657     free(newh);
658 darko 1.36 partymember_printf(p, _("Error: User '%s' does not exist."), old);
659 darko 1.39 goto chhandleend;
660 darko 1.36 }
661    
662 stdarg 1.40 if (user_lookup_by_handle(newh)) {
663     free(old);
664     free(newh);
665     partymember_printf(p, _("Error: User '%s' already exists."), newh);
666     return 0;
667 darko 1.36 }
668    
669 stdarg 1.40 if (!user_change_handle(dest, newh))
670 darko 1.36 partymember_printf(p, _("Ok, changed."));
671 darko 1.39
672     chhandleend:
673 stdarg 1.40 free(newh);
674 darko 1.39 free(old);
675    
676     return BIND_RET_LOG;
677 darko 1.36 }
678    
679 darko 1.39 /* Syntax: chpass <handle> [new_pass] */
680 darko 1.37 static int party_chpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
681     {
682     char *user = NULL, *pass = NULL;
683     user_t *dest;
684    
685     egg_get_args(text, NULL, &user, &pass, NULL);
686    
687 darko 1.38 if (!user || !*user) {
688     partymember_printf(p, _("Syntax: chpass <handle> [pass]"));
689 darko 1.39 goto chpassend;
690 darko 1.37 }
691    
692     dest = user_lookup_by_handle(user);
693     if (!dest) {
694     partymember_printf(p, _("Error: User '%s' does not exist."), user);
695 darko 1.39 goto chpassend;
696 darko 1.37 }
697    
698 darko 1.38 if (pass && *pass && strlen(pass) < 6) {
699 darko 1.37 partymember_printf(p, _("Error: Please use at least 6 characters."));
700 darko 1.39 goto chpassend;
701 darko 1.37 }
702    
703 darko 1.38 if (user_set_pass(dest, pass))
704     partymember_printf(p, _("Removed password for %s."), user);
705     else
706     partymember_printf(p, _("Password for %s is now '%s'."), user, pass);
707 darko 1.39
708     chpassend:
709     free(user);
710     free(pass);
711    
712     return BIND_RET_LOG_COMMAND;
713     }
714    
715     /* Makes sure 'start' and 'limit' arguments for .match are reasonable, or else sets them -1 */
716     static int party_match_getbounds(const char *strstart, const char *strlimit, long *start, long *limit)
717     {
718     char *tmpptr;
719    
720     if (strstart) {
721     *start = strtol(strstart, &tmpptr, 10);
722     if (!*strstart || *tmpptr || *start < 1) { /* Invalid input*/
723     *start = -1;
724     return 0;
725     }
726    
727     if (strlimit) { /* 'start' was really a start and this is now 'limit' */
728     *limit = strtol(strlimit, &tmpptr, 10);
729     if (!*strlimit || *tmpptr || *limit < 1) { /* Invalid input*/
730     *limit = -1;
731     return 0;
732     }
733     }
734     else { /* Ah, no, the only argument specified was the 'limit' */
735     *limit = *start;
736     *start = 0;
737     }
738     }
739     else {
740     *limit = 20;
741     *start = 0;
742     }
743    
744     return 0;
745     }
746    
747     /* Handles case where .match was given mask to match against */
748     static int party_matchwild(partymember_t *p, const char *mask, const char *rest)
749     {
750     char *strstart = NULL, *strlimit = NULL;
751     long start, limit;
752    
753     egg_get_args(rest, NULL, &strstart, &strlimit, NULL);
754    
755     party_match_getbounds(strstart, strlimit, &start, &limit);
756     if (start == -1 || limit == -1)
757     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
758     else
759     partyline_cmd_match_ircmask(p, mask, start, limit);
760    
761     free(strstart);
762     free(strlimit);
763    
764 darko 1.37 return 0;
765     }
766    
767 darko 1.39 /* Handles case where .match was given attributes to match against */
768     static int party_matchattr(partymember_t *p, const char *mask, const char *rest)
769     {
770     char *channel = NULL, *strstart = NULL, *strlimit = NULL;
771     long start, limit;
772     int ischan = 0;
773    
774     egg_get_args(rest, NULL, &channel, &strstart, &strlimit, NULL);
775    
776     /* This is probably the easiest way to conclude if content of 'channel'
777     is *NOT* a number, and thus it is a candidate for a valid channel name */
778     if (channel && (*channel < '0' || *channel > '9'))
779     ischan = 1;
780    
781    
782     if (strlimit) /* .match <flags> <channel> <start> <limit> */
783     party_match_getbounds(strstart, strlimit, &start, &limit);
784     else if (strstart) /* .match <flags> <channel|start> <limit> */
785     party_match_getbounds(ischan?strstart:channel, ischan?NULL:strstart, &start, &limit);
786     else if (ischan) { /* .match <flags> <channel> */
787     start = 0;
788     limit = 20;
789     }
790     else /* .match <flags> [limit] */
791     party_match_getbounds(channel, NULL, &start, &limit);
792    
793     free(strstart);
794     free(strlimit);
795    
796     if (start == -1 || limit == -1)
797     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
798     else
799     partyline_cmd_match_attr(p, mask, ischan?channel:NULL, start, limit);
800    
801     free(channel);
802    
803     return 0;
804     }
805    
806     /* match <attr> [channel] [[start] limit] */
807     /* match <mask> [[start] limit] */
808     static int party_match(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
809     {
810    
811     char *attr = NULL;
812     const char *rest = NULL;
813    
814     /* FIXME - Check if user is allowed to see results.. if !chan && !glob_master && -> error
815     I have left it available to everyone because 'whois' was that way too.
816     We should update both or neither */
817    
818     egg_get_args(text, &rest, &attr, NULL);
819    
820     if (!attr) {
821     partymember_printf(p, _("Syntax: match <attr> [channel] [[start] limit]"));
822     partymember_printf(p, _(" or: match <mask> [[start] limit]"));
823     free(attr);
824     return 0;
825     }
826    
827     if (*attr == '+' || *attr == '-' || *attr == '|')
828     party_matchattr(p, attr, rest);
829     else if (*attr != '&')
830     party_matchwild(p, attr, rest);
831    
832     free(attr);
833    
834     return BIND_RET_LOG;
835     }
836    
837     static bind_list_t core_party_binds[] = { /* Old flags requirement */
838 stdarg 1.41 {NULL, "help", party_help},
839 wingman 1.29 {NULL, "join", party_join}, /* DDD */
840     {NULL, "whisper", party_whisper}, /* DDD */
841 darko 1.39 {NULL, "newpass", party_newpass}, /* DDC */ /* -|- */
842     {NULL, "help", party_help}, /* DDC */ /* -|- */
843 wingman 1.29 {NULL, "part", party_part}, /* DDD */
844 darko 1.39 {NULL, "quit", party_quit}, /* DDD */ /* -|- */
845 wingman 1.29 {NULL, "who", party_who}, /* DDD */
846 darko 1.39 {NULL, "whois", party_whois}, /* DDC */ /* ot|o */
847     {NULL, "match", party_match}, /* DDC */ /* ot|o */
848     {"n", "addlog", party_addlog}, /* DDD */ /* ot|o */
849 wingman 1.30 {"n", "get", party_get}, /* DDC */
850     {"n", "set", party_set}, /* DDC */
851     {"n", "unset", party_unset}, /* DDC */
852 darko 1.39 {"n", "status", party_status}, /* DDC */ /* m|m */
853     {"n", "save", party_save}, /* DDD */ /* m|m */
854     {"n", "die", party_die}, /* DDD */ /* n|- */
855     {"n", "restart", party_restart}, /* DDD */ /* m|- */
856     {"n", "+user", party_plus_user}, /* DDC */ /* m|- */
857     {"n", "-user", party_minus_user}, /* DDC */ /* m|- */
858     {"n", "chattr", party_chattr}, /* DDC */ /* m|m */
859     {"n", "modules", party_modules}, /* DDD */ /* n|- */
860     {"n", "loadmod", party_loadmod}, /* DDD */ /* n|- */
861     {"n", "unloadmod", party_unloadmod}, /* DDD */ /* n|- */
862     {"n", "binds", party_binds}, /* DDD */ /* m|- */
863 stdarg 1.43 {"n", "timers", party_timers},
864 darko 1.39 {"m", "+host", party_plus_host}, /* DDC */ /* t|m */
865     {"m", "-host", party_minus_host}, /* DDC */ /* -|- */
866     {"t", "chhandle", party_chhandle}, /* DDC */ /* t|- */
867     {"t", "chpass", party_chpass}, /* DDC */ /* t|- */
868 stdarg 1.1 {0}
869     };
870    
871 wingman 1.27 void core_party_init(void)
872 stdarg 1.1 {
873     bind_add_list("party", core_party_binds);
874     }
875 darko 1.39

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23