/[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.54 - (hide annotations) (download) (as text)
Sat Apr 14 15:21:13 2007 UTC (12 years ago) by sven
Branch: MAIN
Changes since 1.53: +5 -3 lines
File MIME type: text/x-chdr

 * Fixed various compiler warnings about diffent signedness.
 * Added a new bind: bot. Works just like in eggdrop1.6
 * Added a new struct: botnet_entity. This is used in places where a certain
   event might be caused by either a bot or a partyline user.
 * Added backend for botnet broadcasts, botmsgs (zapf) and botbroadcasts
   (zapf-broad).
 * Added oldbotnet support for actchan, zapf and zapf-broad messages.
 * Improved oldbotnet assocs for mapping 1.6 channel numbers to 1.9 channel
   names. Don't send real assoc messages out because the 1.6 assoc module is
   horribly broken.

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23