| |
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 #include "conversation.h" |
| |
26 #include "blist.h" |
| |
27 #include "notify.h" |
| |
28 #include "util.h" |
| |
29 #include "debug.h" |
| |
30 #include "irc.h" |
| |
31 |
| |
32 #include <stdio.h> |
| |
33 |
| |
34 static char *irc_mask_nick(const char *mask); |
| |
35 static char *irc_mask_userhost(const char *mask); |
| |
36 static void irc_chat_remove_buddy(GaimConversation *convo, char *data[2]); |
| |
37 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc); |
| |
38 |
| |
39 static void irc_msg_handle_privmsg(struct irc_conn *irc, const char *name, |
| |
40 const char *from, const char *to, |
| |
41 const char *rawmsg, gboolean notice); |
| |
42 |
| |
43 static char *irc_mask_nick(const char *mask) |
| |
44 { |
| |
45 char *end, *buf; |
| |
46 |
| |
47 end = strchr(mask, '!'); |
| |
48 if (!end) |
| |
49 buf = g_strdup(mask); |
| |
50 else |
| |
51 buf = g_strndup(mask, end - mask); |
| |
52 |
| |
53 return buf; |
| |
54 } |
| |
55 |
| |
56 static char *irc_mask_userhost(const char *mask) |
| |
57 { |
| |
58 return g_strdup(strchr(mask, '!') + 1); |
| |
59 } |
| |
60 |
| |
61 static void irc_chat_remove_buddy(GaimConversation *convo, char *data[2]) |
| |
62 { |
| |
63 char *message; |
| |
64 |
| |
65 message = g_strdup_printf("quit: %s", data[1]); |
| |
66 |
| |
67 if (gaim_conv_chat_find_user(GAIM_CONV_CHAT(convo), data[0])) |
| |
68 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), data[0], message); |
| |
69 |
| |
70 g_free(message); |
| |
71 } |
| |
72 |
| |
73 void irc_msg_default(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
74 { |
| |
75 gaim_debug(GAIM_DEBUG_INFO, "irc", "Unrecognized message: %s\n", args[0]); |
| |
76 } |
| |
77 |
| |
78 void irc_msg_away(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
79 { |
| |
80 GaimConnection *gc; |
| |
81 char *msg; |
| |
82 |
| |
83 if (!args || !args[1]) |
| |
84 return; |
| |
85 |
| |
86 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { |
| |
87 /* We're doing a whois, show this in the whois dialog */ |
| |
88 irc_msg_whois(irc, name, from, args); |
| |
89 return; |
| |
90 } |
| |
91 |
| |
92 gc = gaim_account_get_connection(irc->account); |
| |
93 if (gc) { |
| |
94 msg = g_markup_escape_text(args[2], -1); |
| |
95 serv_got_im(gc, args[1], msg, GAIM_MESSAGE_AUTO_RESP, time(NULL)); |
| |
96 g_free(msg); |
| |
97 } |
| |
98 } |
| |
99 |
| |
100 void irc_msg_badmode(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
101 { |
| |
102 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
103 |
| |
104 if (!args || !args[1] || !gc) |
| |
105 return; |
| |
106 |
| |
107 gaim_notify_error(gc, NULL, _("Bad mode"), args[1]); |
| |
108 } |
| |
109 |
| |
110 void irc_msg_banned(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
111 { |
| |
112 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
113 char *buf; |
| |
114 |
| |
115 if (!args || !args[1] || !gc) |
| |
116 return; |
| |
117 |
| |
118 buf = g_strdup_printf(_("You are banned from %s."), args[1]); |
| |
119 gaim_notify_error(gc, _("Banned"), _("Banned"), buf); |
| |
120 g_free(buf); |
| |
121 } |
| |
122 |
| |
123 void irc_msg_banfull(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
124 { |
| |
125 GaimConversation *convo; |
| |
126 char *buf, *nick; |
| |
127 |
| |
128 if (!args || !args[0] || !args[1] || !args[2]) |
| |
129 return; |
| |
130 |
| |
131 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); |
| |
132 if (!convo) |
| |
133 return; |
| |
134 |
| |
135 nick = g_markup_escape_text(args[2], -1); |
| |
136 buf = g_strdup_printf(_("Cannot ban %s: banlist is full"), nick); |
| |
137 g_free(nick); |
| |
138 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, |
| |
139 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, |
| |
140 time(NULL)); |
| |
141 g_free(buf); |
| |
142 } |
| |
143 |
| |
144 void irc_msg_chanmode(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
145 { |
| |
146 GaimConversation *convo; |
| |
147 char *buf, *escaped; |
| |
148 |
| |
149 if (!args || !args[1] || !args[2]) |
| |
150 return; |
| |
151 |
| |
152 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); |
| |
153 if (!convo) /* XXX punt on channels we are not in for now */ |
| |
154 return; |
| |
155 |
| |
156 escaped = (args[3] != NULL) ? g_markup_escape_text(args[3], -1) : NULL; |
| |
157 buf = g_strdup_printf("mode for %s: %s %s", args[1], args[2], escaped ? escaped : ""); |
| |
158 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
159 g_free(escaped); |
| |
160 g_free(buf); |
| |
161 |
| |
162 return; |
| |
163 } |
| |
164 |
| |
165 void irc_msg_whois(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
166 { |
| |
167 if (!irc->whois.nick) { |
| |
168 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Unexpected WHOIS reply for %s\n", args[1]); |
| |
169 return; |
| |
170 } |
| |
171 |
| |
172 if (gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { |
| |
173 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Got WHOIS reply for %s while waiting for %s\n", args[1], irc->whois.nick); |
| |
174 return; |
| |
175 } |
| |
176 |
| |
177 if (!strcmp(name, "301")) { |
| |
178 irc->whois.away = g_strdup(args[2]); |
| |
179 } else if (!strcmp(name, "311")) { |
| |
180 irc->whois.userhost = g_strdup_printf("%s@%s", args[2], args[3]); |
| |
181 irc->whois.name = g_strdup(args[5]); |
| |
182 } else if (!strcmp(name, "312")) { |
| |
183 irc->whois.server = g_strdup(args[2]); |
| |
184 irc->whois.serverinfo = g_strdup(args[3]); |
| |
185 } else if (!strcmp(name, "313")) { |
| |
186 irc->whois.ircop = 1; |
| |
187 } else if (!strcmp(name, "317")) { |
| |
188 irc->whois.idle = atoi(args[2]); |
| |
189 if (args[3]) |
| |
190 irc->whois.signon = (time_t)atoi(args[3]); |
| |
191 } else if (!strcmp(name, "319")) { |
| |
192 irc->whois.channels = g_strdup(args[2]); |
| |
193 } else if (!strcmp(name, "320")) { |
| |
194 irc->whois.identified = 1; |
| |
195 } |
| |
196 } |
| |
197 |
| |
198 void irc_msg_endwhois(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
199 { |
| |
200 GaimConnection *gc; |
| |
201 char *tmp, *tmp2; |
| |
202 GaimNotifyUserInfo *user_info; |
| |
203 |
| |
204 if (!irc->whois.nick) { |
| |
205 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Unexpected End of WHOIS for %s\n", args[1]); |
| |
206 return; |
| |
207 } |
| |
208 if (gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { |
| |
209 gaim_debug(GAIM_DEBUG_WARNING, "irc", "Received end of WHOIS for %s, expecting %s\n", args[1], irc->whois.nick); |
| |
210 return; |
| |
211 } |
| |
212 |
| |
213 user_info = gaim_notify_user_info_new(); |
| |
214 |
| |
215 tmp2 = g_markup_escape_text(args[1], -1); |
| |
216 tmp = g_strdup_printf("%s%s%s", tmp2, |
| |
217 (irc->whois.ircop ? _(" <i>(ircop)</i>") : ""), |
| |
218 (irc->whois.identified ? _(" <i>(identified)</i>") : "")); |
| |
219 gaim_notify_user_info_add_pair(user_info, _("Nick"), tmp); |
| |
220 g_free(tmp2); |
| |
221 g_free(tmp); |
| |
222 |
| |
223 if (irc->whois.away) { |
| |
224 tmp = g_markup_escape_text(irc->whois.away, strlen(irc->whois.away)); |
| |
225 g_free(irc->whois.away); |
| |
226 gaim_notify_user_info_add_pair(user_info, _("Away"), tmp); |
| |
227 g_free(tmp); |
| |
228 } |
| |
229 if (irc->whois.userhost) { |
| |
230 tmp = g_markup_escape_text(irc->whois.name, strlen(irc->whois.name)); |
| |
231 g_free(irc->whois.name); |
| |
232 gaim_notify_user_info_add_pair(user_info, _("Username"), irc->whois.userhost); |
| |
233 gaim_notify_user_info_add_pair(user_info, _("Real name"), tmp); |
| |
234 g_free(irc->whois.userhost); |
| |
235 g_free(tmp); |
| |
236 } |
| |
237 if (irc->whois.server) { |
| |
238 tmp = g_strdup_printf("%s (%s)", irc->whois.server, irc->whois.serverinfo); |
| |
239 gaim_notify_user_info_add_pair(user_info, _("Server"), tmp); |
| |
240 g_free(tmp); |
| |
241 g_free(irc->whois.server); |
| |
242 g_free(irc->whois.serverinfo); |
| |
243 } |
| |
244 if (irc->whois.channels) { |
| |
245 gaim_notify_user_info_add_pair(user_info, _("Currently on"), irc->whois.channels); |
| |
246 g_free(irc->whois.channels); |
| |
247 } |
| |
248 if (irc->whois.idle) { |
| |
249 gchar *timex = gaim_str_seconds_to_string(irc->whois.idle); |
| |
250 gaim_notify_user_info_add_pair(user_info, _("Idle for"), timex); |
| |
251 g_free(timex); |
| |
252 gaim_notify_user_info_add_pair(user_info, |
| |
253 _("Online since"), gaim_date_format_full(localtime(&irc->whois.signon))); |
| |
254 } |
| |
255 if (!strcmp(irc->whois.nick, "Paco-Paco")) { |
| |
256 gaim_notify_user_info_add_pair(user_info, |
| |
257 _("<b>Defining adjective:</b>"), _("Glorious")); |
| |
258 } |
| |
259 |
| |
260 gc = gaim_account_get_connection(irc->account); |
| |
261 |
| |
262 gaim_notify_userinfo(gc, irc->whois.nick, user_info, NULL, NULL); |
| |
263 gaim_notify_user_info_destroy(user_info); |
| |
264 |
| |
265 g_free(irc->whois.nick); |
| |
266 memset(&irc->whois, 0, sizeof(irc->whois)); |
| |
267 } |
| |
268 |
| |
269 void irc_msg_list(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
270 { |
| |
271 if (!irc->roomlist) |
| |
272 return; |
| |
273 |
| |
274 if (!strcmp(name, "321")) { |
| |
275 gaim_roomlist_set_in_progress(irc->roomlist, TRUE); |
| |
276 return; |
| |
277 } |
| |
278 |
| |
279 if (!strcmp(name, "323")) { |
| |
280 gaim_roomlist_set_in_progress(irc->roomlist, FALSE); |
| |
281 gaim_roomlist_unref(irc->roomlist); |
| |
282 irc->roomlist = NULL; |
| |
283 return; |
| |
284 } |
| |
285 |
| |
286 if (!strcmp(name, "322")) { |
| |
287 GaimRoomlistRoom *room; |
| |
288 |
| |
289 if (!args[0] || !args[1] || !args[2] || !args[3]) |
| |
290 return; |
| |
291 |
| |
292 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, args[1], NULL); |
| |
293 gaim_roomlist_room_add_field(irc->roomlist, room, args[1]); |
| |
294 gaim_roomlist_room_add_field(irc->roomlist, room, GINT_TO_POINTER(strtol(args[2], NULL, 10))); |
| |
295 gaim_roomlist_room_add_field(irc->roomlist, room, args[3]); |
| |
296 gaim_roomlist_room_add(irc->roomlist, room); |
| |
297 } |
| |
298 } |
| |
299 |
| |
300 void irc_msg_topic(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
301 { |
| |
302 char *chan, *topic, *msg, *nick, *tmp, *tmp2; |
| |
303 GaimConversation *convo; |
| |
304 |
| |
305 if (!strcmp(name, "topic")) { |
| |
306 chan = args[0]; |
| |
307 topic = irc_mirc2txt (args[1]); |
| |
308 } else { |
| |
309 chan = args[1]; |
| |
310 topic = irc_mirc2txt (args[2]); |
| |
311 } |
| |
312 |
| |
313 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, chan, irc->account); |
| |
314 if (!convo) { |
| |
315 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a topic for %s, which doesn't exist\n", chan); |
| |
316 g_free(topic); |
| |
317 return; |
| |
318 } |
| |
319 |
| |
320 /* If this is an interactive update, print it out */ |
| |
321 tmp = g_markup_escape_text(topic, -1); |
| |
322 tmp2 = gaim_markup_linkify(tmp); |
| |
323 g_free(tmp); |
| |
324 if (!strcmp(name, "topic")) { |
| |
325 const char *current_topic = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(convo)); |
| |
326 if (!(current_topic != NULL && strcmp(tmp2, current_topic) == 0)) |
| |
327 { |
| |
328 char *nick_esc; |
| |
329 nick = irc_mask_nick(from); |
| |
330 nick_esc = g_markup_escape_text(nick, -1); |
| |
331 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), nick, topic); |
| |
332 if (*tmp2) |
| |
333 msg = g_strdup_printf(_("%s has changed the topic to: %s"), nick_esc, tmp2); |
| |
334 else |
| |
335 msg = g_strdup_printf(_("%s has cleared the topic."), nick_esc); |
| |
336 g_free(nick_esc); |
| |
337 g_free(nick); |
| |
338 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), from, msg, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
339 g_free(msg); |
| |
340 } |
| |
341 } else { |
| |
342 char *chan_esc = g_markup_escape_text(chan, -1); |
| |
343 msg = g_strdup_printf(_("The topic for %s is: %s"), chan_esc, tmp2); |
| |
344 g_free(chan_esc); |
| |
345 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, topic); |
| |
346 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", msg, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
347 g_free(msg); |
| |
348 } |
| |
349 g_free(tmp2); |
| |
350 g_free(topic); |
| |
351 } |
| |
352 |
| |
353 void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
354 { |
| |
355 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
356 char *buf; |
| |
357 |
| |
358 if (!args || !args[1] || !gc) |
| |
359 return; |
| |
360 |
| |
361 buf = g_strdup_printf(_("Unknown message '%s'"), args[1]); |
| |
362 gaim_notify_error(gc, _("Unknown message"), buf, _("Gaim has sent a message the IRC server did not understand.")); |
| |
363 g_free(buf); |
| |
364 } |
| |
365 |
| |
366 void irc_msg_names(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
367 { |
| |
368 char *names, *cur, *end, *tmp, *msg; |
| |
369 GaimConversation *convo; |
| |
370 |
| |
371 if (!strcmp(name, "366")) { |
| |
372 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, irc->nameconv ? irc->nameconv : args[1], irc->account); |
| |
373 if (!convo) { |
| |
374 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a NAMES list for %s, which doesn't exist\n", args[1]); |
| |
375 g_string_free(irc->names, TRUE); |
| |
376 irc->names = NULL; |
| |
377 g_free(irc->nameconv); |
| |
378 irc->nameconv = NULL; |
| |
379 return; |
| |
380 } |
| |
381 |
| |
382 names = cur = g_string_free(irc->names, FALSE); |
| |
383 irc->names = NULL; |
| |
384 if (irc->nameconv) { |
| |
385 msg = g_strdup_printf(_("Users on %s: %s"), args[1], names ? names : ""); |
| |
386 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) |
| |
387 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
388 else |
| |
389 gaim_conv_im_write(GAIM_CONV_IM(convo), "", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
390 g_free(msg); |
| |
391 g_free(irc->nameconv); |
| |
392 irc->nameconv = NULL; |
| |
393 } else { |
| |
394 GList *users = NULL; |
| |
395 GList *flags = NULL; |
| |
396 |
| |
397 while (*cur) { |
| |
398 GaimConvChatBuddyFlags f = GAIM_CBFLAGS_NONE; |
| |
399 end = strchr(cur, ' '); |
| |
400 if (!end) |
| |
401 end = cur + strlen(cur); |
| |
402 if (*cur == '@') { |
| |
403 f = GAIM_CBFLAGS_OP; |
| |
404 cur++; |
| |
405 } else if (*cur == '%') { |
| |
406 f = GAIM_CBFLAGS_HALFOP; |
| |
407 cur++; |
| |
408 } else if(*cur == '+') { |
| |
409 f = GAIM_CBFLAGS_VOICE; |
| |
410 cur++; |
| |
411 } |
| |
412 tmp = g_strndup(cur, end - cur); |
| |
413 users = g_list_prepend(users, tmp); |
| |
414 flags = g_list_prepend(flags, GINT_TO_POINTER(f)); |
| |
415 cur = end; |
| |
416 if (*cur) |
| |
417 cur++; |
| |
418 } |
| |
419 |
| |
420 if (users != NULL) { |
| |
421 GList *l; |
| |
422 |
| |
423 gaim_conv_chat_add_users(GAIM_CONV_CHAT(convo), users, NULL, flags, FALSE); |
| |
424 |
| |
425 for (l = users; l != NULL; l = l->next) |
| |
426 g_free(l->data); |
| |
427 |
| |
428 g_list_free(users); |
| |
429 g_list_free(flags); |
| |
430 } |
| |
431 } |
| |
432 g_free(names); |
| |
433 } else { |
| |
434 if (!irc->names) |
| |
435 irc->names = g_string_new(""); |
| |
436 |
| |
437 if (irc->names->len && irc->names->str[irc->names->len - 1] != ' ') |
| |
438 irc->names = g_string_append_c(irc->names, ' '); |
| |
439 irc->names = g_string_append(irc->names, args[3]); |
| |
440 } |
| |
441 } |
| |
442 |
| |
443 void irc_msg_motd(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
444 { |
| |
445 GaimConnection *gc; |
| |
446 char *escaped; |
| |
447 if (!strcmp(name, "375")) { |
| |
448 gc = gaim_account_get_connection(irc->account); |
| |
449 if (gc) |
| |
450 gaim_connection_set_display_name(gc, args[0]); |
| |
451 } |
| |
452 |
| |
453 if (!irc->motd) |
| |
454 irc->motd = g_string_new(""); |
| |
455 |
| |
456 escaped = g_markup_escape_text(args[1], -1); |
| |
457 g_string_append_printf(irc->motd, "%s<br>", escaped); |
| |
458 g_free(escaped); |
| |
459 } |
| |
460 |
| |
461 void irc_msg_endmotd(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
462 { |
| |
463 GaimConnection *gc; |
| |
464 GaimStatus *status; |
| |
465 GaimBlistNode *gnode, *cnode, *bnode; |
| |
466 |
| |
467 gc = gaim_account_get_connection(irc->account); |
| |
468 if (!gc) |
| |
469 return; |
| |
470 |
| |
471 gaim_connection_set_state(gc, GAIM_CONNECTED); |
| |
472 |
| |
473 /* If we're away then set our away message */ |
| |
474 status = gaim_account_get_active_status(irc->account); |
| |
475 if (!gaim_status_get_type(status) != GAIM_STATUS_AVAILABLE) |
| |
476 { |
| |
477 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| |
478 prpl_info->set_status(irc->account, status); |
| |
479 } |
| |
480 |
| |
481 /* this used to be in the core, but it's not now */ |
| |
482 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
| |
483 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
| |
484 continue; |
| |
485 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| |
486 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) |
| |
487 continue; |
| |
488 for(bnode = cnode->child; bnode; bnode = bnode->next) { |
| |
489 GaimBuddy *b; |
| |
490 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) |
| |
491 continue; |
| |
492 b = (GaimBuddy *)bnode; |
| |
493 if(b->account == gc->account) { |
| |
494 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); |
| |
495 ib->name = g_strdup(b->name); |
| |
496 g_hash_table_insert(irc->buddies, ib->name, ib); |
| |
497 } |
| |
498 } |
| |
499 } |
| |
500 } |
| |
501 |
| |
502 irc_blist_timeout(irc); |
| |
503 if (!irc->timer) |
| |
504 irc->timer = gaim_timeout_add(45000, (GSourceFunc)irc_blist_timeout, (gpointer)irc); |
| |
505 } |
| |
506 |
| |
507 void irc_msg_time(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
508 { |
| |
509 GaimConnection *gc; |
| |
510 |
| |
511 gc = gaim_account_get_connection(irc->account); |
| |
512 if (gc == NULL || args == NULL || args[2] == NULL) |
| |
513 return; |
| |
514 |
| |
515 gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO, _("Time Response"), |
| |
516 _("The IRC server's local time is:"), |
| |
517 args[2], NULL, NULL); |
| |
518 } |
| |
519 |
| |
520 void irc_msg_nochan(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
521 { |
| |
522 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
523 |
| |
524 if (gc == NULL || args == NULL || args[1] == NULL) |
| |
525 return; |
| |
526 |
| |
527 gaim_notify_error(gc, NULL, _("No such channel"), args[1]); |
| |
528 } |
| |
529 |
| |
530 void irc_msg_nonick(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
531 { |
| |
532 GaimConnection *gc; |
| |
533 GaimConversation *convo; |
| |
534 |
| |
535 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, args[1], irc->account); |
| |
536 if (convo) { |
| |
537 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) /* does this happen? */ |
| |
538 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], _("no such channel"), |
| |
539 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
540 else |
| |
541 gaim_conv_im_write(GAIM_CONV_IM(convo), args[1], _("User is not logged in"), |
| |
542 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
543 } else { |
| |
544 if ((gc = gaim_account_get_connection(irc->account)) == NULL) |
| |
545 return; |
| |
546 gaim_notify_error(gc, NULL, _("No such nick or channel"), args[1]); |
| |
547 } |
| |
548 |
| |
549 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { |
| |
550 g_free(irc->whois.nick); |
| |
551 irc->whois.nick = NULL; |
| |
552 } |
| |
553 } |
| |
554 |
| |
555 void irc_msg_nosend(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
556 { |
| |
557 GaimConnection *gc; |
| |
558 GaimConversation *convo; |
| |
559 |
| |
560 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); |
| |
561 if (convo) { |
| |
562 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], args[2], GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
563 } else { |
| |
564 if ((gc = gaim_account_get_connection(irc->account)) == NULL) |
| |
565 return; |
| |
566 gaim_notify_error(gc, NULL, _("Could not send"), args[2]); |
| |
567 } |
| |
568 } |
| |
569 |
| |
570 void irc_msg_notinchan(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
571 { |
| |
572 GaimConversation *convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); |
| |
573 |
| |
574 gaim_debug(GAIM_DEBUG_INFO, "irc", "We're apparently not in %s, but tried to use it\n", args[1]); |
| |
575 if (convo) { |
| |
576 /*g_slist_remove(irc->gc->buddy_chats, convo); |
| |
577 gaim_conversation_set_account(convo, NULL);*/ |
| |
578 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], args[2], GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
579 } |
| |
580 } |
| |
581 |
| |
582 void irc_msg_notop(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
583 { |
| |
584 GaimConversation *convo; |
| |
585 |
| |
586 if (!args || !args[1] || !args[2]) |
| |
587 return; |
| |
588 |
| |
589 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); |
| |
590 if (!convo) |
| |
591 return; |
| |
592 |
| |
593 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", args[2], GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
594 } |
| |
595 |
| |
596 void irc_msg_invite(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
597 { |
| |
598 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
599 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
| |
600 char *nick = irc_mask_nick(from); |
| |
601 |
| |
602 if (!args || !args[1] || !gc) { |
| |
603 g_free(nick); |
| |
604 g_hash_table_destroy(components); |
| |
605 return; |
| |
606 } |
| |
607 |
| |
608 g_hash_table_insert(components, strdup("channel"), strdup(args[1])); |
| |
609 |
| |
610 serv_got_chat_invite(gc, args[1], nick, NULL, components); |
| |
611 g_free(nick); |
| |
612 } |
| |
613 |
| |
614 void irc_msg_inviteonly(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
615 { |
| |
616 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
617 char *buf; |
| |
618 |
| |
619 if (!args || !args[1] || !gc) |
| |
620 return; |
| |
621 |
| |
622 buf = g_strdup_printf(_("Joining %s requires an invitation."), args[1]); |
| |
623 gaim_notify_error(gc, _("Invitation only"), _("Invitation only"), buf); |
| |
624 g_free(buf); |
| |
625 } |
| |
626 |
| |
627 void irc_msg_ison(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
628 { |
| |
629 char **nicks; |
| |
630 struct irc_buddy *ib; |
| |
631 int i; |
| |
632 |
| |
633 if (!args || !args[1]) |
| |
634 return; |
| |
635 |
| |
636 nicks = g_strsplit(args[1], " ", -1); |
| |
637 |
| |
638 for (i = 0; nicks[i]; i++) { |
| |
639 if ((ib = g_hash_table_lookup(irc->buddies, (gconstpointer)nicks[i])) == NULL) { |
| |
640 continue; |
| |
641 } |
| |
642 ib->flag = TRUE; |
| |
643 } |
| |
644 |
| |
645 g_strfreev(nicks); |
| |
646 |
| |
647 g_hash_table_foreach(irc->buddies, (GHFunc)irc_buddy_status, (gpointer)irc); |
| |
648 } |
| |
649 |
| |
650 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc) |
| |
651 { |
| |
652 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
653 GaimBuddy *buddy = gaim_find_buddy(irc->account, name); |
| |
654 |
| |
655 if (!gc || !buddy) |
| |
656 return; |
| |
657 |
| |
658 if (ib->online && !ib->flag) { |
| |
659 gaim_prpl_got_user_status(irc->account, name, "offline", NULL); |
| |
660 ib->online = FALSE; |
| |
661 } else if (!ib->online && ib->flag) { |
| |
662 gaim_prpl_got_user_status(irc->account, name, "available", NULL); |
| |
663 ib->online = TRUE; |
| |
664 } |
| |
665 } |
| |
666 |
| |
667 void irc_msg_join(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
668 { |
| |
669 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
670 GaimConversation *convo; |
| |
671 char *nick = irc_mask_nick(from), *userhost; |
| |
672 struct irc_buddy *ib; |
| |
673 static int id = 1; |
| |
674 |
| |
675 if (!gc) { |
| |
676 g_free(nick); |
| |
677 return; |
| |
678 } |
| |
679 |
| |
680 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { |
| |
681 /* We are joining a channel for the first time */ |
| |
682 serv_got_joined_chat(gc, id++, args[0]); |
| |
683 g_free(nick); |
| |
684 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, |
| |
685 args[0], |
| |
686 irc->account); |
| |
687 if (convo == NULL) { |
| |
688 gaim_debug_error("irc", "tried to join %s but couldn't\n", args[0]); |
| |
689 return; |
| |
690 } |
| |
691 gaim_conversation_present(convo); |
| |
692 return; |
| |
693 } |
| |
694 |
| |
695 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); |
| |
696 if (convo == NULL) { |
| |
697 gaim_debug(GAIM_DEBUG_ERROR, "irc", "JOIN for %s failed\n", args[0]); |
| |
698 g_free(nick); |
| |
699 return; |
| |
700 } |
| |
701 |
| |
702 userhost = irc_mask_userhost(from); |
| |
703 gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo), nick, userhost, GAIM_CBFLAGS_NONE, TRUE); |
| |
704 |
| |
705 if ((ib = g_hash_table_lookup(irc->buddies, nick)) != NULL) { |
| |
706 ib->flag = TRUE; |
| |
707 irc_buddy_status(nick, ib, irc); |
| |
708 } |
| |
709 |
| |
710 g_free(userhost); |
| |
711 g_free(nick); |
| |
712 } |
| |
713 |
| |
714 void irc_msg_kick(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 = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); |
| |
718 char *nick = irc_mask_nick(from), *buf; |
| |
719 |
| |
720 if (!gc) { |
| |
721 g_free(nick); |
| |
722 return; |
| |
723 } |
| |
724 |
| |
725 if (!convo) { |
| |
726 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Recieved a KICK for unknown channel %s\n", args[0]); |
| |
727 g_free(nick); |
| |
728 return; |
| |
729 } |
| |
730 |
| |
731 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), args[1])) { |
| |
732 buf = g_strdup_printf(_("You have been kicked by %s: (%s)"), nick, args[2]); |
| |
733 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
734 g_free(buf); |
| |
735 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo))); |
| |
736 } else { |
| |
737 buf = g_strdup_printf(_("Kicked by %s (%s)"), nick, args[2]); |
| |
738 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), args[1], buf); |
| |
739 g_free(buf); |
| |
740 } |
| |
741 |
| |
742 g_free(nick); |
| |
743 return; |
| |
744 } |
| |
745 |
| |
746 void irc_msg_mode(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
747 { |
| |
748 GaimConversation *convo; |
| |
749 char *nick = irc_mask_nick(from), *buf; |
| |
750 |
| |
751 if (*args[0] == '#' || *args[0] == '&') { /* Channel */ |
| |
752 char *escaped; |
| |
753 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); |
| |
754 if (!convo) { |
| |
755 gaim_debug(GAIM_DEBUG_ERROR, "irc", "MODE received for %s, which we are not in\n", args[0]); |
| |
756 g_free(nick); |
| |
757 return; |
| |
758 } |
| |
759 escaped = (args[2] != NULL) ? g_markup_escape_text(args[2], -1) : NULL; |
| |
760 buf = g_strdup_printf(_("mode (%s %s) by %s"), args[1], escaped ? escaped : "", nick); |
| |
761 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
762 g_free(escaped); |
| |
763 g_free(buf); |
| |
764 if(args[2]) { |
| |
765 GaimConvChatBuddyFlags newflag, flags; |
| |
766 char *mcur, *cur, *end, *user; |
| |
767 gboolean add = FALSE; |
| |
768 mcur = args[1]; |
| |
769 cur = args[2]; |
| |
770 while (*cur && *mcur) { |
| |
771 if ((*mcur == '+') || (*mcur == '-')) { |
| |
772 add = (*mcur == '+') ? TRUE : FALSE; |
| |
773 mcur++; |
| |
774 continue; |
| |
775 } |
| |
776 end = strchr(cur, ' '); |
| |
777 if (!end) |
| |
778 end = cur + strlen(cur); |
| |
779 user = g_strndup(cur, end - cur); |
| |
780 flags = gaim_conv_chat_user_get_flags(GAIM_CONV_CHAT(convo), user); |
| |
781 newflag = GAIM_CBFLAGS_NONE; |
| |
782 if (*mcur == 'o') |
| |
783 newflag = GAIM_CBFLAGS_OP; |
| |
784 else if (*mcur =='h') |
| |
785 newflag = GAIM_CBFLAGS_HALFOP; |
| |
786 else if (*mcur == 'v') |
| |
787 newflag = GAIM_CBFLAGS_VOICE; |
| |
788 if (newflag) { |
| |
789 if (add) |
| |
790 flags |= newflag; |
| |
791 else |
| |
792 flags &= ~newflag; |
| |
793 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(convo), user, flags); |
| |
794 } |
| |
795 g_free(user); |
| |
796 cur = end; |
| |
797 if (*cur) |
| |
798 cur++; |
| |
799 if (*mcur) |
| |
800 mcur++; |
| |
801 } |
| |
802 } |
| |
803 } else { /* User */ |
| |
804 } |
| |
805 g_free(nick); |
| |
806 } |
| |
807 |
| |
808 void irc_msg_nick(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
809 { |
| |
810 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
811 GaimConversation *conv; |
| |
812 GSList *chats; |
| |
813 char *nick = irc_mask_nick(from); |
| |
814 |
| |
815 if (!gc) { |
| |
816 g_free(nick); |
| |
817 return; |
| |
818 } |
| |
819 chats = gc->buddy_chats; |
| |
820 |
| |
821 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { |
| |
822 gaim_connection_set_display_name(gc, args[0]); |
| |
823 } |
| |
824 |
| |
825 while (chats) { |
| |
826 GaimConvChat *chat = GAIM_CONV_CHAT(chats->data); |
| |
827 /* This is ugly ... */ |
| |
828 if (gaim_conv_chat_find_user(chat, nick)) |
| |
829 gaim_conv_chat_rename_user(chat, nick, args[0]); |
| |
830 chats = chats->next; |
| |
831 } |
| |
832 |
| |
833 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, nick, |
| |
834 irc->account); |
| |
835 if (conv != NULL) |
| |
836 gaim_conversation_set_name(conv, args[0]); |
| |
837 |
| |
838 g_free(nick); |
| |
839 } |
| |
840 |
| |
841 void irc_msg_badnick(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
842 { |
| |
843 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
844 if (gaim_connection_get_state(gc) == GAIM_CONNECTED) { |
| |
845 gaim_notify_error(gc, _("Invalid nickname"), |
| |
846 _("Invalid nickname"), |
| |
847 _("Your selected nickname was rejected by the server. It probably contains invalid characters.")); |
| |
848 |
| |
849 } else { |
| |
850 gc->wants_to_die = TRUE; |
| |
851 gaim_connection_error(gaim_account_get_connection(irc->account), |
| |
852 _("Your selected account name was rejected by the server. It probably contains invalid characters.")); |
| |
853 } |
| |
854 } |
| |
855 |
| |
856 void irc_msg_nickused(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
857 { |
| |
858 char *newnick, *buf, *end; |
| |
859 |
| |
860 if (!args || !args[1]) |
| |
861 return; |
| |
862 |
| |
863 newnick = strdup(args[1]); |
| |
864 end = newnick + strlen(newnick) - 1; |
| |
865 /* try fallbacks */ |
| |
866 if((*end < '9') && (*end >= '1')) { |
| |
867 *end = *end + 1; |
| |
868 } else *end = '1'; |
| |
869 |
| |
870 buf = irc_format(irc, "vn", "NICK", newnick); |
| |
871 irc_send(irc, buf); |
| |
872 g_free(buf); |
| |
873 g_free(newnick); |
| |
874 } |
| |
875 |
| |
876 void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
877 { |
| |
878 if (!args || !args[0] || !args[1]) |
| |
879 return; |
| |
880 |
| |
881 irc_msg_handle_privmsg(irc, name, from, args[0], args[1], TRUE); |
| |
882 } |
| |
883 |
| |
884 void irc_msg_nochangenick(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
885 { |
| |
886 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
887 |
| |
888 if (!args || !args[2] || !gc) |
| |
889 return; |
| |
890 |
| |
891 gaim_notify_error(gc, _("Cannot change nick"), _("Could not change nick"), args[2]); |
| |
892 } |
| |
893 |
| |
894 void irc_msg_part(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
895 { |
| |
896 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
897 GaimConversation *convo; |
| |
898 char *nick, *msg; |
| |
899 |
| |
900 if (!args || !args[0] || !gc) |
| |
901 return; |
| |
902 |
| |
903 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); |
| |
904 if (!convo) { |
| |
905 gaim_debug(GAIM_DEBUG_INFO, "irc", "Got a PART on %s, which doesn't exist -- probably closed\n", args[0]); |
| |
906 return; |
| |
907 } |
| |
908 |
| |
909 nick = irc_mask_nick(from); |
| |
910 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { |
| |
911 char *escaped = g_markup_escape_text(args[1], -1); |
| |
912 msg = g_strdup_printf(_("You have parted the channel%s%s"), |
| |
913 (args[1] && *args[1]) ? ": " : "", |
| |
914 (escaped && *escaped) ? escaped : ""); |
| |
915 g_free(escaped); |
| |
916 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], msg, GAIM_MESSAGE_SYSTEM, time(NULL)); |
| |
917 g_free(msg); |
| |
918 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo))); |
| |
919 } else { |
| |
920 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), nick, args[1]); |
| |
921 } |
| |
922 g_free(nick); |
| |
923 } |
| |
924 |
| |
925 void irc_msg_ping(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
926 { |
| |
927 char *buf; |
| |
928 if (!args || !args[0]) |
| |
929 return; |
| |
930 |
| |
931 buf = irc_format(irc, "v:", "PONG", args[0]); |
| |
932 irc_send(irc, buf); |
| |
933 g_free(buf); |
| |
934 } |
| |
935 |
| |
936 void irc_msg_pong(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
937 { |
| |
938 GaimConversation *convo; |
| |
939 GaimConnection *gc; |
| |
940 char **parts, *msg; |
| |
941 time_t oldstamp; |
| |
942 |
| |
943 if (!args || !args[1]) |
| |
944 return; |
| |
945 |
| |
946 parts = g_strsplit(args[1], " ", 2); |
| |
947 |
| |
948 if (!parts[0] || !parts[1]) { |
| |
949 g_strfreev(parts); |
| |
950 return; |
| |
951 } |
| |
952 |
| |
953 if (sscanf(parts[1], "%lu", &oldstamp) != 1) { |
| |
954 msg = g_strdup(_("Error: invalid PONG from server")); |
| |
955 } else { |
| |
956 msg = g_strdup_printf(_("PING reply -- Lag: %lu seconds"), time(NULL) - oldstamp); |
| |
957 } |
| |
958 |
| |
959 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, parts[0], irc->account); |
| |
960 g_strfreev(parts); |
| |
961 if (convo) { |
| |
962 if (gaim_conversation_get_type (convo) == GAIM_CONV_TYPE_CHAT) |
| |
963 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "PONG", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
964 else |
| |
965 gaim_conv_im_write(GAIM_CONV_IM(convo), "PONG", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
| |
966 } else { |
| |
967 gc = gaim_account_get_connection(irc->account); |
| |
968 if (!gc) { |
| |
969 g_free(msg); |
| |
970 return; |
| |
971 } |
| |
972 gaim_notify_info(gc, NULL, "PONG", msg); |
| |
973 } |
| |
974 g_free(msg); |
| |
975 } |
| |
976 |
| |
977 void irc_msg_privmsg(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
978 { |
| |
979 if (!args || !args[0] || !args[1]) |
| |
980 return; |
| |
981 |
| |
982 irc_msg_handle_privmsg(irc, name, from, args[0], args[1], FALSE); |
| |
983 } |
| |
984 |
| |
985 static void irc_msg_handle_privmsg(struct irc_conn *irc, const char *name, const char *from, const char *to, const char *rawmsg, gboolean notice) |
| |
986 { |
| |
987 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
988 GaimConversation *convo; |
| |
989 char *tmp; |
| |
990 char *msg; |
| |
991 char *nick; |
| |
992 |
| |
993 if (!gc) |
| |
994 return; |
| |
995 |
| |
996 nick = irc_mask_nick(from); |
| |
997 tmp = irc_parse_ctcp(irc, nick, to, rawmsg, notice); |
| |
998 if (!tmp) { |
| |
999 g_free(nick); |
| |
1000 return; |
| |
1001 } |
| |
1002 |
| |
1003 msg = g_markup_escape_text(tmp, -1); |
| |
1004 g_free(tmp); |
| |
1005 |
| |
1006 tmp = irc_mirc2html(msg); |
| |
1007 g_free(msg); |
| |
1008 msg = tmp; |
| |
1009 if (notice) { |
| |
1010 tmp = g_strdup_printf("(notice) %s", msg); |
| |
1011 g_free(msg); |
| |
1012 msg = tmp; |
| |
1013 } |
| |
1014 |
| |
1015 if (!gaim_utf8_strcasecmp(to, gaim_connection_get_display_name(gc))) { |
| |
1016 serv_got_im(gc, nick, msg, 0, time(NULL)); |
| |
1017 } else { |
| |
1018 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, to, irc->account); |
| |
1019 if (convo) |
| |
1020 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), nick, 0, msg, time(NULL)); |
| |
1021 else |
| |
1022 gaim_debug_error("irc", "Got a %s on %s, which does not exist\n", |
| |
1023 notice ? "NOTICE" : "PRIVMSG", to); |
| |
1024 } |
| |
1025 g_free(msg); |
| |
1026 g_free(nick); |
| |
1027 } |
| |
1028 |
| |
1029 void irc_msg_regonly(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
1030 { |
| |
1031 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
1032 char *msg; |
| |
1033 |
| |
1034 if (!args || !args[1] || !args[2] || !gc) |
| |
1035 return; |
| |
1036 |
| |
1037 msg = g_strdup_printf(_("Cannot join %s:"), args[1]); |
| |
1038 gaim_notify_error(gc, _("Cannot join channel"), msg, args[2]); |
| |
1039 g_free(msg); |
| |
1040 } |
| |
1041 |
| |
1042 void irc_msg_quit(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
1043 { |
| |
1044 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
1045 struct irc_buddy *ib; |
| |
1046 char *data[2]; |
| |
1047 |
| |
1048 if (!args || !args[0] || !gc) |
| |
1049 return; |
| |
1050 |
| |
1051 data[0] = irc_mask_nick(from); |
| |
1052 data[1] = args[0]; |
| |
1053 /* XXX this should have an API, I shouldn't grab this directly */ |
| |
1054 g_slist_foreach(gc->buddy_chats, (GFunc)irc_chat_remove_buddy, data); |
| |
1055 |
| |
1056 if ((ib = g_hash_table_lookup(irc->buddies, data[0])) != NULL) { |
| |
1057 ib->flag = FALSE; |
| |
1058 irc_buddy_status(data[0], ib, irc); |
| |
1059 } |
| |
1060 g_free(data[0]); |
| |
1061 |
| |
1062 return; |
| |
1063 } |
| |
1064 |
| |
1065 void irc_msg_unavailable(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
1066 { |
| |
1067 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
1068 |
| |
1069 if (!args || !args[1]) |
| |
1070 return; |
| |
1071 |
| |
1072 gaim_notify_error(gc, NULL, _("Nick or channel is temporarily unavailable."), args[1]); |
| |
1073 } |
| |
1074 |
| |
1075 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
1076 { |
| |
1077 GaimConnection *gc = gaim_account_get_connection(irc->account); |
| |
1078 char *nick, *msg; |
| |
1079 |
| |
1080 if (!args || !args[0] || !gc) |
| |
1081 return; |
| |
1082 |
| |
1083 nick = irc_mask_nick(from); |
| |
1084 msg = g_strdup_printf (_("Wallops from %s"), nick); |
| |
1085 g_free(nick); |
| |
1086 gaim_notify_info(gc, NULL, msg, args[0]); |
| |
1087 g_free(msg); |
| |
1088 } |
| |
1089 |
| |
1090 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args) |
| |
1091 { |
| |
1092 return; |
| |
1093 } |