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