/[cvs]/eggdrop1.9/src/core_party.c
ViewVC logotype

Annotation of /eggdrop1.9/src/core_party.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.14 - (hide annotations) (download) (as text)
Tue Dec 16 03:13:51 2003 UTC (15 years, 5 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 stdarg 1.1 #include <eggdrop/eggdrop.h>
2 stdarg 1.11 #include <ctype.h>
3 wcc 1.14
4 stdarg 1.5 #include "core_config.h"
5 wcc 1.14 #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 stdarg 1.1
17 stdarg 1.4 static int party_join(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
18     {
19 wcc 1.12 if (!text || !*text) {
20     partymember_printf(p, "Syntax: join <channel>");
21 stdarg 1.4 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 wcc 1.12 if (!text || !*text) chan = partychan_get_default(p);
32 stdarg 1.4 else chan = partychan_lookup_name(text);
33     partychan_part(chan, p, "parting");
34     return(0);
35     }
36    
37 stdarg 1.3 static int party_quit(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
38 stdarg 1.1 {
39 wcc 1.12 partymember_printf(p, "Goodbye!");
40     if (!text || !*text) partymember_delete(p, "Quit");
41     else partymember_delete(p, text);
42 stdarg 1.1 return(0);
43     }
44    
45 wcc 1.12 static int party_whisper(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
46 stdarg 1.1 {
47 stdarg 1.13 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 stdarg 1.1 return(0);
68     }
69    
70 stdarg 1.11 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 stdarg 1.6 static int party_set(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
120 stdarg 1.2 {
121 stdarg 1.11 void *root;
122     char *path, *str;
123     const char *next;
124    
125     egg_get_word(text, &next, &path);
126 wcc 1.14 if (!next || !*next || !path || !*path) {
127 stdarg 1.11 partymember_printf(p, "Syntax: set <path> <new value>");
128     if (path) free(path);
129     return(0);
130     }
131 wcc 1.14 while (isspace(*next)) next++;
132    
133 stdarg 1.11 root = lookup_and_check(p, path);
134     free(path);
135     if (!root) return(0);
136    
137     config_get_str(&str, root, NULL);
138 wcc 1.14 partymember_printf(p, "Old value: '%s'", str);
139 stdarg 1.11 config_set_str(next, root, NULL);
140     config_get_str(&str, root, NULL);
141 wcc 1.14 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 stdarg 1.2 return(0);
158     }
159    
160 stdarg 1.6 static int party_save(partymember_t *p, const char *nick, user_t *u, const char *cmd, const char *text)
161 stdarg 1.2 {
162 stdarg 1.11 putlog(LOG_MISC, "*", "Saving user file...");
163 stdarg 1.5 user_save(core_config.userfile);
164 stdarg 1.11 putlog(LOG_MISC, "*", "Saving config file...");
165 stdarg 1.2 core_config_save();
166     return(1);
167     }
168    
169 stdarg 1.5 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 wcc 1.12 partymember_printf(p, "Please use at least 6 characters.");
173 stdarg 1.5 return(0);
174     }
175     user_set_pass(p->user, text);
176 wcc 1.12 partymember_printf(p, "Changed password to '%s'.", text);
177 stdarg 1.5 return(0);
178     }
179    
180 stdarg 1.7 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 wcc 1.12 partymember_printf(p, "Partyline members:");
191 stdarg 1.7 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 stdarg 1.8 partymember_printf(p, " [%5d] %s (%s@%s)", who->pid, who->nick, who->ident, who->host);
196 stdarg 1.7 }
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 wcc 1.12 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 wcc 1.14 flushlogs();
213     unlink(pid_file);
214 stdarg 1.7 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 wcc 1.12 if (newuser) partymember_printf(p, "User '%s' created.", text);
231     else partymember_printf(p, "Could not create user '%s'.", text);
232 stdarg 1.7 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 wcc 1.12 if (!who) partymember_printf(p, "User '%s' not found.");
245 stdarg 1.7 else {
246 wcc 1.12 partymember_printf(p, "Deleting user '%s'.", who->handle);
247 stdarg 1.7 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 stdarg 1.9 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 wcc 1.14 if (!chan || !*chan) {
273 stdarg 1.10 if (who) free(who);
274 stdarg 1.9 partymember_printf(p, "Syntax: chattr <user> [channel] <+/-flags>");
275     return(0);
276     }
277 wcc 1.14 if (!flags || !*flags) {
278 stdarg 1.9 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 wcc 1.12 partymember_printf(p, "Flags for %s are now '%s'.", who, flagstr);
287 stdarg 1.9 }
288     else {
289 wcc 1.12 partymember_printf(p, "'%s' is not a valid user.", who);
290 stdarg 1.9 }
291     free(who);
292     free(flags);
293     if (chan) free(chan);
294     return(0);
295     }
296    
297 wcc 1.12 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 stdarg 1.1 static bind_list_t core_party_binds[] = {
310 stdarg 1.6 {NULL, "join", party_join},
311 wcc 1.12 {NULL, "whisper", party_whisper},
312 stdarg 1.6 {NULL, "newpass", party_newpass},
313     {NULL, "part", party_part},
314     {NULL, "quit", party_quit},
315 stdarg 1.7 {NULL, "who", party_who},
316 stdarg 1.11 {"n", "get", party_get},
317 stdarg 1.6 {"n", "set", party_set},
318 wcc 1.14 {"n", "status", party_status},
319 stdarg 1.6 {"n", "save", party_save},
320 stdarg 1.7 {"n", "die", party_die},
321     {"n", "+user", party_plus_user},
322     {"n", "-user", party_minus_user},
323 stdarg 1.11 {"n", "+host", party_plus_host},
324     {"n", "-host", party_minus_host},
325 stdarg 1.9 {"n", "chattr", party_chattr},
326 wcc 1.12 {"n", "modules", party_modules},
327     {"m", "+host", party_plus_host},
328     {"m", "-host", party_minus_host},
329 stdarg 1.1 {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