Mercurial > pidgin.yaz
annotate src/protocols/irc/cmds.c @ 6371:8f94cce8faa5
[gaim-migrate @ 6876]
I think I touched almost every file. Here's what happened.
I started off fixing up the Makefile.am and configure.ac files to help with
the core/UI split some. Then I got annoyed with the
build_{allow,deny}_list() functions that everything used, and decided to
core/UI split privacy. While doing that, I decided to redesign the dialog.
So now, a lot has changed, but not really so much. Just that most files
got affected.
Oh yeah, and the UI stuff was taken out of internal.h and moved to
gtkinternal.h. If you use this, please be aware of this change.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 05 Aug 2003 10:55:04 +0000 |
parents | 72bbe310ac77 |
children | 05b488eda686 |
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) | |
43 gaim_im_write(GAIM_IM(convo), "", buf, -1, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL)); | |
44 else | |
45 gaim_chat_write(GAIM_CHAT(convo), "", buf, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL)); | |
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 | |
82 action = g_malloc(strlen(args[0]) + 9); | |
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'; | |
116 serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(convo)), | |
117 gaim_connection_get_display_name(gc), | |
118 0, action, time(NULL)); | |
119 g_free(action); | |
120 } | |
121 | |
122 return 1; | |
123 } | |
124 | |
125 int irc_cmd_invite(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
126 { | |
127 char *buf; | |
128 | |
129 if (!args || !args[0] || !(args[1] || target)) | |
130 return 0; | |
131 | |
132 buf = irc_format(irc, "vnc", "INVITE", args[0], args[1] ? args[1] : target); | |
133 irc_send(irc, buf); | |
134 g_free(buf); | |
135 | |
136 return 0; | |
137 } | |
138 | |
139 int irc_cmd_join(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
140 { | |
141 char *buf; | |
142 | |
143 if (!args || !args[0]) | |
144 return 0; | |
145 | |
146 if (args[1]) | |
147 buf = irc_format(irc, "vcv", "JOIN", args[0], args[1]); | |
148 else | |
149 buf = irc_format(irc, "vc", "JOIN", args[0]); | |
150 irc_send(irc, buf); | |
151 g_free(buf); | |
152 | |
153 return 0; | |
154 } | |
155 | |
156 int irc_cmd_kick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
157 { | |
158 char *buf; | |
159 GaimConversation *convo; | |
160 | |
161 if (!args || !args[0]) | |
162 return 0; | |
163 | |
164 convo = gaim_find_conversation_with_account(target, irc->account); | |
165 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
6350 | 166 return 0; |
6333 | 167 |
168 if (args[1]) | |
169 buf = irc_format(irc, "vcn:", "KICK", target, args[0], args[1]); | |
170 else | |
171 buf = irc_format(irc, "vcn", "KICK", target, args[0]); | |
172 irc_send(irc, buf); | |
173 g_free(buf); | |
174 | |
175 return 0; | |
176 } | |
177 | |
178 int irc_cmd_mode(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
179 { | |
180 GaimConnection *gc; | |
181 char *buf; | |
182 | |
183 if (!args) | |
184 return 0; | |
185 | |
186 if (!strcmp(cmd, "mode")) { | |
187 if (!args[0] && (*target == '#' || *target == '&')) | |
188 buf = irc_format(irc, "vc", "MODE", target); | |
189 else if (args[0] && (*args[0] == '+' || *args[0] == '-')) | |
190 buf = irc_format(irc, "vcv", "MODE", target, args[0]); | |
191 else if (args[0]) | |
192 buf = irc_format(irc, "vv", "MODE", args[0]); | |
193 else | |
6350 | 194 return 0; |
6333 | 195 } else if (!strcmp(cmd, "umode")) { |
196 if (!args[0]) | |
6350 | 197 return 0; |
6333 | 198 gc = gaim_account_get_connection(irc->account); |
199 buf = irc_format(irc, "vnv", "MODE", gaim_connection_get_display_name(gc), args[0]); | |
6365 | 200 } else { |
201 return 0; | |
6333 | 202 } |
6365 | 203 |
6333 | 204 irc_send(irc, buf); |
205 g_free(buf); | |
206 | |
207 return 0; | |
208 } | |
209 | |
210 int irc_cmd_names(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
211 { | |
212 char *buf; | |
213 | |
214 if (!args) | |
215 return 0; | |
216 | |
217 buf = irc_format(irc, "vc", "NAMES", args[0] ? args[0] : target); | |
218 irc_send(irc, buf); | |
219 g_free(buf); | |
220 | |
221 irc->nameconv = g_strdup(target); | |
222 | |
223 return 0; | |
224 } | |
225 | |
226 int irc_cmd_nick(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
227 { | |
228 char *buf; | |
229 | |
230 if (!args || !args[0]) | |
231 return 0; | |
232 | |
233 buf = irc_format(irc, "v:", "NICK", args[0]); | |
234 irc_send(irc, buf); | |
235 g_free(buf); | |
236 | |
237 return 0; | |
238 } | |
239 | |
240 int irc_cmd_op(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
241 { | |
242 char **nicks, **ops, *sign, *mode; | |
243 int i = 0, used = 0; | |
244 | |
245 if (!args || !args[0] || !*args[0]) | |
246 return 0; | |
247 | |
248 if (!strcmp(cmd, "op")) { | |
249 sign = "+"; | |
250 mode = "o"; | |
251 } else if (!strcmp(cmd, "deop")) { | |
252 sign = "-"; | |
253 mode = "o"; | |
254 } else if (!strcmp(cmd, "voice")) { | |
255 sign = "+"; | |
256 mode = "v"; | |
257 } else if (!strcmp(cmd, "devoice")) { | |
258 sign = "-"; | |
259 mode = "v"; | |
260 } else { | |
261 gaim_debug(GAIM_DEBUG_ERROR, "irc", "invalid 'op' command '%s'\n", cmd); | |
262 return 0; | |
263 } | |
264 | |
265 nicks = g_strsplit(args[0], " ", -1); | |
266 | |
267 for (i = 0; nicks[i]; i++) | |
268 /* nothing */; | |
269 ops = g_new0(char *, i * 2 + 1); | |
270 | |
271 for (i = 0; nicks[i]; i++) { | |
272 if (!*nicks[i]) | |
273 continue; | |
274 ops[used++] = mode; | |
275 ops[used++] = nicks[i]; | |
276 } | |
277 | |
278 irc_do_mode(irc, target, sign, ops); | |
279 g_free(ops); | |
280 | |
6350 | 281 return 0; |
6333 | 282 } |
283 | |
284 int irc_cmd_part(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
285 { | |
286 char *buf; | |
287 | |
288 if (!args) | |
289 return 0; | |
290 | |
291 if (args[1]) | |
292 buf = irc_format(irc, "vc:", "PART", args[0] ? args[0] : target, args[1]); | |
293 else | |
294 buf = irc_format(irc, "vc", "PART", args[0] ? args[0] : target); | |
295 irc_send(irc, buf); | |
296 g_free(buf); | |
297 | |
298 return 0; | |
299 } | |
300 | |
301 int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
302 { | |
303 char *stamp; | |
304 char *buf; | |
305 | |
306 if (args && args[0]) { | |
307 if (*args[0] == '#' || *args[0] == '&') | |
308 return 0; | |
309 stamp = g_strdup_printf("\001PING %lu\001", time(NULL)); | |
310 buf = irc_format(irc, "vn:", "PRIVMSG", args[0], stamp); | |
311 g_free(stamp); | |
312 } else { | |
6350 | 313 stamp = g_strdup_printf("%s %lu", target, time(NULL)); |
6333 | 314 buf = irc_format(irc, "v:", "PING", stamp); |
315 g_free(stamp); | |
316 } | |
317 irc_send(irc, buf); | |
318 g_free(buf); | |
319 | |
320 return 0; | |
321 } | |
322 | |
323 int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
324 { | |
325 const char *cur, *end; | |
326 char *msg, *buf; | |
327 | |
328 if (!args || !args[0] || !args[1]) | |
329 return 0; | |
330 | |
331 cur = args[1]; | |
332 end = args[1]; | |
333 while (*end && *cur) { | |
334 end = strchr(cur, '\n'); | |
335 if (!end) | |
336 end = cur + strlen(cur); | |
337 msg = g_strndup(cur, end - cur); | |
338 buf = irc_format(irc, "vt:", "PRIVMSG", args[0], msg); | |
339 irc_send(irc, buf); | |
340 g_free(msg); | |
341 g_free(buf); | |
342 cur = end + 1; | |
343 } | |
344 | |
345 return 0; | |
346 } | |
347 | |
348 int irc_cmd_quit(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
349 { | |
350 char *buf; | |
351 | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6365
diff
changeset
|
352 buf = irc_format(irc, "v:", "QUIT", (args && args[0]) ? args[0] : "Download Gaim: " GAIM_WEBSITE); |
6333 | 353 irc_send(irc, buf); |
354 g_free(buf); | |
355 | |
356 return 0; | |
357 } | |
358 | |
359 int irc_cmd_quote(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
360 { | |
361 char *buf; | |
362 | |
363 if (!args || !args[0]) | |
364 return 0; | |
365 | |
366 buf = irc_format(irc, "v", args[0]); | |
367 irc_send(irc, buf); | |
368 g_free(buf); | |
369 | |
370 return 0; | |
371 } | |
372 | |
373 int irc_cmd_query(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
374 { | |
375 GaimConversation *convo; | |
376 GaimConnection *gc; | |
377 | |
378 if (!args || !args[0]) | |
379 return 0; | |
380 | |
381 convo = gaim_conversation_new(GAIM_CONV_IM, irc->account, args[0]); | |
382 | |
383 if (args[1]) { | |
384 gc = gaim_account_get_connection(irc->account); | |
385 irc_cmd_privmsg(irc, cmd, target, args); | |
386 gaim_im_write(GAIM_IM(convo), gaim_connection_get_display_name(gc), | |
387 args[1], -1, WFLAG_SEND, time(NULL)); | |
388 } | |
389 | |
390 return 0; | |
391 } | |
392 | |
393 int irc_cmd_remove(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
394 { | |
395 char *buf; | |
396 | |
397 if (!args || !args[0]) | |
398 return 0; | |
399 | |
400 if (*target != '#' && *target != '&') /* not a channel, punt */ | |
401 return 0; | |
402 | |
403 if (args[1]) | |
404 buf = irc_format(irc, "vcn:", "REMOVE", target, args[0], args[1]); | |
405 else | |
406 buf = irc_format(irc, "vcn", "REMOVE", target, args[0]); | |
407 irc_send(irc, buf); | |
408 g_free(buf); | |
409 | |
410 return 0; | |
411 } | |
412 | |
413 int irc_cmd_topic(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
414 { | |
415 char *buf; | |
416 const char *topic; | |
417 GaimConversation *convo; | |
418 | |
419 if (!args) | |
420 return 0; | |
421 | |
422 convo = gaim_find_conversation_with_account(target, irc->account); | |
423 if (!convo || gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
6350 | 424 return 0; |
6333 | 425 |
426 if (!args[0]) { | |
427 topic = gaim_chat_get_topic (GAIM_CHAT(convo)); | |
428 | |
429 if (topic) | |
6350 | 430 buf = g_strdup_printf(_("current topic is: %s"), topic); |
6333 | 431 else |
432 buf = g_strdup(_("No topic is set")); | |
433 gaim_chat_write(GAIM_CHAT(convo), target, buf, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL)); | |
434 g_free(buf); | |
435 | |
436 return 0; | |
437 } | |
438 | |
439 buf = irc_format(irc, "vt:", "TOPIC", target, args[0]); | |
440 irc_send(irc, buf); | |
441 g_free(buf); | |
442 | |
443 return 0; | |
444 } | |
445 | |
446 int irc_cmd_wallops(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
447 { | |
448 char *buf; | |
449 | |
450 if (!args || !args[0]) | |
6350 | 451 return 0; |
6333 | 452 |
453 if (!strcmp(cmd, "wallops")) | |
454 buf = irc_format(irc, "v:", "WALLOPS", args[0]); | |
455 else if (!strcmp(cmd, "operwall")) | |
456 buf = irc_format(irc, "v:", "OPERWALL", args[0]); | |
6365 | 457 else |
458 return 0; | |
6333 | 459 |
460 irc_send(irc, buf); | |
461 g_free(buf); | |
462 | |
463 return 0; | |
464 } | |
465 | |
466 int irc_cmd_whois(struct irc_conn *irc, const char *cmd, const char *target, const char **args) | |
467 { | |
468 char *buf; | |
469 | |
470 if (!args || !args[0]) | |
471 return 0; | |
472 | |
473 buf = irc_format(irc, "vn", "WHOIS", args[0]); | |
474 irc_send(irc, buf); | |
475 g_free(buf); | |
476 irc->whois.nick = g_strdup(args[0]); | |
477 | |
478 return 0; | |
479 } | |
480 | |
481 static void irc_do_mode(struct irc_conn *irc, const char *target, const char *sign, char **ops) | |
482 { | |
483 char *buf, mode[5]; | |
484 int i = 0; | |
485 | |
486 if (!sign) | |
487 return; | |
488 | |
489 while (ops[i]) { | |
490 if (ops[i + 2] && ops[i + 4]) { | |
491 g_snprintf(mode, sizeof(mode), "%s%s%s%s", sign, | |
492 ops[i], ops[i + 2], ops[i + 4]); | |
493 buf = irc_format(irc, "vcvnnn", "MODE", target, mode, | |
494 ops[i + 1], ops[i + 3], ops[i + 5]); | |
495 i += 6; | |
496 } else if (ops[i + 2]) { | |
497 g_snprintf(mode, sizeof(mode), "%s%s%s", | |
498 sign, ops[i], ops[i + 2]); | |
499 buf = irc_format(irc, "vcvnn", "MODE", target, mode, | |
500 ops[i + 1], ops[i + 3]); | |
501 i += 4; | |
502 } else { | |
503 g_snprintf(mode, sizeof(mode), "%s%s", sign, ops[i]); | |
504 buf = irc_format(irc, "vcvn", "MODE", target, mode, ops[i + 1]); | |
505 i += 2; | |
506 } | |
507 irc_send(irc, buf); | |
508 g_free(buf); | |
509 } | |
6350 | 510 |
511 return; | |
6333 | 512 } |