/[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.29 - (hide annotations) (download) (as text)
Tue Jun 15 19:19:16 2004 UTC (14 years, 10 months ago) by wingman
Branch: MAIN
Changes since 1.28: +24 -24 lines
File MIME type: text/x-chdr
* Added 'DDD' tags to mark stuff for documentation. Example:

	# list of everything which needs to be documented
	grep -nR "DDD" eggdrop1.7/

	# list of all todos
	grep -nR "XXX" eggdrop1.7/

  I'm sure i've missed some binds/commands/vars so if anyone finds more
  - go ahead. After all current stuff is marked we'll (note, that includes
  YOU (whoever reads this! ;-)) begin with eliminating the DDD lines.

  The user who removes most of the DDD lines gets a cold beer ;-)

* Cleaned up and made xml api more consistent

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 wingman 1.29 static const char rcsid[] = "$Id: core_party.c,v 1.28 2004/06/15 11:54:33 wingman 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    
43 wingman 1.27 /* from main.c */
44 wcc 1.14 extern char pid_file[];
45 stdarg 1.1
46 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
47     {
48 wcc 1.12 if (!text || !*text) {
49 wcc 1.16 partymember_printf(p, _("Syntax: join <channel>"));
50 stdarg 1.4 return(0);
51     }
52     partychan_join_name(text, p);
53     return(0);
54     }
55    
56     static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
57     {
58     partychan_t *chan;
59    
60 wcc 1.12 if (!text || !*text) chan = partychan_get_default(p);
61 stdarg 1.4 else chan = partychan_lookup_name(text);
62     partychan_part(chan, p, "parting");
63     return(0);
64     }
65    
66 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
67 stdarg 1.1 {
68 wingman 1.28 if (partyline_terminal_mode && 0 == strcmp (p->nick, PARTY_TERMINAL_NICK)) {
69 wingman 1.27 partymember_printf (p, "You can't leave the partyline in terminal mode.");
70     return -1;
71     }
72    
73 wcc 1.18 partymember_printf(p, "Goodbye!");
74     if (!text || !*text) partymember_delete(p, "Quit");
75 wcc 1.12 else partymember_delete(p, text);
76 stdarg 1.1 return(0);
77     }
78    
79 wcc 1.12 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
80 stdarg 1.1 {
81 stdarg 1.13 char *who;
82     const char *next;
83     partymember_t *dest;
84    
85 stdarg 1.21 egg_get_arg(text, &next, &who);
86 stdarg 1.13 if (!who || !next || !*who || !*next) {
87 wcc 1.16 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
88 stdarg 1.13 goto done;
89     }
90    
91     dest = partymember_lookup_nick(who);
92     if (!dest) {
93 wcc 1.16 partymember_printf(p, _("No such user '%s'."), who);
94 stdarg 1.13 goto done;
95     }
96    
97     partymember_msg(dest, p, next, -1);
98     done:
99     if (who) free(who);
100 stdarg 1.1 return(0);
101     }
102    
103 stdarg 1.22 static void *lookup_setting(partymember_t *p, const char *path)
104 stdarg 1.11 {
105     void *root;
106    
107     root = config_get_root("eggdrop");
108     root = config_exists(root, path, 0, NULL);
109 stdarg 1.22 if (!root) partymember_printf(p, _("That setting does not exist."));
110 stdarg 1.11 return(root);
111     }
112    
113     static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
114     {
115     void *root;
116     char *str = NULL;
117    
118     if (!text || !*text) {
119 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
120 stdarg 1.11 return(0);
121     }
122    
123 stdarg 1.22 root = lookup_setting(p, text);
124 stdarg 1.11 if (!root) return(0);
125    
126     config_get_str(&str, root, NULL);
127 wcc 1.24 if (str) partymember_printf(p, "Current value: '%s'", str);
128     else partymember_printf(p, _("Current value: null (unset)"));
129 stdarg 1.11 return(0);
130     }
131    
132 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
133 stdarg 1.2 {
134 stdarg 1.11 void *root;
135     char *path, *str;
136     const char *next;
137    
138 stdarg 1.21 egg_get_arg(text, &next, &path);
139 stdarg 1.22 if (!path) {
140     partymember_printf(p, _("Syntax: set <path> [new value]"));
141 stdarg 1.11 return(0);
142     }
143 stdarg 1.22 if (!next) {
144     free(path);
145     return party_get(p, nick, u, cmd, text);
146     }
147 wcc 1.14
148 stdarg 1.22 root = lookup_setting(p, path);
149 stdarg 1.11 free(path);
150     if (!root) return(0);
151    
152     config_get_str(&str, root, NULL);
153 wcc 1.16 partymember_printf(p, _("Old value: '%s'"), str);
154 stdarg 1.11 config_set_str(next, root, NULL);
155     config_get_str(&str, root, NULL);
156 stdarg 1.20 if (str) partymember_printf(p, _("New value: '%s'"), str);
157     else partymember_printf(p, _("New value: null (unset)"));
158     return(0);
159     }
160    
161     static int party_unset(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
162     {
163     void *root;
164     char *str;
165    
166     if (!text || !*text) {
167     partymember_printf(p, _("Syntax: unset <path>"));
168     return(0);
169     }
170    
171 stdarg 1.22 root = lookup_setting(p, text);
172 stdarg 1.20 if (!root) return(0);
173    
174     config_get_str(&str, root, NULL);
175     if (str) partymember_printf(p, _("Old value: '%s'"), str);
176     else partymember_printf(p, _("Old value: null (unset)"));
177     config_set_str(NULL, root, NULL);
178     config_get_str(&str, root, NULL);
179     if (str) partymember_printf(p, _("New value: '%s'"), str);
180     else partymember_printf(p, _("New value: null (unset)"));
181 wcc 1.14 return(0);
182     }
183    
184     static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
185     {
186     #ifdef HAVE_UNAME
187     struct utsname un;
188     #endif
189    
190 stdarg 1.20 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
191 wcc 1.16 partymember_printf(p, _("Owner: %s"), core_config.owner);
192     if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
193 wcc 1.14 #ifdef HAVE_UNAME
194 stdarg 1.20 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
195 wcc 1.14 #endif
196 wcc 1.24 partymember_printf(p, _("Help path: %s (%d help entries loaded)"), core_config.help_path, help_count());
197 stdarg 1.20 partymember_printf(p, "");
198     check_bind_status(p, text);
199 stdarg 1.2 return(0);
200     }
201    
202 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
203 stdarg 1.2 {
204 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
205 stdarg 1.5 user_save(core_config.userfile);
206 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
207 stdarg 1.2 core_config_save();
208     return(1);
209     }
210    
211 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
212     {
213     if (!text || strlen(text) < 6) {
214 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
215 stdarg 1.5 return(0);
216     }
217     user_set_pass(p->user, text);
218 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
219 stdarg 1.5 return(0);
220     }
221    
222 stdarg 1.7 static int intsorter(const void *left, const void *right)
223     {
224     return(*(int *)left - *(int *)right);
225     }
226    
227     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
228     {
229     partymember_t *who;
230 stdarg 1.20 int *pids, len, i, width = 0;
231 stdarg 1.7
232 wcc 1.16 partymember_printf(p, _("Partyline members:"));
233 stdarg 1.7 partymember_who(&pids, &len);
234     qsort(pids, len, sizeof(int), intsorter);
235 stdarg 1.20 if (len > 0) {
236     i = pids[len-1];
237     if (!i) i++;
238     while (i != 0) {
239     i /= 10;
240     width++;
241     }
242     }
243 stdarg 1.7 for (i = 0; i < len; i++) {
244     who = partymember_lookup_pid(pids[i]);
245 stdarg 1.20 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
246 stdarg 1.7 }
247     free(pids);
248     return(0);
249     }
250    
251 stdarg 1.23 static int party_whois(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
252     {
253     user_t *who;
254     flags_t flags;
255     char *item, *chan, *setting, *value, flagstr[64];
256     const char *next;
257     int i;
258    
259     if (text && *text) who = user_lookup_by_handle(text);
260     else who = u;
261    
262     if (!who) {
263     partymember_printf(p, "No such user.");
264     return(0);
265     }
266    
267     next = core_config.whois_items;
268     while (next && *next) {
269     egg_get_arg(next, &next, &item);
270     if (!strcasecmp(item, "handle")) {
271     partymember_printf(p, "%s: '%s'", item, who->handle);
272     }
273     else if (!strcasecmp(item, "uid")) {
274     partymember_printf(p, "%s: '%d'", item, who->uid);
275     }
276     else if (!strcasecmp(item, "ircmasks")) {
277     partymember_printf(p, "%s:", item);
278     for (i = 0; i < who->nircmasks; i++) {
279     partymember_printf(p, " %d. '%s'", i+1, who->ircmasks[i]);
280     }
281     }
282     else {
283 stdarg 1.25 if ((setting = strchr(item, '.'))) {
284 stdarg 1.23 chan = item;
285     *setting = 0;
286     setting++;
287     }
288     else {
289     chan = NULL;
290     setting = item;
291     }
292     if (!strcasecmp(setting, "flags")) {
293     user_get_flags(who, chan, &flags);
294     flag_to_str(&flags, flagstr);
295     value = flagstr;
296     }
297     else {
298     user_get_setting(who, chan, setting, &value);
299     }
300    
301     if (chan) partymember_printf(p, "%s.%s: %s", chan, setting, value);
302     else partymember_printf(p, "%s: %s", setting, value);
303     }
304     free(item);
305     }
306     return(0);
307     }
308    
309 stdarg 1.7 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
310     {
311 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
312 wcc 1.12 user_save(core_config.userfile);
313 stdarg 1.19 if (text && *text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
314 wcc 1.16 else putlog(LOG_MISC, "*", _("Bot shutting down."));
315 wcc 1.14 flushlogs();
316     unlink(pid_file);
317 stdarg 1.7 exit(0);
318     }
319    
320     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
321     {
322     user_t *newuser;
323    
324     if (!text || !*text) {
325 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
326 stdarg 1.7 return(0);
327     }
328     if (user_lookup_by_handle(text)) {
329 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
330 stdarg 1.7 return(0);
331     }
332     newuser = user_new(text);
333 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
334     else partymember_printf(p, _("Could not create user '%s'."), text);
335 stdarg 1.7 return(0);
336     }
337    
338     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
339     {
340     user_t *who;
341    
342     if (!text || !*text) {
343 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
344 stdarg 1.7 return(0);
345     }
346     who = user_lookup_by_handle(text);
347 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
348 stdarg 1.7 else {
349 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
350 stdarg 1.7 user_delete(who);
351     }
352     return(0);
353     }
354    
355     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
356     {
357 stdarg 1.25 user_t *who;
358     char *target, *newhost;
359    
360     egg_get_args(text, NULL, &target, &newhost, NULL);
361     if (!target) {
362     partymember_printf(p, _("Syntax: +host [handle] <host>"));
363     return(0);
364     }
365     if (!newhost) {
366     newhost = target;
367     target = NULL;
368     }
369     if (target) {
370     who = user_lookup_by_handle(target);
371     if (!who) {
372     partymember_printf(p, _("User '%s' not found."), target);
373     goto done;
374     }
375     }
376     else {
377     who = u;
378     if (!who) {
379     partymember_printf(p, _("Only valid users can add hosts."));
380     goto done;
381     }
382     }
383     user_add_ircmask(who, newhost);
384     partymember_printf(p, _("Added '%1$s' to user '%2$s'."), newhost, who->handle);
385    
386     done:
387     if (target) free(target);
388     free(newhost);
389    
390 stdarg 1.7 return(0);
391     }
392    
393 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
394     {
395 stdarg 1.25 user_t *who;
396     char *target, *host;
397    
398     egg_get_args(text, NULL, &target, &host, NULL);
399     if (!target) {
400     partymember_printf(p, _("Syntax: -host [handle] <host>"));
401     return(0);
402     }
403     if (!host) {
404     host = target;
405     target = NULL;
406     }
407     if (target) {
408     who = user_lookup_by_handle(target);
409     if (!who) {
410     partymember_printf(p, _("User '%s' not found."), target);
411     goto done;
412     }
413     }
414     else {
415     who = u;
416     if (!who) {
417     partymember_printf(p, _("Only valid users can remove hosts."));
418     goto done;
419     }
420     }
421     if (user_del_ircmask(who, host)) {
422     partymember_printf(p, _("Mask '%1$s' not found for user '%2$s'."), host, who->handle);
423     }
424     else {
425     partymember_printf(p, _("Removed '%1$s' from user '%2$s'."), host, who->handle);
426     }
427    
428     done:
429     if (target) free(target);
430     free(host);
431    
432 stdarg 1.9 return(0);
433     }
434    
435 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
436 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
437     {
438     const char *next;
439     char *who, *flags, *chan;
440     user_t *dest;
441     flags_t flagstruct;
442     char flagstr[64];
443     int n;
444    
445 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
446 wcc 1.14 if (!chan || !*chan) {
447 stdarg 1.10 if (who) free(who);
448 wcc 1.24 partymember_printf(p, _("Syntax: chattr <handle> [channel] <+/-flags>"));
449 stdarg 1.9 return(0);
450     }
451 wcc 1.14 if (!flags || !*flags) {
452 stdarg 1.9 flags = chan;
453     chan = NULL;
454     }
455     dest = user_lookup_by_handle(who);
456     if (dest) {
457     user_set_flag_str(dest, chan, flags);
458     user_get_flags(dest, chan, &flagstruct);
459     flag_to_str(&flagstruct, flagstr);
460 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
461 stdarg 1.9 }
462 wcc 1.24 else partymember_printf(p, _("'%s' is not a valid user."), who);
463 stdarg 1.9 free(who);
464     free(flags);
465     if (chan) free(chan);
466     return(0);
467     }
468    
469 stdarg 1.26 static int party_help(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
470     {
471     help_t *h;
472    
473     if (!text || !*text) {
474     partymember_printf(p, _("Syntax: help <section>"));
475     return(0);
476     }
477    
478     h = help_lookup_by_name(text);
479     if (!h) {
480     partymember_printf(p, _("No help found for '%s'."), text);
481     return(0);
482     }
483    
484     help_print_party(p, h);
485     return(0);
486     }
487    
488     static int party_addlog(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
489     {
490     putlog(LOG_MISC, "*", "%s: %s", nick, text);
491     return(0);
492     }
493    
494 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
495     {
496 stdarg 1.19 const char **modules;
497 wcc 1.12 int nummods, ctr;
498    
499 stdarg 1.19 nummods = module_list(&modules);
500 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
501 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
502     free(modules);
503     return(0);
504     }
505    
506 stdarg 1.26 static int party_loadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
507 wcc 1.24 {
508     if (!text || !*text) {
509 stdarg 1.26 partymember_printf(p, _("Syntax: loadmod <module name>"));
510 wcc 1.24 return(0);
511     }
512 stdarg 1.26 switch (module_load(text)) {
513     case 0:
514     partymember_printf(p, _("Module '%s' loaded successfully."), text);
515     break;
516     case -1:
517     partymember_printf(p, _("Module '%s' is already loaded."), text);
518     break;
519     case -2:
520     partymember_printf(p, _("Module '%s' could not be loaded."), text);
521     break;
522     case -3:
523     partymember_printf(p, _("Module '%s' does not have a valid initialization function. Perhaps it is not an eggdrop module?"), text);
524     break;
525     }
526     return(0);
527     }
528 wcc 1.24
529 stdarg 1.26 static int party_unloadmod(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
530     {
531     if (!text || !*text) {
532     partymember_printf(p, _("Syntax: unloadmod <module name>"));
533 wcc 1.24 return(0);
534     }
535 stdarg 1.26 switch (module_unload(text, EGGMOD_USER)) {
536     case 0:
537     partymember_printf(p, _("Module '%s' unloaded successfully."), text);
538     break;
539     case -1:
540     partymember_printf(p, _("Module '%s' is not loaded."), text);
541     break;
542     case -2:
543     partymember_printf(p, _("Module '%s' has dependencies that are still loaded. You must unload them first."), text);
544     break;
545     case -3:
546     partymember_printf(p, _("Module '%s' refuses to be unloaded by you!"), text);
547     break;
548     }
549 wcc 1.24 return(0);
550     }
551    
552 stdarg 1.1 static bind_list_t core_party_binds[] = {
553 wingman 1.29 {NULL, "join", party_join}, /* DDD */
554     {NULL, "whisper", party_whisper}, /* DDD */
555     {NULL, "newpass", party_newpass}, /* DDD */
556     {NULL, "help", party_help}, /* DDD */
557     {NULL, "part", party_part}, /* DDD */
558     {NULL, "quit", party_quit}, /* DDD */
559     {NULL, "who", party_who}, /* DDD */
560     {NULL, "whois", party_whois}, /* DDD */
561     {"n", "addlog", party_addlog}, /* DDD */
562     {"n", "get", party_get}, /* DDD */
563     {"n", "set", party_set}, /* DDD */
564     {"n", "unset", party_unset}, /* DDD */
565     {"n", "status", party_status}, /* DDD */
566     {"n", "save", party_save}, /* DDD */
567     {"n", "die", party_die}, /* DDD */
568     {"n", "+user", party_plus_user}, /* DDD */
569     {"n", "-user", party_minus_user}, /* DDD */
570     {"n", "chattr", party_chattr}, /* DDD */
571     {"n", "modules", party_modules}, /* DDD */
572     {"n", "loadmod", party_loadmod}, /* DDD */
573     {"n", "unloadmod", party_unloadmod}, /* DDD */
574     {"m", "+host", party_plus_host}, /* DDD */
575     {"m", "-host", party_minus_host}, /* DDD */
576 stdarg 1.1 {0}
577     };
578    
579 wingman 1.27 void core_party_init(void)
580 stdarg 1.1 {
581     bind_add_list("party", core_party_binds);
582     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23