/[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.53 - (hide annotations) (download) (as text)
Sat Dec 2 04:05:11 2006 UTC (12 years, 5 months ago) by sven
Branch: MAIN
Changes since 1.52: +25 -1 lines
File MIME type: text/x-chdr
 * Added a .unlink partyline command (but it only works on local connections
   right now.
 * Fixed a module loading bug that prevented them from being unloaded again.
 * Added some error checking to module unloading that would have made locating
   the above bug much easier.

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.53 static const char rcsid[] = "$Id: core_party.c,v 1.52 2006-11-14 14:51:24 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 sven 1.52 partychan_join_name(text, p, 0);
110 stdarg 1.4 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 sven 1.52 if (!text || !*text) partymember_delete(p, NULL, "Quit");
132     else partymember_delete(p, NULL, 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 sven 1.52 dest = partymember_lookup(who, NULL, -1);
149 stdarg 1.13 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 sven 1.52 static int party_bots(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
261     {
262     int len, bots = 1;
263     char obuf[201] = "";
264     const char *botname;
265     const botnet_bot_t *bot;
266    
267     botname = botnet_get_name();
268     if (strlen(botname) < 100) strcpy(obuf, botname);
269     else sprintf(obuf, "%.96s...", botname);
270    
271     for (bot = botnet_get_head(); bot; bot = bot->next) {
272     ++bots;
273     len = strlen(bot->name);
274     if (strlen(obuf) + (len < 100 ? len : 99) + 2 > 200) {
275     partymember_printf(p, _("Bots: %s"), obuf);
276     if (strlen(botname) < 100) strcpy(obuf, bot->name);
277     else sprintf(obuf, "%.96s...", bot->name);
278     } else {
279     if (strlen(botname) < 100) sprintf(obuf + strlen(obuf), ", %s", bot->name);
280     else sprintf(obuf + strlen(obuf), ", %.96s...", bot->name);
281     }
282     }
283     partymember_printf(p, _("Bots: %s"), obuf);
284     partymember_printf(p, _("Total: %d"), bots);
285     return 0;
286     }
287    
288 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
289 stdarg 1.2 {
290 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
291 stdarg 1.5 user_save(core_config.userfile);
292 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
293 stdarg 1.2 core_config_save();
294     return(1);
295     }
296    
297 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
298     {
299     if (!text || strlen(text) < 6) {
300 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
301 stdarg 1.5 return(0);
302     }
303     user_set_pass(p->user, text);
304 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
305 stdarg 1.5 return(0);
306     }
307    
308 stdarg 1.7 static int intsorter(const void *left, const void *right)
309     {
310     return(*(int *)left - *(int *)right);
311     }
312    
313     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
314     {
315     partymember_t *who;
316 sven 1.52 int *ids, len, i, width = 0;
317 stdarg 1.7
318 wcc 1.16 partymember_printf(p, _("Partyline members:"));
319 sven 1.52 partymember_who(&ids, &len);
320     qsort(ids, len, sizeof(int), intsorter);
321 stdarg 1.20 if (len > 0) {
322 sven 1.52 i = ids[len-1];
323 stdarg 1.20 if (!i) i++;
324     while (i != 0) {
325     i /= 10;
326     width++;
327     }
328     }
329 stdarg 1.7 for (i = 0; i < len; i++) {
330 sven 1.52 who = partymember_lookup(NULL, NULL, ids[i]);
331     partymember_printf(p, " [%*d] %s (%s@%s)", width, who->id, who->nick, who->ident, who->host);
332 stdarg 1.7 }
333 sven 1.52 free(ids);
334 stdarg 1.7 return(0);
335     }
336    
337 stdarg 1.23 static int party_whois(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
338     {
339     user_t *who;
340     flags_t flags;
341     char *item, *chan, *setting, *value, flagstr[64];
342     const char *next;
343     int i;
344    
345     if (text && *text) who = user_lookup_by_handle(text);
346     else who = u;
347    
348     if (!who) {
349     partymember_printf(p, "No such user.");
350     return(0);
351     }
352    
353     next = core_config.whois_items;
354     while (next && *next) {
355     egg_get_arg(next, &next, &item);
356     if (!strcasecmp(item, "handle")) {
357     partymember_printf(p, "%s: '%s'", item, who->handle);
358     }
359     else if (!strcasecmp(item, "uid")) {
360     partymember_printf(p, "%s: '%d'", item, who->uid);
361     }
362     else if (!strcasecmp(item, "ircmasks")) {
363     partymember_printf(p, "%s:", item);
364     for (i = 0; i < who->nircmasks; i++) {
365     partymember_printf(p, " %d. '%s'", i+1, who->ircmasks[i]);
366     }
367     }
368     else {
369 stdarg 1.25 if ((setting = strchr(item, '.'))) {
370 stdarg 1.23 chan = item;
371     *setting = 0;
372     setting++;
373     }
374     else {
375     chan = NULL;
376     setting = item;
377     }
378     if (!strcasecmp(setting, "flags")) {
379     user_get_flags(who, chan, &flags);
380     flag_to_str(&flags, flagstr);
381     value = flagstr;
382     }
383     else {
384     user_get_setting(who, chan, setting, &value);
385     }
386    
387     if (chan) partymember_printf(p, "%s.%s: %s", chan, setting, value);
388     else partymember_printf(p, "%s: %s", setting, value);
389     }
390     free(item);
391     }
392     return(0);
393     }
394    
395 stdarg 1.7 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
396     {
397 darko 1.37 /* XXX: should we really enable hard shutdowns?
398 wingman 1.32 if (*text && 0 == strcmp(text, "force")) {
399     return core_shutdown(SHUTDOWN_HARD, nick, text);
400     } else
401     */
402     return core_shutdown(SHUTDOWN_GRACEFULL, nick, text);
403 stdarg 1.7 }
404    
405     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
406     {
407 sven 1.51 const char *error;
408 stdarg 1.7 user_t *newuser;
409    
410     if (!text || !*text) {
411 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
412 stdarg 1.7 return(0);
413     }
414 sven 1.51
415     error = user_invalid_handle(text);
416     if (error) {
417     partymember_printf(p, _("Error: %s"), error);
418 stdarg 1.7 return(0);
419     }
420     newuser = user_new(text);
421 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
422     else partymember_printf(p, _("Could not create user '%s'."), text);
423 stdarg 1.7 return(0);
424     }
425    
426     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
427     {
428     user_t *who;
429    
430     if (!text || !*text) {
431 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
432 stdarg 1.7 return(0);
433     }
434     who = user_lookup_by_handle(text);
435 sven 1.52 if (!who) partymember_printf(p, _("User '%s' not found."), text);
436 stdarg 1.7 else {
437 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
438 stdarg 1.7 user_delete(who);
439     }
440     return(0);
441     }
442    
443 sven 1.53 static int party_unlink(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
444     {
445     char *botname;
446     const char *reason;
447     botnet_bot_t *bot;
448    
449     egg_get_arg(text, &reason, &botname);
450     if (!botname || !*botname) {
451     partymember_printf(p, _("Syntax: unlink <handle> [reason]"));
452     free(botname);
453     return 0;
454     }
455    
456     bot = botnet_lookup(botname);
457     free(botname);
458     if (!bot) {
459     partymember_printf(p, _("Not connected to that bot."));
460     return 0;
461     }
462     botnet_unlink(p, bot, reason);
463     return 0;
464     }
465    
466 sven 1.52 static int party_link(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
467     {
468     int error;
469     user_t *who;
470    
471     if (!text || !*text) {
472     partymember_printf(p, _("Syntax: link <handle>"));
473     return 0;
474     }
475     who = user_lookup_by_handle(text);
476     if (!who) {
477     partymember_printf(p, _("User '%s' not found."), text);
478     return 0;
479     }
480     error = botnet_link(who);
481     if (!error) return 0;
482    
483     if (error == -1) {
484     partymember_printf(p, _("Error linking to '%s': User is not a bot."), who->handle);
485     } else if (error == -2) {
486     partymember_printf(p, _("Error linking to '%s': Bot type not set."), who->handle);
487     } else if (error == -3) {
488     partymember_printf(p, _("Error linking to '%s': No module loaded to link to that bot type."), who->handle);
489     }
490    
491     return 0;
492     }
493    
494 stdarg 1.7 static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
495     {
496 stdarg 1.25 user_t *who;
497     char *target, *newhost;
498    
499     egg_get_args(text, NULL, &target, &newhost, NULL);
500     if (!target) {
501     partymember_printf(p, _("Syntax: +host [handle] <host>"));
502     return(0);
503     }
504     if (!newhost) {
505     newhost = target;
506     target = NULL;
507     }
508     if (target) {
509     who = user_lookup_by_handle(target);
510     if (!who) {
511     partymember_printf(p, _("User '%s' not found."), target);
512     goto done;
513     }
514     }
515     else {
516     who = u;
517     if (!who) {
518     partymember_printf(p, _("Only valid users can add hosts."));
519     goto done;
520     }
521     }
522     user_add_ircmask(who, newhost);
523     partymember_printf(p, _("Added '%1$s' to user '%2$s'."), newhost, who->handle);
524    
525     done:
526     if (target) free(target);
527     free(newhost);
528    
529 stdarg 1.7 return(0);
530     }
531    
532 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
533     {
534 stdarg 1.25 user_t *who;
535     char *target, *host;
536    
537     egg_get_args(text, NULL, &target, &host, NULL);
538     if (!target) {
539     partymember_printf(p, _("Syntax: -host [handle] <host>"));
540     return(0);
541     }
542     if (!host) {
543     host = target;
544     target = NULL;
545     }
546     if (target) {
547     who = user_lookup_by_handle(target);
548     if (!who) {
549     partymember_printf(p, _("User '%s' not found."), target);
550     goto done;
551     }
552     }
553     else {
554     who = u;
555     if (!who) {
556     partymember_printf(p, _("Only valid users can remove hosts."));
557     goto done;
558     }
559     }
560     if (user_del_ircmask(who, host)) {
561     partymember_printf(p, _("Mask '%1$s' not found for user '%2$s'."), host, who->handle);
562     }
563     else {
564     partymember_printf(p, _("Removed '%1$s' from user '%2$s'."), host, who->handle);
565     }
566    
567     done:
568     if (target) free(target);
569     free(host);
570    
571 stdarg 1.9 return(0);
572     }
573    
574 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
575 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
576     {
577     const char *next;
578     char *who, *flags, *chan;
579     user_t *dest;
580     flags_t flagstruct;
581     char flagstr[64];
582     int n;
583    
584 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
585 wcc 1.14 if (!chan || !*chan) {
586 stdarg 1.10 if (who) free(who);
587 wcc 1.24 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
588 stdarg 1.9 return(0);
589     }
590 wcc 1.14 if (!flags || !*flags) {
591 stdarg 1.9 flags = chan;
592     chan = NULL;
593     }
594     dest = user_lookup_by_handle(who);
595     if (dest) {
596 wingman 1.30 user_set_flags_str(dest, chan, flags);
597 stdarg 1.9 user_get_flags(dest, chan, &flagstruct);
598     flag_to_str(&flagstruct, flagstr);
599 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
600 stdarg 1.9 }
601 wcc 1.24 else partymember_printf(p, _("'%s' is not a valid user."), who);
602 stdarg 1.9 free(who);
603     free(flags);
604     if (chan) free(chan);
605     return(0);
606     }
607    
608 stdarg 1.26 static int party_addlog(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
609     {
610     putlog(LOG_MISC, "*", "%s: %s", nick, text);
611 wingman 1.30
612 wcc 1.46 return(BIND_RET_LOG);
613 stdarg 1.26 }
614    
615 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
616     {
617 stdarg 1.19 const char **modules;
618 wcc 1.12 int nummods, ctr;
619    
620 stdarg 1.19 nummods = module_list(&modules);
621 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
622 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
623     free(modules);
624 wingman 1.30
625 wcc 1.46 return(BIND_RET_LOG);
626 wcc 1.12 }
627    
628 stdarg 1.26 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
629 wcc 1.24 {
630     if (!text || !*text) {
631 stdarg 1.26 partymember_printf(p, _("Syntax: loadmod <module name>"));
632 wingman 1.30 return BIND_RET_BREAK;
633 wcc 1.24 }
634 stdarg 1.26 switch (module_load(text)) {
635     case 0:
636     partymember_printf(p, _("Module '%s' loaded successfully."), text);
637     break;
638     case -1:
639     partymember_printf(p, _("Module '%s' is already loaded."), text);
640     break;
641     case -2:
642     partymember_printf(p, _("Module '%s' could not be loaded."), text);
643     break;
644     case -3:
645     partymember_printf(p, _("Module '%s' does not have a valid initialization function. Perhaps it is not an eggdrop module?"), text);
646     break;
647     }
648 wcc 1.46 return(BIND_RET_LOG);
649 stdarg 1.26 }
650 wcc 1.24
651 stdarg 1.26 static int party_unloadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
652     {
653     if (!text || !*text) {
654     partymember_printf(p, _("Syntax: unloadmod <module name>"));
655 wingman 1.30 return BIND_RET_BREAK;
656 wcc 1.24 }
657 wingman 1.34 switch (module_unload(text, MODULE_USER)) {
658 stdarg 1.26 case 0:
659     partymember_printf(p, _("Module '%s' unloaded successfully."), text);
660     break;
661     case -1:
662     partymember_printf(p, _("Module '%s' is not loaded."), text);
663     break;
664     case -2:
665     partymember_printf(p, _("Module '%s' has dependencies that are still loaded. You must unload them first."), text);
666     break;
667     case -3:
668     partymember_printf(p, _("Module '%s' refuses to be unloaded by you!"), text);
669     break;
670     }
671 wcc 1.46 return(BIND_RET_LOG);
672 wcc 1.24 }
673    
674 wingman 1.32 static int party_binds(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
675     {
676     bind_table_t *table;
677     bind_entry_t *entry;
678     char flags[64];
679    
680 stdarg 1.49 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %s", _("TABLE"), _("SYNTAX"),
681     _("FUNCTION"), _("MASK"), _("FLAGS"), _("HITS"));
682 wingman 1.32 for (table = bind_table_list(); table; table = table->next) {
683     for (entry = table->entries; entry; entry = entry->next) {
684     flag_to_str(&entry->user_flags, flags);
685 stdarg 1.49 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %d", table->name, table->syntax,
686     entry->function_name, entry->mask, flags, entry->nhits);
687 wingman 1.32 }
688     }
689    
690 wcc 1.46 return(BIND_RET_LOG);
691 wingman 1.32 }
692    
693 stdarg 1.43 static int party_timers(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
694     {
695     egg_timer_t *timer;
696     int remain, now;
697    
698     now = timer_get_now_sec(NULL);
699     partymember_printf(p, "ID SEC LEFT NAME");
700     for (timer = timer_list(); timer; timer = timer->next) {
701     remain = timer->trigger_time.sec - now;
702     partymember_printf(p, "%-5d %-8d %s", timer->id, remain, timer->name);
703     }
704     return(BIND_RET_LOG);
705     }
706    
707 stdarg 1.44 static int print_net(partymember_t *p, const char *header, int flags)
708     {
709     int *idx, len;
710     int i, port, peer_port;
711     const char *host, *peer_host;
712     char *self_addr, *peer_addr;
713     sockbuf_handler_t *handler;
714    
715     sockbuf_list(&idx, &len, flags);
716     partymember_printf(p, "%s", header);
717     partymember_printf(p, " %3s %20s %20s %s", _("Idx"), _("Local Address"), _("Foreign Address"), _("Description"));
718     for (i = 0; i < len; i++) {
719     sockbuf_get_self(idx[i], &host, &port);
720     sockbuf_get_peer(idx[i], &peer_host, &peer_port);
721     if (!host) host = "*";
722     if (!peer_host) peer_host = "*";
723     sockbuf_get_handler(idx[i], &handler, NULL);
724     if (port) self_addr = egg_mprintf("%s/%d", host, port);
725     else self_addr = egg_mprintf("%s/*", host);
726     if (peer_port) peer_addr = egg_mprintf("%s/%d", peer_host, peer_port);
727     else peer_addr = egg_mprintf("%s/*", peer_host);
728     partymember_printf(p, " %3d %20s %20s %s", idx[i], self_addr, peer_addr, handler->name);
729     free(self_addr);
730     free(peer_addr);
731     }
732     free(idx);
733     return(0);
734     }
735    
736     static int party_netstats(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
737     {
738     print_net(p, "Server Sockets", SOCKBUF_SERVER);
739     print_net(p, "Incoming Connections", SOCKBUF_INBOUND);
740     print_net(p, "Outgoing Connections", SOCKBUF_CLIENT);
741     return(0);
742     }
743    
744 wingman 1.33 static int party_restart(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
745     {
746     core_restart (nick);
747 darko 1.37
748 wcc 1.46 return(BIND_RET_LOG);
749 wingman 1.33 }
750    
751 darko 1.36 /* Syntax: chhandle <old_handle> <new_handle> */
752     static int party_chhandle(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
753     {
754 sven 1.51 const char *error;
755 stdarg 1.40 char *old = NULL, *newh = NULL;
756 darko 1.36 user_t *dest;
757    
758 stdarg 1.40 egg_get_args(text, NULL, &old, &newh, NULL);
759     if (!old || !newh || !*old || !*newh) {
760     if (old) free(old);
761     if (newh) free(newh);
762 darko 1.36 partymember_printf(p, _("Syntax: chhandle <old_handle> <new_handle>"));
763 sven 1.50 return 0;
764 darko 1.36 }
765    
766     dest = user_lookup_by_handle(old);
767     if (!dest) {
768 sven 1.50 partymember_printf(p, _("Error: User '%s' does not exist."), old);
769 stdarg 1.40 free(old);
770     free(newh);
771 sven 1.50 return 0;
772 darko 1.36 }
773    
774 sven 1.51 error = user_invalid_handle(newh);
775     if (error) {
776     partymember_printf(p, _("Error: %s"), error);
777 stdarg 1.40 free(old);
778     free(newh);
779     return 0;
780 darko 1.36 }
781    
782 stdarg 1.40 if (!user_change_handle(dest, newh))
783 darko 1.36 partymember_printf(p, _("Ok, changed."));
784 darko 1.39
785 stdarg 1.40 free(newh);
786 darko 1.39 free(old);
787    
788 wcc 1.46 return(BIND_RET_LOG);
789 darko 1.36 }
790    
791 darko 1.39 /* Syntax: chpass <handle> [new_pass] */
792 darko 1.37 static int party_chpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
793     {
794     char *user = NULL, *pass = NULL;
795     user_t *dest;
796    
797     egg_get_args(text, NULL, &user, &pass, NULL);
798    
799 darko 1.38 if (!user || !*user) {
800     partymember_printf(p, _("Syntax: chpass <handle> [pass]"));
801 darko 1.39 goto chpassend;
802 darko 1.37 }
803    
804     dest = user_lookup_by_handle(user);
805     if (!dest) {
806     partymember_printf(p, _("Error: User '%s' does not exist."), user);
807 darko 1.39 goto chpassend;
808 darko 1.37 }
809    
810 darko 1.38 if (pass && *pass && strlen(pass) < 6) {
811 darko 1.37 partymember_printf(p, _("Error: Please use at least 6 characters."));
812 darko 1.39 goto chpassend;
813 darko 1.37 }
814    
815 darko 1.38 if (user_set_pass(dest, pass))
816     partymember_printf(p, _("Removed password for %s."), user);
817     else
818     partymember_printf(p, _("Password for %s is now '%s'."), user, pass);
819 darko 1.39
820     chpassend:
821     free(user);
822     free(pass);
823    
824 lordares 1.47 return(BIND_RET_LOG_COMMAND);
825 darko 1.39 }
826    
827     /* Makes sure 'start' and 'limit' arguments for .match are reasonable, or else sets them -1 */
828     static int party_match_getbounds(const char *strstart, const char *strlimit, long *start, long *limit)
829     {
830     char *tmpptr;
831    
832     if (strstart) {
833     *start = strtol(strstart, &tmpptr, 10);
834     if (!*strstart || *tmpptr || *start < 1) { /* Invalid input*/
835     *start = -1;
836     return 0;
837     }
838    
839     if (strlimit) { /* 'start' was really a start and this is now 'limit' */
840     *limit = strtol(strlimit, &tmpptr, 10);
841     if (!*strlimit || *tmpptr || *limit < 1) { /* Invalid input*/
842     *limit = -1;
843     return 0;
844     }
845     }
846     else { /* Ah, no, the only argument specified was the 'limit' */
847     *limit = *start;
848     *start = 0;
849     }
850     }
851     else {
852     *limit = 20;
853     *start = 0;
854     }
855    
856     return 0;
857     }
858    
859     /* Handles case where .match was given mask to match against */
860     static int party_matchwild(partymember_t *p, const char *mask, const char *rest)
861     {
862     char *strstart = NULL, *strlimit = NULL;
863     long start, limit;
864    
865     egg_get_args(rest, NULL, &strstart, &strlimit, NULL);
866    
867     party_match_getbounds(strstart, strlimit, &start, &limit);
868     if (start == -1 || limit == -1)
869     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
870     else
871     partyline_cmd_match_ircmask(p, mask, start, limit);
872    
873     free(strstart);
874     free(strlimit);
875    
876 darko 1.37 return 0;
877     }
878    
879 darko 1.39 /* Handles case where .match was given attributes to match against */
880     static int party_matchattr(partymember_t *p, const char *mask, const char *rest)
881     {
882     char *channel = NULL, *strstart = NULL, *strlimit = NULL;
883     long start, limit;
884     int ischan = 0;
885    
886     egg_get_args(rest, NULL, &channel, &strstart, &strlimit, NULL);
887    
888     /* This is probably the easiest way to conclude if content of 'channel'
889     is *NOT* a number, and thus it is a candidate for a valid channel name */
890     if (channel && (*channel < '0' || *channel > '9'))
891     ischan = 1;
892    
893    
894     if (strlimit) /* .match <flags> <channel> <start> <limit> */
895     party_match_getbounds(strstart, strlimit, &start, &limit);
896     else if (strstart) /* .match <flags> <channel|start> <limit> */
897     party_match_getbounds(ischan?strstart:channel, ischan?NULL:strstart, &start, &limit);
898     else if (ischan) { /* .match <flags> <channel> */
899     start = 0;
900     limit = 20;
901     }
902     else /* .match <flags> [limit] */
903     party_match_getbounds(channel, NULL, &start, &limit);
904    
905     free(strstart);
906     free(strlimit);
907    
908     if (start == -1 || limit == -1)
909     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
910     else
911     partyline_cmd_match_attr(p, mask, ischan?channel:NULL, start, limit);
912    
913     free(channel);
914    
915     return 0;
916     }
917    
918     /* match <attr> [channel] [[start] limit] */
919     /* match <mask> [[start] limit] */
920     static int party_match(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
921     {
922    
923     char *attr = NULL;
924     const char *rest = NULL;
925    
926     /* FIXME - Check if user is allowed to see results.. if !chan && !glob_master && -> error
927     I have left it available to everyone because 'whois' was that way too.
928     We should update both or neither */
929    
930     egg_get_args(text, &rest, &attr, NULL);
931    
932     if (!attr) {
933     partymember_printf(p, _("Syntax: match <attr> [channel] [[start] limit]"));
934     partymember_printf(p, _(" or: match <mask> [[start] limit]"));
935     free(attr);
936     return 0;
937     }
938    
939     if (*attr == '+' || *attr == '-' || *attr == '|')
940     party_matchattr(p, attr, rest);
941     else if (*attr != '&')
942     party_matchwild(p, attr, rest);
943    
944     free(attr);
945    
946 wcc 1.46 return(BIND_RET_LOG);
947 darko 1.39 }
948    
949     static bind_list_t core_party_binds[] = { /* Old flags requirement */
950 stdarg 1.41 {NULL, "help", party_help},
951 wingman 1.29 {NULL, "join", party_join}, /* DDD */
952     {NULL, "whisper", party_whisper}, /* DDD */
953 darko 1.39 {NULL, "newpass", party_newpass}, /* DDC */ /* -|- */
954     {NULL, "help", party_help}, /* DDC */ /* -|- */
955 wingman 1.29 {NULL, "part", party_part}, /* DDD */
956 darko 1.39 {NULL, "quit", party_quit}, /* DDD */ /* -|- */
957 wingman 1.29 {NULL, "who", party_who}, /* DDD */
958 darko 1.39 {NULL, "whois", party_whois}, /* DDC */ /* ot|o */
959     {NULL, "match", party_match}, /* DDC */ /* ot|o */
960 sven 1.52 {NULL, "bots", party_bots}, /* DDD */ /* -|- */
961 darko 1.39 {"n", "addlog", party_addlog}, /* DDD */ /* ot|o */
962 wingman 1.30 {"n", "get", party_get}, /* DDC */
963     {"n", "set", party_set}, /* DDC */
964     {"n", "unset", party_unset}, /* DDC */
965 darko 1.39 {"n", "status", party_status}, /* DDC */ /* m|m */
966     {"n", "save", party_save}, /* DDD */ /* m|m */
967     {"n", "die", party_die}, /* DDD */ /* n|- */
968     {"n", "restart", party_restart}, /* DDD */ /* m|- */
969     {"n", "+user", party_plus_user}, /* DDC */ /* m|- */
970     {"n", "-user", party_minus_user}, /* DDC */ /* m|- */
971 sven 1.53 {"n", "unlink", party_unlink}, /* DDD */ /* t|- */
972 sven 1.52 {"n", "link", party_link}, /* DDD */ /* t|- */
973 darko 1.39 {"n", "chattr", party_chattr}, /* DDC */ /* m|m */
974     {"n", "modules", party_modules}, /* DDD */ /* n|- */
975     {"n", "loadmod", party_loadmod}, /* DDD */ /* n|- */
976     {"n", "unloadmod", party_unloadmod}, /* DDD */ /* n|- */
977     {"n", "binds", party_binds}, /* DDD */ /* m|- */
978 stdarg 1.43 {"n", "timers", party_timers},
979 stdarg 1.44 {"n", "netstats", party_netstats},
980 darko 1.39 {"m", "+host", party_plus_host}, /* DDC */ /* t|m */
981     {"m", "-host", party_minus_host}, /* DDC */ /* -|- */
982     {"t", "chhandle", party_chhandle}, /* DDC */ /* t|- */
983     {"t", "chpass", party_chpass}, /* DDC */ /* t|- */
984 stdarg 1.1 {0}
985     };
986    
987 wingman 1.27 void core_party_init(void)
988 stdarg 1.1 {
989     bind_add_list("party", core_party_binds);
990     }
991 darko 1.39

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23