/[cvs]/eggdrop1.9/src/core_party.c
ViewVC logotype

Contents of /eggdrop1.9/src/core_party.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.20 - (show annotations) (download) (as text)
Sat Dec 20 00:34:37 2003 UTC (15 years, 6 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 /* 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
20 #ifndef lint
21 static const char rcsid[] = "$Id: core_party.c,v 1.19 2003/12/19 01:08:58 stdarg Exp $";
22 #endif
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <eggdrop/eggdrop.h>
29 #include <ctype.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include "core_config.h"
34 #include "core_binds.h"
35 #include "logfile.h"
36
37 #ifdef HAVE_UNAME
38 # include <sys/utsname.h>
39 #endif
40
41 extern char pid_file[];
42
43 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
44 {
45 if (!text || !*text) {
46 partymember_printf(p, _("Syntax: join <channel>"));
47 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 if (!text || !*text) chan = partychan_get_default(p);
58 else chan = partychan_lookup_name(text);
59 partychan_part(chan, p, "parting");
60 return(0);
61 }
62
63 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
64 {
65 partymember_printf(p, "Goodbye!");
66 if (!text || !*text) partymember_delete(p, "Quit");
67 else partymember_delete(p, text);
68 return(0);
69 }
70
71 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
72 {
73 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 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
81 goto done;
82 }
83
84 dest = partymember_lookup_nick(who);
85 if (!dest) {
86 partymember_printf(p, _("No such user '%s'."), who);
87 goto done;
88 }
89
90 partymember_msg(dest, p, next, -1);
91 done:
92 if (who) free(who);
93 return(0);
94 }
95
96 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 partymember_printf(p, _("That setting does not exist."));
106 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 partymember_printf(p, _("You cannot access that setting."));
119 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 partymember_printf(p, _("Syntax: get <path>"));
129 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 partymember_printf(p, _("==> null (unset)"));
141 }
142 return(0);
143 }
144
145 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
146 {
147 void *root;
148 char *path, *str;
149 const char *next;
150
151 egg_get_word(text, &next, &path);
152 if (!next || !*next || !path || !*path) {
153 partymember_printf(p, _("Syntax: set <path> <new value>"));
154 if (path) free(path);
155 return(0);
156 }
157 while (isspace(*next)) next++;
158
159 root = lookup_and_check(p, path);
160 free(path);
161 if (!root) return(0);
162
163 config_get_str(&str, root, NULL);
164 partymember_printf(p, _("Old value: '%s'"), str);
165 config_set_str(next, root, NULL);
166 config_get_str(&str, root, NULL);
167 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 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 partymember_printf(p, _("I am %1$s, running Eggdrop %2$s."), core_config.botname, VERSION);
202 partymember_printf(p, _("Owner: %s"), core_config.owner);
203 if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
204 #ifdef HAVE_UNAME
205 if (!uname(&un)) partymember_printf(p, _("OS: %1$s %2$s"), un.sysname, un.release);
206 #endif
207 partymember_printf(p, "");
208 check_bind_status(p, text);
209 return(0);
210 }
211
212 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
213 {
214 putlog(LOG_MISC, "*", _("Saving user file..."));
215 user_save(core_config.userfile);
216 putlog(LOG_MISC, "*", _("Saving config file..."));
217 core_config_save();
218 return(1);
219 }
220
221 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 partymember_printf(p, _("Please use at least 6 characters."));
225 return(0);
226 }
227 user_set_pass(p->user, text);
228 partymember_printf(p, _("Changed password to '%s'."), text);
229 return(0);
230 }
231
232 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 int *pids, len, i, width = 0;
241
242 partymember_printf(p, _("Partyline members:"));
243 partymember_who(&pids, &len);
244 qsort(pids, len, sizeof(int), intsorter);
245 if (len > 0) {
246 i = pids[len-1];
247 if (!i) i++;
248 while (i != 0) {
249 i /= 10;
250 width++;
251 }
252 }
253 for (i = 0; i < len; i++) {
254 who = partymember_lookup_pid(pids[i]);
255 partymember_printf(p, " [%*d] %s (%s@%s)", width, who->pid, who->nick, who->ident, who->host);
256 }
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 putlog(LOG_MISC, "*", _("Saving user file..."));
264 user_save(core_config.userfile);
265 if (text && *text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
266 else putlog(LOG_MISC, "*", _("Bot shutting down."));
267 flushlogs();
268 unlink(pid_file);
269 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 partymember_printf(p, _("Syntax: +user <handle>"));
278 return(0);
279 }
280 if (user_lookup_by_handle(text)) {
281 partymember_printf(p, _("User '%s' already exists!"));
282 return(0);
283 }
284 newuser = user_new(text);
285 if (newuser) partymember_printf(p, _("User '%s' created."), text);
286 else partymember_printf(p, _("Could not create user '%s'."), text);
287 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 partymember_printf(p, _("Syntax: -user <handle>"));
296 return(0);
297 }
298 who = user_lookup_by_handle(text);
299 if (!who) partymember_printf(p, _("User '%s' not found."));
300 else {
301 partymember_printf(p, _("Deleting user '%s'."), who->handle);
302 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 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 if (!chan || !*chan) {
328 if (who) free(who);
329 partymember_printf(p, _("Syntax: chattr <user> [channel] <+/-flags>"));
330 return(0);
331 }
332 if (!flags || !*flags) {
333 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 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
342 }
343 else {
344 partymember_printf(p, _("'%s' is not a valid user."), who);
345 }
346 free(who);
347 free(flags);
348 if (chan) free(chan);
349 return(0);
350 }
351
352 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
353 {
354 const char **modules;
355 int nummods, ctr;
356
357 nummods = module_list(&modules);
358 partymember_printf(p, _("Loaded modules:"));
359 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
360 free(modules);
361 return(0);
362 }
363
364 static bind_list_t core_party_binds[] = {
365 {NULL, "join", party_join},
366 {NULL, "whisper", party_whisper},
367 {NULL, "newpass", party_newpass},
368 {NULL, "part", party_part},
369 {NULL, "quit", party_quit},
370 {NULL, "who", party_who},
371 {"n", "get", party_get},
372 {"n", "set", party_set},
373 {"n", "unset", party_unset},
374 {"n", "status", party_status},
375 {"n", "save", party_save},
376 {"n", "die", party_die},
377 {"n", "+user", party_plus_user},
378 {"n", "-user", party_minus_user},
379 {"n", "+host", party_plus_host},
380 {"n", "-host", party_minus_host},
381 {"n", "chattr", party_chattr},
382 {"n", "modules", party_modules},
383 {"m", "+host", party_plus_host},
384 {"m", "-host", party_minus_host},
385 {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