Mercurial > pidgin
annotate src/protocols/irc/cmds.c @ 8351:ffa642240fc1
[gaim-migrate @ 9075]
marv is incredibly patient, waiting a long time for this to go in
you should all be using Jabber for file transfer anyway, but if you're
still stuck in the stone age, now you can transfer files via IRC
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 27 Feb 2004 01:45:26 +0000 |
parents | 7a6e30eb7aad |
children | 77baefe979c6 |
rev | line source |
---|---|
6333 | 1 /** |
2 * @file cmds.c | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 | |
23 #include "internal.h" | |
24 | |
25 #include "conversation.h" | |
26 #include "notify.h" | |
27 #include "debug.h" | |
28 #include "irc.h" | |
29 | |
30 | |
31 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops); | |
32 | |
33 int irc_cmd_default(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
34 { | |
35 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); | |
36 char *buf; | |
37 | |
38 if (!convo) | |
6350 | 39 return 1; |
6333 | 40 |
41 buf = g_strdup_printf(_("Unknown command: %s"), cmd); | |
42 if (gaim_conversation_get_type(convo) == GAIM_CONV_IM) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
43 gaim_conv_im_write(GAIM_CONV_IM(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 44 else |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
45 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 46 g_free(buf); |
47 | |
48 return 1; | |
49 } | |
50 | |
51 int irc_cmd_away(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
52 { | |
53 char *buf, *message, *cur; | |
54 | |
55 if (args[0] && strcmp(cmd, "back")) { | |
56 message = strdup(args[0]); | |
57 for (cur = message; *cur; cur++) { | |
58 if (*cur == '\n') | |
59 *cur = ' '; | |
60 } | |
61 buf = irc_format(irc, "v:", "AWAY", message); | |
62 g_free(message); | |
63 } else { | |
64 buf = irc_format(irc, "v", "AWAY"); | |
65 } | |
66 irc_send(irc, buf); | |
67 g_free(buf); | |
68 | |
69 return 0; | |
70 } | |
71 | |
72 int irc_cmd_ctcp_action(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
73 { | |
74 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
75 char *action, *dst, **newargs; | |
76 const char *src; | |
77 GaimConversation *convo; | |
78 | |
79 if (!args || !args[0] || !gc) | |
80 return 0; | |
81 | |
6376 | 82 action = g_malloc(strlen(args[0]) + 10); |
6333 | 83 |
84 sprintf(action, "\001ACTION "); | |
85 | |
86 src = args[0]; | |
87 dst = action + 8; | |
88 while (*src) { | |
89 if (*src == '\n') { | |
90 if (*(src + 1) == '\0') { | |
91 break; | |
92 } else { | |
93 *dst++ = ' '; | |
94 src++; | |
95 continue; | |
96 } | |
97 } | |
98 *dst++ = *src++; | |
99 } | |
100 *dst++ = '\001'; | |
101 *dst = '\0'; | |
102 | |
103 newargs = g_new0(char *, 2); | |
104 newargs[0] = g_strdup(target); | |
105 newargs[1] = action; | |
106 irc_cmd_privmsg(irc, cmd, target, (const char **)newargs); | |
107 g_free(newargs[0]); | |
108 g_free(newargs[1]); | |
109 g_free(newargs); | |
110 | |
111 convo = gaim_find_conversation_with_account(target, irc->account); | |
112 if (convo && gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) { | |
113 action = g_strdup_printf("/me %s", args[0]); | |
114 if (action[strlen(action) - 1] == '\n') | |
115 action[strlen(action) - 1] = '\0'; | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
116 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), |
6333 | 117 gaim_connection_get_display_name(gc), |
118 0, action, time(NULL)); | |
119 g_free(action); | |
120 } | |
121 | |
122 return 1; | |
123 } | |
124 | |
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
125 int irc_cmd_help(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
126 { |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
127 GaimConversation *convo = gaim_find_conversation_with_account(target, irc->account); |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
128 |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
129 /* XXX we should eventually have per-command help */ |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
130 |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
131 if (!convo) |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
132 return 0; |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
133 |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
134 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
135 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", _("<B>Supported IRC Commands:</B><BR>" |
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
136 "AWAY INVITE JOIN KICK<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
137 "ME MODE MSG NAMES<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
138 "NICK OP DEOP OPERWALL<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
139 "PART PING QUERY QUIT<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
140 "QUOTE REMOVE TOPIC UMODE<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
141 "VOICE DEVOICE WALLOPS WHOIS<BR>"), |
6621 | 142 GAIM_MESSAGE_NO_LOG, time(NULL)); |
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
143 } else { |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
144 gaim_conv_im_write(GAIM_CONV_IM(convo), "", _("<B>Supported IRC Commands:</B><BR>" |
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
145 "AWAY JOIN ME MODE<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
146 "MSG NICK OPERWALL PING<BR>" |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
147 "QUERY QUIT QUOTE UMODE<BR>" |
6982 | 148 "WALLOPS WHOIS"), GAIM_MESSAGE_NO_LOG, time(NULL)); |
6415
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
149 } |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
150 |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
151 return 0; |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
152 } |
e3be6b9744b7
[gaim-migrate @ 6922]
Christian Hammond <chipx86@chipx86.com>
parents:
6376
diff
changeset
|
153 |
6333 | 154 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
155 { | |
156 char *buf; | |
157 | |
158 if (!args || !args[0] || !(args[1] || target)) | |
159 return 0; | |
160 | |
161 buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
162 irc_send(irc, buf); | |
163 g_free(buf); | |
164 | |
165 return 0; | |
166 } | |
167 | |
168 int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
169 { | |
170 char *buf; | |
171 | |
172 if (!args || !args[0]) | |
173 return 0; | |
174 | |
175 if (args[1]) | |
176 buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
177 else | |
178 buf = irc_format(irc, "vc", "JOIN", args[0]); | |
179 irc_send(irc, buf); | |
180 g_free(buf); | |
181 | |
182 return 0; | |
183 } | |
184 | |
185 int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
186 { | |
187 char *buf; | |
188 GaimConversation *convo; | |
189 | |
190 if (!args || !args[0]) | |
191 return 0; | |
192 | |
193 convo = gaim_find_conversation_with_account(target, irc->account); | |
194 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
6350 | 195 return 0; |
6333 | 196 |
197 if (args[1]) | |
198 buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
199 else | |
200 buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
201 irc_send(irc, buf); | |
202 g_free(buf); | |
203 | |
204 return 0; | |
205 } | |
206 | |
8114 | 207 int irc_cmd_list(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
208 { | |
209 char *buf; | |
210 | |
211 buf = irc_format(irc, "v", "LIST"); | |
212 irc_send(irc, buf); | |
213 g_free(buf); | |
214 | |
215 return 0; | |
216 } | |
217 | |
6333 | 218 int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) |
219 { | |
220 GaimConnection *gc; | |
221 char *buf; | |
222 | |
223 if (!args) | |
224 return 0; | |
225 | |
226 if (!strcmp(cmd, "mode")) { | |
227 if (!args[0] && (*target == '#' || *target == '&')) | |
228 buf = irc_format(irc, "vc", "MODE", target); | |
229 else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
230 buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
231 else if (args[0]) | |
232 buf = irc_format(irc, "vv", "MODE", args[0]); | |
233 else | |
6350 | 234 return 0; |
6333 | 235 } else if (!strcmp(cmd, "umode")) { |
236 if (!args[0]) | |
6350 | 237 return 0; |
6333 | 238 gc = gaim_account_get_connection(irc->account); |
239 buf = irc_format(irc, "vnv", "MODE", gaim_connection_get_display_name(gc), args[0]); | |
6365 | 240 } else { |
241 return 0; | |
6333 | 242 } |
6365 | 243 |
6333 | 244 irc_send(irc, buf); |
245 g_free(buf); | |
246 | |
247 return 0; | |
248 } | |
249 | |
250 int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
251 { | |
252 char *buf; | |
253 | |
254 if (!args) | |
255 return 0; | |
256 | |
257 buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
258 irc_send(irc, buf); | |
259 g_free(buf); | |
260 | |
261 irc->nameconv = g_strdup(target); | |
262 | |
263 return 0; | |
264 } | |
265 | |
266 int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
267 { | |
268 char *buf; | |
269 | |
270 if (!args || !args[0]) | |
271 return 0; | |
272 | |
273 buf = irc_format(irc, "v:", "NICK", args[0]); | |
274 irc_send(irc, buf); | |
275 g_free(buf); | |
276 | |
277 return 0; | |
278 } | |
279 | |
280 int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
281 { | |
282 char **nicks, **ops, *sign, *mode; | |
283 int i = 0, used = 0; | |
284 | |
285 if (!args || !args[0] || !*args[0]) | |
286 return 0; | |
287 | |
288 if (!strcmp(cmd, "op")) { | |
289 sign = "+"; | |
290 mode = "o"; | |
291 } else if (!strcmp(cmd, "deop")) { | |
292 sign = "-"; | |
293 mode = "o"; | |
294 } else if (!strcmp(cmd, "voice")) { | |
295 sign = "+"; | |
296 mode = "v"; | |
297 } else if (!strcmp(cmd, "devoice")) { | |
298 sign = "-"; | |
299 mode = "v"; | |
300 } else { | |
301 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); | |
302 return 0; | |
303 } | |
304 | |
305 nicks = g_strsplit(args[0], " ", -1); | |
306 | |
307 for (i = 0; nicks[i]; i++) | |
308 /* nothing */; | |
309 ops = g_new0(char *, i * 2 + 1); | |
310 | |
311 for (i = 0; nicks[i]; i++) { | |
312 if (!*nicks[i]) | |
313 continue; | |
314 ops[used++] = mode; | |
315 ops[used++] = nicks[i]; | |
316 } | |
317 | |
318 irc_do_mode(irc, target, sign, ops); | |
319 g_free(ops); | |
320 | |
6350 | 321 return 0; |
6333 | 322 } |
323 | |
324 int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
325 { | |
326 char *buf; | |
327 | |
328 if (!args) | |
329 return 0; | |
330 | |
331 if (args[1]) | |
332 buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
333 else | |
334 buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
335 irc_send(irc, buf); | |
336 g_free(buf); | |
337 | |
338 return 0; | |
339 } | |
340 | |
341 int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
342 { | |
343 char *stamp; | |
344 char *buf; | |
345 | |
346 if (args && args[0]) { | |
347 if (*args[0] == '#' || *args[0] == '&') | |
348 return 0; | |
349 stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
350 buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
351 g_free(stamp); | |
352 } else { | |
6350 | 353 stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
6333 | 354 buf = irc_format(irc, "v:", "PING", stamp); |
355 g_free(stamp); | |
356 } | |
357 irc_send(irc, buf); | |
358 g_free(buf); | |
359 | |
360 return 0; | |
361 } | |
362 | |
363 int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
364 { | |
365 const char *cur, *end; | |
366 char *msg, *buf; | |
367 | |
368 if (!args || !args[0] || !args[1]) | |
369 return 0; | |
370 | |
371 cur = args[1]; | |
372 end = args[1]; | |
373 while (*end && *cur) { | |
374 end = strchr(cur, '\n'); | |
375 if (!end) | |
376 end = cur + strlen(cur); | |
377 msg = g_strndup(cur, end - cur); | |
378 buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
379 irc_send(irc, buf); | |
380 g_free(msg); | |
381 g_free(buf); | |
382 cur = end + 1; | |
383 } | |
384 | |
385 return 0; | |
386 } | |
387 | |
388 int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
389 { | |
390 char *buf; | |
391 | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6365
diff
changeset
|
392 buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : "Download Gaim: " GAIM_WEBSITE); |
6333 | 393 irc_send(irc, buf); |
394 g_free(buf); | |
395 | |
396 return 0; | |
397 } | |
398 | |
399 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
400 { | |
401 char *buf; | |
402 | |
403 if (!args || !args[0]) | |
404 return 0; | |
405 | |
406 buf = irc_format(irc, "v", args[0]); | |
407 irc_send(irc, buf); | |
408 g_free(buf); | |
409 | |
410 return 0; | |
411 } | |
412 | |
413 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
414 { | |
415 GaimConversation *convo; | |
416 GaimConnection *gc; | |
417 | |
418 if (!args || !args[0]) | |
419 return 0; | |
420 | |
421 convo = gaim_conversation_new(GAIM_CONV_IM, irc->account, args[0]); | |
422 | |
423 if (args[1]) { | |
424 gc = gaim_account_get_connection(irc->account); | |
425 irc_cmd_privmsg(irc, cmd, target, args); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
426 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), |
6982 | 427 args[1], GAIM_MESSAGE_SEND, time(NULL)); |
6333 | 428 } |
429 | |
430 return 0; | |
431 } | |
432 | |
433 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
434 { | |
435 char *buf; | |
436 | |
437 if (!args || !args[0]) | |
438 return 0; | |
439 | |
440 if (*target != '#' && *target != '&') /* not a channel, punt */ | |
441 return 0; | |
442 | |
443 if (args[1]) | |
444 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
445 else | |
446 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
447 irc_send(irc, buf); | |
448 g_free(buf); | |
449 | |
450 return 0; | |
451 } | |
452 | |
453 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
454 { | |
455 char *buf; | |
456 const char *topic; | |
457 GaimConversation *convo; | |
458 | |
459 if (!args) | |
460 return 0; | |
461 | |
462 convo = gaim_find_conversation_with_account(target, irc->account); | |
463 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
6350 | 464 return 0; |
6333 | 465 |
466 if (!args[0]) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
467 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(convo)); |
6333 | 468 |
469 if (topic) | |
6350 | 470 buf = g_strdup_printf(_("current topic is: %s"), topic); |
6333 | 471 else |
472 buf = g_strdup(_("No topic is set")); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
473 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), target, buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 474 g_free(buf); |
475 | |
476 return 0; | |
477 } | |
478 | |
479 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
480 irc_send(irc, buf); | |
481 g_free(buf); | |
482 | |
483 return 0; | |
484 } | |
485 | |
486 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
487 { | |
488 char *buf; | |
489 | |
490 if (!args || !args[0]) | |
6350 | 491 return 0; |
6333 | 492 |
493 if (!strcmp(cmd, "wallops")) | |
494 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
495 else if (!strcmp(cmd, "operwall")) | |
496 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
6365 | 497 else |
498 return 0; | |
6333 | 499 |
500 irc_send(irc, buf); | |
501 g_free(buf); | |
502 | |
503 return 0; | |
504 } | |
505 | |
506 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
507 { | |
508 char *buf; | |
509 | |
510 if (!args || !args[0]) | |
511 return 0; | |
512 | |
513 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
514 irc_send(irc, buf); | |
515 g_free(buf); | |
516 irc->whois.nick = g_strdup(args[0]); | |
517 | |
518 return 0; | |
519 } | |
520 | |
521 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
522 { | |
523 char *buf, mode[5]; | |
524 int i = 0; | |
525 | |
526 if (!sign) | |
527 return; | |
528 | |
529 while (ops[i]) { | |
530 if (ops[i + 2] && ops[i + 4]) { | |
531 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
532 ops[i], ops[i + 2], ops[i + 4]); | |
533 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
534 ops[i + 1], ops[i + 3], ops[i + 5]); | |
535 i += 6; | |
536 } else if (ops[i + 2]) { | |
537 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
538 sign, ops[i], ops[i + 2]); | |
539 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
540 ops[i + 1], ops[i + 3]); | |
541 i += 4; | |
542 } else { | |
543 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
544 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
545 i += 2; | |
546 } | |
547 irc_send(irc, buf); | |
548 g_free(buf); | |
549 } | |
6350 | 550 |
551 return; | |
6333 | 552 } |