Mercurial > pidgin
annotate libgaim/protocols/irc/msgs.c @ 15153:38cdfbb371b1
[gaim-migrate @ 17939]
Compile warning fixes
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 10 Dec 2006 08:29:03 +0000 |
parents | b81e4e44b509 |
children | ccad8138a4b2 |
rev | line source |
---|---|
14192 | 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 void irc_msg_handle_privmsg(struct irc_conn *irc, const char *name, | |
40 const char *from, const char *to, | |
41 const char *rawmsg, gboolean notice); | |
42 | |
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 { | |
63 char *message; | |
64 | |
65 message = g_strdup_printf("quit: %s", data[1]); | |
66 | |
67 if (gaim_conv_chat_find_user(GAIM_CONV_CHAT(convo), data[0])) | |
68 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), data[0], message); | |
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; | |
81 char *msg; | |
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); | |
93 if (gc) { | |
94 msg = g_markup_escape_text(args[2], -1); | |
95 serv_got_im(gc, args[1], msg, GAIM_MESSAGE_AUTO_RESP, time(NULL)); | |
96 g_free(msg); | |
97 } | |
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 | |
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 | |
131 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); | |
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 | |
144 void irc_msg_chanmode(struct irc_conn *irc, const char *name, const char *from, char **args) | |
145 { | |
146 GaimConversation *convo; | |
147 char *buf, *escaped; | |
148 | |
149 if (!args || !args[1] || !args[2]) | |
150 return; | |
151 | |
152 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); | |
153 if (!convo) /* XXX punt on channels we are not in for now */ | |
154 return; | |
155 | |
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 : ""); | |
158 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", buf, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
159 g_free(escaped); | |
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; | |
15153 | 201 char *tmp, *tmp2; |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
202 GaimNotifyUserInfo *user_info; |
14192 | 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 | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
213 user_info = gaim_notify_user_info_new(); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
214 |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
215 tmp2 = g_markup_escape_text(args[1], -1); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
216 tmp = g_strdup_printf("%s%s%s", tmp2, |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
217 (irc->whois.ircop ? _(" <i>(ircop)</i>") : ""), |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
218 (irc->whois.identified ? _(" <i>(identified)</i>") : "")); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
219 gaim_notify_user_info_add_pair(user_info, _("Nick"), tmp); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
220 g_free(tmp2); |
14192 | 221 g_free(tmp); |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
222 |
14192 | 223 if (irc->whois.away) { |
224 tmp = g_markup_escape_text(irc->whois.away, strlen(irc->whois.away)); | |
225 g_free(irc->whois.away); | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
226 gaim_notify_user_info_add_pair(user_info, _("Away"), tmp); |
14192 | 227 g_free(tmp); |
228 } | |
229 if (irc->whois.userhost) { | |
230 tmp = g_markup_escape_text(irc->whois.name, strlen(irc->whois.name)); | |
231 g_free(irc->whois.name); | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
232 gaim_notify_user_info_add_pair(user_info, _("Username"), irc->whois.userhost); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
233 gaim_notify_user_info_add_pair(user_info, _("Real name"), tmp); |
14192 | 234 g_free(irc->whois.userhost); |
235 g_free(tmp); | |
236 } | |
237 if (irc->whois.server) { | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
238 tmp = g_strdup_printf("%s (%s)", irc->whois.server, irc->whois.serverinfo); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
239 gaim_notify_user_info_add_pair(user_info, _("Server"), tmp); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
240 g_free(tmp); |
14192 | 241 g_free(irc->whois.server); |
242 g_free(irc->whois.serverinfo); | |
243 } | |
244 if (irc->whois.channels) { | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
245 gaim_notify_user_info_add_pair(user_info, _("Currently on"), irc->whois.channels); |
14192 | 246 g_free(irc->whois.channels); |
247 } | |
248 if (irc->whois.idle) { | |
249 gchar *timex = gaim_str_seconds_to_string(irc->whois.idle); | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
250 gaim_notify_user_info_add_pair(user_info, _("Idle for"), timex); |
14192 | 251 g_free(timex); |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
252 gaim_notify_user_info_add_pair(user_info, |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
253 _("Online since"), gaim_date_format_full(localtime(&irc->whois.signon))); |
14192 | 254 } |
255 if (!strcmp(irc->whois.nick, "Paco-Paco")) { | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
256 gaim_notify_user_info_add_pair(user_info, |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
257 _("<b>Defining adjective:</b>"), _("Glorious")); |
14192 | 258 } |
259 | |
260 gc = gaim_account_get_connection(irc->account); | |
261 | |
15143
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
262 gaim_notify_userinfo(gc, irc->whois.nick, user_info, NULL, NULL); |
b81e4e44b509
[gaim-migrate @ 17929]
Evan Schoenberg <evan.s@dreskin.net>
parents:
14669
diff
changeset
|
263 gaim_notify_user_info_destroy(user_info); |
14192 | 264 |
265 g_free(irc->whois.nick); | |
266 memset(&irc->whois, 0, sizeof(irc->whois)); | |
267 } | |
268 | |
269 void irc_msg_list(struct irc_conn *irc, const char *name, const char *from, char **args) | |
270 { | |
271 if (!irc->roomlist) | |
272 return; | |
273 | |
274 if (!strcmp(name, "321")) { | |
275 gaim_roomlist_set_in_progress(irc->roomlist, TRUE); | |
276 return; | |
277 } | |
278 | |
279 if (!strcmp(name, "323")) { | |
280 gaim_roomlist_set_in_progress(irc->roomlist, FALSE); | |
281 gaim_roomlist_unref(irc->roomlist); | |
282 irc->roomlist = NULL; | |
283 return; | |
284 } | |
285 | |
286 if (!strcmp(name, "322")) { | |
287 GaimRoomlistRoom *room; | |
288 | |
289 if (!args[0] || !args[1] || !args[2] || !args[3]) | |
290 return; | |
291 | |
292 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, args[1], NULL); | |
293 gaim_roomlist_room_add_field(irc->roomlist, room, args[1]); | |
294 gaim_roomlist_room_add_field(irc->roomlist, room, GINT_TO_POINTER(strtol(args[2], NULL, 10))); | |
295 gaim_roomlist_room_add_field(irc->roomlist, room, args[3]); | |
296 gaim_roomlist_room_add(irc->roomlist, room); | |
297 } | |
298 } | |
299 | |
300 void irc_msg_topic(struct irc_conn *irc, const char *name, const char *from, char **args) | |
301 { | |
302 char *chan, *topic, *msg, *nick, *tmp, *tmp2; | |
303 GaimConversation *convo; | |
304 | |
305 if (!strcmp(name, "topic")) { | |
306 chan = args[0]; | |
307 topic = irc_mirc2txt (args[1]); | |
308 } else { | |
309 chan = args[1]; | |
310 topic = irc_mirc2txt (args[2]); | |
311 } | |
312 | |
313 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, chan, irc->account); | |
314 if (!convo) { | |
315 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a topic for %s, which doesn't exist\n", chan); | |
316 g_free(topic); | |
317 return; | |
318 } | |
319 | |
320 /* If this is an interactive update, print it out */ | |
321 tmp = g_markup_escape_text(topic, -1); | |
322 tmp2 = gaim_markup_linkify(tmp); | |
323 g_free(tmp); | |
324 if (!strcmp(name, "topic")) { | |
325 const char *current_topic = gaim_conv_chat_get_topic(GAIM_CONV_CHAT(convo)); | |
326 if (!(current_topic != NULL && strcmp(tmp2, current_topic) == 0)) | |
327 { | |
328 char *nick_esc; | |
329 nick = irc_mask_nick(from); | |
330 nick_esc = g_markup_escape_text(nick, -1); | |
331 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), nick, topic); | |
332 if (*tmp2) | |
333 msg = g_strdup_printf(_("%s has changed the topic to: %s"), nick_esc, tmp2); | |
334 else | |
335 msg = g_strdup_printf(_("%s has cleared the topic."), nick_esc); | |
336 g_free(nick_esc); | |
337 g_free(nick); | |
338 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), from, msg, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
339 g_free(msg); | |
340 } | |
341 } else { | |
342 char *chan_esc = g_markup_escape_text(chan, -1); | |
343 msg = g_strdup_printf(_("The topic for %s is: %s"), chan_esc, tmp2); | |
344 g_free(chan_esc); | |
345 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, topic); | |
346 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", msg, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
347 g_free(msg); | |
348 } | |
349 g_free(tmp2); | |
350 g_free(topic); | |
351 } | |
352 | |
353 void irc_msg_unknown(struct irc_conn *irc, const char *name, const char *from, char **args) | |
354 { | |
355 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
356 char *buf; | |
357 | |
358 if (!args || !args[1] || !gc) | |
359 return; | |
360 | |
361 buf = g_strdup_printf(_("Unknown message '%s'"), args[1]); | |
362 gaim_notify_error(gc, _("Unknown message"), buf, _("Gaim has sent a message the IRC server did not understand.")); | |
363 g_free(buf); | |
364 } | |
365 | |
366 void irc_msg_names(struct irc_conn *irc, const char *name, const char *from, char **args) | |
367 { | |
368 char *names, *cur, *end, *tmp, *msg; | |
369 GaimConversation *convo; | |
370 | |
371 if (!strcmp(name, "366")) { | |
372 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, irc->nameconv ? irc->nameconv : args[1], irc->account); | |
373 if (!convo) { | |
374 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got a NAMES list for %s, which doesn't exist\n", args[1]); | |
375 g_string_free(irc->names, TRUE); | |
376 irc->names = NULL; | |
377 g_free(irc->nameconv); | |
378 irc->nameconv = NULL; | |
379 return; | |
380 } | |
381 | |
382 names = cur = g_string_free(irc->names, FALSE); | |
383 irc->names = NULL; | |
384 if (irc->nameconv) { | |
385 msg = g_strdup_printf(_("Users on %s: %s"), args[1], names ? names : ""); | |
386 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) | |
387 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
388 else | |
389 gaim_conv_im_write(GAIM_CONV_IM(convo), "", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
390 g_free(msg); | |
391 g_free(irc->nameconv); | |
392 irc->nameconv = NULL; | |
393 } else { | |
394 GList *users = NULL; | |
395 GList *flags = NULL; | |
396 | |
397 while (*cur) { | |
398 GaimConvChatBuddyFlags f = GAIM_CBFLAGS_NONE; | |
399 end = strchr(cur, ' '); | |
400 if (!end) | |
401 end = cur + strlen(cur); | |
402 if (*cur == '@') { | |
403 f = GAIM_CBFLAGS_OP; | |
404 cur++; | |
405 } else if (*cur == '%') { | |
406 f = GAIM_CBFLAGS_HALFOP; | |
407 cur++; | |
408 } else if(*cur == '+') { | |
409 f = GAIM_CBFLAGS_VOICE; | |
410 cur++; | |
411 } | |
412 tmp = g_strndup(cur, end - cur); | |
413 users = g_list_prepend(users, tmp); | |
414 flags = g_list_prepend(flags, GINT_TO_POINTER(f)); | |
415 cur = end; | |
416 if (*cur) | |
417 cur++; | |
418 } | |
419 | |
420 if (users != NULL) { | |
421 GList *l; | |
422 | |
423 gaim_conv_chat_add_users(GAIM_CONV_CHAT(convo), users, NULL, flags, FALSE); | |
424 | |
425 for (l = users; l != NULL; l = l->next) | |
426 g_free(l->data); | |
427 | |
428 g_list_free(users); | |
429 g_list_free(flags); | |
430 } | |
431 } | |
432 g_free(names); | |
433 } else { | |
434 if (!irc->names) | |
435 irc->names = g_string_new(""); | |
436 | |
437 irc->names = g_string_append(irc->names, args[3]); | |
438 } | |
439 } | |
440 | |
441 void irc_msg_motd(struct irc_conn *irc, const char *name, const char *from, char **args) | |
442 { | |
443 GaimConnection *gc; | |
444 char *escaped; | |
445 if (!strcmp(name, "375")) { | |
446 gc = gaim_account_get_connection(irc->account); | |
447 if (gc) | |
448 gaim_connection_set_display_name(gc, args[0]); | |
449 } | |
450 | |
451 if (!irc->motd) | |
452 irc->motd = g_string_new(""); | |
453 | |
454 escaped = g_markup_escape_text(args[1], -1); | |
455 g_string_append_printf(irc->motd, "%s<br>", escaped); | |
456 g_free(escaped); | |
457 } | |
458 | |
459 void irc_msg_endmotd(struct irc_conn *irc, const char *name, const char *from, char **args) | |
460 { | |
461 GaimConnection *gc; | |
462 GaimStatus *status; | |
463 GaimBlistNode *gnode, *cnode, *bnode; | |
464 | |
465 gc = gaim_account_get_connection(irc->account); | |
466 if (!gc) | |
467 return; | |
468 | |
469 gaim_connection_set_state(gc, GAIM_CONNECTED); | |
470 | |
471 /* If we're away then set our away message */ | |
472 status = gaim_account_get_active_status(irc->account); | |
473 if (!gaim_status_get_type(status) != GAIM_STATUS_AVAILABLE) | |
474 { | |
475 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
476 prpl_info->set_status(irc->account, status); | |
477 } | |
478 | |
479 /* this used to be in the core, but it's not now */ | |
480 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
481 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
482 continue; | |
483 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
484 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
485 continue; | |
486 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
487 GaimBuddy *b; | |
488 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
489 continue; | |
490 b = (GaimBuddy *)bnode; | |
491 if(b->account == gc->account) { | |
492 struct irc_buddy *ib = g_new0(struct irc_buddy, 1); | |
493 ib->name = g_strdup(b->name); | |
494 g_hash_table_insert(irc->buddies, ib->name, ib); | |
495 } | |
496 } | |
497 } | |
498 } | |
499 | |
500 irc_blist_timeout(irc); | |
501 if (!irc->timer) | |
502 irc->timer = gaim_timeout_add(45000, (GSourceFunc)irc_blist_timeout, (gpointer)irc); | |
503 } | |
504 | |
505 void irc_msg_time(struct irc_conn *irc, const char *name, const char *from, char **args) | |
506 { | |
507 GaimConnection *gc; | |
508 | |
509 gc = gaim_account_get_connection(irc->account); | |
510 if (gc == NULL || args == NULL || args[2] == NULL) | |
511 return; | |
512 | |
513 gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO, _("Time Response"), | |
514 _("The IRC server's local time is:"), | |
515 args[2], NULL, NULL); | |
516 } | |
517 | |
518 void irc_msg_nochan(struct irc_conn *irc, const char *name, const char *from, char **args) | |
519 { | |
520 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
521 | |
522 if (gc == NULL || args == NULL || args[1] == NULL) | |
523 return; | |
524 | |
525 gaim_notify_error(gc, NULL, _("No such channel"), args[1]); | |
526 } | |
527 | |
528 void irc_msg_nonick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
529 { | |
530 GaimConnection *gc; | |
531 GaimConversation *convo; | |
532 | |
533 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, args[1], irc->account); | |
534 if (convo) { | |
535 if (gaim_conversation_get_type(convo) == GAIM_CONV_TYPE_CHAT) /* does this happen? */ | |
536 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], _("no such channel"), | |
537 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
538 else | |
539 gaim_conv_im_write(GAIM_CONV_IM(convo), args[1], _("User is not logged in"), | |
540 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
541 } else { | |
542 if ((gc = gaim_account_get_connection(irc->account)) == NULL) | |
543 return; | |
544 gaim_notify_error(gc, NULL, _("No such nick or channel"), args[1]); | |
545 } | |
546 | |
547 if (irc->whois.nick && !gaim_utf8_strcasecmp(irc->whois.nick, args[1])) { | |
548 g_free(irc->whois.nick); | |
549 irc->whois.nick = NULL; | |
550 } | |
551 } | |
552 | |
553 void irc_msg_nosend(struct irc_conn *irc, const char *name, const char *from, char **args) | |
554 { | |
555 GaimConnection *gc; | |
556 GaimConversation *convo; | |
557 | |
558 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); | |
559 if (convo) { | |
560 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], args[2], GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
561 } else { | |
562 if ((gc = gaim_account_get_connection(irc->account)) == NULL) | |
563 return; | |
564 gaim_notify_error(gc, NULL, _("Could not send"), args[2]); | |
565 } | |
566 } | |
567 | |
568 void irc_msg_notinchan(struct irc_conn *irc, const char *name, const char *from, char **args) | |
569 { | |
570 GaimConversation *convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); | |
571 | |
572 gaim_debug(GAIM_DEBUG_INFO, "irc", "We're apparently not in %s, but tried to use it\n", args[1]); | |
573 if (convo) { | |
574 /*g_slist_remove(irc->gc->buddy_chats, convo); | |
575 gaim_conversation_set_account(convo, NULL);*/ | |
576 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[1], args[2], GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
577 } | |
578 } | |
579 | |
580 void irc_msg_notop(struct irc_conn *irc, const char *name, const char *from, char **args) | |
581 { | |
582 GaimConversation *convo; | |
583 | |
584 if (!args || !args[1] || !args[2]) | |
585 return; | |
586 | |
587 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[1], irc->account); | |
588 if (!convo) | |
589 return; | |
590 | |
591 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "", args[2], GAIM_MESSAGE_SYSTEM, time(NULL)); | |
592 } | |
593 | |
594 void irc_msg_invite(struct irc_conn *irc, const char *name, const char *from, char **args) | |
595 { | |
596 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
597 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
598 char *nick = irc_mask_nick(from); | |
599 | |
600 if (!args || !args[1] || !gc) { | |
601 g_free(nick); | |
602 g_hash_table_destroy(components); | |
603 return; | |
604 } | |
605 | |
606 g_hash_table_insert(components, strdup("channel"), strdup(args[1])); | |
607 | |
608 serv_got_chat_invite(gc, args[1], nick, NULL, components); | |
609 g_free(nick); | |
610 } | |
611 | |
612 void irc_msg_inviteonly(struct irc_conn *irc, const char *name, const char *from, char **args) | |
613 { | |
614 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
615 char *buf; | |
616 | |
617 if (!args || !args[1] || !gc) | |
618 return; | |
619 | |
620 buf = g_strdup_printf(_("Joining %s requires an invitation."), args[1]); | |
621 gaim_notify_error(gc, _("Invitation only"), _("Invitation only"), buf); | |
622 g_free(buf); | |
623 } | |
624 | |
625 void irc_msg_ison(struct irc_conn *irc, const char *name, const char *from, char **args) | |
626 { | |
627 char **nicks; | |
628 struct irc_buddy *ib; | |
629 int i; | |
630 | |
631 if (!args || !args[1]) | |
632 return; | |
633 | |
634 nicks = g_strsplit(args[1], " ", -1); | |
635 | |
636 for (i = 0; nicks[i]; i++) { | |
637 if ((ib = g_hash_table_lookup(irc->buddies, (gconstpointer)nicks[i])) == NULL) { | |
638 continue; | |
639 } | |
640 ib->flag = TRUE; | |
641 } | |
642 | |
643 g_strfreev(nicks); | |
644 | |
645 g_hash_table_foreach(irc->buddies, (GHFunc)irc_buddy_status, (gpointer)irc); | |
646 } | |
647 | |
648 static void irc_buddy_status(char *name, struct irc_buddy *ib, struct irc_conn *irc) | |
649 { | |
650 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
651 GaimBuddy *buddy = gaim_find_buddy(irc->account, name); | |
652 | |
653 if (!gc || !buddy) | |
654 return; | |
655 | |
656 if (ib->online && !ib->flag) { | |
657 gaim_prpl_got_user_status(irc->account, name, "offline", NULL); | |
658 ib->online = FALSE; | |
659 } else if (!ib->online && ib->flag) { | |
660 gaim_prpl_got_user_status(irc->account, name, "available", NULL); | |
661 ib->online = TRUE; | |
662 } | |
663 } | |
664 | |
665 void irc_msg_join(struct irc_conn *irc, const char *name, const char *from, char **args) | |
666 { | |
667 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
668 GaimConversation *convo; | |
669 char *nick = irc_mask_nick(from), *userhost; | |
670 struct irc_buddy *ib; | |
671 static int id = 1; | |
672 | |
673 if (!gc) { | |
674 g_free(nick); | |
675 return; | |
676 } | |
677 | |
678 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { | |
679 /* We are joining a channel for the first time */ | |
680 serv_got_joined_chat(gc, id++, args[0]); | |
681 g_free(nick); | |
682 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, | |
683 args[0], | |
684 irc->account); | |
685 if (convo == NULL) { | |
686 gaim_debug_error("irc", "tried to join %s but couldn't\n", args[0]); | |
687 return; | |
688 } | |
689 gaim_conversation_present(convo); | |
690 return; | |
691 } | |
692 | |
693 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); | |
694 if (convo == NULL) { | |
695 gaim_debug(GAIM_DEBUG_ERROR, "irc", "JOIN for %s failed\n", args[0]); | |
696 g_free(nick); | |
697 return; | |
698 } | |
699 | |
700 userhost = irc_mask_userhost(from); | |
701 gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo), nick, userhost, GAIM_CBFLAGS_NONE, TRUE); | |
702 | |
703 if ((ib = g_hash_table_lookup(irc->buddies, nick)) != NULL) { | |
704 ib->flag = TRUE; | |
705 irc_buddy_status(nick, ib, irc); | |
706 } | |
707 | |
708 g_free(userhost); | |
709 g_free(nick); | |
710 } | |
711 | |
712 void irc_msg_kick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
713 { | |
714 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
715 GaimConversation *convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); | |
716 char *nick = irc_mask_nick(from), *buf; | |
717 | |
718 if (!gc) { | |
719 g_free(nick); | |
720 return; | |
721 } | |
722 | |
723 if (!convo) { | |
724 gaim_debug(GAIM_DEBUG_ERROR, "irc", "Recieved a KICK for unknown channel %s\n", args[0]); | |
725 g_free(nick); | |
726 return; | |
727 } | |
728 | |
729 if (!gaim_utf8_strcasecmp(gaim_connection_get_display_name(gc), args[1])) { | |
730 buf = g_strdup_printf(_("You have been kicked by %s: (%s)"), nick, args[2]); | |
731 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
732 g_free(buf); | |
733 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo))); | |
734 } else { | |
735 buf = g_strdup_printf(_("Kicked by %s (%s)"), nick, args[2]); | |
736 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), args[1], buf); | |
737 g_free(buf); | |
738 } | |
739 | |
740 g_free(nick); | |
741 return; | |
742 } | |
743 | |
744 void irc_msg_mode(struct irc_conn *irc, const char *name, const char *from, char **args) | |
745 { | |
746 GaimConversation *convo; | |
747 char *nick = irc_mask_nick(from), *buf; | |
748 | |
749 if (*args[0] == '#' || *args[0] == '&') { /* Channel */ | |
750 char *escaped; | |
751 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); | |
752 if (!convo) { | |
753 gaim_debug(GAIM_DEBUG_ERROR, "irc", "MODE received for %s, which we are not in\n", args[0]); | |
754 g_free(nick); | |
755 return; | |
756 } | |
757 escaped = (args[2] != NULL) ? g_markup_escape_text(args[2], -1) : NULL; | |
758 buf = g_strdup_printf(_("mode (%s %s) by %s"), args[1], escaped ? escaped : "", nick); | |
759 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], buf, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
760 g_free(escaped); | |
761 g_free(buf); | |
762 if(args[2]) { | |
763 GaimConvChatBuddyFlags newflag, flags; | |
764 char *mcur, *cur, *end, *user; | |
765 gboolean add = FALSE; | |
766 mcur = args[1]; | |
767 cur = args[2]; | |
768 while (*cur && *mcur) { | |
769 if ((*mcur == '+') || (*mcur == '-')) { | |
770 add = (*mcur == '+') ? TRUE : FALSE; | |
771 mcur++; | |
772 continue; | |
773 } | |
774 end = strchr(cur, ' '); | |
775 if (!end) | |
776 end = cur + strlen(cur); | |
777 user = g_strndup(cur, end - cur); | |
778 flags = gaim_conv_chat_user_get_flags(GAIM_CONV_CHAT(convo), user); | |
779 newflag = GAIM_CBFLAGS_NONE; | |
780 if (*mcur == 'o') | |
781 newflag = GAIM_CBFLAGS_OP; | |
782 else if (*mcur =='h') | |
783 newflag = GAIM_CBFLAGS_HALFOP; | |
784 else if (*mcur == 'v') | |
785 newflag = GAIM_CBFLAGS_VOICE; | |
786 if (newflag) { | |
787 if (add) | |
788 flags |= newflag; | |
789 else | |
790 flags &= ~newflag; | |
791 gaim_conv_chat_user_set_flags(GAIM_CONV_CHAT(convo), user, flags); | |
792 } | |
793 g_free(user); | |
794 cur = end; | |
795 if (*cur) | |
796 cur++; | |
797 if (*mcur) | |
798 mcur++; | |
799 } | |
800 } | |
801 } else { /* User */ | |
802 } | |
803 g_free(nick); | |
804 } | |
805 | |
806 void irc_msg_nick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
807 { | |
808 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
809 GaimConversation *conv; | |
810 GSList *chats; | |
811 char *nick = irc_mask_nick(from); | |
812 | |
813 if (!gc) { | |
814 g_free(nick); | |
815 return; | |
816 } | |
817 chats = gc->buddy_chats; | |
818 | |
819 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { | |
820 gaim_connection_set_display_name(gc, args[0]); | |
821 } | |
822 | |
823 while (chats) { | |
824 GaimConvChat *chat = GAIM_CONV_CHAT(chats->data); | |
825 /* This is ugly ... */ | |
826 if (gaim_conv_chat_find_user(chat, nick)) | |
827 gaim_conv_chat_rename_user(chat, nick, args[0]); | |
828 chats = chats->next; | |
829 } | |
830 | |
831 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, nick, | |
832 irc->account); | |
833 if (conv != NULL) | |
834 gaim_conversation_set_name(conv, args[0]); | |
835 | |
836 g_free(nick); | |
837 } | |
838 | |
839 void irc_msg_badnick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
840 { | |
841 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
842 if (gaim_connection_get_state(gc) == GAIM_CONNECTED) { | |
843 gaim_notify_error(gc, _("Invalid nickname"), | |
844 _("Invalid nickname"), | |
845 _("Your selected nickname was rejected by the server. It probably contains invalid characters.")); | |
846 | |
847 } else { | |
14669 | 848 gc->wants_to_die = TRUE; |
14192 | 849 gaim_connection_error(gaim_account_get_connection(irc->account), |
850 _("Your selected account name was rejected by the server. It probably contains invalid characters.")); | |
851 } | |
852 } | |
853 | |
854 void irc_msg_nickused(struct irc_conn *irc, const char *name, const char *from, char **args) | |
855 { | |
856 char *newnick, *buf, *end; | |
857 | |
858 if (!args || !args[1]) | |
859 return; | |
860 | |
861 newnick = strdup(args[1]); | |
862 end = newnick + strlen(newnick) - 1; | |
863 /* try fallbacks */ | |
864 if((*end < '9') && (*end >= '1')) { | |
865 *end = *end + 1; | |
866 } else *end = '1'; | |
867 | |
868 buf = irc_format(irc, "vn", "NICK", newnick); | |
869 irc_send(irc, buf); | |
870 g_free(buf); | |
871 g_free(newnick); | |
872 } | |
873 | |
874 void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args) | |
875 { | |
876 if (!args || !args[0] || !args[1]) | |
877 return; | |
878 | |
879 irc_msg_handle_privmsg(irc, name, from, args[0], args[1], TRUE); | |
880 } | |
881 | |
882 void irc_msg_nochangenick(struct irc_conn *irc, const char *name, const char *from, char **args) | |
883 { | |
884 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
885 | |
886 if (!args || !args[2] || !gc) | |
887 return; | |
888 | |
889 gaim_notify_error(gc, _("Cannot change nick"), _("Could not change nick"), args[2]); | |
890 } | |
891 | |
892 void irc_msg_part(struct irc_conn *irc, const char *name, const char *from, char **args) | |
893 { | |
894 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
895 GaimConversation *convo; | |
896 char *nick, *msg; | |
897 | |
898 if (!args || !args[0] || !gc) | |
899 return; | |
900 | |
901 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], irc->account); | |
902 if (!convo) { | |
903 gaim_debug(GAIM_DEBUG_INFO, "irc", "Got a PART on %s, which doesn't exist -- probably closed\n", args[0]); | |
904 return; | |
905 } | |
906 | |
907 nick = irc_mask_nick(from); | |
908 if (!gaim_utf8_strcasecmp(nick, gaim_connection_get_display_name(gc))) { | |
909 char *escaped = g_markup_escape_text(args[1], -1); | |
910 msg = g_strdup_printf(_("You have parted the channel%s%s"), | |
911 (args[1] && *args[1]) ? ": " : "", | |
912 (escaped && *escaped) ? escaped : ""); | |
913 g_free(escaped); | |
914 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), args[0], msg, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
915 g_free(msg); | |
916 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo))); | |
917 } else { | |
918 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo), nick, args[1]); | |
919 } | |
920 g_free(nick); | |
921 } | |
922 | |
923 void irc_msg_ping(struct irc_conn *irc, const char *name, const char *from, char **args) | |
924 { | |
925 char *buf; | |
926 if (!args || !args[0]) | |
927 return; | |
928 | |
929 buf = irc_format(irc, "v:", "PONG", args[0]); | |
930 irc_send(irc, buf); | |
931 g_free(buf); | |
932 } | |
933 | |
934 void irc_msg_pong(struct irc_conn *irc, const char *name, const char *from, char **args) | |
935 { | |
936 GaimConversation *convo; | |
937 GaimConnection *gc; | |
938 char **parts, *msg; | |
939 time_t oldstamp; | |
940 | |
941 if (!args || !args[1]) | |
942 return; | |
943 | |
944 parts = g_strsplit(args[1], " ", 2); | |
945 | |
946 if (!parts[0] || !parts[1]) { | |
947 g_strfreev(parts); | |
948 return; | |
949 } | |
950 | |
951 if (sscanf(parts[1], "%lu", &oldstamp) != 1) { | |
952 msg = g_strdup(_("Error: invalid PONG from server")); | |
953 } else { | |
954 msg = g_strdup_printf(_("PING reply -- Lag: %lu seconds"), time(NULL) - oldstamp); | |
955 } | |
956 | |
957 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, parts[0], irc->account); | |
958 g_strfreev(parts); | |
959 if (convo) { | |
960 if (gaim_conversation_get_type (convo) == GAIM_CONV_TYPE_CHAT) | |
961 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), "PONG", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
962 else | |
963 gaim_conv_im_write(GAIM_CONV_IM(convo), "PONG", msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
964 } else { | |
965 gc = gaim_account_get_connection(irc->account); | |
966 if (!gc) { | |
967 g_free(msg); | |
968 return; | |
969 } | |
970 gaim_notify_info(gc, NULL, "PONG", msg); | |
971 } | |
972 g_free(msg); | |
973 } | |
974 | |
975 void irc_msg_privmsg(struct irc_conn *irc, const char *name, const char *from, char **args) | |
976 { | |
977 if (!args || !args[0] || !args[1]) | |
978 return; | |
979 | |
980 irc_msg_handle_privmsg(irc, name, from, args[0], args[1], FALSE); | |
981 } | |
982 | |
983 static void irc_msg_handle_privmsg(struct irc_conn *irc, const char *name, const char *from, const char *to, const char *rawmsg, gboolean notice) | |
984 { | |
985 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
986 GaimConversation *convo; | |
987 char *tmp; | |
988 char *msg; | |
989 char *nick; | |
990 | |
991 if (!gc) | |
992 return; | |
993 | |
994 nick = irc_mask_nick(from); | |
995 tmp = irc_parse_ctcp(irc, nick, to, rawmsg, notice); | |
996 if (!tmp) { | |
997 g_free(nick); | |
998 return; | |
999 } | |
1000 | |
1001 msg = g_markup_escape_text(tmp, -1); | |
1002 g_free(tmp); | |
1003 | |
1004 tmp = irc_mirc2html(msg); | |
1005 g_free(msg); | |
1006 msg = tmp; | |
1007 if (notice) { | |
1008 tmp = g_strdup_printf("(notice) %s", msg); | |
1009 g_free(msg); | |
1010 msg = tmp; | |
1011 } | |
1012 | |
1013 if (!gaim_utf8_strcasecmp(to, gaim_connection_get_display_name(gc))) { | |
1014 serv_got_im(gc, nick, msg, 0, time(NULL)); | |
1015 } else { | |
1016 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, to, irc->account); | |
1017 if (convo) | |
1018 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)), nick, 0, msg, time(NULL)); | |
1019 else | |
1020 gaim_debug_error("irc", "Got a %s on %s, which does not exist\n", | |
1021 notice ? "NOTICE" : "PRIVMSG", to); | |
1022 } | |
1023 g_free(msg); | |
1024 g_free(nick); | |
1025 } | |
1026 | |
1027 void irc_msg_regonly(struct irc_conn *irc, const char *name, const char *from, char **args) | |
1028 { | |
1029 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
1030 char *msg; | |
1031 | |
1032 if (!args || !args[1] || !args[2] || !gc) | |
1033 return; | |
1034 | |
1035 msg = g_strdup_printf(_("Cannot join %s:"), args[1]); | |
1036 gaim_notify_error(gc, _("Cannot join channel"), msg, args[2]); | |
1037 g_free(msg); | |
1038 } | |
1039 | |
1040 void irc_msg_quit(struct irc_conn *irc, const char *name, const char *from, char **args) | |
1041 { | |
1042 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
1043 struct irc_buddy *ib; | |
1044 char *data[2]; | |
1045 | |
1046 if (!args || !args[0] || !gc) | |
1047 return; | |
1048 | |
1049 data[0] = irc_mask_nick(from); | |
1050 data[1] = args[0]; | |
1051 /* XXX this should have an API, I shouldn't grab this directly */ | |
1052 g_slist_foreach(gc->buddy_chats, (GFunc)irc_chat_remove_buddy, data); | |
1053 | |
1054 if ((ib = g_hash_table_lookup(irc->buddies, data[0])) != NULL) { | |
1055 ib->flag = FALSE; | |
1056 irc_buddy_status(data[0], ib, irc); | |
1057 } | |
1058 g_free(data[0]); | |
1059 | |
1060 return; | |
1061 } | |
1062 | |
1063 void irc_msg_unavailable(struct irc_conn *irc, const char *name, const char *from, char **args) | |
1064 { | |
1065 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
1066 | |
1067 if (!args || !args[1]) | |
1068 return; | |
1069 | |
1070 gaim_notify_error(gc, NULL, _("Nick or channel is temporarily unavailable."), args[1]); | |
1071 } | |
1072 | |
1073 void irc_msg_wallops(struct irc_conn *irc, const char *name, const char *from, char **args) | |
1074 { | |
1075 GaimConnection *gc = gaim_account_get_connection(irc->account); | |
1076 char *nick, *msg; | |
1077 | |
1078 if (!args || !args[0] || !gc) | |
1079 return; | |
1080 | |
1081 nick = irc_mask_nick(from); | |
1082 msg = g_strdup_printf (_("Wallops from %s"), nick); | |
1083 g_free(nick); | |
1084 gaim_notify_info(gc, NULL, msg, args[0]); | |
1085 g_free(msg); | |
1086 } | |
1087 | |
1088 void irc_msg_ignore(struct irc_conn *irc, const char *name, const char *from, char **args) | |
1089 { | |
1090 return; | |
1091 } |