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