6333
|
1 /**
|
|
2 * @file msgs.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 /* XXX g_show_info_text */
|
|
26 #include "gaim.h"
|
|
27
|
|
28 #include "conversation.h"
|
|
29 #include "blist.h"
|
|
30 #include "notify.h"
|
|
31 #include "util.h"
|
|
32 #include "debug.h"
|
|
33 #include "irc.h"
|
|
34
|
|
35 #include <stdio.h>
|
|
36
|
|
37 static char *irc_mask_nick(const char *mask);
|
|
38 static char *irc_mask_userhost(const char *mask);
|
|
39 static void irc_chat_remove_buddy(GaimConversation *convo, char *data[2]);
|
|
40 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc);
|
|
41
|
|
42 static char *irc_mask_nick(const char *mask)
|
|
43 {
|
|
44 char *end, *buf;
|
|
45
|
|
46 end = strchr(mask, '!');
|
|
47 if (!end)
|
|
48 buf = g_strdup(mask);
|
|
49 else
|
|
50 buf = g_strndup(mask, end - mask);
|
|
51
|
|
52 return buf;
|
|
53 }
|
|
54
|
|
55 static char *irc_mask_userhost(const char *mask)
|
|
56 {
|
|
57 return g_strdup(strchr(mask, '!') + 1);
|
|
58 }
|
|
59
|
|
60 static void irc_chat_remove_buddy(GaimConversation *convo, char *data[2])
|
|
61 {
|
|
62 GList *users = gaim_chat_get_users(GAIM_CHAT(convo));
|
|
63 char *message = g_strdup_printf("quit: %s", data[1]);
|
|
64
|
|
65 if (g_list_find_custom(users, data[0], (GCompareFunc)(strcmp)))
|
|
66 gaim_chat_remove_user(GAIM_CHAT(convo), data[0], message);
|
|
67
|
|
68 g_free(message);
|
|
69 }
|
|
70
|
|
71 void irc_msg_default(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
72 {
|
|
73 gaim_debug(GAIM_DEBUG_INFO, "irc", "Unrecognized message: %s\n", args[0]);
|
|
74 }
|
|
75
|
|
76 void irc_msg_away(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
77 {
|
|
78 GaimConnection *gc;
|
|
79
|
|
80 if (!args || !args[1])
|
|
81 return;
|
|
82
|
|
83 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) {
|
|
84 /* We're doing a whois, show this in the whois dialog */
|
|
85 irc_msg_whois(irc, name, from, args);
|
|
86 return;
|
|
87 }
|
|
88
|
|
89 gc = gaim_account_get_connection(irc->account);
|
|
90 if (gc)
|
|
91 serv_got_im(gc, args[1], args[2], IM_FLAG_AWAY, time(NULL), -1);
|
|
92 }
|
|
93
|
|
94 void irc_msg_badmode(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
95 {
|
|
96 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
97
|
|
98 if (!args || !args[1] || !gc)
|
|
99 return;
|
|
100
|
|
101 gaim_notify_error(gc, NULL, _("Bad mode"), args[1]);
|
|
102 }
|
|
103
|
|
104 void irc_msg_banned(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
105 {
|
|
106 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
107 char *buf;
|
|
108
|
|
109 if (!args || !args[1] || !gc)
|
|
110 return;
|
|
111
|
|
112 buf = g_strdup_printf(_("You are banned from %s."), args[1]);
|
|
113 gaim_notify_error(gc, _("Banned"), _("Banned"), buf);
|
|
114 g_free(buf);
|
|
115 }
|
|
116
|
|
117 void irc_msg_chanmode(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
118 {
|
|
119 GaimConversation *convo;
|
|
120 char *buf;
|
|
121
|
|
122 if (!args || !args[1] || !args[2])
|
|
123 return;
|
|
124
|
|
125 convo = gaim_find_conversation_with_account(args[1], irc->account);
|
|
126 if (!convo) /* XXX punt on channels we are not in for now */
|
|
127 return;
|
|
128
|
|
129 buf = g_strdup_printf("mode for %s: %s %s", args[1], args[2], args[3] ? args[3] : "");
|
|
130 gaim_chat_write(GAIM_CHAT(convo), "", buf, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
131 g_free(buf);
|
|
132
|
|
133 return;
|
|
134 }
|
|
135
|
|
136 void irc_msg_whois(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
137 {
|
|
138 if (!irc->whois.nick) {
|
|
139 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Unexpected WHOIS reply for %s\n", args[1]);
|
|
140 return;
|
|
141 }
|
|
142
|
|
143 if (gaim_utf8_strcasecmp(irc->whois.nick, args[1])) {
|
|
144 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Got WHOIS reply for %s while waiting for %s\n", args[1], irc->whois.nick);
|
|
145 return;
|
|
146 }
|
|
147
|
|
148 if (!strcmp(name, "301")) {
|
|
149 irc->whois.away = g_strdup(args[2]);
|
|
150 } else if (!strcmp(name, "311")) {
|
|
151 irc->whois.userhost = g_strdup_printf("%s@%s", args[2], args[3]);
|
|
152 irc->whois.name = g_strdup(args[5]);
|
|
153 } else if (!strcmp(name, "312")) {
|
|
154 irc->whois.server = g_strdup(args[2]);
|
|
155 irc->whois.serverinfo = g_strdup(args[3]);
|
|
156 } else if (!strcmp(name, "313")) {
|
|
157 irc->whois.ircop = 1;
|
|
158 } else if (!strcmp(name, "317")) {
|
|
159 irc->whois.idle = atoi(args[2]);
|
|
160 if (args[3])
|
|
161 irc->whois.signon = (time_t)atoi(args[3]);
|
|
162 } else if (!strcmp(name, "319")) {
|
|
163 irc->whois.channels = g_strdup(args[2]);
|
|
164 } else if (!strcmp(name, "320")) {
|
|
165 irc->whois.identified = 1;
|
|
166 }
|
|
167 }
|
|
168
|
|
169 void irc_msg_endwhois(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
170 {
|
|
171 GaimConnection *gc;
|
|
172 GString *info;
|
|
173 char *str;
|
|
174
|
|
175 if (!irc->whois.nick) {
|
|
176 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Unexpected End of WHOIS for %s\n", args[1]);
|
|
177 return;
|
|
178 }
|
|
179 if (gaim_utf8_strcasecmp(irc->whois.nick, args[1])) {
|
|
180 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Received end of WHOIS for %s, expecting %s\n", args[1], irc->whois.nick);
|
|
181 return;
|
|
182 }
|
|
183
|
|
184 info = g_string_new("");
|
|
185 g_string_append_printf(info, "<b>%s:</b> %s%s%s<br>", _("Nick"), args[1],
|
|
186 irc->whois.ircop ? _(" <i>(ircop)</i>") : "",
|
|
187 irc->whois.identified ? _(" <i>(identified)</i>") : "");
|
|
188 if (irc->whois.away) {
|
|
189 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Away"), irc->whois.away);
|
|
190 g_free(irc->whois.away);
|
|
191 }
|
|
192 if (irc->whois.userhost) {
|
|
193 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Username"), irc->whois.userhost);
|
|
194 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Realname"), irc->whois.name);
|
|
195 g_free(irc->whois.userhost);
|
|
196 g_free(irc->whois.name);
|
|
197 }
|
|
198 if (irc->whois.server) {
|
|
199 g_string_append_printf(info, "<b>%s:</b> %s (%s)<br>", _("Server"), irc->whois.server, irc->whois.serverinfo);
|
|
200 g_free(irc->whois.server);
|
|
201 g_free(irc->whois.serverinfo);
|
|
202 }
|
|
203 if (irc->whois.channels) {
|
|
204 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Currently on"), irc->whois.channels);
|
|
205 g_free(irc->whois.channels);
|
|
206 }
|
|
207 if (irc->whois.idle) {
|
|
208 g_string_append_printf(info, _("<b>Idle for:</b> %d days, %02d:%02d:%02d<br>"),
|
|
209 irc->whois.idle / 86400, (irc->whois.idle % 86400) / 3600,
|
|
210 (irc->whois.idle % 3600) / 60, irc->whois.idle % 60);
|
|
211 g_string_append_printf(info, "<b>%s:</b> %s", _("Online since"), ctime(&irc->whois.signon));
|
|
212 }
|
|
213 if (!strcmp(irc->whois.nick, "Paco-Paco")) {
|
|
214 g_string_append_printf(info, _("<br><b>Defining adjective:</b> Glorious<br>"));
|
|
215 }
|
|
216
|
|
217 gc = gaim_account_get_connection(irc->account);
|
|
218 str = g_string_free(info, FALSE);
|
|
219 g_show_info_text(gc, irc->whois.nick, 2, str, NULL);
|
|
220 g_free(str);
|
|
221 memset(&irc->whois, 0, sizeof(irc->whois));
|
|
222 }
|
|
223
|
|
224 void irc_msg_topic(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
225 {
|
|
226 char *chan, *topic, *msg, *nick;
|
|
227 GaimConversation *convo;
|
|
228
|
|
229 if (!strcmp(name, "topic")) {
|
|
230 chan = args[0];
|
|
231 topic = args[1];
|
|
232 } else {
|
|
233 chan = args[1];
|
|
234 topic = args[2];
|
|
235 }
|
|
236
|
|
237 convo = gaim_find_conversation_with_account(chan, irc->account);
|
|
238 if (!convo) {
|
|
239 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a topic for %s, which doesn't exist\n", chan);
|
|
240 }
|
|
241 gaim_chat_set_topic(GAIM_CHAT(convo), NULL, topic);
|
|
242 /* If this is an interactive update, print it out */
|
|
243 if (!strcmp(name, "topic")) {
|
|
244 nick = irc_mask_nick(from);
|
|
245 msg = g_strdup_printf(_("%s has changed the topic to: %s"), nick, topic);
|
|
246 g_free(nick);
|
|
247 gaim_chat_write(GAIM_CHAT(convo), from, msg, WFLAG_SYSTEM, time(NULL));
|
|
248 g_free(msg);
|
|
249 } else {
|
|
250 msg = g_strdup_printf(_("The topic for %s is: %s"), chan, topic);
|
|
251 gaim_chat_write(GAIM_CHAT(convo), "", msg, WFLAG_SYSTEM, time(NULL));
|
|
252 g_free(msg);
|
|
253 }
|
|
254 }
|
|
255
|
|
256 void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
257 {
|
|
258 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
259 char *buf;
|
|
260
|
|
261 if (!args || !args[1] || !gc)
|
|
262 return;
|
|
263
|
|
264 buf = g_strdup_printf(_("Unknown message '%s'"), args[1]);
|
|
265 gaim_notify_error(gc, _("Unknown message"), buf, _("Gaim has sent a message the IRC server did not understand."));
|
|
266 g_free(buf);
|
|
267 }
|
|
268
|
|
269 void irc_msg_names(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
270 {
|
|
271 char *names, *cur, *end, *tmp, *msg;
|
|
272 GaimConversation *convo;
|
|
273
|
|
274 if (!strcmp(name, "366")) {
|
|
275 convo = gaim_find_conversation_with_account(irc->nameconv ? irc->nameconv : args[1], irc->account);
|
|
276 if (!convo) {
|
|
277 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a NAMES list for %s, which doesn't exist\n", args[2]);
|
|
278 g_string_free(irc->names, TRUE);
|
|
279 irc->names = NULL;
|
|
280 g_free(irc->nameconv);
|
|
281 irc->nameconv = NULL;
|
|
282 return;
|
|
283 }
|
|
284
|
|
285 names = cur = g_string_free(irc->names, FALSE);
|
|
286 irc->names = NULL;
|
|
287 if (irc->nameconv) {
|
|
288 msg = g_strdup_printf("Users on %s: %s", args[1], names);
|
|
289 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT)
|
|
290 gaim_chat_write(GAIM_CHAT(convo), "", msg, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
291 else
|
|
292 gaim_im_write(GAIM_IM(convo), "", msg, -1, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
293 g_free(msg);
|
|
294 g_free(irc->nameconv);
|
|
295 irc->nameconv = NULL;
|
|
296 } else {
|
|
297 while (*cur) {
|
|
298 end = strchr(cur, ' ');
|
|
299 if (!end)
|
|
300 end = cur + strlen(cur);
|
|
301 if (*cur == '@' || *cur == '%' || *cur == '+')
|
|
302 cur++;
|
|
303 tmp = g_strndup(cur, end - cur);
|
|
304 gaim_chat_add_user(GAIM_CHAT(convo), tmp, NULL);
|
|
305 g_free(tmp);
|
|
306 cur = end;
|
|
307 if (*cur)
|
|
308 cur++;
|
|
309 }
|
|
310 }
|
|
311 g_free(names);
|
|
312 } else {
|
|
313 if (!irc->names)
|
|
314 irc->names = g_string_new("");
|
|
315
|
|
316 irc->names = g_string_append(irc->names, args[3]);
|
|
317 }
|
|
318 }
|
|
319
|
|
320 void irc_msg_motd(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
321 {
|
|
322 GaimConnection *gc;
|
|
323 if (!strcmp(name, "375")) {
|
|
324 gc = gaim_account_get_connection(irc->account);
|
|
325 if (gc)
|
|
326 gaim_connection_set_display_name(gc, args[0]);
|
|
327 }
|
|
328
|
|
329 if (!irc->motd)
|
|
330 irc->motd = g_string_new("");
|
|
331
|
|
332 g_string_append_printf(irc->motd, "%s<br>", args[1]);
|
|
333 }
|
|
334
|
|
335 void irc_msg_endmotd(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
336 {
|
|
337 GaimConnection *gc;
|
|
338
|
|
339 gc = gaim_account_get_connection(irc->account);
|
|
340 if (!gc)
|
|
341 return;
|
|
342
|
|
343 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
|
344
|
|
345 irc_blist_timeout(irc);
|
|
346 irc->timer = g_timeout_add(45000, (GSourceFunc)irc_blist_timeout, (gpointer)irc);
|
|
347 }
|
|
348
|
|
349 void irc_msg_nonick(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
350 {
|
|
351 GaimConnection *gc;
|
|
352 GaimConversation *convo;
|
|
353
|
|
354 convo = gaim_find_conversation_with_account(args[1], irc->account);
|
|
355 if (convo) {
|
|
356 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) /* does this happen? */
|
|
357 gaim_chat_write(GAIM_CHAT(convo), args[1], _("no such channel"),
|
|
358 WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
359 else
|
|
360 gaim_im_write(GAIM_IM(convo), args[1], _("User is not logged in"), -1,
|
|
361 WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
362 } else {
|
|
363 if ((gc = gaim_account_get_connection(irc->account)) == NULL)
|
|
364 return;
|
|
365 gaim_notify_error(gc, NULL, _("No such nick or channel"), args[1]);
|
|
366 }
|
|
367
|
|
368 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) {
|
|
369 g_free(irc->whois.nick);
|
|
370 irc->whois.nick = NULL;
|
|
371 }
|
|
372 }
|
|
373
|
|
374 void irc_msg_nosend(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
375 {
|
|
376 GaimConnection *gc;
|
|
377 GaimConversation *convo;
|
|
378
|
|
379 convo = gaim_find_conversation_with_account(args[1], irc->account);
|
|
380 if (convo) {
|
|
381 gaim_chat_write(GAIM_CHAT(convo), args[1], args[2], WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
382 } else {
|
|
383 if ((gc = gaim_account_get_connection(irc->account)) == NULL)
|
|
384 return;
|
|
385 gaim_notify_error(gc, NULL, _("Could not send"), args[2]);
|
|
386 }
|
|
387 }
|
|
388
|
|
389 void irc_msg_notinchan(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
390 {
|
|
391 GaimConversation *convo = gaim_find_conversation_with_account(args[1], irc->account);
|
|
392
|
|
393 gaim_debug(GAIM_DEBUG_INFO, "irc", "We're apparently not in %s, but tried to use it\n", args[1]);
|
|
394 if (convo) {
|
|
395 /*g_slist_remove(irc->gc->buddy_chats, convo);
|
|
396 gaim_conversation_set_account(convo, NULL);*/
|
|
397 gaim_chat_write(GAIM_CHAT(convo), args[1], args[2], WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
398 }
|
|
399 }
|
|
400
|
|
401 void irc_msg_notop(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
402 {
|
|
403 GaimConversation *convo;
|
|
404
|
|
405 if (!args || !args[1] || !args[2])
|
|
406 return;
|
|
407
|
|
408 convo = gaim_find_conversation_with_account(args[1], irc->account);
|
|
409 if (!convo)
|
|
410 return;
|
|
411
|
|
412 gaim_chat_write(GAIM_CHAT(convo), "", args[2], WFLAG_SYSTEM, time(NULL));
|
|
413 }
|
|
414
|
|
415 void irc_msg_invite(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
416 {
|
|
417 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
418 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
419 char *nick = irc_mask_nick(from);
|
|
420
|
|
421 if (!args || !args[1] || !gc) {
|
|
422 g_free(nick);
|
|
423 g_hash_table_destroy(components);
|
|
424 return;
|
|
425 }
|
|
426
|
|
427 g_hash_table_insert(components, strdup("channel"), strdup(args[1]));
|
|
428
|
|
429 serv_got_chat_invite(gc, args[1], nick, NULL, components);
|
|
430 g_free(nick);
|
|
431 }
|
|
432
|
|
433 void irc_msg_inviteonly(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
434 {
|
|
435 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
436 char *buf;
|
|
437
|
|
438 if (!args || !args[1] || !gc)
|
|
439 return;
|
|
440
|
|
441 buf = g_strdup_printf(_("Joining %s requires an invitation."), args[1]);
|
|
442 gaim_notify_error(gc, _("Invitation only"), _("Invitation only"), buf);
|
|
443 g_free(buf);
|
|
444 }
|
|
445
|
|
446 void irc_msg_ison(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
447 {
|
|
448 char **nicks;
|
|
449 struct irc_buddy *ib;
|
|
450 int i;
|
|
451
|
|
452 if (!args || !args[1])
|
|
453 return;
|
|
454
|
|
455 nicks = g_strsplit(args[1], " ", -1);
|
|
456
|
|
457 for (i = 0; nicks[i]; i++) {
|
|
458 if ((ib = g_hash_table_lookup(irc->buddies, (gconstpointer)nicks[i])) == NULL) {
|
|
459 continue;
|
|
460 }
|
|
461 ib->flag = TRUE;
|
|
462 }
|
|
463
|
|
464 g_hash_table_foreach(irc->buddies, (GHFunc)irc_buddy_status, (gpointer)irc);
|
|
465 }
|
|
466
|
|
467 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc)
|
|
468 {
|
|
469 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
470 struct buddy *buddy = gaim_find_buddy(irc->account, name);
|
|
471
|
|
472 if (!gc || !buddy)
|
|
473 return;
|
|
474
|
|
475 if (ib->online && !ib->flag) {
|
|
476 serv_got_update(gc, buddy->name, 0, 0, 0, 0, 0);
|
|
477 ib->online = FALSE;
|
|
478 }
|
|
479
|
|
480 if (!ib->online && ib->flag) {
|
|
481 serv_got_update(gc, buddy->name, 1, 0, 0, 0, 0);
|
|
482 ib->online = TRUE;
|
|
483 }
|
|
484 }
|
|
485
|
|
486 void irc_msg_join(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
487 {
|
|
488 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
489 GaimConversation *convo;
|
|
490 char *nick = irc_mask_nick(from), *userhost;
|
|
491 static int id = 1;
|
|
492
|
|
493 if (!gc) {
|
|
494 g_free(nick);
|
|
495 return;
|
|
496 }
|
|
497
|
|
498 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) {
|
|
499 /* We are joining a channel for the first time */
|
|
500 serv_got_joined_chat(gc, id++, args[0]);
|
|
501 g_free(nick);
|
|
502 return;
|
|
503 }
|
|
504
|
|
505 convo = gaim_find_conversation_with_account(args[0], irc->account);
|
|
506 if (convo == NULL) {
|
|
507 gaim_debug(GAIM_DEBUG_ERROR, "irc", "JOIN for %s failed\n", args[0]);
|
|
508 g_free(nick);
|
|
509 return;
|
|
510 }
|
|
511
|
|
512 userhost = irc_mask_userhost(from);
|
|
513 gaim_chat_add_user(GAIM_CHAT(convo), nick, userhost);
|
|
514 g_free(userhost);
|
|
515 g_free(nick);
|
|
516 }
|
|
517
|
|
518 void irc_msg_kick(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
519 {
|
|
520 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
521 GaimConversation *convo = gaim_find_conversation_with_account(args[0], irc->account);
|
|
522 char *nick = irc_mask_nick(from), *buf;
|
|
523
|
|
524 if (!gc) {
|
|
525 g_free(nick);
|
|
526 return;
|
|
527 }
|
|
528
|
|
529 if (!convo) {
|
|
530 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Recieved a KICK for unknown channel %s\n", args[0]);
|
|
531 g_free(nick);
|
|
532 return;
|
|
533 }
|
|
534
|
|
535 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), args[1])) {
|
|
536 buf = g_strdup_printf(_("You have been kicked by %s: (%s)"), nick, args[2]);
|
|
537 gaim_chat_write(GAIM_CHAT(convo), args[0], buf, WFLAG_SYSTEM, time(NULL));
|
|
538 g_free(buf);
|
|
539 /*g_slist_remove(irc->gc->buddy_chats, convo);
|
|
540 gaim_conversation_set_account(convo, NULL);*/
|
|
541 /*g_list_free(gaim_chat_get_users(GAIM_CHAT(convo)));
|
|
542 gaim_chat_set_users(GAIM_CHAT(convo), NULL);*/
|
|
543 } else {
|
|
544 buf = g_strdup_printf(_("Kicked by %s (%s)"), nick, args[2]);
|
|
545 gaim_chat_remove_user(GAIM_CHAT(convo), args[1], buf);
|
|
546 g_free(buf);
|
|
547 }
|
|
548
|
|
549 g_free(nick);
|
|
550 return;
|
|
551 }
|
|
552
|
|
553 void irc_msg_mode(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
554 {
|
|
555 GaimConversation *convo;
|
|
556 char *nick = irc_mask_nick(from), *buf;
|
|
557
|
|
558 if (*args[0] == '#' || *args[0] == '&') { /* Channel */
|
|
559 convo = gaim_find_conversation_with_account(args[0], irc->account);
|
|
560 if (!convo) {
|
|
561 gaim_debug(GAIM_DEBUG_ERROR, "irc", "MODE received for %s, which we are not in\n", args[0]);
|
|
562 g_free(nick);
|
|
563 return;
|
|
564 }
|
|
565 buf = g_strdup_printf(_("mode (%s %s) by %s"), args[1], args[2] ? args[2] : "", nick);
|
|
566 gaim_chat_write(GAIM_CHAT(convo), args[0], buf, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
567 g_free(buf);
|
|
568 } else { /* User */
|
|
569 }
|
|
570 g_free(nick);
|
|
571 }
|
|
572
|
|
573 void irc_msg_nick(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
574 {
|
|
575 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
576 GSList *chats;
|
|
577 char *nick = irc_mask_nick(from);
|
|
578
|
|
579 if (!gc) {
|
|
580 g_free(nick);
|
|
581 return;
|
|
582 }
|
|
583 chats = gc->buddy_chats;
|
|
584
|
|
585 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) {
|
|
586 gaim_connection_set_display_name(gc, args[0]);
|
|
587 }
|
|
588
|
|
589 while (chats) {
|
|
590 GaimChat *chat = GAIM_CHAT(chats->data);
|
|
591 GList *users = gaim_chat_get_users(chat);
|
|
592
|
|
593 while (users) {
|
|
594 char *user = users->data;
|
|
595
|
|
596 if (!strcmp(nick, user)) {
|
|
597 gaim_chat_rename_user(chat, user, args[0]);
|
|
598 users = gaim_chat_get_users(chat);
|
|
599 break;
|
|
600 }
|
|
601 users = users->next;
|
|
602 }
|
|
603 chats = chats->next;
|
|
604 }
|
|
605 g_free(nick);
|
|
606 }
|
|
607
|
|
608 void irc_msg_nickused(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
609 {
|
|
610 char *newnick, *buf, *end;
|
|
611
|
|
612 if (!args || !args[1])
|
|
613 return;
|
|
614
|
|
615 newnick = strdup(args[1]);
|
|
616 end = newnick + strlen(newnick) - 1;
|
|
617 /* try three fallbacks */
|
|
618 if (*end == 2) *end = '3';
|
|
619 else if (*end == 1) *end = '2';
|
|
620 else *end = '1';
|
|
621
|
|
622 buf = irc_format(irc, "vn", "NICK", newnick);
|
|
623 irc_send(irc, buf);
|
|
624 g_free(buf);
|
|
625 }
|
|
626
|
|
627 void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
628 {
|
|
629 char *newargs[2];
|
|
630
|
|
631 newargs[0] = " notice "; /* The spaces are magic, leave 'em in! */
|
|
632 newargs[1] = args[1];
|
|
633 irc_msg_privmsg(irc, name, from, newargs);
|
|
634 }
|
|
635
|
|
636 void irc_msg_part(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
637 {
|
|
638 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
639 GaimConversation *convo;
|
|
640 char *nick, *msg;
|
|
641
|
|
642 if (!args || !args[0] || !args[1] || !gc)
|
|
643 return;
|
|
644
|
|
645 convo = gaim_find_conversation_with_account(args[0], irc->account);
|
|
646 if (!convo) {
|
|
647 gaim_debug(GAIM_DEBUG_INFO, "irc", "Got a PART on %s, which doesn't exist -- probably closed\n", args[0]);
|
|
648 return;
|
|
649 }
|
|
650
|
|
651 nick = irc_mask_nick(from);
|
|
652 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) {
|
|
653 msg = g_strdup_printf(_("You have parted the channel%s%s"), *args[1] ? ": " : "", args[1]);
|
|
654 gaim_chat_write(GAIM_CHAT(convo), args[0], msg, WFLAG_SYSTEM, time(NULL));
|
|
655 g_free(msg);
|
|
656 } else {
|
|
657 gaim_chat_remove_user(GAIM_CHAT(convo), nick, args[1]);
|
|
658 }
|
|
659 g_free(nick);
|
|
660 }
|
|
661
|
|
662 void irc_msg_ping(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
663 {
|
|
664 char *buf;
|
|
665 if (!args || !args[0])
|
|
666 return;
|
|
667
|
|
668 buf = irc_format(irc, "v:", "PONG", args[0]);
|
|
669 irc_send(irc, buf);
|
|
670 g_free(buf);
|
|
671 }
|
|
672
|
|
673 void irc_msg_pong(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
674 {
|
|
675 GaimConversation *convo;
|
|
676 GaimConnection *gc;
|
|
677 char **parts, *msg;
|
|
678 time_t oldstamp;
|
|
679
|
|
680 if (!args || !args[1])
|
|
681 return;
|
|
682
|
|
683 parts = g_strsplit(args[1], " ", 2);
|
|
684
|
|
685 if (!parts[0] || !parts[1]) {
|
|
686 g_strfreev(parts);
|
|
687 return;
|
|
688 }
|
|
689
|
|
690 if (sscanf(parts[1], "%lu", &oldstamp) != 1) {
|
|
691 msg = g_strdup(_("Error: invalid PONG from server"));
|
|
692 } else {
|
|
693 msg = g_strdup_printf(_("PING reply -- Lag: %d seconds"), time(NULL) - oldstamp);
|
|
694 }
|
|
695
|
|
696 convo = gaim_find_conversation_with_account(parts[0], irc->account);
|
|
697 g_strfreev(parts);
|
|
698 if (convo) {
|
|
699 if (gaim_conversation_get_type (convo) == GAIM_CONV_CHAT)
|
|
700 gaim_chat_write(GAIM_CHAT(convo), "PONG", msg, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
701 else
|
|
702 gaim_im_write(GAIM_IM(convo), "PONG", msg, -1, WFLAG_SYSTEM|WFLAG_NOLOG, time(NULL));
|
|
703 } else {
|
|
704 gc = gaim_account_get_connection(irc->account);
|
|
705 if (!gc) {
|
|
706 g_free(msg);
|
|
707 return;
|
|
708 }
|
|
709 gaim_notify_info(gc, NULL, "PONG", msg);
|
|
710 }
|
|
711 g_free(msg);
|
|
712 }
|
|
713
|
|
714 void irc_msg_privmsg(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
715 {
|
|
716 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
717 GaimConversation *convo;
|
|
718 char *nick = irc_mask_nick(from), *tmp, *msg;
|
|
719 int notice = 0;
|
|
720
|
|
721 if (!args || !args[0] || !args[1] || !gc) {
|
|
722 g_free(nick);
|
|
723 return;
|
|
724 }
|
|
725
|
|
726 notice = !strcmp(args[0], " notice ");
|
|
727 tmp = irc_parse_ctcp(irc, nick, args[0], args[1], notice);
|
|
728 if (!tmp) {
|
|
729 g_free(nick);
|
|
730 return;
|
|
731 }
|
|
732 msg = irc_mirc2html(tmp);
|
|
733 g_free(tmp);
|
|
734 if (notice) {
|
|
735 tmp = g_strdup_printf("(notice) %s", msg);
|
|
736 g_free(msg);
|
|
737 msg = tmp;
|
|
738 }
|
|
739
|
|
740 if (!gaim_utf8_strcasecmp(args[0], gaim_connection_get_display_name(gc))) {
|
|
741 serv_got_im(gc, nick, msg, 0, time(NULL), -1);
|
|
742 } else if (notice) {
|
|
743 serv_got_im(gc, nick, msg, 0, time(NULL), -1);
|
|
744 } else {
|
|
745 convo = gaim_find_conversation_with_account(args[0], irc->account);
|
|
746 if (convo)
|
|
747 serv_got_chat_in(gc, gaim_chat_get_id(GAIM_CHAT(convo)), nick, 0, msg, time(NULL));
|
|
748 else
|
|
749 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a PRIVMSG on %s, which does not exist\n", args[0]);
|
|
750 }
|
|
751 g_free(msg);
|
|
752 g_free(nick);
|
|
753 }
|
|
754
|
|
755 void irc_msg_quit(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
756 {
|
|
757 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
758 char *data[2];
|
|
759
|
|
760 if (!args || !args[0] || !gc)
|
|
761 return;
|
|
762
|
|
763 data[0] = irc_mask_nick(from);
|
|
764 data[1] = args[0];
|
|
765 /* XXX this should have an API, I shouldn't grab this directly */
|
|
766 g_slist_foreach(gc->buddy_chats, (GFunc)irc_chat_remove_buddy, data);
|
|
767 g_free(data[0]);
|
|
768
|
|
769 return;
|
|
770 }
|
|
771
|
|
772 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
773 {
|
|
774 GaimConnection *gc = gaim_account_get_connection(irc->account);
|
|
775 char *nick, *msg;
|
|
776
|
|
777 if (!args || !args[0] || !gc)
|
|
778 return;
|
|
779
|
|
780 nick = irc_mask_nick(from);
|
|
781 msg = g_strdup_printf (_("Wallops from %s"), nick);
|
|
782 g_free(nick);
|
|
783 gaim_notify_info(gc, NULL, msg, args[0]);
|
|
784 g_free(msg);
|
|
785 }
|
|
786
|
|
787 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args)
|
|
788 {
|
|
789 return;
|
|
790 }
|