/[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.17 - (hide annotations) (download) (as text)
Wed Dec 17 08:12:43 2003 UTC (15 years, 4 months ago) by wcc
Branch: MAIN
Changes since 1.16: +3 -1 lines
File MIME type: text/x-chdr
* Should do it..

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 wcc 1.17 static const char rcsid[] = "$Id: core_party.c,v 1.16 2003/12/16 22:36:38 wcc 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     #include "logfile.h"
35    
36 wcc 1.14 #ifdef HAVE_UNAME
37     # include <sys/utsname.h>
38     #endif
39    
40     extern char pid_file[];
41 stdarg 1.1
42 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
43     {
44 wcc 1.12 if (!text || !*text) {
45 wcc 1.16 partymember_printf(p, _("Syntax: join <channel>"));
46 stdarg 1.4 return(0);
47     }
48     partychan_join_name(text, p);
49     return(0);
50     }
51    
52     static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
53     {
54     partychan_t *chan;
55    
56 wcc 1.12 if (!text || !*text) chan = partychan_get_default(p);
57 stdarg 1.4 else chan = partychan_lookup_name(text);
58     partychan_part(chan, p, "parting");
59     return(0);
60     }
61    
62 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
63 stdarg 1.1 {
64 wcc 1.16 partymember_printf(p, _("Goodbye!"));
65     if (!text || !*text) partymember_delete(p, _("Quit"));
66 wcc 1.12 else partymember_delete(p, text);
67 stdarg 1.1 return(0);
68     }
69    
70 wcc 1.12 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
71 stdarg 1.1 {
72 stdarg 1.13 char *who;
73     const char *next;
74     partymember_t *dest;
75    
76     egg_get_word(text, &next, &who);
77     if (next) while (isspace(*next)) next++;
78     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.11 static void *lookup_and_check(partymember_t *p, const char *path)
96     {
97     void *root;
98     char *flags;
99     flags_t uflags, rflags;
100    
101     root = config_get_root("eggdrop");
102     root = config_exists(root, path, 0, NULL);
103     if (!root) {
104 wcc 1.16 partymember_printf(p, _("That setting was not found."));
105 stdarg 1.11 return(NULL);
106     }
107    
108     config_get_str(&flags, root, "flags", 0, NULL);
109     if (flags) {
110     flag_from_str(&rflags, flags);
111     if (!p->user) goto nope;
112     user_get_flags(p->user, NULL, &uflags);
113     if (!flag_match_partial(&uflags, &rflags)) goto nope;
114     }
115     return(root);
116     nope:
117 wcc 1.16 partymember_printf(p, _("You cannot access that setting."));
118 stdarg 1.11 return(NULL);
119     }
120    
121     static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
122     {
123     void *root;
124     char *str = NULL;
125    
126     if (!text || !*text) {
127 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
128 stdarg 1.11 return(0);
129     }
130    
131     root = lookup_and_check(p, text);
132     if (!root) return(0);
133    
134     config_get_str(&str, root, NULL);
135     if (str) {
136     partymember_printf(p, "==> '%s'", str);
137     }
138     else {
139 wcc 1.16 partymember_printf(p, _("Config setting not found."));
140 stdarg 1.11 }
141     return(0);
142     }
143    
144 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
145 stdarg 1.2 {
146 stdarg 1.11 void *root;
147     char *path, *str;
148     const char *next;
149    
150     egg_get_word(text, &next, &path);
151 wcc 1.14 if (!next || !*next || !path || !*path) {
152 wcc 1.16 partymember_printf(p, _("Syntax: set <path> <new value>"));
153 stdarg 1.11 if (path) free(path);
154     return(0);
155     }
156 wcc 1.14 while (isspace(*next)) next++;
157    
158 stdarg 1.11 root = lookup_and_check(p, path);
159     free(path);
160     if (!root) return(0);
161    
162     config_get_str(&str, root, NULL);
163 wcc 1.16 partymember_printf(p, _("Old value: '%s'"), str);
164 stdarg 1.11 config_set_str(next, root, NULL);
165     config_get_str(&str, root, NULL);
166 wcc 1.16 partymember_printf(p, _("New value: '%s'"), str);
167 wcc 1.14 return(0);
168     }
169    
170     static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
171     {
172     #ifdef HAVE_UNAME
173     struct utsname un;
174     #endif
175    
176 wcc 1.16 partymember_printf(p, _("I am %s, running Eggdrop %s."), core_config.botname, VERSION);
177     partymember_printf(p, _("Owner: %s"), core_config.owner);
178     if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
179 wcc 1.14 #ifdef HAVE_UNAME
180 wcc 1.16 if (!uname(&un) >= 0) partymember_printf(p, _("OS: %s %s"), un.sysname, un.release);
181 wcc 1.14 #endif
182 stdarg 1.2 return(0);
183     }
184    
185 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
186 stdarg 1.2 {
187 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
188 stdarg 1.5 user_save(core_config.userfile);
189 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
190 stdarg 1.2 core_config_save();
191     return(1);
192     }
193    
194 stdarg 1.5 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
195     {
196     if (!text || strlen(text) < 6) {
197 wcc 1.16 partymember_printf(p, _("Please use at least 6 characters."));
198 stdarg 1.5 return(0);
199     }
200     user_set_pass(p->user, text);
201 wcc 1.16 partymember_printf(p, _("Changed password to '%s'."), text);
202 stdarg 1.5 return(0);
203     }
204    
205 stdarg 1.7 static int intsorter(const void *left, const void *right)
206     {
207     return(*(int *)left - *(int *)right);
208     }
209    
210     static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
211     {
212     partymember_t *who;
213     int *pids, len, i;
214    
215 wcc 1.16 partymember_printf(p, _("Partyline members:"));
216 stdarg 1.7 partymember_who(&pids, &len);
217     qsort(pids, len, sizeof(int), intsorter);
218     for (i = 0; i < len; i++) {
219     who = partymember_lookup_pid(pids[i]);
220 stdarg 1.8 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
221 stdarg 1.7 }
222     free(pids);
223     return(0);
224     }
225    
226     static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
227     {
228 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
229 wcc 1.12 user_save(core_config.userfile);
230 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
231 wcc 1.12 core_config_save();
232 wcc 1.16 if (!text || !*text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
233     else putlog(LOG_MISC, "*", _("Bot shutting down."));
234 wcc 1.14 flushlogs();
235     unlink(pid_file);
236 stdarg 1.7 exit(0);
237     }
238    
239     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
240     {
241     user_t *newuser;
242    
243     if (!text || !*text) {
244 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
245 stdarg 1.7 return(0);
246     }
247     if (user_lookup_by_handle(text)) {
248 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
249 stdarg 1.7 return(0);
250     }
251     newuser = user_new(text);
252 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
253     else partymember_printf(p, _("Could not create user '%s'."), text);
254 stdarg 1.7 return(0);
255     }
256    
257     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
258     {
259     user_t *who;
260    
261     if (!text || !*text) {
262 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
263 stdarg 1.7 return(0);
264     }
265     who = user_lookup_by_handle(text);
266 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
267 stdarg 1.7 else {
268 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
269 stdarg 1.7 user_delete(who);
270     }
271     return(0);
272     }
273    
274     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
275     {
276     return(0);
277     }
278    
279 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
280     {
281     return(0);
282     }
283    
284     static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
285     {
286     const char *next;
287     char *who, *flags, *chan;
288     user_t *dest;
289     flags_t flagstruct;
290     char flagstr[64];
291     int n;
292    
293     n = egg_get_words(text, &next, &who, &chan, &flags, NULL);
294 wcc 1.14 if (!chan || !*chan) {
295 stdarg 1.10 if (who) free(who);
296 wcc 1.16 partymember_printf(p, _("Syntax: chattr <user> [channel] <+/-flags>"));
297 stdarg 1.9 return(0);
298     }
299 wcc 1.14 if (!flags || !*flags) {
300 stdarg 1.9 flags = chan;
301     chan = NULL;
302     }
303     dest = user_lookup_by_handle(who);
304     if (dest) {
305     user_set_flag_str(dest, chan, flags);
306     user_get_flags(dest, chan, &flagstruct);
307     flag_to_str(&flagstruct, flagstr);
308 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
309 stdarg 1.9 }
310     else {
311 wcc 1.16 partymember_printf(p, _("'%s' is not a valid user."), who);
312 stdarg 1.9 }
313     free(who);
314     free(flags);
315     if (chan) free(chan);
316     return(0);
317     }
318    
319 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
320     {
321     char **modules;
322     int nummods, ctr;
323    
324     nummods = get_module_list(&modules);
325 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
326 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
327     free(modules);
328     return(0);
329     }
330    
331 stdarg 1.1 static bind_list_t core_party_binds[] = {
332 stdarg 1.6 {NULL, "join", party_join},
333 wcc 1.12 {NULL, "whisper", party_whisper},
334 stdarg 1.6 {NULL, "newpass", party_newpass},
335     {NULL, "part", party_part},
336     {NULL, "quit", party_quit},
337 stdarg 1.7 {NULL, "who", party_who},
338 stdarg 1.11 {"n", "get", party_get},
339 stdarg 1.6 {"n", "set", party_set},
340 wcc 1.14 {"n", "status", party_status},
341 stdarg 1.6 {"n", "save", party_save},
342 stdarg 1.7 {"n", "die", party_die},
343     {"n", "+user", party_plus_user},
344     {"n", "-user", party_minus_user},
345 stdarg 1.11 {"n", "+host", party_plus_host},
346     {"n", "-host", party_minus_host},
347 stdarg 1.9 {"n", "chattr", party_chattr},
348 wcc 1.12 {"n", "modules", party_modules},
349     {"m", "+host", party_plus_host},
350     {"m", "-host", party_minus_host},
351 stdarg 1.1 {0}
352     };
353    
354     void core_party_init()
355     {
356     bind_add_list("party", core_party_binds);
357     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23