/[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.12 - (hide annotations) (download) (as text)
Mon Dec 15 21:41:03 2003 UTC (15 years, 4 months ago) by wcc
Branch: MAIN
Changes since 1.11: +41 -17 lines
File MIME type: text/x-chdr
* Party commands.

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23