/[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.41 - (hide annotations) (download) (as text)
Wed Sep 29 15:38:39 2004 UTC (14 years, 6 months ago) by stdarg
Branch: MAIN
Changes since 1.40: +31 -8 lines
File MIME type: text/x-chdr
*** empty log message ***

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23