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