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