/[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.22 - (hide annotations) (download) (as text)
Sat Jan 10 01:43:18 2004 UTC (15 years, 3 months ago) by stdarg
Branch: MAIN
Changes since 1.21: +14 -26 lines
File MIME type: text/x-chdr
* Stats for sockbufs

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.22 static const char rcsid[] = "$Id: core_party.c,v 1.21 2003/12/23 22:23:04 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     char *flags;
99    
100     root = config_get_root("eggdrop");
101     root = config_exists(root, path, 0, NULL);
102 stdarg 1.22 if (!root) partymember_printf(p, _("That setting does not exist."));
103 stdarg 1.11 return(root);
104     }
105    
106     static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
107     {
108     void *root;
109     char *str = NULL;
110    
111     if (!text || !*text) {
112 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
113 stdarg 1.11 return(0);
114     }
115    
116 stdarg 1.22 root = lookup_setting(p, text);
117 stdarg 1.11 if (!root) return(0);
118    
119     config_get_str(&str, root, NULL);
120     if (str) {
121 stdarg 1.22 partymember_printf(p, "Current value: '%s'", str);
122 stdarg 1.11 }
123     else {
124 stdarg 1.22 partymember_printf(p, _("Current value: null (unset)"));
125 stdarg 1.11 }
126     return(0);
127     }
128    
129 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
130 stdarg 1.2 {
131 stdarg 1.11 void *root;
132     char *path, *str;
133     const char *next;
134    
135 stdarg 1.21 egg_get_arg(text, &next, &path);
136 stdarg 1.22 if (!path) {
137     partymember_printf(p, _("Syntax: set <path> [new value]"));
138 stdarg 1.11 return(0);
139     }
140 stdarg 1.22 if (!next) {
141     free(path);
142     return party_get(p, nick, u, cmd, text);
143     }
144 wcc 1.14
145 stdarg 1.22 root = lookup_setting(p, path);
146 stdarg 1.11 free(path);
147     if (!root) return(0);
148    
149     config_get_str(&str, root, NULL);
150 wcc 1.16 partymember_printf(p, _("Old value: '%s'"), str);
151 stdarg 1.11 config_set_str(next, root, NULL);
152     config_get_str(&str, root, NULL);
153 stdarg 1.20 if (str) partymember_printf(p, _("New value: '%s'"), str);
154     else partymember_printf(p, _("New value: null (unset)"));
155     return(0);
156     }
157    
158     static int party_unset(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
159     {
160     void *root;
161     char *str;
162    
163     if (!text || !*text) {
164     partymember_printf(p, _("Syntax: unset <path>"));
165     return(0);
166     }
167    
168 stdarg 1.22 root = lookup_setting(p, text);
169 stdarg 1.20 if (!root) return(0);
170    
171     config_get_str(&str, root, NULL);
172     if (str) partymember_printf(p, _("Old value: '%s'"), str);
173     else partymember_printf(p, _("Old value: null (unset)"));
174     config_set_str(NULL, root, NULL);
175     config_get_str(&str, root, NULL);
176     if (str) partymember_printf(p, _("New value: '%s'"), str);
177     else partymember_printf(p, _("New value: null (unset)"));
178 wcc 1.14 return(0);
179     }
180    
181     static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
182     {
183     #ifdef HAVE_UNAME
184     struct utsname un;
185     #endif
186    
187 stdarg 1.20 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
188 wcc 1.16 partymember_printf(p, _("Owner: %s"), core_config.owner);
189     if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
190 wcc 1.14 #ifdef HAVE_UNAME
191 stdarg 1.20 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
192 wcc 1.14 #endif
193 stdarg 1.20 partymember_printf(p, "");
194     check_bind_status(p, text);
195 stdarg 1.2 return(0);
196     }
197    
198 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
199 stdarg 1.2 {
200 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
201 stdarg 1.5 user_save(core_config.userfile);
202 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
203 stdarg 1.2 core_config_save();
204     return(1);
205     }
206    
207 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
208     {
209     if (!text || strlen(text) < 6) {
210 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
211 stdarg 1.5 return(0);
212     }
213     user_set_pass(p->user, text);
214 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
215 stdarg 1.5 return(0);
216     }
217    
218 stdarg 1.7 static int intsorter(const void *left, const void *right)
219     {
220     return(*(int *)left - *(int *)right);
221     }
222    
223     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
224     {
225     partymember_t *who;
226 stdarg 1.20 int *pids, len, i, width = 0;
227 stdarg 1.7
228 wcc 1.16 partymember_printf(p, _("Partyline members:"));
229 stdarg 1.7 partymember_who(&pids, &len);
230     qsort(pids, len, sizeof(int), intsorter);
231 stdarg 1.20 if (len > 0) {
232     i = pids[len-1];
233     if (!i) i++;
234     while (i != 0) {
235     i /= 10;
236     width++;
237     }
238     }
239 stdarg 1.7 for (i = 0; i < len; i++) {
240     who = partymember_lookup_pid(pids[i]);
241 stdarg 1.20 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
242 stdarg 1.7 }
243     free(pids);
244     return(0);
245     }
246    
247     static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
248     {
249 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
250 wcc 1.12 user_save(core_config.userfile);
251 stdarg 1.19 if (text && *text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
252 wcc 1.16 else putlog(LOG_MISC, "*", _("Bot shutting down."));
253 wcc 1.14 flushlogs();
254     unlink(pid_file);
255 stdarg 1.7 exit(0);
256     }
257    
258     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
259     {
260     user_t *newuser;
261    
262     if (!text || !*text) {
263 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
264 stdarg 1.7 return(0);
265     }
266     if (user_lookup_by_handle(text)) {
267 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
268 stdarg 1.7 return(0);
269     }
270     newuser = user_new(text);
271 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
272     else partymember_printf(p, _("Could not create user '%s'."), text);
273 stdarg 1.7 return(0);
274     }
275    
276     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
277     {
278     user_t *who;
279    
280     if (!text || !*text) {
281 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
282 stdarg 1.7 return(0);
283     }
284     who = user_lookup_by_handle(text);
285 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
286 stdarg 1.7 else {
287 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
288 stdarg 1.7 user_delete(who);
289     }
290     return(0);
291     }
292    
293     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
294     {
295     return(0);
296     }
297    
298 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
299     {
300     return(0);
301     }
302    
303 stdarg 1.21 /* Syntax: chattr <user> [chan] <flags> */
304 stdarg 1.9 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
305     {
306     const char *next;
307     char *who, *flags, *chan;
308     user_t *dest;
309     flags_t flagstruct;
310     char flagstr[64];
311     int n;
312    
313 stdarg 1.21 n = egg_get_args(text, &next, &who, &chan, &flags, NULL);
314 wcc 1.14 if (!chan || !*chan) {
315 stdarg 1.10 if (who) free(who);
316 wcc 1.16 partymember_printf(p, _("Syntax: chattr <user> [channel] <+/-flags>"));
317 stdarg 1.9 return(0);
318     }
319 wcc 1.14 if (!flags || !*flags) {
320 stdarg 1.9 flags = chan;
321     chan = NULL;
322     }
323     dest = user_lookup_by_handle(who);
324     if (dest) {
325     user_set_flag_str(dest, chan, flags);
326     user_get_flags(dest, chan, &flagstruct);
327     flag_to_str(&flagstruct, flagstr);
328 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
329 stdarg 1.9 }
330     else {
331 wcc 1.16 partymember_printf(p, _("'%s' is not a valid user."), who);
332 stdarg 1.9 }
333     free(who);
334     free(flags);
335     if (chan) free(chan);
336     return(0);
337     }
338    
339 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
340     {
341 stdarg 1.19 const char **modules;
342 wcc 1.12 int nummods, ctr;
343    
344 stdarg 1.19 nummods = module_list(&modules);
345 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
346 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
347     free(modules);
348     return(0);
349     }
350    
351 stdarg 1.1 static bind_list_t core_party_binds[] = {
352 stdarg 1.6 {NULL, "join", party_join},
353 wcc 1.12 {NULL, "whisper", party_whisper},
354 stdarg 1.6 {NULL, "newpass", party_newpass},
355     {NULL, "part", party_part},
356     {NULL, "quit", party_quit},
357 stdarg 1.7 {NULL, "who", party_who},
358 stdarg 1.11 {"n", "get", party_get},
359 stdarg 1.6 {"n", "set", party_set},
360 stdarg 1.20 {"n", "unset", party_unset},
361 wcc 1.14 {"n", "status", party_status},
362 stdarg 1.6 {"n", "save", party_save},
363 stdarg 1.7 {"n", "die", party_die},
364     {"n", "+user", party_plus_user},
365     {"n", "-user", party_minus_user},
366 stdarg 1.11 {"n", "+host", party_plus_host},
367     {"n", "-host", party_minus_host},
368 stdarg 1.9 {"n", "chattr", party_chattr},
369 wcc 1.12 {"n", "modules", party_modules},
370     {"m", "+host", party_plus_host},
371     {"m", "-host", party_minus_host},
372 stdarg 1.1 {0}
373     };
374    
375     void core_party_init()
376     {
377     bind_add_list("party", core_party_binds);
378     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23