/[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.15 - (hide annotations) (download) (as text)
Tue Dec 16 21:45:35 2003 UTC (15 years, 4 months ago) by wcc
Branch: MAIN
Changes since 1.14: +28 -5 lines
File MIME type: text/x-chdr
* src/ cleanups.

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23