/[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.51 - (hide annotations) (download) (as text)
Sun Oct 1 00:48:59 2006 UTC (12 years, 7 months ago) by sven
Branch: MAIN
Changes since 1.50: +10 -5 lines
File MIME type: text/x-chdr

Added sanity checks to usernames. All non-printable characters as well
as " *?" are rejected. The " " is necessary but "*" und "?" might be ok,
so this may change in the future.

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.51 static const char rcsid[] = "$Id: core_party.c,v 1.50 2006-08-22 01:41:28 sven 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 sven 1.51 const char *error;
380 stdarg 1.7 user_t *newuser;
381    
382     if (!text || !*text) {
383 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
384 stdarg 1.7 return(0);
385     }
386 sven 1.51
387     error = user_invalid_handle(text);
388     if (error) {
389     partymember_printf(p, _("Error: %s"), error);
390 stdarg 1.7 return(0);
391     }
392     newuser = user_new(text);
393 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
394     else partymember_printf(p, _("Could not create user '%s'."), text);
395 stdarg 1.7 return(0);
396     }
397    
398     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
399     {
400     user_t *who;
401    
402     if (!text || !*text) {
403 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
404 stdarg 1.7 return(0);
405     }
406     who = user_lookup_by_handle(text);
407 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
408 stdarg 1.7 else {
409 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
410 stdarg 1.7 user_delete(who);
411     }
412     return(0);
413     }
414    
415     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
416     {
417 stdarg 1.25 user_t *who;
418     char *target, *newhost;
419    
420     egg_get_args(text, NULL, &target, &newhost, NULL);
421     if (!target) {
422     partymember_printf(p, _("Syntax: +host [handle] <host>"));
423     return(0);
424     }
425     if (!newhost) {
426     newhost = target;
427     target = NULL;
428     }
429     if (target) {
430     who = user_lookup_by_handle(target);
431     if (!who) {
432     partymember_printf(p, _("User '%s' not found."), target);
433     goto done;
434     }
435     }
436     else {
437     who = u;
438     if (!who) {
439     partymember_printf(p, _("Only valid users can add hosts."));
440     goto done;
441     }
442     }
443     user_add_ircmask(who, newhost);
444     partymember_printf(p, _("Added '%1$s' to user '%2$s'."), newhost, who->handle);
445    
446     done:
447     if (target) free(target);
448     free(newhost);
449    
450 stdarg 1.7 return(0);
451     }
452    
453 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
454     {
455 stdarg 1.25 user_t *who;
456     char *target, *host;
457    
458     egg_get_args(text, NULL, &target, &host, NULL);
459     if (!target) {
460     partymember_printf(p, _("Syntax: -host [handle] <host>"));
461     return(0);
462     }
463     if (!host) {
464     host = target;
465     target = NULL;
466     }
467     if (target) {
468     who = user_lookup_by_handle(target);
469     if (!who) {
470     partymember_printf(p, _("User '%s' not found."), target);
471     goto done;
472     }
473     }
474     else {
475     who = u;
476     if (!who) {
477     partymember_printf(p, _("Only valid users can remove hosts."));
478     goto done;
479     }
480     }
481     if (user_del_ircmask(who, host)) {
482     partymember_printf(p, _("Mask '%1$s' not found for user '%2$s'."), host, who->handle);
483     }
484     else {
485     partymember_printf(p, _("Removed '%1$s' from user '%2$s'."), host, who->handle);
486     }
487    
488     done:
489     if (target) free(target);
490     free(host);
491    
492 stdarg 1.9 return(0);
493     }
494    
495 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
496 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
497     {
498     const char *next;
499     char *who, *flags, *chan;
500     user_t *dest;
501     flags_t flagstruct;
502     char flagstr[64];
503     int n;
504    
505 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
506 wcc 1.14 if (!chan || !*chan) {
507 stdarg 1.10 if (who) free(who);
508 wcc 1.24 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
509 stdarg 1.9 return(0);
510     }
511 wcc 1.14 if (!flags || !*flags) {
512 stdarg 1.9 flags = chan;
513     chan = NULL;
514     }
515     dest = user_lookup_by_handle(who);
516     if (dest) {
517 wingman 1.30 user_set_flags_str(dest, chan, flags);
518 stdarg 1.9 user_get_flags(dest, chan, &flagstruct);
519     flag_to_str(&flagstruct, flagstr);
520 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
521 stdarg 1.9 }
522 wcc 1.24 else partymember_printf(p, _("'%s' is not a valid user."), who);
523 stdarg 1.9 free(who);
524     free(flags);
525     if (chan) free(chan);
526     return(0);
527     }
528    
529 stdarg 1.26 static int party_addlog(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
530     {
531     putlog(LOG_MISC, "*", "%s: %s", nick, text);
532 wingman 1.30
533 wcc 1.46 return(BIND_RET_LOG);
534 stdarg 1.26 }
535    
536 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
537     {
538 stdarg 1.19 const char **modules;
539 wcc 1.12 int nummods, ctr;
540    
541 stdarg 1.19 nummods = module_list(&modules);
542 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
543 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
544     free(modules);
545 wingman 1.30
546 wcc 1.46 return(BIND_RET_LOG);
547 wcc 1.12 }
548    
549 stdarg 1.26 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
550 wcc 1.24 {
551     if (!text || !*text) {
552 stdarg 1.26 partymember_printf(p, _("Syntax: loadmod <module name>"));
553 wingman 1.30 return BIND_RET_BREAK;
554 wcc 1.24 }
555 stdarg 1.26 switch (module_load(text)) {
556     case 0:
557     partymember_printf(p, _("Module '%s' loaded successfully."), text);
558     break;
559     case -1:
560     partymember_printf(p, _("Module '%s' is already loaded."), text);
561     break;
562     case -2:
563     partymember_printf(p, _("Module '%s' could not be loaded."), text);
564     break;
565     case -3:
566     partymember_printf(p, _("Module '%s' does not have a valid initialization function. Perhaps it is not an eggdrop module?"), text);
567     break;
568     }
569 wcc 1.46 return(BIND_RET_LOG);
570 stdarg 1.26 }
571 wcc 1.24
572 stdarg 1.26 static int party_unloadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
573     {
574     if (!text || !*text) {
575     partymember_printf(p, _("Syntax: unloadmod <module name>"));
576 wingman 1.30 return BIND_RET_BREAK;
577 wcc 1.24 }
578 wingman 1.34 switch (module_unload(text, MODULE_USER)) {
579 stdarg 1.26 case 0:
580     partymember_printf(p, _("Module '%s' unloaded successfully."), text);
581     break;
582     case -1:
583     partymember_printf(p, _("Module '%s' is not loaded."), text);
584     break;
585     case -2:
586     partymember_printf(p, _("Module '%s' has dependencies that are still loaded. You must unload them first."), text);
587     break;
588     case -3:
589     partymember_printf(p, _("Module '%s' refuses to be unloaded by you!"), text);
590     break;
591     }
592 wcc 1.46 return(BIND_RET_LOG);
593 wcc 1.24 }
594    
595 wingman 1.32 static int party_binds(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
596     {
597     bind_table_t *table;
598     bind_entry_t *entry;
599     char flags[64];
600    
601 stdarg 1.49 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %s", _("TABLE"), _("SYNTAX"),
602     _("FUNCTION"), _("MASK"), _("FLAGS"), _("HITS"));
603 wingman 1.32 for (table = bind_table_list(); table; table = table->next) {
604     for (entry = table->entries; entry; entry = entry->next) {
605     flag_to_str(&entry->user_flags, flags);
606 stdarg 1.49 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %d", table->name, table->syntax,
607     entry->function_name, entry->mask, flags, entry->nhits);
608 wingman 1.32 }
609     }
610    
611 wcc 1.46 return(BIND_RET_LOG);
612 wingman 1.32 }
613    
614 stdarg 1.43 static int party_timers(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
615     {
616     egg_timer_t *timer;
617     int remain, now;
618    
619     now = timer_get_now_sec(NULL);
620     partymember_printf(p, "ID SEC LEFT NAME");
621     for (timer = timer_list(); timer; timer = timer->next) {
622     remain = timer->trigger_time.sec - now;
623     partymember_printf(p, "%-5d %-8d %s", timer->id, remain, timer->name);
624     }
625     return(BIND_RET_LOG);
626     }
627    
628 stdarg 1.44 static int print_net(partymember_t *p, const char *header, int flags)
629     {
630     int *idx, len;
631     int i, port, peer_port;
632     const char *host, *peer_host;
633     char *self_addr, *peer_addr;
634     sockbuf_handler_t *handler;
635    
636     sockbuf_list(&idx, &len, flags);
637     partymember_printf(p, "%s", header);
638     partymember_printf(p, " %3s %20s %20s %s", _("Idx"), _("Local Address"), _("Foreign Address"), _("Description"));
639     for (i = 0; i < len; i++) {
640     sockbuf_get_self(idx[i], &host, &port);
641     sockbuf_get_peer(idx[i], &peer_host, &peer_port);
642     if (!host) host = "*";
643     if (!peer_host) peer_host = "*";
644     sockbuf_get_handler(idx[i], &handler, NULL);
645     if (port) self_addr = egg_mprintf("%s/%d", host, port);
646     else self_addr = egg_mprintf("%s/*", host);
647     if (peer_port) peer_addr = egg_mprintf("%s/%d", peer_host, peer_port);
648     else peer_addr = egg_mprintf("%s/*", peer_host);
649     partymember_printf(p, " %3d %20s %20s %s", idx[i], self_addr, peer_addr, handler->name);
650     free(self_addr);
651     free(peer_addr);
652     }
653     free(idx);
654     return(0);
655     }
656    
657     static int party_netstats(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
658     {
659     print_net(p, "Server Sockets", SOCKBUF_SERVER);
660     print_net(p, "Incoming Connections", SOCKBUF_INBOUND);
661     print_net(p, "Outgoing Connections", SOCKBUF_CLIENT);
662     return(0);
663     }
664    
665 wingman 1.33 static int party_restart(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
666     {
667     core_restart (nick);
668 darko 1.37
669 wcc 1.46 return(BIND_RET_LOG);
670 wingman 1.33 }
671    
672 darko 1.36 /* Syntax: chhandle <old_handle> <new_handle> */
673     static int party_chhandle(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
674     {
675 sven 1.51 const char *error;
676 stdarg 1.40 char *old = NULL, *newh = NULL;
677 darko 1.36 user_t *dest;
678    
679 stdarg 1.40 egg_get_args(text, NULL, &old, &newh, NULL);
680     if (!old || !newh || !*old || !*newh) {
681     if (old) free(old);
682     if (newh) free(newh);
683 darko 1.36 partymember_printf(p, _("Syntax: chhandle <old_handle> <new_handle>"));
684 sven 1.50 return 0;
685 darko 1.36 }
686    
687     dest = user_lookup_by_handle(old);
688     if (!dest) {
689 sven 1.50 partymember_printf(p, _("Error: User '%s' does not exist."), old);
690 stdarg 1.40 free(old);
691     free(newh);
692 sven 1.50 return 0;
693 darko 1.36 }
694    
695 sven 1.51 error = user_invalid_handle(newh);
696     if (error) {
697     partymember_printf(p, _("Error: %s"), error);
698 stdarg 1.40 free(old);
699     free(newh);
700     return 0;
701 darko 1.36 }
702    
703 stdarg 1.40 if (!user_change_handle(dest, newh))
704 darko 1.36 partymember_printf(p, _("Ok, changed."));
705 darko 1.39
706 stdarg 1.40 free(newh);
707 darko 1.39 free(old);
708    
709 wcc 1.46 return(BIND_RET_LOG);
710 darko 1.36 }
711    
712 darko 1.39 /* Syntax: chpass <handle> [new_pass] */
713 darko 1.37 static int party_chpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
714     {
715     char *user = NULL, *pass = NULL;
716     user_t *dest;
717    
718     egg_get_args(text, NULL, &user, &pass, NULL);
719    
720 darko 1.38 if (!user || !*user) {
721     partymember_printf(p, _("Syntax: chpass <handle> [pass]"));
722 darko 1.39 goto chpassend;
723 darko 1.37 }
724    
725     dest = user_lookup_by_handle(user);
726     if (!dest) {
727     partymember_printf(p, _("Error: User '%s' does not exist."), user);
728 darko 1.39 goto chpassend;
729 darko 1.37 }
730    
731 darko 1.38 if (pass && *pass && strlen(pass) < 6) {
732 darko 1.37 partymember_printf(p, _("Error: Please use at least 6 characters."));
733 darko 1.39 goto chpassend;
734 darko 1.37 }
735    
736 darko 1.38 if (user_set_pass(dest, pass))
737     partymember_printf(p, _("Removed password for %s."), user);
738     else
739     partymember_printf(p, _("Password for %s is now '%s'."), user, pass);
740 darko 1.39
741     chpassend:
742     free(user);
743     free(pass);
744    
745 lordares 1.47 return(BIND_RET_LOG_COMMAND);
746 darko 1.39 }
747    
748     /* Makes sure 'start' and 'limit' arguments for .match are reasonable, or else sets them -1 */
749     static int party_match_getbounds(const char *strstart, const char *strlimit, long *start, long *limit)
750     {
751     char *tmpptr;
752    
753     if (strstart) {
754     *start = strtol(strstart, &tmpptr, 10);
755     if (!*strstart || *tmpptr || *start < 1) { /* Invalid input*/
756     *start = -1;
757     return 0;
758     }
759    
760     if (strlimit) { /* 'start' was really a start and this is now 'limit' */
761     *limit = strtol(strlimit, &tmpptr, 10);
762     if (!*strlimit || *tmpptr || *limit < 1) { /* Invalid input*/
763     *limit = -1;
764     return 0;
765     }
766     }
767     else { /* Ah, no, the only argument specified was the 'limit' */
768     *limit = *start;
769     *start = 0;
770     }
771     }
772     else {
773     *limit = 20;
774     *start = 0;
775     }
776    
777     return 0;
778     }
779    
780     /* Handles case where .match was given mask to match against */
781     static int party_matchwild(partymember_t *p, const char *mask, const char *rest)
782     {
783     char *strstart = NULL, *strlimit = NULL;
784     long start, limit;
785    
786     egg_get_args(rest, NULL, &strstart, &strlimit, NULL);
787    
788     party_match_getbounds(strstart, strlimit, &start, &limit);
789     if (start == -1 || limit == -1)
790     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
791     else
792     partyline_cmd_match_ircmask(p, mask, start, limit);
793    
794     free(strstart);
795     free(strlimit);
796    
797 darko 1.37 return 0;
798     }
799    
800 darko 1.39 /* Handles case where .match was given attributes to match against */
801     static int party_matchattr(partymember_t *p, const char *mask, const char *rest)
802     {
803     char *channel = NULL, *strstart = NULL, *strlimit = NULL;
804     long start, limit;
805     int ischan = 0;
806    
807     egg_get_args(rest, NULL, &channel, &strstart, &strlimit, NULL);
808    
809     /* This is probably the easiest way to conclude if content of 'channel'
810     is *NOT* a number, and thus it is a candidate for a valid channel name */
811     if (channel && (*channel < '0' || *channel > '9'))
812     ischan = 1;
813    
814    
815     if (strlimit) /* .match <flags> <channel> <start> <limit> */
816     party_match_getbounds(strstart, strlimit, &start, &limit);
817     else if (strstart) /* .match <flags> <channel|start> <limit> */
818     party_match_getbounds(ischan?strstart:channel, ischan?NULL:strstart, &start, &limit);
819     else if (ischan) { /* .match <flags> <channel> */
820     start = 0;
821     limit = 20;
822     }
823     else /* .match <flags> [limit] */
824     party_match_getbounds(channel, NULL, &start, &limit);
825    
826     free(strstart);
827     free(strlimit);
828    
829     if (start == -1 || limit == -1)
830     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
831     else
832     partyline_cmd_match_attr(p, mask, ischan?channel:NULL, start, limit);
833    
834     free(channel);
835    
836     return 0;
837     }
838    
839     /* match <attr> [channel] [[start] limit] */
840     /* match <mask> [[start] limit] */
841     static int party_match(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
842     {
843    
844     char *attr = NULL;
845     const char *rest = NULL;
846    
847     /* FIXME - Check if user is allowed to see results.. if !chan && !glob_master && -> error
848     I have left it available to everyone because 'whois' was that way too.
849     We should update both or neither */
850    
851     egg_get_args(text, &rest, &attr, NULL);
852    
853     if (!attr) {
854     partymember_printf(p, _("Syntax: match <attr> [channel] [[start] limit]"));
855     partymember_printf(p, _(" or: match <mask> [[start] limit]"));
856     free(attr);
857     return 0;
858     }
859    
860     if (*attr == '+' || *attr == '-' || *attr == '|')
861     party_matchattr(p, attr, rest);
862     else if (*attr != '&')
863     party_matchwild(p, attr, rest);
864    
865     free(attr);
866    
867 wcc 1.46 return(BIND_RET_LOG);
868 darko 1.39 }
869    
870     static bind_list_t core_party_binds[] = { /* Old flags requirement */
871 stdarg 1.41 {NULL, "help", party_help},
872 wingman 1.29 {NULL, "join", party_join}, /* DDD */
873     {NULL, "whisper", party_whisper}, /* DDD */
874 darko 1.39 {NULL, "newpass", party_newpass}, /* DDC */ /* -|- */
875     {NULL, "help", party_help}, /* DDC */ /* -|- */
876 wingman 1.29 {NULL, "part", party_part}, /* DDD */
877 darko 1.39 {NULL, "quit", party_quit}, /* DDD */ /* -|- */
878 wingman 1.29 {NULL, "who", party_who}, /* DDD */
879 darko 1.39 {NULL, "whois", party_whois}, /* DDC */ /* ot|o */
880     {NULL, "match", party_match}, /* DDC */ /* ot|o */
881     {"n", "addlog", party_addlog}, /* DDD */ /* ot|o */
882 wingman 1.30 {"n", "get", party_get}, /* DDC */
883     {"n", "set", party_set}, /* DDC */
884     {"n", "unset", party_unset}, /* DDC */
885 darko 1.39 {"n", "status", party_status}, /* DDC */ /* m|m */
886     {"n", "save", party_save}, /* DDD */ /* m|m */
887     {"n", "die", party_die}, /* DDD */ /* n|- */
888     {"n", "restart", party_restart}, /* DDD */ /* m|- */
889     {"n", "+user", party_plus_user}, /* DDC */ /* m|- */
890     {"n", "-user", party_minus_user}, /* DDC */ /* m|- */
891     {"n", "chattr", party_chattr}, /* DDC */ /* m|m */
892     {"n", "modules", party_modules}, /* DDD */ /* n|- */
893     {"n", "loadmod", party_loadmod}, /* DDD */ /* n|- */
894     {"n", "unloadmod", party_unloadmod}, /* DDD */ /* n|- */
895     {"n", "binds", party_binds}, /* DDD */ /* m|- */
896 stdarg 1.43 {"n", "timers", party_timers},
897 stdarg 1.44 {"n", "netstats", party_netstats},
898 darko 1.39 {"m", "+host", party_plus_host}, /* DDC */ /* t|m */
899     {"m", "-host", party_minus_host}, /* DDC */ /* -|- */
900     {"t", "chhandle", party_chhandle}, /* DDC */ /* t|- */
901     {"t", "chpass", party_chpass}, /* DDC */ /* t|- */
902 stdarg 1.1 {0}
903     };
904    
905 wingman 1.27 void core_party_init(void)
906 stdarg 1.1 {
907     bind_add_list("party", core_party_binds);
908     }
909 darko 1.39

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23