/[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.23 - (hide annotations) (download) (as text)
Sun Jan 11 12:02:38 2004 UTC (15 years, 3 months ago) by stdarg
Branch: MAIN
Changes since 1.22: +60 -2 lines
File MIME type: text/x-chdr
* Initial .whois command with whois_items variable to control displayed fields

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.23 static const char rcsid[] = "$Id: core_party.c,v 1.22 2004/01/10 01:43:18 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 <eggdrop/eggdrop.h>
29     #include <ctype.h>
30     #include <unistd.h>
31 wcc 1.17 #include <string.h>
32     #include <stdlib.h>
33 wcc 1.15 #include "core_config.h"
34 stdarg 1.20 #include "core_binds.h"
35 wcc 1.15 #include "logfile.h"
36    
37 wcc 1.14 #ifdef HAVE_UNAME
38     # include <sys/utsname.h>
39     #endif
40    
41     extern char pid_file[];
42 stdarg 1.1
43 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
44     {
45 wcc 1.12 if (!text || !*text) {
46 wcc 1.16 partymember_printf(p, _("Syntax: join <channel>"));
47 stdarg 1.4 return(0);
48     }
49     partychan_join_name(text, p);
50     return(0);
51     }
52    
53     static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
54     {
55     partychan_t *chan;
56    
57 wcc 1.12 if (!text || !*text) chan = partychan_get_default(p);
58 stdarg 1.4 else chan = partychan_lookup_name(text);
59     partychan_part(chan, p, "parting");
60     return(0);
61     }
62    
63 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
64 stdarg 1.1 {
65 wcc 1.18 partymember_printf(p, "Goodbye!");
66     if (!text || !*text) partymember_delete(p, "Quit");
67 wcc 1.12 else partymember_delete(p, text);
68 stdarg 1.1 return(0);
69     }
70    
71 wcc 1.12 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
72 stdarg 1.1 {
73 stdarg 1.13 char *who;
74     const char *next;
75     partymember_t *dest;
76    
77 stdarg 1.21 egg_get_arg(text, &next, &who);
78 stdarg 1.13 if (!who || !next || !*who || !*next) {
79 wcc 1.16 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
80 stdarg 1.13 goto done;
81     }
82    
83     dest = partymember_lookup_nick(who);
84     if (!dest) {
85 wcc 1.16 partymember_printf(p, _("No such user '%s'."), who);
86 stdarg 1.13 goto done;
87     }
88    
89     partymember_msg(dest, p, next, -1);
90     done:
91     if (who) free(who);
92 stdarg 1.1 return(0);
93     }
94    
95 stdarg 1.22 static void *lookup_setting(partymember_t *p, const char *path)
96 stdarg 1.11 {
97     void *root;
98    
99     root = config_get_root("eggdrop");
100     root = config_exists(root, path, 0, NULL);
101 stdarg 1.22 if (!root) partymember_printf(p, _("That setting does not exist."));
102 stdarg 1.11 return(root);
103     }
104    
105     static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
106     {
107     void *root;
108     char *str = NULL;
109    
110     if (!text || !*text) {
111 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
112 stdarg 1.11 return(0);
113     }
114    
115 stdarg 1.22 root = lookup_setting(p, text);
116 stdarg 1.11 if (!root) return(0);
117    
118     config_get_str(&str, root, NULL);
119     if (str) {
120 stdarg 1.22 partymember_printf(p, "Current value: '%s'", str);
121 stdarg 1.11 }
122     else {
123 stdarg 1.22 partymember_printf(p, _("Current value: null (unset)"));
124 stdarg 1.11 }
125     return(0);
126     }
127    
128 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
129 stdarg 1.2 {
130 stdarg 1.11 void *root;
131     char *path, *str;
132     const char *next;
133    
134 stdarg 1.21 egg_get_arg(text, &next, &path);
135 stdarg 1.22 if (!path) {
136     partymember_printf(p, _("Syntax: set <path> [new value]"));
137 stdarg 1.11 return(0);
138     }
139 stdarg 1.22 if (!next) {
140     free(path);
141     return party_get(p, nick, u, cmd, text);
142     }
143 wcc 1.14
144 stdarg 1.22 root = lookup_setting(p, path);
145 stdarg 1.11 free(path);
146     if (!root) return(0);
147    
148     config_get_str(&str, root, NULL);
149 wcc 1.16 partymember_printf(p, _("Old value: '%s'"), str);
150 stdarg 1.11 config_set_str(next, root, NULL);
151     config_get_str(&str, root, NULL);
152 stdarg 1.20 if (str) partymember_printf(p, _("New value: '%s'"), str);
153     else partymember_printf(p, _("New value: null (unset)"));
154     return(0);
155     }
156    
157     static int party_unset(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
158     {
159     void *root;
160     char *str;
161    
162     if (!text || !*text) {
163     partymember_printf(p, _("Syntax: unset <path>"));
164     return(0);
165     }
166    
167 stdarg 1.22 root = lookup_setting(p, text);
168 stdarg 1.20 if (!root) return(0);
169    
170     config_get_str(&str, root, NULL);
171     if (str) partymember_printf(p, _("Old value: '%s'"), str);
172     else partymember_printf(p, _("Old value: null (unset)"));
173     config_set_str(NULL, root, NULL);
174     config_get_str(&str, root, NULL);
175     if (str) partymember_printf(p, _("New value: '%s'"), str);
176     else partymember_printf(p, _("New value: null (unset)"));
177 wcc 1.14 return(0);
178     }
179    
180     static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
181     {
182     #ifdef HAVE_UNAME
183     struct utsname un;
184     #endif
185    
186 stdarg 1.20 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
187 wcc 1.16 partymember_printf(p, _("Owner: %s"), core_config.owner);
188     if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
189 wcc 1.14 #ifdef HAVE_UNAME
190 stdarg 1.20 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
191 wcc 1.14 #endif
192 stdarg 1.20 partymember_printf(p, "");
193     check_bind_status(p, text);
194 stdarg 1.2 return(0);
195     }
196    
197 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
198 stdarg 1.2 {
199 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
200 stdarg 1.5 user_save(core_config.userfile);
201 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
202 stdarg 1.2 core_config_save();
203     return(1);
204     }
205    
206 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
207     {
208     if (!text || strlen(text) < 6) {
209 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
210 stdarg 1.5 return(0);
211     }
212     user_set_pass(p->user, text);
213 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
214 stdarg 1.5 return(0);
215     }
216    
217 stdarg 1.7 static int intsorter(const void *left, const void *right)
218     {
219     return(*(int *)left - *(int *)right);
220     }
221    
222     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
223     {
224     partymember_t *who;
225 stdarg 1.20 int *pids, len, i, width = 0;
226 stdarg 1.7
227 wcc 1.16 partymember_printf(p, _("Partyline members:"));
228 stdarg 1.7 partymember_who(&pids, &len);
229     qsort(pids, len, sizeof(int), intsorter);
230 stdarg 1.20 if (len > 0) {
231     i = pids[len-1];
232     if (!i) i++;
233     while (i != 0) {
234     i /= 10;
235     width++;
236     }
237     }
238 stdarg 1.7 for (i = 0; i < len; i++) {
239     who = partymember_lookup_pid(pids[i]);
240 stdarg 1.20 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
241 stdarg 1.7 }
242     free(pids);
243     return(0);
244     }
245    
246 stdarg 1.23 static int party_whois(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
247     {
248     user_t *who;
249     flags_t flags;
250     char *item, *chan, *setting, *value, flagstr[64];
251     const char *next;
252     int i;
253    
254     if (text && *text) who = user_lookup_by_handle(text);
255     else who = u;
256    
257     if (!who) {
258     partymember_printf(p, "No such user.");
259     return(0);
260     }
261    
262     next = core_config.whois_items;
263     while (next && *next) {
264     egg_get_arg(next, &next, &item);
265     if (!strcasecmp(item, "handle")) {
266     partymember_printf(p, "%s: '%s'", item, who->handle);
267     }
268     else if (!strcasecmp(item, "uid")) {
269     partymember_printf(p, "%s: '%d'", item, who->uid);
270     }
271     else if (!strcasecmp(item, "ircmasks")) {
272     partymember_printf(p, "%s:", item);
273     for (i = 0; i < who->nircmasks; i++) {
274     partymember_printf(p, " %d. '%s'", i+1, who->ircmasks[i]);
275     }
276     }
277     else {
278     if (setting = strchr(item, '.')) {
279     chan = item;
280     *setting = 0;
281     setting++;
282     }
283     else {
284     chan = NULL;
285     setting = item;
286     }
287     if (!strcasecmp(setting, "flags")) {
288     user_get_flags(who, chan, &flags);
289     flag_to_str(&flags, flagstr);
290     value = flagstr;
291     }
292     else {
293     user_get_setting(who, chan, setting, &value);
294     }
295    
296     if (chan) partymember_printf(p, "%s.%s: %s", chan, setting, value);
297     else partymember_printf(p, "%s: %s", setting, value);
298     }
299     free(item);
300     }
301     return(0);
302     }
303    
304 stdarg 1.7 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
305     {
306 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
307 wcc 1.12 user_save(core_config.userfile);
308 stdarg 1.19 if (text && *text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
309 wcc 1.16 else putlog(LOG_MISC, "*", _("Bot shutting down."));
310 wcc 1.14 flushlogs();
311     unlink(pid_file);
312 stdarg 1.7 exit(0);
313     }
314    
315     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
316     {
317     user_t *newuser;
318    
319     if (!text || !*text) {
320 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
321 stdarg 1.7 return(0);
322     }
323     if (user_lookup_by_handle(text)) {
324 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
325 stdarg 1.7 return(0);
326     }
327     newuser = user_new(text);
328 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
329     else partymember_printf(p, _("Could not create user '%s'."), text);
330 stdarg 1.7 return(0);
331     }
332    
333     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
334     {
335     user_t *who;
336    
337     if (!text || !*text) {
338 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
339 stdarg 1.7 return(0);
340     }
341     who = user_lookup_by_handle(text);
342 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
343 stdarg 1.7 else {
344 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
345 stdarg 1.7 user_delete(who);
346     }
347     return(0);
348     }
349    
350     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
351     {
352     return(0);
353     }
354    
355 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
356     {
357     return(0);
358     }
359    
360 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
361 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
362     {
363     const char *next;
364     char *who, *flags, *chan;
365     user_t *dest;
366     flags_t flagstruct;
367     char flagstr[64];
368     int n;
369    
370 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
371 wcc 1.14 if (!chan || !*chan) {
372 stdarg 1.10 if (who) free(who);
373 wcc 1.16 partymember_printf(p, _("Syntax: chattr <user> [channel] <+/-flags>"));
374 stdarg 1.9 return(0);
375     }
376 wcc 1.14 if (!flags || !*flags) {
377 stdarg 1.9 flags = chan;
378     chan = NULL;
379     }
380     dest = user_lookup_by_handle(who);
381     if (dest) {
382     user_set_flag_str(dest, chan, flags);
383     user_get_flags(dest, chan, &flagstruct);
384     flag_to_str(&flagstruct, flagstr);
385 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
386 stdarg 1.9 }
387     else {
388 wcc 1.16 partymember_printf(p, _("'%s' is not a valid user."), who);
389 stdarg 1.9 }
390     free(who);
391     free(flags);
392     if (chan) free(chan);
393     return(0);
394     }
395    
396 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
397     {
398 stdarg 1.19 const char **modules;
399 wcc 1.12 int nummods, ctr;
400    
401 stdarg 1.19 nummods = module_list(&modules);
402 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
403 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
404     free(modules);
405     return(0);
406     }
407    
408 stdarg 1.1 static bind_list_t core_party_binds[] = {
409 stdarg 1.6 {NULL, "join", party_join},
410 wcc 1.12 {NULL, "whisper", party_whisper},
411 stdarg 1.6 {NULL, "newpass", party_newpass},
412     {NULL, "part", party_part},
413     {NULL, "quit", party_quit},
414 stdarg 1.7 {NULL, "who", party_who},
415 stdarg 1.23 {NULL, "whois", party_whois},
416 stdarg 1.11 {"n", "get", party_get},
417 stdarg 1.6 {"n", "set", party_set},
418 stdarg 1.20 {"n", "unset", party_unset},
419 wcc 1.14 {"n", "status", party_status},
420 stdarg 1.6 {"n", "save", party_save},
421 stdarg 1.7 {"n", "die", party_die},
422     {"n", "+user", party_plus_user},
423     {"n", "-user", party_minus_user},
424 stdarg 1.11 {"n", "+host", party_plus_host},
425     {"n", "-host", party_minus_host},
426 stdarg 1.9 {"n", "chattr", party_chattr},
427 wcc 1.12 {"n", "modules", party_modules},
428     {"m", "+host", party_plus_host},
429     {"m", "-host", party_minus_host},
430 stdarg 1.1 {0}
431     };
432    
433     void core_party_init()
434     {
435     bind_add_list("party", core_party_binds);
436     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23