/[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.14 - (show annotations) (download) (as text)
Tue Dec 16 03:13:51 2003 UTC (15 years, 6 months ago) by wcc
Branch: MAIN
Changes since 1.13: +37 -6 lines
File MIME type: text/x-chdr
* main.c cleanups.
* Added pidfile and die_on_sigterm to config.
* Added 'act' party command.
* Started a 'status' party command.
* Removed config.tcl.
* General cleanups.

1 #include <eggdrop/eggdrop.h>
2 #include <ctype.h>
3
4 #include "core_config.h"
5 #include "logfile.h"
6
7 #ifdef HAVE_CONFIG_H
8 # include <config.h>
9 #endif
10
11 #ifdef HAVE_UNAME
12 # include <sys/utsname.h>
13 #endif
14
15 extern char pid_file[];
16
17 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
18 {
19 if (!text || !*text) {
20 partymember_printf(p, "Syntax: join <channel>");
21 return(0);
22 }
23 partychan_join_name(text, p);
24 return(0);
25 }
26
27 static int party_part(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
28 {
29 partychan_t *chan;
30
31 if (!text || !*text) chan = partychan_get_default(p);
32 else chan = partychan_lookup_name(text);
33 partychan_part(chan, p, "parting");
34 return(0);
35 }
36
37 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
38 {
39 partymember_printf(p, "Goodbye!");
40 if (!text || !*text) partymember_delete(p, "Quit");
41 else partymember_delete(p, text);
42 return(0);
43 }
44
45 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
46 {
47 char *who;
48 const char *next;
49 partymember_t *dest;
50
51 egg_get_word(text, &next, &who);
52 if (next) while (isspace(*next)) next++;
53 if (!who || !next || !*who || !*next) {
54 partymember_printf(p, "Syntax: whisper <partylineuser> <msg>");
55 goto done;
56 }
57
58 dest = partymember_lookup_nick(who);
59 if (!dest) {
60 partymember_printf(p, "No such user '%s'.", who);
61 goto done;
62 }
63
64 partymember_msg(dest, p, next, -1);
65 done:
66 if (who) free(who);
67 return(0);
68 }
69
70 static void *lookup_and_check(partymember_t *p, const char *path)
71 {
72 void *root;
73 char *flags;
74 flags_t uflags, rflags;
75
76 root = config_get_root("eggdrop");
77 root = config_exists(root, path, 0, NULL);
78 if (!root) {
79 partymember_printf(p, "That setting was not found.");
80 return(NULL);
81 }
82
83 config_get_str(&flags, root, "flags", 0, NULL);
84 if (flags) {
85 flag_from_str(&rflags, flags);
86 if (!p->user) goto nope;
87 user_get_flags(p->user, NULL, &uflags);
88 if (!flag_match_partial(&uflags, &rflags)) goto nope;
89 }
90 return(root);
91 nope:
92 partymember_printf(p, "You cannot access that setting.");
93 return(NULL);
94 }
95
96 static int party_get(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
97 {
98 void *root;
99 char *str = NULL;
100
101 if (!text || !*text) {
102 partymember_printf(p, "Syntax: get <path>");
103 return(0);
104 }
105
106 root = lookup_and_check(p, text);
107 if (!root) return(0);
108
109 config_get_str(&str, root, NULL);
110 if (str) {
111 partymember_printf(p, "==> '%s'", str);
112 }
113 else {
114 partymember_printf(p, "Config setting not found.");
115 }
116 return(0);
117 }
118
119 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
120 {
121 void *root;
122 char *path, *str;
123 const char *next;
124
125 egg_get_word(text, &next, &path);
126 if (!next || !*next || !path || !*path) {
127 partymember_printf(p, "Syntax: set <path> <new value>");
128 if (path) free(path);
129 return(0);
130 }
131 while (isspace(*next)) next++;
132
133 root = lookup_and_check(p, path);
134 free(path);
135 if (!root) return(0);
136
137 config_get_str(&str, root, NULL);
138 partymember_printf(p, "Old value: '%s'", str);
139 config_set_str(next, root, NULL);
140 config_get_str(&str, root, NULL);
141 partymember_printf(p, "New value: '%s'", str);
142 return(0);
143 }
144
145 static int party_status(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
146 {
147 #ifdef HAVE_UNAME
148 struct utsname un;
149 #endif
150
151 partymember_printf(p, "I am %s, running Eggdrop %s.", core_config.botname, VERSION);
152 partymember_printf(p, "Owner: %s", core_config.owner);
153 if (core_config.admin) partymember_printf(p, "Admin: %s", core_config.admin);
154 #ifdef HAVE_UNAME
155 if (!uname(&un) >= 0) partymember_printf(p, "OS: %s %s", un.sysname, un.release);
156 #endif
157 return(0);
158 }
159
160 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
161 {
162 putlog(LOG_MISC, "*", "Saving user file...");
163 user_save(core_config.userfile);
164 putlog(LOG_MISC, "*", "Saving config file...");
165 core_config_save();
166 return(1);
167 }
168
169 static int party_newpass(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
170 {
171 if (!text || strlen(text) < 6) {
172 partymember_printf(p, "Please use at least 6 characters.");
173 return(0);
174 }
175 user_set_pass(p->user, text);
176 partymember_printf(p, "Changed password to '%s'.", text);
177 return(0);
178 }
179
180 static int intsorter(const void *left, const void *right)
181 {
182 return(*(int *)left - *(int *)right);
183 }
184
185 static int party_who(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
186 {
187 partymember_t *who;
188 int *pids, len, i;
189
190 partymember_printf(p, "Partyline members:");
191 partymember_who(&pids, &len);
192 qsort(pids, len, sizeof(int), intsorter);
193 for (i = 0; i < len; i++) {
194 who = partymember_lookup_pid(pids[i]);
195 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
196 }
197 free(pids);
198 return(0);
199 }
200
201 static int party_die(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
202 {
203 char *reason;
204
205 if (!text || !*text) reason = "No reason given.";
206 else reason = text;
207 putlog(LOG_MISC, "*", "Saving user file...");
208 user_save(core_config.userfile);
209 putlog(LOG_MISC, "*", "Saving config file...");
210 core_config_save();
211 putlog(LOG_MISC, "*", "Bot shutting down: %s", reason);
212 flushlogs();
213 unlink(pid_file);
214 exit(0);
215 }
216
217 static int party_plus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
218 {
219 user_t *newuser;
220
221 if (!text || !*text) {
222 partymember_printf(p, "Syntax: +user <handle>");
223 return(0);
224 }
225 if (user_lookup_by_handle(text)) {
226 partymember_printf(p, "User '%s' already exists!");
227 return(0);
228 }
229 newuser = user_new(text);
230 if (newuser) partymember_printf(p, "User '%s' created.", text);
231 else partymember_printf(p, "Could not create user '%s'.", text);
232 return(0);
233 }
234
235 static int party_minus_user(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
236 {
237 user_t *who;
238
239 if (!text || !*text) {
240 partymember_printf(p, "Syntax: -user <handle>");
241 return(0);
242 }
243 who = user_lookup_by_handle(text);
244 if (!who) partymember_printf(p, "User '%s' not found.");
245 else {
246 partymember_printf(p, "Deleting user '%s'.", who->handle);
247 user_delete(who);
248 }
249 return(0);
250 }
251
252 static int party_plus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
253 {
254 return(0);
255 }
256
257 static int party_minus_host(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
258 {
259 return(0);
260 }
261
262 static int party_chattr(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
263 {
264 const char *next;
265 char *who, *flags, *chan;
266 user_t *dest;
267 flags_t flagstruct;
268 char flagstr[64];
269 int n;
270
271 n = egg_get_words(text, &next, &who, &chan, &flags, NULL);
272 if (!chan || !*chan) {
273 if (who) free(who);
274 partymember_printf(p, "Syntax: chattr <user> [channel] <+/-flags>");
275 return(0);
276 }
277 if (!flags || !*flags) {
278 flags = chan;
279 chan = NULL;
280 }
281 dest = user_lookup_by_handle(who);
282 if (dest) {
283 user_set_flag_str(dest, chan, flags);
284 user_get_flags(dest, chan, &flagstruct);
285 flag_to_str(&flagstruct, flagstr);
286 partymember_printf(p, "Flags for %s are now '%s'.", who, flagstr);
287 }
288 else {
289 partymember_printf(p, "'%s' is not a valid user.", who);
290 }
291 free(who);
292 free(flags);
293 if (chan) free(chan);
294 return(0);
295 }
296
297 static int party_modules(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
298 {
299 char **modules;
300 int nummods, ctr;
301
302 nummods = get_module_list(&modules);
303 partymember_printf(p, "Loaded modules:");
304 for (ctr = 0; ctr < nummods; ctr++) partymember_printf(p, " %s", modules[ctr]);
305 free(modules);
306 return(0);
307 }
308
309 static bind_list_t core_party_binds[] = {
310 {NULL, "join", party_join},
311 {NULL, "whisper", party_whisper},
312 {NULL, "newpass", party_newpass},
313 {NULL, "part", party_part},
314 {NULL, "quit", party_quit},
315 {NULL, "who", party_who},
316 {"n", "get", party_get},
317 {"n", "set", party_set},
318 {"n", "status", party_status},
319 {"n", "save", party_save},
320 {"n", "die", party_die},
321 {"n", "+user", party_plus_user},
322 {"n", "-user", party_minus_user},
323 {"n", "+host", party_plus_host},
324 {"n", "-host", party_minus_host},
325 {"n", "chattr", party_chattr},
326 {"n", "modules", party_modules},
327 {"m", "+host", party_plus_host},
328 {"m", "-host", party_minus_host},
329 {0}
330 };
331
332 void core_party_init()
333 {
334 bind_add_list("party", core_party_binds);
335 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23