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