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