/[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.49 - (show annotations) (download) (as text)
Mon Jun 19 15:47:33 2006 UTC (12 years, 11 months ago) by stdarg
Branch: MAIN
Changes since 1.48: +5 -5 lines
File MIME type: text/x-chdr

* Got rid of bind entry id's since they weren't really used anywhere
* Got rid of "fake binds" for scripts since it had some problems dealing
with bind tables that never came into being

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23