/[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.44 - (hide annotations) (download) (as text)
Sun Oct 10 04:55:11 2004 UTC (14 years, 6 months ago) by stdarg
Branch: MAIN
Changes since 1.43: +39 -1 lines
File MIME type: text/x-chdr
* Added .netstats command to see network connections... may add traffic stats later

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23