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