/[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.55 - (hide annotations) (download) (as text)
Sun Apr 22 13:18:32 2007 UTC (12 years, 2 months ago) by sven
Branch: MAIN
CVS Tags: HEAD
Changes since 1.54: +22 -18 lines
File MIME type: text/x-chdr

 * Complete oldbotnet support expect for (user)file sharing.

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.55 static const char rcsid[] = "$Id: core_party.c,v 1.54 2007-04-14 15:21:13 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 sven 1.55 char *via;
471     const char *target;
472     botnet_bot_t *dst = NULL;
473     botnet_entity_t src = user_entity(p);
474 sven 1.52
475     if (!text || !*text) {
476 sven 1.55 partymember_printf(p, _("Syntax: link <handle> [via-bot]"));
477 sven 1.52 return 0;
478     }
479    
480 sven 1.55 egg_get_arg(text, &target, &via);
481     while (target && isspace(*target)) ++target;
482    
483     if (target && *target) {
484     dst = botnet_lookup(via);
485     if (!dst && strcmp(via, botnet_get_name())) {
486     partymember_printf(p, _("No such bot: %s."), via);
487     free(via);
488     return 0;
489     }
490     free(via);
491     } else {
492     target = text;
493     free(via);
494     }
495     botnet_link(&src, dst, target);
496 sven 1.52
497     return 0;
498     }
499    
500 stdarg 1.7 static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
501     {
502 stdarg 1.25 user_t *who;
503     char *target, *newhost;
504    
505     egg_get_args(text, NULL, &target, &newhost, NULL);
506     if (!target) {
507     partymember_printf(p, _("Syntax: +host [handle] <host>"));
508     return(0);
509     }
510     if (!newhost) {
511     newhost = target;
512     target = NULL;
513     }
514     if (target) {
515     who = user_lookup_by_handle(target);
516     if (!who) {
517     partymember_printf(p, _("User '%s' not found."), target);
518     goto done;
519     }
520     }
521     else {
522     who = u;
523     if (!who) {
524     partymember_printf(p, _("Only valid users can add hosts."));
525     goto done;
526     }
527     }
528     user_add_ircmask(who, newhost);
529     partymember_printf(p, _("Added '%1$s' to user '%2$s'."), newhost, who->handle);
530    
531     done:
532     if (target) free(target);
533     free(newhost);
534    
535 stdarg 1.7 return(0);
536     }
537    
538 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
539     {
540 stdarg 1.25 user_t *who;
541     char *target, *host;
542    
543     egg_get_args(text, NULL, &target, &host, NULL);
544     if (!target) {
545     partymember_printf(p, _("Syntax: -host [handle] <host>"));
546     return(0);
547     }
548     if (!host) {
549     host = target;
550     target = NULL;
551     }
552     if (target) {
553     who = user_lookup_by_handle(target);
554     if (!who) {
555     partymember_printf(p, _("User '%s' not found."), target);
556     goto done;
557     }
558     }
559     else {
560     who = u;
561     if (!who) {
562     partymember_printf(p, _("Only valid users can remove hosts."));
563     goto done;
564     }
565     }
566     if (user_del_ircmask(who, host)) {
567     partymember_printf(p, _("Mask '%1$s' not found for user '%2$s'."), host, who->handle);
568     }
569     else {
570     partymember_printf(p, _("Removed '%1$s' from user '%2$s'."), host, who->handle);
571     }
572    
573     done:
574     if (target) free(target);
575     free(host);
576    
577 stdarg 1.9 return(0);
578     }
579    
580 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
581 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
582     {
583     const char *next;
584     char *who, *flags, *chan;
585     user_t *dest;
586     flags_t flagstruct;
587     char flagstr[64];
588     int n;
589    
590 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
591 wcc 1.14 if (!chan || !*chan) {
592 stdarg 1.10 if (who) free(who);
593 wcc 1.24 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
594 stdarg 1.9 return(0);
595     }
596 wcc 1.14 if (!flags || !*flags) {
597 stdarg 1.9 flags = chan;
598     chan = NULL;
599     }
600     dest = user_lookup_by_handle(who);
601     if (dest) {
602 wingman 1.30 user_set_flags_str(dest, chan, flags);
603 stdarg 1.9 user_get_flags(dest, chan, &flagstruct);
604     flag_to_str(&flagstruct, flagstr);
605 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
606 stdarg 1.9 }
607 wcc 1.24 else partymember_printf(p, _("'%s' is not a valid user."), who);
608 stdarg 1.9 free(who);
609     free(flags);
610     if (chan) free(chan);
611     return(0);
612     }
613    
614 stdarg 1.26 static int party_addlog(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
615     {
616     putlog(LOG_MISC, "*", "%s: %s", nick, text);
617 wingman 1.30
618 wcc 1.46 return(BIND_RET_LOG);
619 stdarg 1.26 }
620    
621 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
622     {
623 stdarg 1.19 const char **modules;
624 wcc 1.12 int nummods, ctr;
625    
626 stdarg 1.19 nummods = module_list(&modules);
627 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
628 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
629     free(modules);
630 wingman 1.30
631 wcc 1.46 return(BIND_RET_LOG);
632 wcc 1.12 }
633    
634 stdarg 1.26 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
635 wcc 1.24 {
636     if (!text || !*text) {
637 stdarg 1.26 partymember_printf(p, _("Syntax: loadmod <module name>"));
638 wingman 1.30 return BIND_RET_BREAK;
639 wcc 1.24 }
640 stdarg 1.26 switch (module_load(text)) {
641     case 0:
642     partymember_printf(p, _("Module '%s' loaded successfully."), text);
643     break;
644     case -1:
645     partymember_printf(p, _("Module '%s' is already loaded."), text);
646     break;
647     case -2:
648     partymember_printf(p, _("Module '%s' could not be loaded."), text);
649     break;
650     case -3:
651     partymember_printf(p, _("Module '%s' does not have a valid initialization function. Perhaps it is not an eggdrop module?"), text);
652     break;
653     }
654 wcc 1.46 return(BIND_RET_LOG);
655 stdarg 1.26 }
656 wcc 1.24
657 stdarg 1.26 static int party_unloadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
658     {
659     if (!text || !*text) {
660     partymember_printf(p, _("Syntax: unloadmod <module name>"));
661 wingman 1.30 return BIND_RET_BREAK;
662 wcc 1.24 }
663 wingman 1.34 switch (module_unload(text, MODULE_USER)) {
664 stdarg 1.26 case 0:
665     partymember_printf(p, _("Module '%s' unloaded successfully."), text);
666     break;
667     case -1:
668     partymember_printf(p, _("Module '%s' is not loaded."), text);
669     break;
670     case -2:
671     partymember_printf(p, _("Module '%s' has dependencies that are still loaded. You must unload them first."), text);
672     break;
673     case -3:
674     partymember_printf(p, _("Module '%s' refuses to be unloaded by you!"), text);
675     break;
676     }
677 wcc 1.46 return(BIND_RET_LOG);
678 wcc 1.24 }
679    
680 wingman 1.32 static int party_binds(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
681     {
682     bind_table_t *table;
683     bind_entry_t *entry;
684     char flags[64];
685    
686 stdarg 1.49 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %s", _("TABLE"), _("SYNTAX"),
687     _("FUNCTION"), _("MASK"), _("FLAGS"), _("HITS"));
688 wingman 1.32 for (table = bind_table_list(); table; table = table->next) {
689     for (entry = table->entries; entry; entry = entry->next) {
690     flag_to_str(&entry->user_flags, flags);
691 stdarg 1.49 partymember_printf(p, "%-16s %-16s %-16s %-10s %-5s %d", table->name, table->syntax,
692     entry->function_name, entry->mask, flags, entry->nhits);
693 wingman 1.32 }
694     }
695    
696 wcc 1.46 return(BIND_RET_LOG);
697 wingman 1.32 }
698    
699 stdarg 1.43 static int party_timers(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
700     {
701     egg_timer_t *timer;
702     int remain, now;
703    
704     now = timer_get_now_sec(NULL);
705     partymember_printf(p, "ID SEC LEFT NAME");
706     for (timer = timer_list(); timer; timer = timer->next) {
707     remain = timer->trigger_time.sec - now;
708     partymember_printf(p, "%-5d %-8d %s", timer->id, remain, timer->name);
709     }
710     return(BIND_RET_LOG);
711     }
712    
713 stdarg 1.44 static int print_net(partymember_t *p, const char *header, int flags)
714     {
715     int *idx, len;
716     int i, port, peer_port;
717     const char *host, *peer_host;
718     char *self_addr, *peer_addr;
719     sockbuf_handler_t *handler;
720    
721     sockbuf_list(&idx, &len, flags);
722     partymember_printf(p, "%s", header);
723     partymember_printf(p, " %3s %20s %20s %s", _("Idx"), _("Local Address"), _("Foreign Address"), _("Description"));
724     for (i = 0; i < len; i++) {
725     sockbuf_get_self(idx[i], &host, &port);
726     sockbuf_get_peer(idx[i], &peer_host, &peer_port);
727     if (!host) host = "*";
728     if (!peer_host) peer_host = "*";
729     sockbuf_get_handler(idx[i], &handler, NULL);
730     if (port) self_addr = egg_mprintf("%s/%d", host, port);
731     else self_addr = egg_mprintf("%s/*", host);
732     if (peer_port) peer_addr = egg_mprintf("%s/%d", peer_host, peer_port);
733     else peer_addr = egg_mprintf("%s/*", peer_host);
734     partymember_printf(p, " %3d %20s %20s %s", idx[i], self_addr, peer_addr, handler->name);
735     free(self_addr);
736     free(peer_addr);
737     }
738     free(idx);
739     return(0);
740     }
741    
742     static int party_netstats(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
743     {
744     print_net(p, "Server Sockets", SOCKBUF_SERVER);
745     print_net(p, "Incoming Connections", SOCKBUF_INBOUND);
746     print_net(p, "Outgoing Connections", SOCKBUF_CLIENT);
747     return(0);
748     }
749    
750 wingman 1.33 static int party_restart(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
751     {
752     core_restart (nick);
753 darko 1.37
754 wcc 1.46 return(BIND_RET_LOG);
755 wingman 1.33 }
756    
757 darko 1.36 /* Syntax: chhandle <old_handle> <new_handle> */
758     static int party_chhandle(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
759     {
760 sven 1.51 const char *error;
761 stdarg 1.40 char *old = NULL, *newh = NULL;
762 darko 1.36 user_t *dest;
763    
764 stdarg 1.40 egg_get_args(text, NULL, &old, &newh, NULL);
765     if (!old || !newh || !*old || !*newh) {
766     if (old) free(old);
767     if (newh) free(newh);
768 darko 1.36 partymember_printf(p, _("Syntax: chhandle <old_handle> <new_handle>"));
769 sven 1.50 return 0;
770 darko 1.36 }
771    
772     dest = user_lookup_by_handle(old);
773     if (!dest) {
774 sven 1.50 partymember_printf(p, _("Error: User '%s' does not exist."), old);
775 stdarg 1.40 free(old);
776     free(newh);
777 sven 1.50 return 0;
778 darko 1.36 }
779    
780 sven 1.51 error = user_invalid_handle(newh);
781     if (error) {
782     partymember_printf(p, _("Error: %s"), error);
783 stdarg 1.40 free(old);
784     free(newh);
785     return 0;
786 darko 1.36 }
787    
788 stdarg 1.40 if (!user_change_handle(dest, newh))
789 darko 1.36 partymember_printf(p, _("Ok, changed."));
790 darko 1.39
791 stdarg 1.40 free(newh);
792 darko 1.39 free(old);
793    
794 wcc 1.46 return(BIND_RET_LOG);
795 darko 1.36 }
796    
797 darko 1.39 /* Syntax: chpass <handle> [new_pass] */
798 darko 1.37 static int party_chpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
799     {
800     char *user = NULL, *pass = NULL;
801     user_t *dest;
802    
803     egg_get_args(text, NULL, &user, &pass, NULL);
804    
805 darko 1.38 if (!user || !*user) {
806     partymember_printf(p, _("Syntax: chpass <handle> [pass]"));
807 darko 1.39 goto chpassend;
808 darko 1.37 }
809    
810     dest = user_lookup_by_handle(user);
811     if (!dest) {
812     partymember_printf(p, _("Error: User '%s' does not exist."), user);
813 darko 1.39 goto chpassend;
814 darko 1.37 }
815    
816 darko 1.38 if (pass && *pass && strlen(pass) < 6) {
817 darko 1.37 partymember_printf(p, _("Error: Please use at least 6 characters."));
818 darko 1.39 goto chpassend;
819 darko 1.37 }
820    
821 darko 1.38 if (user_set_pass(dest, pass))
822     partymember_printf(p, _("Removed password for %s."), user);
823     else
824     partymember_printf(p, _("Password for %s is now '%s'."), user, pass);
825 darko 1.39
826     chpassend:
827     free(user);
828     free(pass);
829    
830 lordares 1.47 return(BIND_RET_LOG_COMMAND);
831 darko 1.39 }
832    
833     /* Makes sure 'start' and 'limit' arguments for .match are reasonable, or else sets them -1 */
834     static int party_match_getbounds(const char *strstart, const char *strlimit, long *start, long *limit)
835     {
836     char *tmpptr;
837    
838     if (strstart) {
839     *start = strtol(strstart, &tmpptr, 10);
840     if (!*strstart || *tmpptr || *start < 1) { /* Invalid input*/
841     *start = -1;
842     return 0;
843     }
844    
845     if (strlimit) { /* 'start' was really a start and this is now 'limit' */
846     *limit = strtol(strlimit, &tmpptr, 10);
847     if (!*strlimit || *tmpptr || *limit < 1) { /* Invalid input*/
848     *limit = -1;
849     return 0;
850     }
851     }
852     else { /* Ah, no, the only argument specified was the 'limit' */
853     *limit = *start;
854     *start = 0;
855     }
856     }
857     else {
858     *limit = 20;
859     *start = 0;
860     }
861    
862     return 0;
863     }
864    
865     /* Handles case where .match was given mask to match against */
866     static int party_matchwild(partymember_t *p, const char *mask, const char *rest)
867     {
868     char *strstart = NULL, *strlimit = NULL;
869     long start, limit;
870    
871     egg_get_args(rest, NULL, &strstart, &strlimit, NULL);
872    
873     party_match_getbounds(strstart, strlimit, &start, &limit);
874     if (start == -1 || limit == -1)
875     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
876     else
877     partyline_cmd_match_ircmask(p, mask, start, limit);
878    
879     free(strstart);
880     free(strlimit);
881    
882 darko 1.37 return 0;
883     }
884    
885 darko 1.39 /* Handles case where .match was given attributes to match against */
886     static int party_matchattr(partymember_t *p, const char *mask, const char *rest)
887     {
888     char *channel = NULL, *strstart = NULL, *strlimit = NULL;
889     long start, limit;
890     int ischan = 0;
891    
892     egg_get_args(rest, NULL, &channel, &strstart, &strlimit, NULL);
893    
894     /* This is probably the easiest way to conclude if content of 'channel'
895     is *NOT* a number, and thus it is a candidate for a valid channel name */
896     if (channel && (*channel < '0' || *channel > '9'))
897     ischan = 1;
898    
899    
900     if (strlimit) /* .match <flags> <channel> <start> <limit> */
901     party_match_getbounds(strstart, strlimit, &start, &limit);
902     else if (strstart) /* .match <flags> <channel|start> <limit> */
903     party_match_getbounds(ischan?strstart:channel, ischan?NULL:strstart, &start, &limit);
904     else if (ischan) { /* .match <flags> <channel> */
905     start = 0;
906     limit = 20;
907     }
908     else /* .match <flags> [limit] */
909     party_match_getbounds(channel, NULL, &start, &limit);
910    
911     free(strstart);
912     free(strlimit);
913    
914     if (start == -1 || limit == -1)
915     partymember_printf(p, _("Error: 'start' and 'limit' must be positive integers"));
916     else
917     partyline_cmd_match_attr(p, mask, ischan?channel:NULL, start, limit);
918    
919     free(channel);
920    
921     return 0;
922     }
923    
924     /* match <attr> [channel] [[start] limit] */
925     /* match <mask> [[start] limit] */
926     static int party_match(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
927     {
928    
929     char *attr = NULL;
930     const char *rest = NULL;
931    
932     /* FIXME - Check if user is allowed to see results.. if !chan && !glob_master && -> error
933     I have left it available to everyone because 'whois' was that way too.
934     We should update both or neither */
935    
936     egg_get_args(text, &rest, &attr, NULL);
937    
938     if (!attr) {
939     partymember_printf(p, _("Syntax: match <attr> [channel] [[start] limit]"));
940     partymember_printf(p, _(" or: match <mask> [[start] limit]"));
941     free(attr);
942     return 0;
943     }
944    
945     if (*attr == '+' || *attr == '-' || *attr == '|')
946     party_matchattr(p, attr, rest);
947     else if (*attr != '&')
948     party_matchwild(p, attr, rest);
949    
950     free(attr);
951    
952 wcc 1.46 return(BIND_RET_LOG);
953 darko 1.39 }
954    
955     static bind_list_t core_party_binds[] = { /* Old flags requirement */
956 stdarg 1.41 {NULL, "help", party_help},
957 wingman 1.29 {NULL, "join", party_join}, /* DDD */
958     {NULL, "whisper", party_whisper}, /* DDD */
959 darko 1.39 {NULL, "newpass", party_newpass}, /* DDC */ /* -|- */
960     {NULL, "help", party_help}, /* DDC */ /* -|- */
961 wingman 1.29 {NULL, "part", party_part}, /* DDD */
962 darko 1.39 {NULL, "quit", party_quit}, /* DDD */ /* -|- */
963 wingman 1.29 {NULL, "who", party_who}, /* DDD */
964 darko 1.39 {NULL, "whois", party_whois}, /* DDC */ /* ot|o */
965     {NULL, "match", party_match}, /* DDC */ /* ot|o */
966 sven 1.52 {NULL, "bots", party_bots}, /* DDD */ /* -|- */
967 darko 1.39 {"n", "addlog", party_addlog}, /* DDD */ /* ot|o */
968 wingman 1.30 {"n", "get", party_get}, /* DDC */
969     {"n", "set", party_set}, /* DDC */
970     {"n", "unset", party_unset}, /* DDC */
971 darko 1.39 {"n", "status", party_status}, /* DDC */ /* m|m */
972     {"n", "save", party_save}, /* DDD */ /* m|m */
973     {"n", "die", party_die}, /* DDD */ /* n|- */
974     {"n", "restart", party_restart}, /* DDD */ /* m|- */
975     {"n", "+user", party_plus_user}, /* DDC */ /* m|- */
976     {"n", "-user", party_minus_user}, /* DDC */ /* m|- */
977 sven 1.53 {"n", "unlink", party_unlink}, /* DDD */ /* t|- */
978 sven 1.52 {"n", "link", party_link}, /* DDD */ /* t|- */
979 darko 1.39 {"n", "chattr", party_chattr}, /* DDC */ /* m|m */
980     {"n", "modules", party_modules}, /* DDD */ /* n|- */
981     {"n", "loadmod", party_loadmod}, /* DDD */ /* n|- */
982     {"n", "unloadmod", party_unloadmod}, /* DDD */ /* n|- */
983     {"n", "binds", party_binds}, /* DDD */ /* m|- */
984 stdarg 1.43 {"n", "timers", party_timers},
985 stdarg 1.44 {"n", "netstats", party_netstats},
986 darko 1.39 {"m", "+host", party_plus_host}, /* DDC */ /* t|m */
987     {"m", "-host", party_minus_host}, /* DDC */ /* -|- */
988     {"t", "chhandle", party_chhandle}, /* DDC */ /* t|- */
989     {"t", "chpass", party_chpass}, /* DDC */ /* t|- */
990 stdarg 1.1 {0}
991     };
992    
993 wingman 1.27 void core_party_init(void)
994 stdarg 1.1 {
995     bind_add_list("party", core_party_binds);
996     }
997 darko 1.39

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23