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

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

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


Revision 1.42 - (show annotations) (download) (as text)
Wed Sep 29 18:03:53 2004 UTC (15 years ago) by stdarg
Branch: MAIN
Changes since 1.41: +38 -2 lines
File MIME type: text/x-chdr
*** empty log message ***

1 /* 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
20 #ifndef lint
21 static const char rcsid[] = "$Id: core_party.c,v 1.41 2004/09/29 15:38:39 stdarg Exp $";
22 #endif
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <ctype.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <stdlib.h>
32
33 #ifdef HAVE_UNAME
34 # include <sys/utsname.h>
35 #endif
36
37 #include <eggdrop/eggdrop.h>
38
39 #include "core_config.h"
40 #include "core_binds.h"
41 #include "logfile.h"
42 #include "terminal.h" /* TERMINAL_NICK */
43 #include "main.h" /* SHUTDOWN_*, core_shutdown, core_restart */
44
45 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 xml_node_t *node, *arg, *desc, *see;
51 char *argname, *argdesc;
52 int optional;
53
54
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 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 return(0);
91 }
92
93 /* No, do a search. */
94 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 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
111 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
112 {
113 if (!text || !*text) {
114 partymember_printf(p, _("Syntax: join <channel>"));
115 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 if (!text || !*text) chan = partychan_get_default(p);
126 else chan = partychan_lookup_name(text);
127 partychan_part(chan, p, "parting");
128 return(0);
129 }
130
131 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
132 {
133 if (0 == strcmp (p->nick, TERMINAL_NICK)) {
134 partymember_printf (p, "You can't leave the partyline in terminal mode.");
135 return -1;
136 }
137
138 partymember_printf(p, "Goodbye!");
139 if (!text || !*text) partymember_delete(p, "Quit");
140 else partymember_delete(p, text);
141 return(0);
142 }
143
144 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
145 {
146 char *who;
147 const char *next;
148 partymember_t *dest;
149
150 egg_get_arg(text, &next, &who);
151 if (!who || !next || !*who || !*next) {
152 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
153 goto done;
154 }
155
156 dest = partymember_lookup_nick(who);
157 if (!dest) {
158 partymember_printf(p, _("No such user '%s'."), who);
159 goto done;
160 }
161
162 partymember_msg(dest, p, next, -1);
163 done:
164 if (who) free(who);
165 return(0);
166 }
167
168 static void *lookup_setting(partymember_t *p, const char *path)
169 {
170 void *root;
171
172 root = config_get_root("eggdrop");
173 root = config_exists(root, path, 0, NULL);
174 if (!root) partymember_printf(p, _("That setting does not exist."));
175 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 partymember_printf(p, _("Syntax: get <path>"));
185 return(0);
186 }
187
188 root = lookup_setting(p, text);
189 if (!root) return(0);
190
191 config_get_str(&str, root, NULL);
192 if (str) partymember_printf(p, "Current value: '%s'", str);
193 else partymember_printf(p, _("Current value: null (unset)"));
194 return(0);
195 }
196
197 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
198 {
199 void *root;
200 char *path, *str;
201 const char *next;
202
203 egg_get_arg(text, &next, &path);
204 if (!path) {
205 partymember_printf(p, _("Syntax: set <path> [new value]"));
206 return(0);
207 }
208 if (!next) {
209 free(path);
210 return party_get(p, nick, u, cmd, text);
211 }
212
213 root = lookup_setting(p, path);
214 free(path);
215 if (!root) return(0);
216
217 config_get_str(&str, root, NULL);
218 partymember_printf(p, _("Old value: '%s'"), str);
219 config_set_str(next, root, NULL);
220 config_get_str(&str, root, NULL);
221 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 root = lookup_setting(p, text);
237 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 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 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
256 partymember_printf(p, _("Owner: %s"), core_config.owner);
257 if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
258 #ifdef HAVE_UNAME
259 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
260 #endif
261 partymember_printf(p, _("Help path: %s (%d entries, %d sections)"),
262 core_config.help_path, 0, 0);
263 partymember_printf(p, "");
264 check_bind_status(p, text);
265 return(0);
266 }
267
268 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
269 {
270 putlog(LOG_MISC, "*", _("Saving user file..."));
271 user_save(core_config.userfile);
272 putlog(LOG_MISC, "*", _("Saving config file..."));
273 core_config_save();
274 return(1);
275 }
276
277 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 partymember_printf(p, _("Please use at least 6 characters."));
281 return(0);
282 }
283 user_set_pass(p->user, text);
284 partymember_printf(p, _("Changed password to '%s'."), text);
285 return(0);
286 }
287
288 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 int *pids, len, i, width = 0;
297
298 partymember_printf(p, _("Partyline members:"));
299 partymember_who(&pids, &len);
300 qsort(pids, len, sizeof(int), intsorter);
301 if (len > 0) {
302 i = pids[len-1];
303 if (!i) i++;
304 while (i != 0) {
305 i /= 10;
306 width++;
307 }
308 }
309 for (i = 0; i < len; i++) {
310 who = partymember_lookup_pid(pids[i]);
311 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
312 }
313 free(pids);
314 return(0);
315 }
316
317 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 if ((setting = strchr(item, '.'))) {
350 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 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
376 {
377 /* XXX: should we really enable hard shutdowns?
378 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 }
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 partymember_printf(p, _("Syntax: +user <handle>"));
391 return(0);
392 }
393 if (user_lookup_by_handle(text)) {
394 partymember_printf(p, _("User '%s' already exists!"));
395 return(0);
396 }
397 newuser = user_new(text);
398 if (newuser) partymember_printf(p, _("User '%s' created."), text);
399 else partymember_printf(p, _("Could not create user '%s'."), text);
400 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 partymember_printf(p, _("Syntax: -user <handle>"));
409 return(0);
410 }
411 who = user_lookup_by_handle(text);
412 if (!who) partymember_printf(p, _("User '%s' not found."));
413 else {
414 partymember_printf(p, _("Deleting user '%s'."), who->handle);
415 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 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 return(0);
456 }
457
458 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
459 {
460 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 return(0);
498 }
499
500 /* Syntax: chattr <user> [chan] <flags> */
501 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 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
511 if (!chan || !*chan) {
512 if (who) free(who);
513 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
514 return(0);
515 }
516 if (!flags || !*flags) {
517 flags = chan;
518 chan = NULL;
519 }
520 dest = user_lookup_by_handle(who);
521 if (dest) {
522 user_set_flags_str(dest, chan, flags);
523 user_get_flags(dest, chan, &flagstruct);
524 flag_to_str(&flagstruct, flagstr);
525 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
526 }
527 else partymember_printf(p, _("'%s' is not a valid user."), who);
528 free(who);
529 free(flags);
530 if (chan) free(chan);
531 return(0);
532 }
533
534 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
538 return BIND_RET_LOG;
539 }
540
541 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
542 {
543 const char **modules;
544 int nummods, ctr;
545
546 nummods = module_list(&modules);
547 partymember_printf(p, _("Loaded modules:"));
548 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
549 free(modules);
550
551 return BIND_RET_LOG;
552 }
553
554 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
555 {
556 if (!text || !*text) {
557 partymember_printf(p, _("Syntax: loadmod <module name>"));
558 return BIND_RET_BREAK;
559 }
560 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 return BIND_RET_LOG;
575 }
576
577 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 return BIND_RET_BREAK;
582 }
583 switch (module_unload(text, MODULE_USER)) {
584 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 return BIND_RET_LOG;
598 }
599
600 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 static int party_restart(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
620 {
621 core_restart (nick);
622
623 return BIND_RET_LOG;
624 }
625
626 /* Syntax: chhandle <old_handle> <new_handle> */
627 static int party_chhandle(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
628 {
629 char *old = NULL, *newh = NULL;
630 user_t *dest;
631
632 egg_get_args(text, NULL, &old, &newh, NULL);
633 if (!old || !newh || !*old || !*newh) {
634 if (old) free(old);
635 if (newh) free(newh);
636 partymember_printf(p, _("Syntax: chhandle <old_handle> <new_handle>"));
637 goto chhandleend;
638 }
639
640 dest = user_lookup_by_handle(old);
641 if (!dest) {
642 free(old);
643 free(newh);
644 partymember_printf(p, _("Error: User '%s' does not exist."), old);
645 goto chhandleend;
646 }
647
648 if (user_lookup_by_handle(newh)) {
649 free(old);
650 free(newh);
651 partymember_printf(p, _("Error: User '%s' already exists."), newh);
652 return 0;
653 }
654
655 if (!user_change_handle(dest, newh))
656 partymember_printf(p, _("Ok, changed."));
657
658 chhandleend:
659 free(newh);
660 free(old);
661
662 return BIND_RET_LOG;
663 }
664
665 /* Syntax: chpass <handle> [new_pass] */
666 static int party_chpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
667 {
668 char *user = NULL, *pass = NULL;
669 user_t *dest;
670
671 egg_get_args(text, NULL, &user, &pass, NULL);
672
673 if (!user || !*user) {
674 partymember_printf(p, _("Syntax: chpass <handle> [pass]"));
675 goto chpassend;
676 }
677
678 dest = user_lookup_by_handle(user);
679 if (!dest) {
680 partymember_printf(p, _("Error: User '%s' does not exist."), user);
681 goto chpassend;
682 }
683
684 if (pass && *pass && strlen(pass) < 6) {
685 partymember_printf(p, _("Error: Please use at least 6 characters."));
686 goto chpassend;
687 }
688
689 if (user_set_pass(dest, pass))
690 partymember_printf(p, _("Removed password for %s."), user);
691 else
692 partymember_printf(p, _("Password for %s is now '%s'."), user, pass);
693
694 chpassend:
695 free(user);
696 free(pass);
697
698 return BIND_RET_LOG_COMMAND;
699 }
700
701 /* Makes sure 'start' and 'limit' arguments for .match are reasonable, or else sets them -1 */
702 static int party_match_getbounds(const char *strstart, const char *strlimit, long *start, long *limit)
703 {
704 char *tmpptr;
705
706 if (strstart) {
707 *start = strtol(strstart, &tmpptr, 10);
708 if (!*strstart || *tmpptr || *start < 1) { /* Invalid input*/
709 *start = -1;
710 return 0;
711 }
712
713 if (strlimit) { /* 'start' was really a start and this is now 'limit' */
714 *limit = strtol(strlimit, &tmpptr, 10);
715 if (!*strlimit || *tmpptr || *limit < 1) { /* Invalid input*/
716 *limit = -1;
717 return 0;
718 }
719 }
720 else { /* Ah, no, the only argument specified was the 'limit' */
721 *limit = *start;
722 *start = 0;
723 }
724 }
725 else {
726 *limit = 20;
727 *start = 0;
728 }
729
730 return 0;
731 }
732
733 /* Handles case where .match was given mask to match against */
734 static int party_matchwild(partymember_t *p, const char *mask, const char *rest)
735 {
736 char *strstart = NULL, *strlimit = NULL;
737 long start, limit;
738
739 egg_get_args(rest, NULL, &strstart, &strlimit, NULL);
740
741 party_match_getbounds(strstart, strlimit, &start, &limit);
742 if (start == -1 || limit == -1)
743 partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
744 else
745 partyline_cmd_match_ircmask(p, mask, start, limit);
746
747 free(strstart);
748 free(strlimit);
749
750 return 0;
751 }
752
753 /* Handles case where .match was given attributes to match against */
754 static int party_matchattr(partymember_t *p, const char *mask, const char *rest)
755 {
756 char *channel = NULL, *strstart = NULL, *strlimit = NULL;
757 long start, limit;
758 int ischan = 0;
759
760 egg_get_args(rest, NULL, &channel, &strstart, &strlimit, NULL);
761
762 /* This is probably the easiest way to conclude if content of 'channel'
763 is *NOT* a number, and thus it is a candidate for a valid channel name */
764 if (channel && (*channel < '0' || *channel > '9'))
765 ischan = 1;
766
767
768 if (strlimit) /* .match <flags> <channel> <start> <limit> */
769 party_match_getbounds(strstart, strlimit, &start, &limit);
770 else if (strstart) /* .match <flags> <channel|start> <limit> */
771 party_match_getbounds(ischan?strstart:channel, ischan?NULL:strstart, &start, &limit);
772 else if (ischan) { /* .match <flags> <channel> */
773 start = 0;
774 limit = 20;
775 }
776 else /* .match <flags> [limit] */
777 party_match_getbounds(channel, NULL, &start, &limit);
778
779 free(strstart);
780 free(strlimit);
781
782 if (start == -1 || limit == -1)
783 partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
784 else
785 partyline_cmd_match_attr(p, mask, ischan?channel:NULL, start, limit);
786
787 free(channel);
788
789 return 0;
790 }
791
792 /* match <attr> [channel] [[start] limit] */
793 /* match <mask> [[start] limit] */
794 static int party_match(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
795 {
796
797 char *attr = NULL;
798 const char *rest = NULL;
799
800 /* FIXME - Check if user is allowed to see results.. if !chan && !glob_master && -> error
801 I have left it available to everyone because 'whois' was that way too.
802 We should update both or neither */
803
804 egg_get_args(text, &rest, &attr, NULL);
805
806 if (!attr) {
807 partymember_printf(p, _("Syntax: match <attr> [channel] [[start] limit]"));
808 partymember_printf(p, _(" or: match <mask> [[start] limit]"));
809 free(attr);
810 return 0;
811 }
812
813 if (*attr == '+' || *attr == '-' || *attr == '|')
814 party_matchattr(p, attr, rest);
815 else if (*attr != '&')
816 party_matchwild(p, attr, rest);
817
818 free(attr);
819
820 return BIND_RET_LOG;
821 }
822
823 static bind_list_t core_party_binds[] = { /* Old flags requirement */
824 {NULL, "help", party_help},
825 {NULL, "join", party_join}, /* DDD */
826 {NULL, "whisper", party_whisper}, /* DDD */
827 {NULL, "newpass", party_newpass}, /* DDC */ /* -|- */
828 {NULL, "help", party_help}, /* DDC */ /* -|- */
829 {NULL, "part", party_part}, /* DDD */
830 {NULL, "quit", party_quit}, /* DDD */ /* -|- */
831 {NULL, "who", party_who}, /* DDD */
832 {NULL, "whois", party_whois}, /* DDC */ /* ot|o */
833 {NULL, "match", party_match}, /* DDC */ /* ot|o */
834 {"n", "addlog", party_addlog}, /* DDD */ /* ot|o */
835 {"n", "get", party_get}, /* DDC */
836 {"n", "set", party_set}, /* DDC */
837 {"n", "unset", party_unset}, /* DDC */
838 {"n", "status", party_status}, /* DDC */ /* m|m */
839 {"n", "save", party_save}, /* DDD */ /* m|m */
840 {"n", "die", party_die}, /* DDD */ /* n|- */
841 {"n", "restart", party_restart}, /* DDD */ /* m|- */
842 {"n", "+user", party_plus_user}, /* DDC */ /* m|- */
843 {"n", "-user", party_minus_user}, /* DDC */ /* m|- */
844 {"n", "chattr", party_chattr}, /* DDC */ /* m|m */
845 {"n", "modules", party_modules}, /* DDD */ /* n|- */
846 {"n", "loadmod", party_loadmod}, /* DDD */ /* n|- */
847 {"n", "unloadmod", party_unloadmod}, /* DDD */ /* n|- */
848 {"n", "binds", party_binds}, /* DDD */ /* m|- */
849 {"m", "+host", party_plus_host}, /* DDC */ /* t|m */
850 {"m", "-host", party_minus_host}, /* DDC */ /* -|- */
851 {"t", "chhandle", party_chhandle}, /* DDC */ /* t|- */
852 {"t", "chpass", party_chpass}, /* DDC */ /* t|- */
853 {0}
854 };
855
856 void core_party_init(void)
857 {
858 bind_add_list("party", core_party_binds);
859 }
860

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23