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