/[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.48 - (hide annotations) (download) (as text)
Thu Dec 29 01:38:12 2005 UTC (13 years, 4 months ago) by sven
Branch: MAIN
Changes since 1.47: +5 -5 lines
File MIME type: text/x-chdr

 * timer IDs are now checked for overflows (like that's ever gonna happen)
 * binds are assigned a unique non-zero id
 * this ID is displayed in the partyline's ".binds" output
 * bind_entry_lookup now searches *all* bind tables if the "table" parameter is NULL
 * added "unbind_id" and "rebind_id" scripting functions that do the same thing as the non "_id" functions but use the bind ID instead of string guessing

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 sven 1.48 static const char rcsid[] = "$Id: core_party.c,v 1.47 2005-12-01 22:18:52 lordares Exp $";
22 wcc 1.15 #endif
23 wcc 1.14
24 stdarg 1.45 #include <eggdrop/eggdrop.h>
25 wcc 1.15 #include <unistd.h>
26    
27 wcc 1.14 #ifdef HAVE_UNAME
28     # include <sys/utsname.h>
29     #endif
30    
31 wcc 1.24 #include "core_config.h"
32     #include "core_binds.h"
33     #include "logfile.h"
34 wingman 1.33 #include "terminal.h" /* TERMINAL_NICK */
35 wingman 1.32 #include "main.h" /* SHUTDOWN_*, core_shutdown, core_restart */
36 wcc 1.24
37 stdarg 1.41 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 stdarg 1.42 xml_node_t *node, *arg, *desc, *see;
43     char *argname, *argdesc;
44     int optional;
45    
46 stdarg 1.41
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 stdarg 1.42 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 stdarg 1.41 return(0);
83     }
84    
85     /* No, do a search. */
86 stdarg 1.42 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 stdarg 1.41 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 stdarg 1.1
103 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
104     {
105 wcc 1.12 if (!text || !*text) {
106 wcc 1.16 partymember_printf(p, _("Syntax: join <channel>"));
107 stdarg 1.4 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 wcc 1.12 if (!text || !*text) chan = partychan_get_default(p);
118 stdarg 1.4 else chan = partychan_lookup_name(text);
119     partychan_part(chan, p, "parting");
120     return(0);
121     }
122    
123 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
124 stdarg 1.1 {
125 wingman 1.33 if (0 == strcmp (p->nick, TERMINAL_NICK)) {
126 wingman 1.27 partymember_printf (p, "You can't leave the partyline in terminal mode.");
127     return -1;
128     }
129 darko 1.37
130 wcc 1.18 partymember_printf(p, "Goodbye!");
131     if (!text || !*text) partymember_delete(p, "Quit");
132 wcc 1.12 else partymember_delete(p, text);
133 stdarg 1.1 return(0);
134     }
135    
136 wcc 1.12 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
137 stdarg 1.1 {
138 stdarg 1.13 char *who;
139     const char *next;
140     partymember_t *dest;
141    
142 stdarg 1.21 egg_get_arg(text, &next, &who);
143 stdarg 1.13 if (!who || !next || !*who || !*next) {
144 wcc 1.16 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
145 stdarg 1.13 goto done;
146     }
147    
148     dest = partymember_lookup_nick(who);
149     if (!dest) {
150 wcc 1.16 partymember_printf(p, _("No such user '%s'."), who);
151 stdarg 1.13 goto done;
152     }
153    
154     partymember_msg(dest, p, next, -1);
155     done:
156     if (who) free(who);
157 stdarg 1.1 return(0);
158     }
159    
160 stdarg 1.22 static void *lookup_setting(partymember_t *p, const char *path)
161 stdarg 1.11 {
162     void *root;
163    
164     root = config_get_root("eggdrop");
165     root = config_exists(root, path, 0, NULL);
166 stdarg 1.22 if (!root) partymember_printf(p, _("That setting does not exist."));
167 stdarg 1.11 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 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
177 stdarg 1.11 return(0);
178     }
179    
180 stdarg 1.22 root = lookup_setting(p, text);
181 stdarg 1.11 if (!root) return(0);
182    
183     config_get_str(&str, root, NULL);
184 wcc 1.24 if (str) partymember_printf(p, "Current value: '%s'", str);
185     else partymember_printf(p, _("Current value: null (unset)"));
186 stdarg 1.11 return(0);
187     }
188    
189 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
190 stdarg 1.2 {
191 stdarg 1.11 void *root;
192     char *path, *str;
193     const char *next;
194    
195 stdarg 1.21 egg_get_arg(text, &next, &path);
196 stdarg 1.22 if (!path) {
197     partymember_printf(p, _("Syntax: set <path> [new value]"));
198 stdarg 1.11 return(0);
199     }
200 stdarg 1.22 if (!next) {
201     free(path);
202     return party_get(p, nick, u, cmd, text);
203     }
204 wcc 1.14
205 stdarg 1.22 root = lookup_setting(p, path);
206 stdarg 1.11 free(path);
207     if (!root) return(0);
208    
209     config_get_str(&str, root, NULL);
210 wcc 1.16 partymember_printf(p, _("Old value: '%s'"), str);
211 stdarg 1.11 config_set_str(next, root, NULL);
212     config_get_str(&str, root, NULL);
213 stdarg 1.20 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 stdarg 1.22 root = lookup_setting(p, text);
229 stdarg 1.20 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 wcc 1.14 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 stdarg 1.20 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
248 wcc 1.16 partymember_printf(p, _("Owner: %s"), core_config.owner);
249     if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
250 wcc 1.14 #ifdef HAVE_UNAME
251 stdarg 1.20 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
252 wcc 1.14 #endif
253 stdarg 1.35 partymember_printf(p, _("Help path: %s (%d entries, %d sections)"),
254 stdarg 1.40 core_config.help_path, 0, 0);
255 stdarg 1.20 partymember_printf(p, "");
256     check_bind_status(p, text);
257 stdarg 1.2 return(0);
258     }
259    
260 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
261 stdarg 1.2 {
262 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
263 stdarg 1.5 user_save(core_config.userfile);
264 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
265 stdarg 1.2 core_config_save();
266     return(1);
267     }
268    
269 stdarg 1.5 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 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
273 stdarg 1.5 return(0);
274     }
275     user_set_pass(p->user, text);
276 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
277 stdarg 1.5 return(0);
278     }
279    
280 stdarg 1.7 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 stdarg 1.20 int *pids, len, i, width = 0;
289 stdarg 1.7
290 wcc 1.16 partymember_printf(p, _("Partyline members:"));
291 stdarg 1.7 partymember_who(&pids, &len);
292     qsort(pids, len, sizeof(int), intsorter);
293 stdarg 1.20 if (len > 0) {
294     i = pids[len-1];
295     if (!i) i++;
296     while (i != 0) {
297     i /= 10;
298     width++;
299     }
300     }
301 stdarg 1.7 for (i = 0; i < len; i++) {
302     who = partymember_lookup_pid(pids[i]);
303 stdarg 1.20 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
304 stdarg 1.7 }
305     free(pids);
306     return(0);
307     }
308    
309 stdarg 1.23 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 stdarg 1.25 if ((setting = strchr(item, '.'))) {
342 stdarg 1.23 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 stdarg 1.7 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
368     {
369 darko 1.37 /* XXX: should we really enable hard shutdowns?
370 wingman 1.32 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 stdarg 1.7 }
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 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
383 stdarg 1.7 return(0);
384     }
385     if (user_lookup_by_handle(text)) {
386 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
387 stdarg 1.7 return(0);
388     }
389     newuser = user_new(text);
390 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
391     else partymember_printf(p, _("Could not create user '%s'."), text);
392 stdarg 1.7 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 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
401 stdarg 1.7 return(0);
402     }
403     who = user_lookup_by_handle(text);
404 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
405 stdarg 1.7 else {
406 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
407 stdarg 1.7 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 stdarg 1.25 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 stdarg 1.7 return(0);
448     }
449    
450 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
451     {
452 stdarg 1.25 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 stdarg 1.9 return(0);
490     }
491    
492 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
493 stdarg 1.9 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 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
503 wcc 1.14 if (!chan || !*chan) {
504 stdarg 1.10 if (who) free(who);
505 wcc 1.24 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
506 stdarg 1.9 return(0);
507     }
508 wcc 1.14 if (!flags || !*flags) {
509 stdarg 1.9 flags = chan;
510     chan = NULL;
511     }
512     dest = user_lookup_by_handle(who);
513     if (dest) {
514 wingman 1.30 user_set_flags_str(dest, chan, flags);
515 stdarg 1.9 user_get_flags(dest, chan, &flagstruct);
516     flag_to_str(&flagstruct, flagstr);
517 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
518 stdarg 1.9 }
519 wcc 1.24 else partymember_printf(p, _("'%s' is not a valid user."), who);
520 stdarg 1.9 free(who);
521     free(flags);
522     if (chan) free(chan);
523     return(0);
524     }
525    
526 stdarg 1.26 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 wingman 1.30
530 wcc 1.46 return(BIND_RET_LOG);
531 stdarg 1.26 }
532    
533 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
534     {
535 stdarg 1.19 const char **modules;
536 wcc 1.12 int nummods, ctr;
537    
538 stdarg 1.19 nummods = module_list(&modules);
539 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
540 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
541     free(modules);
542 wingman 1.30
543 wcc 1.46 return(BIND_RET_LOG);
544 wcc 1.12 }
545    
546 stdarg 1.26 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
547 wcc 1.24 {
548     if (!text || !*text) {
549 stdarg 1.26 partymember_printf(p, _("Syntax: loadmod <module name>"));
550 wingman 1.30 return BIND_RET_BREAK;
551 wcc 1.24 }
552 stdarg 1.26 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 wcc 1.46 return(BIND_RET_LOG);
567 stdarg 1.26 }
568 wcc 1.24
569 stdarg 1.26 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 wingman 1.30 return BIND_RET_BREAK;
574 wcc 1.24 }
575 wingman 1.34 switch (module_unload(text, MODULE_USER)) {
576 stdarg 1.26 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 wcc 1.46 return(BIND_RET_LOG);
590 wcc 1.24 }
591    
592 wingman 1.32 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 sven 1.48 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %5s %s", _("TABLE"), _("SYNTAX"),
599     _("FUNCTION"), _("MASK"), _("FLAGS"), _("ID"), _("HITS"));
600 wingman 1.32 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 sven 1.48 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %5i %i", table->name, table->syntax,
604     entry->function_name, entry->mask, flags, entry->id, entry->nhits);
605 wingman 1.32 }
606     }
607    
608 wcc 1.46 return(BIND_RET_LOG);
609 wingman 1.32 }
610    
611 stdarg 1.43 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 stdarg 1.44 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 wingman 1.33 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 darko 1.37
666 wcc 1.46 return(BIND_RET_LOG);
667 wingman 1.33 }
668    
669 darko 1.36 /* 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 stdarg 1.40 char *old = NULL, *newh = NULL;
673 darko 1.36 user_t *dest;
674    
675 stdarg 1.40 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 darko 1.36 partymember_printf(p, _("Syntax: chhandle <old_handle> <new_handle>"));
680 darko 1.39 goto chhandleend;
681 darko 1.36 }
682    
683     dest = user_lookup_by_handle(old);
684     if (!dest) {
685 stdarg 1.40 free(old);
686     free(newh);
687 darko 1.36 partymember_printf(p, _("Error: User '%s' does not exist."), old);
688 darko 1.39 goto chhandleend;
689 darko 1.36 }
690    
691 stdarg 1.40 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 darko 1.36 }
697    
698 stdarg 1.40 if (!user_change_handle(dest, newh))
699 darko 1.36 partymember_printf(p, _("Ok, changed."));
700 darko 1.39
701     chhandleend:
702 stdarg 1.40 free(newh);
703 darko 1.39 free(old);
704    
705 wcc 1.46 return(BIND_RET_LOG);
706 darko 1.36 }
707    
708 darko 1.39 /* Syntax: chpass <handle> [new_pass] */
709 darko 1.37 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 darko 1.38 if (!user || !*user) {
717     partymember_printf(p, _("Syntax: chpass <handle> [pass]"));
718 darko 1.39 goto chpassend;
719 darko 1.37 }
720    
721     dest = user_lookup_by_handle(user);
722     if (!dest) {
723     partymember_printf(p, _("Error: User '%s' does not exist."), user);
724 darko 1.39 goto chpassend;
725 darko 1.37 }
726    
727 darko 1.38 if (pass && *pass && strlen(pass) < 6) {
728 darko 1.37 partymember_printf(p, _("Error: Please use at least 6 characters."));
729 darko 1.39 goto chpassend;
730 darko 1.37 }
731    
732 darko 1.38 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 darko 1.39
737     chpassend:
738     free(user);
739     free(pass);
740    
741 lordares 1.47 return(BIND_RET_LOG_COMMAND);
742 darko 1.39 }
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 darko 1.37 return 0;
794     }
795    
796 darko 1.39 /* 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 wcc 1.46 return(BIND_RET_LOG);
864 darko 1.39 }
865    
866     static bind_list_t core_party_binds[] = { /* Old flags requirement */
867 stdarg 1.41 {NULL, "help", party_help},
868 wingman 1.29 {NULL, "join", party_join}, /* DDD */
869     {NULL, "whisper", party_whisper}, /* DDD */
870 darko 1.39 {NULL, "newpass", party_newpass}, /* DDC */ /* -|- */
871     {NULL, "help", party_help}, /* DDC */ /* -|- */
872 wingman 1.29 {NULL, "part", party_part}, /* DDD */
873 darko 1.39 {NULL, "quit", party_quit}, /* DDD */ /* -|- */
874 wingman 1.29 {NULL, "who", party_who}, /* DDD */
875 darko 1.39 {NULL, "whois", party_whois}, /* DDC */ /* ot|o */
876     {NULL, "match", party_match}, /* DDC */ /* ot|o */
877     {"n", "addlog", party_addlog}, /* DDD */ /* ot|o */
878 wingman 1.30 {"n", "get", party_get}, /* DDC */
879     {"n", "set", party_set}, /* DDC */
880     {"n", "unset", party_unset}, /* DDC */
881 darko 1.39 {"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 stdarg 1.43 {"n", "timers", party_timers},
893 stdarg 1.44 {"n", "netstats", party_netstats},
894 darko 1.39 {"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 stdarg 1.1 {0}
899     };
900    
901 wingman 1.27 void core_party_init(void)
902 stdarg 1.1 {
903     bind_add_list("party", core_party_binds);
904     }
905 darko 1.39

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23