/[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.22 - (show annotations) (download) (as text)
Sat Jan 10 01:43:18 2004 UTC (15 years, 9 months ago) by stdarg
Branch: MAIN
Changes since 1.21: +14 -26 lines
File MIME type: text/x-chdr
* Stats for sockbufs

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23