/[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.16 - (show annotations) (download) (as text)
Tue Dec 16 22:36:38 2003 UTC (15 years, 6 months ago) by wcc
Branch: MAIN
Changes since 1.15: +37 -40 lines
File MIME type: text/x-chdr
* src/ gettextification.
* More cleanups.

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.15 2003/12/16 21:45:35 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 "core_config.h"
32 #include "logfile.h"
33
34 #ifdef HAVE_UNAME
35 # include <sys/utsname.h>
36 #endif
37
38 extern char pid_file[];
39
40 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
41 {
42 if (!text || !*text) {
43 partymember_printf(p, _("Syntax: join <channel>"));
44 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 if (!text || !*text) chan = partychan_get_default(p);
55 else chan = partychan_lookup_name(text);
56 partychan_part(chan, p, "parting");
57 return(0);
58 }
59
60 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
61 {
62 partymember_printf(p, _("Goodbye!"));
63 if (!text || !*text) partymember_delete(p, _("Quit"));
64 else partymember_delete(p, text);
65 return(0);
66 }
67
68 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
69 {
70 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 partymember_printf(p, _("Syntax: whisper <partylineuser> <msg>"));
78 goto done;
79 }
80
81 dest = partymember_lookup_nick(who);
82 if (!dest) {
83 partymember_printf(p, _("No such user '%s'."), who);
84 goto done;
85 }
86
87 partymember_msg(dest, p, next, -1);
88 done:
89 if (who) free(who);
90 return(0);
91 }
92
93 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 partymember_printf(p, _("That setting was not found."));
103 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 partymember_printf(p, _("You cannot access that setting."));
116 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 partymember_printf(p, _("Syntax: get <path>"));
126 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 partymember_printf(p, _("Config setting not found."));
138 }
139 return(0);
140 }
141
142 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
143 {
144 void *root;
145 char *path, *str;
146 const char *next;
147
148 egg_get_word(text, &next, &path);
149 if (!next || !*next || !path || !*path) {
150 partymember_printf(p, _("Syntax: set <path> <new value>"));
151 if (path) free(path);
152 return(0);
153 }
154 while (isspace(*next)) next++;
155
156 root = lookup_and_check(p, path);
157 free(path);
158 if (!root) return(0);
159
160 config_get_str(&str, root, NULL);
161 partymember_printf(p, _("Old value: '%s'"), str);
162 config_set_str(next, root, NULL);
163 config_get_str(&str, root, NULL);
164 partymember_printf(p, _("New value: '%s'"), str);
165 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 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 #ifdef HAVE_UNAME
178 if (!uname(&un) >= 0) partymember_printf(p, _("OS: %s %s"), un.sysname, un.release);
179 #endif
180 return(0);
181 }
182
183 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
184 {
185 putlog(LOG_MISC, "*", _("Saving user file..."));
186 user_save(core_config.userfile);
187 putlog(LOG_MISC, "*", _("Saving config file..."));
188 core_config_save();
189 return(1);
190 }
191
192 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 partymember_printf(p, _("Please use at least 6 characters."));
196 return(0);
197 }
198 user_set_pass(p->user, text);
199 partymember_printf(p, _("Changed password to '%s'."), text);
200 return(0);
201 }
202
203 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 partymember_printf(p, _("Partyline members:"));
214 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 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
219 }
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 putlog(LOG_MISC, "*", _("Saving user file..."));
227 user_save(core_config.userfile);
228 putlog(LOG_MISC, "*", _("Saving config file..."));
229 core_config_save();
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 char **modules;
320 int nummods, ctr;
321
322 nummods = get_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