/[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.13 - (show annotations) (download) (as text)
Mon Dec 15 23:52:49 2003 UTC (15 years, 6 months ago) by stdarg
Branch: MAIN
Changes since 1.12: +20 -0 lines
File MIME type: text/x-chdr
* Whisper command for partyline messages (better name than .note?)
* egg_server_api.h contains the server module's api (as a test.. not done)

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23