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