/[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.19 - (show annotations) (download) (as text)
Fri Dec 19 01:08:58 2003 UTC (15 years, 10 months ago) by stdarg
Branch: MAIN
Changes since 1.18: +4 -6 lines
File MIME type: text/x-chdr
* Fix .die to show the proper die message
* Remove auto-save of config on .die
* Make module list use const

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.18 2003/12/18 03:54:46 wcc 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 "logfile.h"
35
36 #ifdef HAVE_UNAME
37 # include <sys/utsname.h>
38 #endif
39
40 extern char pid_file[];
41
42 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
43 {
44 if (!text || !*text) {
45 partymember_printf(p, _("Syntax: join <channel>"));
46 return(0);
47 }
48 partychan_join_name(text, p);
49 return(0);
50 }
51
52 static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
53 {
54 partychan_t *chan;
55
56 if (!text || !*text) chan = partychan_get_default(p);
57 else chan = partychan_lookup_name(text);
58 partychan_part(chan, p, "parting");
59 return(0);
60 }
61
62 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
63 {
64 partymember_printf(p, "Goodbye!");
65 if (!text || !*text) partymember_delete(p, "Quit");
66 else partymember_delete(p, text);
67 return(0);
68 }
69
70 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
71 {
72 char *who;
73 const char *next;
74 partymember_t *dest;
75
76 egg_get_word(text, &next, &who);
77 if (next) while (isspace(*next)) next++;
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_and_check(partymember_t *p, const char *path)
96 {
97 void *root;
98 char *flags;
99 flags_t uflags, rflags;
100
101 root = config_get_root("eggdrop");
102 root = config_exists(root, path, 0, NULL);
103 if (!root) {
104 partymember_printf(p, _("That setting was not found."));
105 return(NULL);
106 }
107
108 config_get_str(&flags, root, "flags", 0, NULL);
109 if (flags) {
110 flag_from_str(&rflags, flags);
111 if (!p->user) goto nope;
112 user_get_flags(p->user, NULL, &uflags);
113 if (!flag_match_partial(&uflags, &rflags)) goto nope;
114 }
115 return(root);
116 nope:
117 partymember_printf(p, _("You cannot access that setting."));
118 return(NULL);
119 }
120
121 static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
122 {
123 void *root;
124 char *str = NULL;
125
126 if (!text || !*text) {
127 partymember_printf(p, _("Syntax: get <path>"));
128 return(0);
129 }
130
131 root = lookup_and_check(p, text);
132 if (!root) return(0);
133
134 config_get_str(&str, root, NULL);
135 if (str) {
136 partymember_printf(p, "==> '%s'", str);
137 }
138 else {
139 partymember_printf(p, _("Config setting not found."));
140 }
141 return(0);
142 }
143
144 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
145 {
146 void *root;
147 char *path, *str;
148 const char *next;
149
150 egg_get_word(text, &next, &path);
151 if (!next || !*next || !path || !*path) {
152 partymember_printf(p, _("Syntax: set <path> <new value>"));
153 if (path) free(path);
154 return(0);
155 }
156 while (isspace(*next)) next++;
157
158 root = lookup_and_check(p, path);
159 free(path);
160 if (!root) return(0);
161
162 config_get_str(&str, root, NULL);
163 partymember_printf(p, _("Old value: '%s'"), str);
164 config_set_str(next, root, NULL);
165 config_get_str(&str, root, NULL);
166 partymember_printf(p, _("New value: '%s'"), str);
167 return(0);
168 }
169
170 static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
171 {
172 #ifdef HAVE_UNAME
173 struct utsname un;
174 #endif
175
176 partymember_printf(p, _("I am %s, running Eggdrop %s."), core_config.botname, VERSION);
177 partymember_printf(p, _("Owner: %s"), core_config.owner);
178 if (core_config.admin) partymember_printf(p, _("Admin: %s"), core_config.admin);
179 #ifdef HAVE_UNAME
180 if (!uname(&un) >= 0) partymember_printf(p, _("OS: %s %s"), un.sysname, un.release);
181 #endif
182 return(0);
183 }
184
185 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
186 {
187 putlog(LOG_MISC, "*", _("Saving user file..."));
188 user_save(core_config.userfile);
189 putlog(LOG_MISC, "*", _("Saving config file..."));
190 core_config_save();
191 return(1);
192 }
193
194 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
195 {
196 if (!text || strlen(text) < 6) {
197 partymember_printf(p, _("Please use at least 6 characters."));
198 return(0);
199 }
200 user_set_pass(p->user, text);
201 partymember_printf(p, _("Changed password to '%s'."), text);
202 return(0);
203 }
204
205 static int intsorter(const void *left, const void *right)
206 {
207 return(*(int *)left - *(int *)right);
208 }
209
210 static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
211 {
212 partymember_t *who;
213 int *pids, len, i;
214
215 partymember_printf(p, _("Partyline members:"));
216 partymember_who(&pids, &len);
217 qsort(pids, len, sizeof(int), intsorter);
218 for (i = 0; i < len; i++) {
219 who = partymember_lookup_pid(pids[i]);
220 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
221 }
222 free(pids);
223 return(0);
224 }
225
226 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
227 {
228 putlog(LOG_MISC, "*", _("Saving user file..."));
229 user_save(core_config.userfile);
230 if (text && *text) putlog(LOG_MISC, "*", _("Bot shutting down: %s"), text);
231 else putlog(LOG_MISC, "*", _("Bot shutting down."));
232 flushlogs();
233 unlink(pid_file);
234 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 partymember_printf(p, _("Syntax: +user <handle>"));
243 return(0);
244 }
245 if (user_lookup_by_handle(text)) {
246 partymember_printf(p, _("User '%s' already exists!"));
247 return(0);
248 }
249 newuser = user_new(text);
250 if (newuser) partymember_printf(p, _("User '%s' created."), text);
251 else partymember_printf(p, _("Could not create user '%s'."), text);
252 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 partymember_printf(p, _("Syntax: -user <handle>"));
261 return(0);
262 }
263 who = user_lookup_by_handle(text);
264 if (!who) partymember_printf(p, _("User '%s' not found."));
265 else {
266 partymember_printf(p, _("Deleting user '%s'."), who->handle);
267 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 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 if (!chan || !*chan) {
293 if (who) free(who);
294 partymember_printf(p, _("Syntax: chattr <user> [channel] <+/-flags>"));
295 return(0);
296 }
297 if (!flags || !*flags) {
298 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 partymember_printf(p, _("Flags for %s are now '%s'."), who, flagstr);
307 }
308 else {
309 partymember_printf(p, _("'%s' is not a valid user."), who);
310 }
311 free(who);
312 free(flags);
313 if (chan) free(chan);
314 return(0);
315 }
316
317 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
318 {
319 const char **modules;
320 int nummods, ctr;
321
322 nummods = module_list(&modules);
323 partymember_printf(p, _("Loaded modules:"));
324 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
325 free(modules);
326 return(0);
327 }
328
329 static bind_list_t core_party_binds[] = {
330 {NULL, "join", party_join},
331 {NULL, "whisper", party_whisper},
332 {NULL, "newpass", party_newpass},
333 {NULL, "part", party_part},
334 {NULL, "quit", party_quit},
335 {NULL, "who", party_who},
336 {"n", "get", party_get},
337 {"n", "set", party_set},
338 {"n", "status", party_status},
339 {"n", "save", party_save},
340 {"n", "die", party_die},
341 {"n", "+user", party_plus_user},
342 {"n", "-user", party_minus_user},
343 {"n", "+host", party_plus_host},
344 {"n", "-host", party_minus_host},
345 {"n", "chattr", party_chattr},
346 {"n", "modules", party_modules},
347 {"m", "+host", party_plus_host},
348 {"m", "-host", party_minus_host},
349 {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