Mercurial > pidgin
annotate src/protocols/irc/msgs.c @ 7877:828856b7fe30
[gaim-migrate @ 8531]
I suppose IRC should handle 403 (no such channel)
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Sun, 14 Dec 2003 23:20:41 +0000 |
parents | bf630f7dfdcd |
children | 7a6e30eb7aad |
rev | line source |
---|---|
6333 | 1 /** |
2 * @file msgs.c | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 | |
23 #include "internal.h" | |
24 | |
25 #include "conversation.h" | |
26 #include "blist.h" | |
27 #include "notify.h" | |
28 #include "util.h" | |
29 #include "debug.h" | |
30 #include "irc.h" | |
31 | |
32 #include <stdio.h> | |
33 | |
34 static char *irc_mask_nick(const char *mask); | |
35 static char *irc_mask_userhost(const char *mask); | |
36 static void irc_chat_remove_buddy(GaimConversation *convo, char *data[2]); | |
37 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc); | |
38 | |
39 static char *irc_mask_nick(const char *mask) | |
40 { | |
41 char *end, *buf; | |
42 | |
43 end = strchr(mask, '!'); | |
44 if (!end) | |
45 buf = g_strdup(mask); | |
46 else | |
47 buf = g_strndup(mask, end - mask); | |
48 | |
49 return buf; | |
50 } | |
51 | |
52 static char *irc_mask_userhost(const char *mask) | |
53 { | |
54 return g_strdup(strchr(mask, '!') + 1); | |
55 } | |
56 | |
57 static void irc_chat_remove_buddy(GaimConversation *convo, char *data[2]) | |
58 { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
59 GList *users = gaim_conv_chat_get_users(GAIM_CONV_CHAT(convo)); |
6333 | 60 char *message = g_strdup_printf("quit: %s", data[1]); |
61 | |
62 if (g_list_find_custom(users, data[0], (GCompareFunc)(strcmp))) | |
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(""); | |
183 g_string_append_printf(info, "<b>%s:</b> %s%s%s<br>", _("Nick"), args[1], | |
184 irc->whois.ircop ? _(" <i>(ircop)</i>") : "", | |
185 irc->whois.identified ? _(" <i>(identified)</i>") : ""); | |
186 if (irc->whois.away) { | |
187 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Away"), irc->whois.away); | |
188 g_free(irc->whois.away); | |
189 } | |
190 if (irc->whois.userhost) { | |
191 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Username"), irc->whois.userhost); | |
192 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Realname"), irc->whois.name); | |
193 g_free(irc->whois.userhost); | |
194 g_free(irc->whois.name); | |
195 } | |
196 if (irc->whois.server) { | |
197 g_string_append_printf(info, "<b>%s:</b> %s (%s)<br>", _("Server"), irc->whois.server, irc->whois.serverinfo); | |
198 g_free(irc->whois.server); | |
199 g_free(irc->whois.serverinfo); | |
200 } | |
201 if (irc->whois.channels) { | |
202 g_string_append_printf(info, "<b>%s:</b> %s<br>", _("Currently on"), irc->whois.channels); | |
203 g_free(irc->whois.channels); | |
204 } | |
205 if (irc->whois.idle) { | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7062
diff
changeset
|
206 gchar *timex = gaim_str_seconds_to_string(irc->whois.idle); |
6357 | 207 g_string_append_printf(info, _("<b>Idle for:</b> %s<br>"), timex); |
208 g_free(timex); | |
6333 | 209 g_string_append_printf(info, "<b>%s:</b> %s", _("Online since"), ctime(&irc->whois.signon)); |
210 } | |
211 if (!strcmp(irc->whois.nick, "Paco-Paco")) { | |
212 g_string_append_printf(info, _("<br><b>Defining adjective:</b> Glorious<br>")); | |
213 } | |
214 | |
215 gc = gaim_account_get_connection(irc->account); | |
216 str = g_string_free(info, FALSE); | |
7062
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
217 |
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
218 g_snprintf(buffer, sizeof(buffer), |
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
219 _("Buddy Information for %s"), irc->whois.nick); |
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
220 gaim_notify_formatted(gc, NULL, buffer, NULL, str, NULL, NULL); |
86ed8b2aa665
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
221 |
6333 | 222 g_free(str); |
223 memset(&irc->whois, 0, sizeof(irc->whois)); | |
224 } | |
225 | |
226 void irc_msg_topic(struct irc_conn *irc, const char *name, const char *from, char **args) | |
227 { | |
228 char *chan, *topic, *msg, *nick; | |
229 GaimConversation *convo; | |
230 | |
231 if (!strcmp(name, "topic")) { | |
232 chan = args[0]; | |
233 topic = args[1]; | |
234 } else { | |
235 chan = args[1]; | |
236 topic = args[2]; | |
237 } | |
238 | |
239 convo = gaim_find_conversation_with_account(chan, irc->account); | |
240 if (!convo) { | |
241 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a topic for %s, which doesn't exist\n", chan); | |
242 } | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
243 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, topic); |
6333 | 244 /* If this is an interactive update, print it out */ |
245 if (!strcmp(name, "topic")) { | |
246 nick = irc_mask_nick(from); | |
247 msg = g_strdup_printf(_("%s has changed the topic to: %s"), nick, topic); | |
248 g_free(nick); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
249 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), from, msg, GAIM_MESSAGE_SYSTEM, time(NULL)); |
6333 | 250 g_free(msg); |
251 } else { | |
252 msg = g_strdup_printf(_("The topic for %s is: %s"), chan, topic); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
253 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", msg, GAIM_MESSAGE_SYSTEM, time(NULL)); |
6333 | 254 g_free(msg); |
255 } | |
256 } | |
257 | |
258 void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args) | |
259 { | |
260 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
261 char *buf; | |
262 | |
263 if (!args || !args[1] || !gc) | |
264 return; | |
265 | |
266 buf = g_strdup_printf(_("Unknown message '%s'"), args[1]); | |
267 gaim_notify_error(gc, _("Unknown message"), buf, _("Gaim has sent a message the IRC server did not understand.")); | |
268 g_free(buf); | |
269 } | |
270 | |
271 void irc_msg_names(struct irc_conn *irc, const char *name, const char *from, char **args) | |
272 { | |
273 char *names, *cur, *end, *tmp, *msg; | |
274 GaimConversation *convo; | |
275 | |
276 if (!strcmp(name, "366")) { | |
277 convo = gaim_find_conversation_with_account(irc->nameconv ? irc->nameconv : args[1], irc->account); | |
278 if (!convo) { | |
279 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a NAMES list for %s, which doesn't exist\n", args[2]); | |
280 g_string_free(irc->names, TRUE); | |
281 irc->names = NULL; | |
282 g_free(irc->nameconv); | |
283 irc->nameconv = NULL; | |
284 return; | |
285 } | |
286 | |
287 names = cur = g_string_free(irc->names, FALSE); | |
288 irc->names = NULL; | |
289 if (irc->nameconv) { | |
290 msg = g_strdup_printf("Users on %s: %s", args[1], names); | |
291 if (gaim_conversation_get_type(convo) == GAIM_CONV_CHAT) | |
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|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 293 else |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
294 gaim_conv_im_write(GAIM_CONV_IM(convo), "", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 295 g_free(msg); |
296 g_free(irc->nameconv); | |
297 irc->nameconv = NULL; | |
298 } else { | |
6407
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
299 GList *users = NULL; |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
300 |
6333 | 301 while (*cur) { |
302 end = strchr(cur, ' '); | |
303 if (!end) | |
304 end = cur + strlen(cur); | |
305 if (*cur == '@' || *cur == '%' || *cur == '+') | |
306 cur++; | |
307 tmp = g_strndup(cur, end - cur); | |
6407
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
308 users = g_list_append(users, tmp); |
6333 | 309 cur = end; |
310 if (*cur) | |
311 cur++; | |
312 } | |
6407
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
313 |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
314 if (users != NULL) { |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
315 GList *l; |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
316 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
317 gaim_conv_chat_add_users(GAIM_CONV_CHAT(convo), users); |
6407
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
318 |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
319 for (l = users; l != NULL; l = l->next) |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
320 g_free(l->data); |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
321 |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
322 g_list_free(users); |
ba0b99a72be2
[gaim-migrate @ 6913]
Christian Hammond <chipx86@chipx86.com>
parents:
6357
diff
changeset
|
323 } |
6333 | 324 } |
325 g_free(names); | |
326 } else { | |
327 if (!irc->names) | |
328 irc->names = g_string_new(""); | |
329 | |
330 irc->names = g_string_append(irc->names, args[3]); | |
331 } | |
332 } | |
333 | |
334 void irc_msg_motd(struct irc_conn *irc, const char *name, const char *from, char **args) | |
335 { | |
336 GaimConnection *gc; | |
337 if (!strcmp(name, "375")) { | |
338 gc = gaim_account_get_connection(irc->account); | |
339 if (gc) | |
340 gaim_connection_set_display_name(gc, args[0]); | |
341 } | |
342 | |
343 if (!irc->motd) | |
344 irc->motd = g_string_new(""); | |
345 | |
346 g_string_append_printf(irc->motd, "%s<br>", args[1]); | |
347 } | |
348 | |
349 void irc_msg_endmotd(struct irc_conn *irc, const char *name, const char *from, char **args) | |
350 { | |
351 GaimConnection *gc; | |
352 | |
353 gc = gaim_account_get_connection(irc->account); | |
354 if (!gc) | |
355 return; | |
356 | |
357 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
358 | |
359 irc_blist_timeout(irc); | |
360 irc->timer = g_timeout_add(45000, (GSourceFunc)irc_blist_timeout, (gpointer)irc); | |
361 } | |
362 | |
7877 | 363 void irc_msg_nochan(struct irc_conn *irc, const char *name, const char *from, char **args) |
364 { | |
365 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
366 | |
367 if (gc == NULL || args == NULL || args[1] == NULL) | |
368 return; | |
369 | |
370 gaim_notify_error(gc, NULL, _("No such channel"), args[1]); | |
371 } | |
372 | |
6333 | 373 void irc_msg_nonick(struct irc_conn *irc, const char *name, const char *from, char **args) |
374 { | |
375 GaimConnection *gc; | |
376 GaimConversation *convo; | |
377 | |
378 convo = gaim_find_conversation_with_account(args[1], irc->account); | |
379 if (convo) { | |
380 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
|
381 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], _("no such channel"), |
6621 | 382 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 383 else |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
384 gaim_conv_im_write(GAIM_CONV_IM(convo), args[1], _("User is not logged in"), |
6621 | 385 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 386 } else { |
387 if ((gc = gaim_account_get_connection(irc->account)) == NULL) | |
388 return; | |
389 gaim_notify_error(gc, NULL, _("No such nick or channel"), args[1]); | |
390 } | |
391 | |
392 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { | |
393 g_free(irc->whois.nick); | |
394 irc->whois.nick = NULL; | |
395 } | |
396 } | |
397 | |
398 void irc_msg_nosend(struct irc_conn *irc, const char *name, const char *from, char **args) | |
399 { | |
400 GaimConnection *gc; | |
401 GaimConversation *convo; | |
402 | |
403 convo = gaim_find_conversation_with_account(args[1], irc->account); | |
404 if (convo) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
405 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], args[2], GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 406 } else { |
407 if ((gc = gaim_account_get_connection(irc->account)) == NULL) | |
408 return; | |
409 gaim_notify_error(gc, NULL, _("Could not send"), args[2]); | |
410 } | |
411 } | |
412 | |
413 void irc_msg_notinchan(struct irc_conn *irc, const char *name, const char *from, char **args) | |
414 { | |
415 GaimConversation *convo = gaim_find_conversation_with_account(args[1], irc->account); | |
416 | |
417 gaim_debug(GAIM_DEBUG_INFO, "irc", "We're apparently not in %s, but tried to use it\n", args[1]); | |
418 if (convo) { | |
419 /*g_slist_remove(irc->gc->buddy_chats, convo); | |
420 gaim_conversation_set_account(convo, NULL);*/ | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
421 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], args[2], GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 422 } |
423 } | |
424 | |
425 void irc_msg_notop(struct irc_conn *irc, const char *name, const char *from, char **args) | |
426 { | |
427 GaimConversation *convo; | |
428 | |
429 if (!args || !args[1] || !args[2]) | |
430 return; | |
431 | |
432 convo = gaim_find_conversation_with_account(args[1], irc->account); | |
433 if (!convo) | |
434 return; | |
435 | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
436 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", args[2], GAIM_MESSAGE_SYSTEM, time(NULL)); |
6333 | 437 } |
438 | |
439 void irc_msg_invite(struct irc_conn *irc, const char *name, const char *from, char **args) | |
440 { | |
441 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
442 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
443 char *nick = irc_mask_nick(from); | |
444 | |
445 if (!args || !args[1] || !gc) { | |
446 g_free(nick); | |
447 g_hash_table_destroy(components); | |
448 return; | |
449 } | |
450 | |
451 g_hash_table_insert(components, strdup("channel"), strdup(args[1])); | |
452 | |
453 serv_got_chat_invite(gc, args[1], nick, NULL, components); | |
454 g_free(nick); | |
455 } | |
456 | |
457 void irc_msg_inviteonly(struct irc_conn *irc, const char *name, const char *from, char **args) | |
458 { | |
459 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
460 char *buf; | |
461 | |
462 if (!args || !args[1] || !gc) | |
463 return; | |
464 | |
465 buf = g_strdup_printf(_("Joining %s requires an invitation."), args[1]); | |
466 gaim_notify_error(gc, _("Invitation only"), _("Invitation only"), buf); | |
467 g_free(buf); | |
468 } | |
469 | |
470 void irc_msg_ison(struct irc_conn *irc, const char *name, const char *from, char **args) | |
471 { | |
472 char **nicks; | |
473 struct irc_buddy *ib; | |
474 int i; | |
475 | |
476 if (!args || !args[1]) | |
477 return; | |
478 | |
479 nicks = g_strsplit(args[1], " ", -1); | |
480 | |
481 for (i = 0; nicks[i]; i++) { | |
482 if ((ib = g_hash_table_lookup(irc->buddies, (gconstpointer)nicks[i])) == NULL) { | |
483 continue; | |
484 } | |
485 ib->flag = TRUE; | |
486 } | |
487 | |
6350 | 488 g_strfreev(nicks); |
489 | |
6333 | 490 g_hash_table_foreach(irc->buddies, (GHFunc)irc_buddy_status, (gpointer)irc); |
491 } | |
492 | |
493 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc) | |
494 { | |
495 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
6695 | 496 GaimBuddy *buddy = gaim_find_buddy(irc->account, name); |
6333 | 497 |
498 if (!gc || !buddy) | |
499 return; | |
500 | |
501 if (ib->online && !ib->flag) { | |
502 serv_got_update(gc, buddy->name, 0, 0, 0, 0, 0); | |
503 ib->online = FALSE; | |
504 } | |
505 | |
506 if (!ib->online && ib->flag) { | |
507 serv_got_update(gc, buddy->name, 1, 0, 0, 0, 0); | |
508 ib->online = TRUE; | |
509 } | |
510 } | |
511 | |
512 void irc_msg_join(struct irc_conn *irc, const char *name, const char *from, char **args) | |
513 { | |
514 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
515 GaimConversation *convo; | |
516 char *nick = irc_mask_nick(from), *userhost; | |
517 static int id = 1; | |
518 | |
519 if (!gc) { | |
520 g_free(nick); | |
521 return; | |
522 } | |
523 | |
524 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { | |
525 /* We are joining a channel for the first time */ | |
526 serv_got_joined_chat(gc, id++, args[0]); | |
527 g_free(nick); | |
528 return; | |
529 } | |
530 | |
531 convo = gaim_find_conversation_with_account(args[0], irc->account); | |
532 if (convo == NULL) { | |
533 gaim_debug(GAIM_DEBUG_ERROR, "irc", "JOIN for %s failed\n", args[0]); | |
534 g_free(nick); | |
535 return; | |
536 } | |
537 | |
538 userhost = irc_mask_userhost(from); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
539 gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo), nick, userhost); |
6333 | 540 g_free(userhost); |
541 g_free(nick); | |
542 } | |
543 | |
544 void irc_msg_kick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
545 { | |
546 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
547 GaimConversation *convo = gaim_find_conversation_with_account(args[0], irc->account); | |
548 char *nick = irc_mask_nick(from), *buf; | |
549 | |
550 if (!gc) { | |
551 g_free(nick); | |
552 return; | |
553 } | |
554 | |
555 if (!convo) { | |
556 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Recieved a KICK for unknown channel %s\n", args[0]); | |
557 g_free(nick); | |
558 return; | |
559 } | |
560 | |
561 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), args[1])) { | |
562 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
|
563 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL)); |
6333 | 564 g_free(buf); |
565 /*g_slist_remove(irc->gc->buddy_chats, convo); | |
566 gaim_conversation_set_account(convo, NULL);*/ | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
567 /*g_list_free(gaim_conv_chat_get_users(GAIM_CONV_CHAT(convo))); |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
568 gaim_conv_chat_set_users(GAIM_CONV_CHAT(convo), NULL);*/ |
6333 | 569 } else { |
570 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
|
571 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), args[1], buf); |
6333 | 572 g_free(buf); |
573 } | |
574 | |
575 g_free(nick); | |
576 return; | |
577 } | |
578 | |
579 void irc_msg_mode(struct irc_conn *irc, const char *name, const char *from, char **args) | |
580 { | |
581 GaimConversation *convo; | |
582 char *nick = irc_mask_nick(from), *buf; | |
583 | |
584 if (*args[0] == '#' || *args[0] == '&') { /* Channel */ | |
585 convo = gaim_find_conversation_with_account(args[0], irc->account); | |
586 if (!convo) { | |
587 gaim_debug(GAIM_DEBUG_ERROR, "irc", "MODE received for %s, which we are not in\n", args[0]); | |
588 g_free(nick); | |
589 return; | |
590 } | |
591 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
|
592 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 593 g_free(buf); |
594 } else { /* User */ | |
595 } | |
596 g_free(nick); | |
597 } | |
598 | |
599 void irc_msg_nick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
600 { | |
601 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
602 GSList *chats; | |
603 char *nick = irc_mask_nick(from); | |
604 | |
605 if (!gc) { | |
606 g_free(nick); | |
607 return; | |
608 } | |
609 chats = gc->buddy_chats; | |
610 | |
611 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { | |
612 gaim_connection_set_display_name(gc, args[0]); | |
613 } | |
614 | |
615 while (chats) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
616 GaimConvChat *chat = GAIM_CONV_CHAT(chats->data); |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
617 GList *users = gaim_conv_chat_get_users(chat); |
6333 | 618 |
619 while (users) { | |
620 char *user = users->data; | |
621 | |
622 if (!strcmp(nick, user)) { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
623 gaim_conv_chat_rename_user(chat, user, args[0]); |
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
624 users = gaim_conv_chat_get_users(chat); |
6333 | 625 break; |
626 } | |
627 users = users->next; | |
628 } | |
629 chats = chats->next; | |
630 } | |
631 g_free(nick); | |
632 } | |
633 | |
634 void irc_msg_nickused(struct irc_conn *irc, const char *name, const char *from, char **args) | |
635 { | |
636 char *newnick, *buf, *end; | |
637 | |
638 if (!args || !args[1]) | |
639 return; | |
640 | |
641 newnick = strdup(args[1]); | |
642 end = newnick + strlen(newnick) - 1; | |
643 /* try three fallbacks */ | |
644 if (*end == 2) *end = '3'; | |
645 else if (*end == 1) *end = '2'; | |
646 else *end = '1'; | |
647 | |
648 buf = irc_format(irc, "vn", "NICK", newnick); | |
649 irc_send(irc, buf); | |
650 g_free(buf); | |
651 } | |
652 | |
653 void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args) | |
654 { | |
655 char *newargs[2]; | |
656 | |
657 newargs[0] = " notice "; /* The spaces are magic, leave 'em in! */ | |
658 newargs[1] = args[1]; | |
659 irc_msg_privmsg(irc, name, from, newargs); | |
660 } | |
661 | |
6718 | 662 void irc_msg_nochangenick(struct irc_conn *irc, const char *name, const char *from, char **args) |
663 { | |
664 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
665 char *msg; | |
666 | |
6753 | 667 if (!args || !args[2] || !gc) |
6718 | 668 return; |
669 | |
6753 | 670 msg = g_strdup_printf(_("Could not change nick")); |
6718 | 671 gaim_notify_error(gc, _("Cannot change nick"), msg, args[2]); |
672 g_free(msg); | |
673 } | |
674 | |
6333 | 675 void irc_msg_part(struct irc_conn *irc, const char *name, const char *from, char **args) |
676 { | |
677 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
678 GaimConversation *convo; | |
679 char *nick, *msg; | |
680 | |
681 if (!args || !args[0] || !args[1] || !gc) | |
682 return; | |
683 | |
684 convo = gaim_find_conversation_with_account(args[0], irc->account); | |
685 if (!convo) { | |
686 gaim_debug(GAIM_DEBUG_INFO, "irc", "Got a PART on %s, which doesn't exist -- probably closed\n", args[0]); | |
687 return; | |
688 } | |
689 | |
690 nick = irc_mask_nick(from); | |
691 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { | |
692 msg = g_strdup_printf(_("You have parted the channel%s%s"), *args[1] ? ": " : "", args[1]); | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
693 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], msg, GAIM_MESSAGE_SYSTEM, time(NULL)); |
6333 | 694 g_free(msg); |
695 } else { | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
696 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), nick, args[1]); |
6333 | 697 } |
698 g_free(nick); | |
699 } | |
700 | |
701 void irc_msg_ping(struct irc_conn *irc, const char *name, const char *from, char **args) | |
702 { | |
703 char *buf; | |
704 if (!args || !args[0]) | |
705 return; | |
706 | |
707 buf = irc_format(irc, "v:", "PONG", args[0]); | |
708 irc_send(irc, buf); | |
709 g_free(buf); | |
710 } | |
711 | |
712 void irc_msg_pong(struct irc_conn *irc, const char *name, const char *from, char **args) | |
713 { | |
714 GaimConversation *convo; | |
715 GaimConnection *gc; | |
716 char **parts, *msg; | |
717 time_t oldstamp; | |
718 | |
719 if (!args || !args[1]) | |
720 return; | |
721 | |
722 parts = g_strsplit(args[1], " ", 2); | |
723 | |
724 if (!parts[0] || !parts[1]) { | |
725 g_strfreev(parts); | |
726 return; | |
727 } | |
728 | |
729 if (sscanf(parts[1], "%lu", &oldstamp) != 1) { | |
730 msg = g_strdup(_("Error: invalid PONG from server")); | |
731 } else { | |
6350 | 732 msg = g_strdup_printf(_("PING reply -- Lag: %lu seconds"), time(NULL) - oldstamp); |
6333 | 733 } |
734 | |
735 convo = gaim_find_conversation_with_account(parts[0], irc->account); | |
736 g_strfreev(parts); | |
737 if (convo) { | |
738 if (gaim_conversation_get_type (convo) == GAIM_CONV_CHAT) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
739 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "PONG", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 740 else |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
741 gaim_conv_im_write(GAIM_CONV_IM(convo), "PONG", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); |
6333 | 742 } else { |
743 gc = gaim_account_get_connection(irc->account); | |
744 if (!gc) { | |
745 g_free(msg); | |
746 return; | |
747 } | |
748 gaim_notify_info(gc, NULL, "PONG", msg); | |
749 } | |
750 g_free(msg); | |
751 } | |
752 | |
753 void irc_msg_privmsg(struct irc_conn *irc, const char *name, const char *from, char **args) | |
754 { | |
755 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
756 GaimConversation *convo; | |
757 char *nick = irc_mask_nick(from), *tmp, *msg; | |
758 int notice = 0; | |
759 | |
760 if (!args || !args[0] || !args[1] || !gc) { | |
761 g_free(nick); | |
762 return; | |
763 } | |
764 | |
765 notice = !strcmp(args[0], " notice "); | |
766 tmp = irc_parse_ctcp(irc, nick, args[0], args[1], notice); | |
767 if (!tmp) { | |
768 g_free(nick); | |
769 return; | |
770 } | |
771 msg = irc_mirc2html(tmp); | |
772 g_free(tmp); | |
773 if (notice) { | |
774 tmp = g_strdup_printf("(notice) %s", msg); | |
775 g_free(msg); | |
776 msg = tmp; | |
777 } | |
778 | |
779 if (!gaim_utf8_strcasecmp(args[0], gaim_connection_get_display_name(gc))) { | |
6982 | 780 serv_got_im(gc, nick, msg, 0, time(NULL)); |
6333 | 781 } else if (notice) { |
6982 | 782 serv_got_im(gc, nick, msg, 0, time(NULL)); |
6333 | 783 } else { |
784 convo = gaim_find_conversation_with_account(args[0], irc->account); | |
785 if (convo) | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7108
diff
changeset
|
786 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), nick, 0, msg, time(NULL)); |
6333 | 787 else |
788 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a PRIVMSG on %s, which does not exist\n", args[0]); | |
789 } | |
790 g_free(msg); | |
791 g_free(nick); | |
792 } | |
793 | |
6714 | 794 void irc_msg_regonly(struct irc_conn *irc, const char *name, const char *from, char **args) |
795 { | |
796 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
797 char *msg; | |
798 | |
799 if (!args || !args[1] || !args[2] || !gc) | |
800 return; | |
801 | |
802 msg = g_strdup_printf(_("Cannot join %s:"), args[1]); | |
803 gaim_notify_error(gc, _("Cannot join channel"), msg, args[2]); | |
804 g_free(msg); | |
805 } | |
806 | |
6333 | 807 void irc_msg_quit(struct irc_conn *irc, const char *name, const char *from, char **args) |
808 { | |
809 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
810 char *data[2]; | |
811 | |
812 if (!args || !args[0] || !gc) | |
813 return; | |
814 | |
815 data[0] = irc_mask_nick(from); | |
816 data[1] = args[0]; | |
817 /* XXX this should have an API, I shouldn't grab this directly */ | |
818 g_slist_foreach(gc->buddy_chats, (GFunc)irc_chat_remove_buddy, data); | |
819 g_free(data[0]); | |
820 | |
821 return; | |
822 } | |
823 | |
824 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args) | |
825 { | |
826 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
827 char *nick, *msg; | |
828 | |
829 if (!args || !args[0] || !gc) | |
830 return; | |
831 | |
832 nick = irc_mask_nick(from); | |
833 msg = g_strdup_printf (_("Wallops from %s"), nick); | |
834 g_free(nick); | |
835 gaim_notify_info(gc, NULL, msg, args[0]); | |
836 g_free(msg); | |
837 } | |
838 | |
839 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args) | |
840 { | |
841 return; | |
842 } |