/[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.23 - (show annotations) (download) (as text)
Sun Jan 11 12:02:38 2004 UTC (15 years, 9 months ago) by stdarg
Branch: MAIN
Changes since 1.22: +60 -2 lines
File MIME type: text/x-chdr
* Initial .whois command with whois_items variable to control displayed fields

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23