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