/[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.16 - (hide annotations) (download) (as text)
Tue Dec 16 22:36:38 2003 UTC (15 years, 4 months ago) by wcc
Branch: MAIN
Changes since 1.15: +37 -40 lines
File MIME type: text/x-chdr
* src/ gettextification.
* More 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 wcc 1.16 static const char rcsid[] = "$Id: core_party.c,v 1.15 2003/12/16 21:45:35 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     #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 wcc 1.16 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.16 partymember_printf(p, _("Goodbye!"));
63     if (!text || !*text) partymember_delete(p, _("Quit"));
64 wcc 1.12 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 wcc 1.16 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
78 stdarg 1.13 goto done;
79     }
80    
81     dest = partymember_lookup_nick(who);
82     if (!dest) {
83 wcc 1.16 partymember_printf(p, _("No such user '%s'."), who);
84 stdarg 1.13 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 wcc 1.16 partymember_printf(p, _("That setting was not found."));
103 stdarg 1.11 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 wcc 1.16 partymember_printf(p, _("You cannot access that setting."));
116 stdarg 1.11 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 wcc 1.16 partymember_printf(p, _("Syntax: get <path>"));
126 stdarg 1.11 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 wcc 1.16 partymember_printf(p, _("Config setting not found."));
138 stdarg 1.11 }
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 wcc 1.16 partymember_printf(p, _("Syntax: set <path> <new value>"));
151 stdarg 1.11 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.16 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.16 partymember_printf(p, _("New value: '%s'"), str);
165 wcc 1.14 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 wcc 1.16 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 wcc 1.14 #ifdef HAVE_UNAME
178 wcc 1.16 if (!uname(&un) >= 0) partymember_printf(p, _("OS: %s %s"), un.sysname, un.release);
179 wcc 1.14 #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 wcc 1.16 putlog(LOG_MISC, "*", _("Saving user file..."));
186 stdarg 1.5 user_save(core_config.userfile);
187 wcc 1.16 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.16 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.16 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.16 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.16 putlog(LOG_MISC, "*", _("Saving user file..."));
227 wcc 1.12 user_save(core_config.userfile);
228 wcc 1.16 putlog(LOG_MISC, "*", _("Saving config file..."));
229 wcc 1.12 core_config_save();
230 wcc 1.16 if (!text || !*text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
231     else putlog(LOG_MISC, "*", _("Bot shutting down."));
232 wcc 1.14 flushlogs();
233     unlink(pid_file);
234 stdarg 1.7 exit(0);
235     }
236    
237     static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
238     {
239     user_t *newuser;
240    
241     if (!text || !*text) {
242 wcc 1.16 partymember_printf(p, _("Syntax: +user <handle>"));
243 stdarg 1.7 return(0);
244     }
245     if (user_lookup_by_handle(text)) {
246 wcc 1.16 partymember_printf(p, _("User '%s' already exists!"));
247 stdarg 1.7 return(0);
248     }
249     newuser = user_new(text);
250 wcc 1.16 if (newuser) partymember_printf(p, _("User '%s' created."), text);
251     else partymember_printf(p, _("Could not create user '%s'."), text);
252 stdarg 1.7 return(0);
253     }
254    
255     static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
256     {
257     user_t *who;
258    
259     if (!text || !*text) {
260 wcc 1.16 partymember_printf(p, _("Syntax: -user <handle>"));
261 stdarg 1.7 return(0);
262     }
263     who = user_lookup_by_handle(text);
264 wcc 1.16 if (!who) partymember_printf(p, _("User '%s' not found."));
265 stdarg 1.7 else {
266 wcc 1.16 partymember_printf(p, _("Deleting user '%s'."), who->handle);
267 stdarg 1.7 user_delete(who);
268     }
269     return(0);
270     }
271    
272     static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
273     {
274     return(0);
275     }
276    
277 stdarg 1.9 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
278     {
279     return(0);
280     }
281    
282     static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
283     {
284     const char *next;
285     char *who, *flags, *chan;
286     user_t *dest;
287     flags_t flagstruct;
288     char flagstr[64];
289     int n;
290    
291     n = egg_get_words(text, &next, &who, &chan, &flags, NULL);
292 wcc 1.14 if (!chan || !*chan) {
293 stdarg 1.10 if (who) free(who);
294 wcc 1.16 partymember_printf(p, _("Syntax: chattr <user> [channel] <+/-flags>"));
295 stdarg 1.9 return(0);
296     }
297 wcc 1.14 if (!flags || !*flags) {
298 stdarg 1.9 flags = chan;
299     chan = NULL;
300     }
301     dest = user_lookup_by_handle(who);
302     if (dest) {
303     user_set_flag_str(dest, chan, flags);
304     user_get_flags(dest, chan, &flagstruct);
305     flag_to_str(&flagstruct, flagstr);
306 wcc 1.16 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
307 stdarg 1.9 }
308     else {
309 wcc 1.16 partymember_printf(p, _("'%s' is not a valid user."), who);
310 stdarg 1.9 }
311     free(who);
312     free(flags);
313     if (chan) free(chan);
314     return(0);
315     }
316    
317 wcc 1.12 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
318     {
319     char **modules;
320     int nummods, ctr;
321    
322     nummods = get_module_list(&modules);
323 wcc 1.16 partymember_printf(p, _("Loaded modules:"));
324 wcc 1.12 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
325     free(modules);
326     return(0);
327     }
328    
329 stdarg 1.1 static bind_list_t core_party_binds[] = {
330 stdarg 1.6 {NULL, "join", party_join},
331 wcc 1.12 {NULL, "whisper", party_whisper},
332 stdarg 1.6 {NULL, "newpass", party_newpass},
333     {NULL, "part", party_part},
334     {NULL, "quit", party_quit},
335 stdarg 1.7 {NULL, "who", party_who},
336 stdarg 1.11 {"n", "get", party_get},
337 stdarg 1.6 {"n", "set", party_set},
338 wcc 1.14 {"n", "status", party_status},
339 stdarg 1.6 {"n", "save", party_save},
340 stdarg 1.7 {"n", "die", party_die},
341     {"n", "+user", party_plus_user},
342     {"n", "-user", party_minus_user},
343 stdarg 1.11 {"n", "+host", party_plus_host},
344     {"n", "-host", party_minus_host},
345 stdarg 1.9 {"n", "chattr", party_chattr},
346 wcc 1.12 {"n", "modules", party_modules},
347     {"m", "+host", party_plus_host},
348     {"m", "-host", party_minus_host},
349 stdarg 1.1 {0}
350     };
351    
352     void core_party_init()
353     {
354     bind_add_list("party", core_party_binds);
355     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23