/[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.20 - (hide annotations) (download) (as text)
Sat Dec 20 00:34:37 2003 UTC (15 years, 4 months ago) by stdarg
Branch: MAIN
Changes since 1.19: +44 -8 lines
File MIME type: text/x-chdr
* Server saves nick list and server list

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23