Mercurial > pidgin.yaz
annotate plugins/irc.c @ 1790:c4864ac7792b
[gaim-migrate @ 1800]
left-justify for whiny-ass bitches
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 01 May 2001 02:55:49 +0000 |
parents | 1e0613d9526b |
children | 1b61db419774 |
rev | line source |
---|---|
987 | 1 /* |
2 * gaim - IRC Protocol Plugin | |
3 * | |
1672 | 4 * Copyright (C) 2000-2001, Rob Flynn <rob@tgflinux.com> |
987 | 5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
23 #include "../config.h" | |
24 | |
25 | |
26 #include <netdb.h> | |
27 #include <gtk/gtk.h> | |
28 #include <unistd.h> | |
29 #include <errno.h> | |
30 #include <netinet/in.h> | |
31 #include <arpa/inet.h> | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
32 #include <fcntl.h> |
987 | 33 #include <string.h> |
34 #include <stdlib.h> | |
35 #include <stdio.h> | |
36 #include <time.h> | |
37 #include <sys/socket.h> | |
38 #include <sys/stat.h> | |
39 #include "multi.h" | |
40 #include "prpl.h" | |
41 #include "gaim.h" | |
42 | |
1178 | 43 #include "pixmaps/free_icon.xpm" |
44 | |
1011 | 45 #define IRC_BUF_LEN 4096 |
46 | |
1022 | 47 |
1011 | 48 static int chat_id = 0; |
49 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
50 struct irc_channel { |
1011 | 51 int id; |
52 gchar *name; | |
53 }; | |
54 | |
55 struct irc_data { | |
56 int fd; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
57 int inpa; /* used for non-block logins */ |
1011 | 58 |
1022 | 59 int timer; |
60 | |
61 int totalblocks; | |
62 int recblocks; | |
63 | |
64 GSList *templist; | |
1011 | 65 GList *channels; |
66 }; | |
67 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
68 static char *irc_name() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
69 { |
1008 | 70 return "IRC"; |
71 } | |
72 | |
1675 | 73 static void irc_get_info(struct gaim_connection *gc, char *who); |
74 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
75 char *name() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
76 { |
1008 | 77 return "IRC"; |
78 } | |
79 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
80 char *description() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
81 { |
1008 | 82 return "Allows gaim to use the IRC protocol"; |
83 } | |
84 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
85 static void irc_join_chat(struct gaim_connection *gc, int id, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
86 { |
1011 | 87 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
88 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 89 |
90 g_snprintf(buf, IRC_BUF_LEN, "JOIN %s\n", name); | |
91 write(idata->fd, buf, strlen(buf)); | |
1742 | 92 write(idata->fd, buf, strlen(buf)); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
93 |
1011 | 94 g_free(buf); |
95 } | |
96 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
97 static void irc_update_user(struct gaim_connection *gc, char *name, int status) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
98 { |
1022 | 99 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
100 struct irc_channel *u; | |
101 GSList *temp = idata->templist; | |
102 | |
103 /* Loop through our list */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
104 |
1022 | 105 while (temp) { |
106 u = (struct irc_channel *)temp->data; | |
107 if (g_strcasecmp(u->name, name) == 0) { | |
108 u->id = status; | |
109 return; | |
110 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
111 |
1022 | 112 temp = g_slist_next(temp); |
113 } | |
114 return; | |
115 } | |
116 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
117 static void irc_request_buddy_update(struct gaim_connection *gc) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
118 { |
1022 | 119 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1046
4593605da0e2
[gaim-migrate @ 1056]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1022
diff
changeset
|
120 GSList *grp = gc->groups; |
4593605da0e2
[gaim-migrate @ 1056]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1022
diff
changeset
|
121 GSList *person; |
1022 | 122 struct group *g; |
123 struct buddy *b; | |
124 struct irc_channel *u; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
125 gchar buf[IRC_BUF_LEN + 1]; |
1022 | 126 |
127 if (idata->templist != NULL) | |
128 return; | |
129 | |
130 idata->recblocks = 0; | |
131 idata->totalblocks = 1; | |
132 | |
1105 | 133 /* First, let's check to see if we have anyone on our buddylist */ |
134 if (!grp) { | |
135 return; | |
136 } | |
137 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
138 /* Send the first part of our request */ |
1022 | 139 write(idata->fd, "ISON", 4); |
140 | |
141 /* Step through our list of groups */ | |
142 while (grp) { | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
143 |
1022 | 144 g = (struct group *)grp->data; |
145 person = g->members; | |
146 | |
147 while (person) { | |
148 b = (struct buddy *)person->data; | |
149 | |
150 /* We will store our buddy info here. I know, this is cheap | |
151 * but hey, its the exact same data structure. Why should we | |
152 * bother with making another one */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
153 |
1022 | 154 u = g_new0(struct irc_channel, 1); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
155 u->id = 0; /* Assume by default that they're offline */ |
1022 | 156 u->name = strdup(b->name); |
157 | |
158 write(idata->fd, " ", 1); | |
159 write(idata->fd, u->name, strlen(u->name)); | |
160 idata->templist = g_slist_append(idata->templist, u); | |
161 | |
162 person = person->next; | |
163 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
164 |
1022 | 165 grp = g_slist_next(grp); |
166 } | |
167 write(idata->fd, "\n", 1); | |
168 } | |
169 | |
170 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
171 static void irc_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
172 { |
1011 | 173 |
1742 | 174 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
175 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 176 |
177 /* Before we actually send this, we should check to see if they're trying | |
1674 | 178 * To issue a command and handle it properly. */ |
1011 | 179 |
1674 | 180 if (message[0] == '/') |
181 { | |
182 /* I'll change the implementation of this a little later :-) */ | |
183 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | |
184 /* We have /me!! We have /me!! :-) */ | |
1011 | 185 |
1674 | 186 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
187 strcpy(temp, message + 4); | |
188 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%cACTION %s%c\n", who, '\001', temp, '\001'); | |
189 g_free(temp); | |
190 } | |
1675 | 191 else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { |
192 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
193 strcpy(temp, message + 7); | |
194 irc_get_info(gc, temp); | |
195 g_free(temp); | |
196 | |
197 return; | |
198 } | |
199 | |
1674 | 200 } |
201 else { | |
1011 | 202 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG %s :%s\n", who, message); |
203 } | |
204 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
205 write(idata->fd, buf, strlen(buf)); |
1011 | 206 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
207 g_free(buf); |
1011 | 208 } |
209 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
210 static int find_id_by_name(struct gaim_connection *gc, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
211 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
212 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 213 GList *templist; |
214 struct irc_channel *channel; | |
215 | |
216 templist = ((struct irc_data *)gc->proto_data)->channels; | |
217 | |
218 while (templist) { | |
219 channel = (struct irc_channel *)templist->data; | |
220 | |
221 g_snprintf(temp, IRC_BUF_LEN, "#%s", channel->name); | |
222 | |
223 if (g_strcasecmp(temp, name) == 0) { | |
224 g_free(temp); | |
225 return channel->id; | |
226 } | |
227 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
228 templist = templist->next; |
1011 | 229 } |
230 | |
231 g_free(temp); | |
232 | |
233 /* Return -1 if we have no ID */ | |
234 return -1; | |
235 } | |
236 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
237 static struct irc_channel *find_channel_by_name(struct gaim_connection *gc, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
238 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
239 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1011 | 240 GList *templist; |
241 struct irc_channel *channel; | |
242 | |
243 templist = ((struct irc_data *)gc->proto_data)->channels; | |
244 | |
245 while (templist) { | |
246 channel = (struct irc_channel *)templist->data; | |
247 | |
248 g_snprintf(temp, IRC_BUF_LEN, "%s", channel->name); | |
249 | |
250 if (g_strcasecmp(temp, name) == 0) { | |
251 g_free(temp); | |
252 return channel; | |
253 } | |
254 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
255 templist = templist->next; |
1011 | 256 } |
257 | |
258 g_free(temp); | |
259 | |
260 /* If we found nothing, return nothing :-) */ | |
261 return NULL; | |
262 } | |
263 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
264 static struct irc_channel *find_channel_by_id(struct gaim_connection *gc, int id) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
265 { |
1011 | 266 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
267 struct irc_channel *channel; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
268 |
1011 | 269 GList *temp; |
270 | |
271 temp = idata->channels; | |
272 | |
273 while (temp) { | |
274 channel = (struct irc_channel *)temp->data; | |
275 | |
276 if (channel->id == id) { | |
277 /* We've found our man */ | |
278 return channel; | |
279 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
280 |
1011 | 281 temp = temp->next; |
282 } | |
283 | |
284 | |
285 /* If we didnt find one, return NULL */ | |
286 return NULL; | |
287 } | |
288 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
289 static void irc_chat_send(struct gaim_connection *gc, int id, char *message) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
290 { |
1011 | 291 |
1742 | 292 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1021 | 293 struct irc_channel *channel = NULL; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
294 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
1742 | 295 char **kick; |
296 gboolean is_command = FALSE; | |
1011 | 297 /* First lets get our current channel */ |
298 channel = find_channel_by_id(gc, id); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
299 |
1011 | 300 |
301 if (!channel) { | |
302 /* If for some reason we've lost our channel, let's bolt */ | |
1021 | 303 g_free(buf); |
1011 | 304 return; |
305 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
306 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
307 |
1011 | 308 /* Before we actually send this, we should check to see if they're trying |
1675 | 309 * To issue a command and handle it properly. */ |
1011 | 310 |
1675 | 311 if (message[0] == '/') |
1742 | 312 { |
313 | |
314 if ((g_strncasecmp(message, "/me ", 4) == 0) && (strlen(message) > 4)) { | |
315 /* We have /me!! We have /me!! :-) */ | |
316 | |
317 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
318 strcpy(temp, message + 4); | |
319 | |
320 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%cACTION %s%c\n", channel->name, '\001', temp, | |
321 '\001'); | |
322 g_free(temp); | |
323 } | |
324 else if ((g_strncasecmp(message, "/op ", 4) == 0) && (strlen(message) > 4)) { | |
325 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
326 strcpy(temp, message + 4); | |
327 | |
328 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +o %s\n", channel->name, temp); | |
329 | |
330 g_free(temp); | |
331 is_command = TRUE; | |
332 | |
333 } | |
334 else if ((g_strncasecmp(message, "/deop ", 6) == 0) && (strlen(message) > 6)) { | |
335 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
336 strcpy(temp, message + 6); | |
337 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -o %s\n", channel->name, temp); | |
338 | |
339 g_free(temp); | |
340 is_command = TRUE; | |
1675 | 341 } |
1742 | 342 |
343 else if ((g_strncasecmp(message, "/voice ", 7) == 0) && (strlen(message) > 7)) { | |
344 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
345 strcpy(temp, message + 7); | |
346 | |
347 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s +v %s\n", channel->name, temp); | |
348 | |
349 g_free(temp); | |
350 is_command = TRUE; | |
351 | |
352 } | |
353 else if ((g_strncasecmp(message, "/devoice ", 9) == 0) && (strlen(message) > 9)) { | |
354 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
355 strcpy(temp, message + 6); | |
356 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s -v %s\n", channel->name, temp); | |
357 | |
358 g_free(temp); | |
359 is_command = TRUE; | |
360 } | |
361 else if ((g_strncasecmp(message, "/mode ", 6) == 0) && (strlen(message) > 6)) { | |
362 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
363 strcpy(temp, message + 6); | |
364 g_snprintf(buf, IRC_BUF_LEN, "MODE #%s %s\n", channel->name, temp); | |
365 g_free(temp); | |
366 is_command = TRUE; | |
367 } | |
368 | |
369 else if (!g_strncasecmp(message, "/whois ", 7) && (strlen(message) > 7)) { | |
370 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
371 | |
372 strcpy(temp, message + 7); | |
373 irc_get_info(gc, temp); | |
374 g_free(temp); | |
375 | |
376 | |
377 } | |
378 | |
379 else if (!g_strncasecmp(message, "/raw ", 5) && (strlen(message) > 5)){ | |
380 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
381 strcpy(temp, message + 5); | |
382 g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
383 g_free(temp); | |
384 is_command = TRUE; | |
385 } | |
1675 | 386 |
1742 | 387 else if (!g_strncasecmp(message, "/quote ", 7) && (strlen(message) >7)) { |
388 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
389 strcpy(temp, message + 7); | |
390 g_snprintf(buf, IRC_BUF_LEN, "%s\r\n", temp); | |
391 g_free(temp); | |
392 is_command = TRUE; | |
393 } | |
394 | |
395 else if (!g_strncasecmp(message, "/kick ", 6) && (strlen(message) > 6)) { | |
396 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
397 strcpy(temp, message + 6); | |
398 kick = g_strsplit(temp, " ", 2); | |
399 g_snprintf(buf, IRC_BUF_LEN, "KICK #%s %s :%s\r\n", channel->name, kick[0], kick[1]); | |
400 g_free(temp); | |
401 is_command = TRUE; | |
402 } | |
403 | |
404 /* FIXME: I'll go back in and grab this later. -- Rob */ | |
405 /* | |
406 I THOUGHT THIS WOULD WORK, BUT I WAS WRONG. WOULD SOMEONE KINDLY FIX IT? | |
1675 | 407 |
1742 | 408 |
409 else if (!g_strncasecmp(message, "/help", 5)) { | |
410 gchar *temp = (gchar *) g_malloc(IRC_BUF_LEN + 1); | |
411 strcpy(temp, message + 5); | |
412 if (temp == "") { | |
413 | |
414 serv_got_chat_in(gc, id, "gAIM", 0, "Available Commands:"); | |
415 serv_got_chat_in(gc, id, "gAIM", 0, " "); | |
416 serv_got_chat_in(gc, id, "gAIM", 0, "<b>op voice kick </b>"); | |
417 serv_got_chat_in(gc, id, "gAIM", 0, "<b>deop devoice whois</b>"); | |
418 serv_got_chat_in(gc, id, "gAIM", 0, "<b>me raw quote</b>"); | |
419 serv_got_chat_in(gc, id, "gAIM", 0, "<b>mode</b>"); | |
420 } | |
421 else { | |
422 serv_got_chat_in(gc, id, "gAIM", 0, "Usage: "); | |
423 if (temp == "op") | |
424 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/op <nick></b> - Gives operator status to user."); | |
425 else if (temp == "deop") | |
426 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/deop <nick></b> - Removes operator status from user."); | |
427 else if (temp == "me") | |
428 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/me <action></b> - Sends an action to the channel."); | |
429 else if (temp == "mode") | |
430 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/mode {[+|-}|o|p|s|i|t|n|b|v} [<limit][<nick>][<ban mask]</b> - Changes channel and user modes."); | |
431 else if (temp == "voice") | |
432 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/voice <nick></b> - Gives voice status to user."); | |
433 else if (temp == "devoice") | |
434 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/devoice <nick></b> - Removes voice status from user."); | |
435 else if (temp == "raw") | |
436 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
437 else if (temp == "kick") | |
438 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/kick [<comment>]</b> - Kicks a user out of the channel."); | |
439 else if (temp == "whois") | |
440 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/whois <nick></b> - Gets information about user."); | |
441 else if (temp == "quote") | |
442 serv_got_chat_in(gc, id, "gAIM", 0, "<b>/raw <text></b> - Sends raw text to the server."); | |
443 else | |
444 serv_got_chat_in(gc, id, "gAIM", 0, "No such command."); | |
445 } | |
446 | |
447 g_free(temp); | |
448 is_command = TRUE; | |
449 } | |
450 */ | |
451 | |
452 } | |
453 | |
1675 | 454 else { |
1742 | 455 g_snprintf(buf, IRC_BUF_LEN, "PRIVMSG #%s :%s\n", channel->name, message); |
456 | |
457 } | |
458 | |
459 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
460 write(idata->fd, buf, strlen(buf)); |
1742 | 461 |
1011 | 462 /* Since AIM expects us to receive the message we send, we gotta fake it */ |
1742 | 463 if (is_command==FALSE) |
1764 | 464 serv_got_chat_in(gc, id, gc->username, 0, message, time((time_t)NULL)); |
1742 | 465 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
466 g_free(buf); |
1742 | 467 |
468 | |
1008 | 469 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
470 static struct conversation *find_conversation_by_id(struct gaim_connection *gc, int id) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
471 { |
1014 | 472 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
473 GSList *bc = gc->buddy_chats; | |
474 struct conversation *b = NULL; | |
475 | |
476 while (bc) { | |
477 b = (struct conversation *)bc->data; | |
478 if (id == b->id) { | |
479 break; | |
480 } | |
481 bc = bc->next; | |
482 b = NULL; | |
483 } | |
484 | |
485 if (!b) { | |
486 return NULL; | |
487 } | |
488 | |
489 return b; | |
490 } | |
491 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
492 static struct conversation *find_conversation_by_name(struct gaim_connection *gc, char *name) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
493 { |
1014 | 494 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
495 GSList *bc = gc->buddy_chats; | |
496 struct conversation *b = NULL; | |
497 | |
498 while (bc) { | |
1301 | 499 int x; |
1014 | 500 b = (struct conversation *)bc->data; |
501 | |
502 if (g_strcasecmp(name, b->name) == 0) { | |
503 break; | |
504 } | |
505 bc = bc->next; | |
506 b = NULL; | |
507 } | |
508 | |
509 if (!b) { | |
510 return NULL; | |
511 } | |
512 | |
513 return b; | |
514 } | |
515 | |
516 | |
517 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
518 static void irc_callback(gpointer data, gint source, GdkInputCondition condition) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
519 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
520 struct gaim_connection *gc = data; |
1011 | 521 int i = 0; |
522 gchar buf[4096]; | |
523 gchar **buf2; | |
524 struct irc_data *idata; | |
1742 | 525 |
526 idata = (struct irc_data *)gc->proto_data; | |
1011 | 527 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
528 |
1011 | 529 do { |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
530 if (read(idata->fd, buf + i, 1) < 0) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
531 hide_login_progress(gc, "Read error"); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
532 signoff(gc); |
1105 | 533 return; |
1011 | 534 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
535 } while (buf[i++] != '\n'); |
1011 | 536 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
537 buf[--i] = '\0'; |
1301 | 538 g_strchomp(buf); |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
539 g_print("%s\n", buf); |
1105 | 540 |
541 /* Check for errors */ | |
542 | |
543 if (((strstr(buf, "ERROR :") && (!strstr(buf, "PRIVMSG ")) && | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
544 (!strstr(buf, "NOTICE ")) && (strlen(buf) > 7)))) { |
1105 | 545 |
546 gchar *u_errormsg; | |
547 | |
548 /* Let's get our error message */ | |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
549 u_errormsg = g_strdup(buf + 7); |
1105 | 550 |
551 /* We got our error message. Now, let's reaise an | |
552 * error dialog */ | |
553 | |
554 do_error_dialog(u_errormsg, "Gaim: IRC Error"); | |
555 | |
556 /* And our necessary garbage collection */ | |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
557 g_free(u_errormsg); |
1105 | 558 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
559 |
1673 | 560 /* This should be a whois response. I only care about the first (311) one. I might do |
561 * the other's later. They're boring. */ | |
562 | |
563 if (((strstr(buf, " 311 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
564 char **res; | |
565 | |
566 res = g_strsplit(buf, " ", 7); | |
567 | |
568 if (!strcmp(res[1], "311")) | |
569 { | |
570 char buf[8192]; | |
571 | |
572 g_snprintf(buf, 4096, "<b>Nick:</b> %s<br>" | |
573 "<b>Host:</b> %s@%s<br>" | |
574 "<b>Name:</b> %s<br>", res[3], res[4], res[5], res[7]+1); | |
575 | |
576 g_show_info_text(buf); | |
577 } | |
578 | |
579 g_strfreev(res); | |
580 } | |
581 | |
1676 | 582 /* Autoresponse to an away message */ |
583 if (((strstr(buf, " 301 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { | |
584 char **res; | |
585 | |
586 res = g_strsplit(buf, " ", 5); | |
587 | |
588 if (!strcmp(res[1], "301")) | |
1764 | 589 serv_got_im(gc, res[3], res[4] + 1, 1, time((time_t)NULL)); |
1676 | 590 |
591 g_strfreev(res); | |
592 } | |
593 | |
1014 | 594 /* Parse the list of names that we receive when we first sign on to |
595 * a channel */ | |
596 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
597 if (((strstr(buf, " 353 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { |
1014 | 598 gchar u_host[255]; |
599 gchar u_command[32]; | |
600 gchar u_channel[128]; | |
601 gchar u_names[IRC_BUF_LEN + 1]; | |
602 struct conversation *convo = NULL; | |
603 int j; | |
604 | |
605 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
606 u_host[j] = buf[i]; | |
607 } | |
608 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
609 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
610 i++; |
1014 | 611 |
612 for (j = 0; buf[i] != ' '; j++, i++) { | |
613 u_command[j] = buf[i]; | |
614 } | |
615 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
616 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
617 i++; |
1014 | 618 |
619 for (j = 0; buf[i] != '#'; j++, i++) { | |
620 } | |
621 i++; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
622 |
1014 | 623 for (j = 0; buf[i] != ':'; j++, i++) { |
624 u_channel[j] = buf[i]; | |
625 } | |
626 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
627 u_channel[j - 1] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
628 i++; |
1014 | 629 |
630 while ((buf[i] == ' ') || (buf[i] == ':')) { | |
631 i++; | |
632 } | |
633 | |
634 strcpy(u_names, buf + i); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
635 |
1014 | 636 buf2 = g_strsplit(u_names, " ", 0); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
637 |
1014 | 638 /* Let's get our conversation window */ |
639 convo = find_conversation_by_name(gc, u_channel); | |
640 | |
641 if (!convo) { | |
642 return; | |
643 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
644 |
1014 | 645 /* Now that we've parsed the hell out of this big |
646 * mess, let's try to split up the names properly */ | |
647 | |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
648 for (i = 0; buf2[i] != NULL; i++) |
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
649 add_chat_buddy(convo, buf2[i]); |
1021 | 650 |
651 /* And free our pointers */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
652 g_strfreev(buf2); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
653 |
1014 | 654 return; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
655 |
1014 | 656 } |
657 | |
1022 | 658 /* Receive a list of users that are currently online */ |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
659 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
660 if (((strstr(buf, " 303 ")) && (!strstr(buf, "PRIVMSG")) && (!strstr(buf, "NOTICE")))) { |
1022 | 661 gchar u_host[255]; |
662 gchar u_command[32]; | |
663 gchar u_names[IRC_BUF_LEN + 1]; | |
664 int j; | |
665 | |
666 for (j = 0, i = 0; buf[i] != ' '; j++, i++) { | |
667 u_host[j] = buf[i]; | |
668 } | |
669 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
670 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
671 i++; |
1022 | 672 |
673 for (j = 0; buf[i] != ' '; j++, i++) { | |
674 u_command[j] = buf[i]; | |
675 } | |
676 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
677 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
678 i++; |
1022 | 679 |
680 for (j = 0; buf[i] != ':'; j++, i++) { | |
681 /* My Nick */ | |
682 } | |
683 i++; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
684 |
1022 | 685 strcpy(u_names, buf + i); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
686 |
1022 | 687 buf2 = g_strsplit(u_names, " ", 0); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
688 |
1022 | 689 /* Now that we've parsed the hell out of this big |
690 * mess, let's try to split up the names properly */ | |
691 | |
692 for (i = 0; buf2[i] != NULL; i++) { | |
693 /* If we have a name here then our buddy is online. We should | |
694 * update our temporary gslist accordingly. When we achieve our maximum | |
695 * list of names then we should force an update */ | |
696 | |
697 irc_update_user(gc, buf2[i], 1); | |
698 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
699 |
1022 | 700 /* Increase our received blocks counter */ |
701 idata->recblocks++; | |
702 | |
703 /* If we have our total number of blocks */ | |
704 if (idata->recblocks == idata->totalblocks) { | |
705 GSList *temp; | |
706 struct irc_channel *u; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
707 |
1022 | 708 /* Let's grab our list of people and bring them all on or off line */ |
709 temp = idata->templist; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
710 |
1022 | 711 /* Loop */ |
712 while (temp) { | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
713 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
714 u = temp->data; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
715 |
1022 | 716 /* Tell Gaim to bring the person on or off line */ |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
717 serv_got_update(gc, u->name, u->id, 0, 0, 0, 0, 0); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
718 |
1022 | 719 /* Grab the next entry */ |
720 temp = g_slist_next(temp); | |
721 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
722 |
1022 | 723 /* And now, let's delete all of our entries */ |
724 temp = idata->templist; | |
725 while (temp) { | |
726 u = temp->data; | |
727 g_free(u->name); | |
728 temp = g_slist_remove(temp, u); | |
729 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
730 |
1022 | 731 /* Reset our list */ |
732 idata->totalblocks = 0; | |
733 idata->recblocks = 0; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
734 |
1022 | 735 idata->templist = NULL; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
736 |
1022 | 737 return; |
738 } | |
739 | |
740 /* And free our pointers */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
741 g_strfreev(buf2); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
742 |
1022 | 743 return; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
744 |
1022 | 745 } |
746 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
747 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
748 if ((strstr(buf, " JOIN ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
1011 | 749 |
750 gchar u_channel[128]; | |
1012 | 751 gchar u_nick[128]; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
752 |
1011 | 753 struct irc_channel *channel; |
754 int id; | |
755 int j; | |
756 | |
1012 | 757 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { |
758 u_nick[j] = buf[i]; | |
759 } | |
760 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
761 u_nick[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
762 i++; |
1012 | 763 |
764 for (j = 0; buf[i] != '#'; j++, i++) { | |
1011 | 765 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
766 |
1011 | 767 i++; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
768 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
769 strcpy(u_channel, buf + i); |
1011 | 770 |
1301 | 771 g_strchomp(u_channel); |
772 | |
1014 | 773 /* Looks like we're going to join the channel for real |
774 * now. Let's create a valid channel structure and add | |
775 * it to our list. Let's make sure that | |
1011 | 776 * we are not already in a channel first */ |
777 | |
778 channel = find_channel_by_name(gc, u_channel); | |
779 | |
780 if (!channel) { | |
1301 | 781 |
1011 | 782 chat_id++; |
783 | |
784 channel = g_new0(struct irc_channel, 1); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
785 |
1011 | 786 channel->id = chat_id; |
787 channel->name = strdup(u_channel); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
788 |
1011 | 789 idata->channels = g_list_append(idata->channels, channel); |
790 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
791 serv_got_joined_chat(gc, chat_id, u_channel); |
1011 | 792 } else { |
1014 | 793 struct conversation *convo = NULL; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
794 |
1014 | 795 /* Someone else joined. Find their conversation |
796 * window */ | |
797 convo = find_conversation_by_id(gc, channel->id); | |
798 | |
799 /* And add their name to it */ | |
800 add_chat_buddy(convo, u_nick); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
801 |
1011 | 802 } |
803 | |
804 return; | |
805 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
806 |
1504
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
807 if ((strstr(buf, " NICK ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
808 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
809 gchar old[128]; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
810 gchar new[128]; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
811 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
812 GList *templist; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
813 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
814 struct irc_channel *channel; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
815 int id; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
816 int j; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
817 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
818 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
819 old[j] = buf[i]; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
820 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
821 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
822 old[j] = '\0'; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
823 i++; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
824 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
825 for (j = 0; buf[i] != ':'; j++, i++) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
826 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
827 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
828 i++; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
829 strcpy(new, buf + i); |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
830 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
831 g_strchomp(new); |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
832 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
833 templist = ((struct irc_data *)gc->proto_data)->channels; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
834 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
835 while (templist) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
836 struct conversation *convo = NULL; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
837 channel = templist->data; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
838 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
839 convo = find_conversation_by_id(gc, channel->id); |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
840 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
841 rename_chat_buddy(convo, old, new); |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
842 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
843 templist = templist->next; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
844 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
845 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
846 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
847 if ((strstr(buf, "QUIT ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
848 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
849 gchar u_nick[128]; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
850 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
851 GList *templist; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
852 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
853 struct irc_channel *channel; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
854 int j; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
855 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
856 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
857 u_nick[j] = buf[i]; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
858 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
859 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
860 u_nick[j] = '\0'; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
861 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
862 templist = ((struct irc_data *)gc->proto_data)->channels; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
863 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
864 while (templist) { |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
865 struct conversation *convo = NULL; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
866 channel = templist->data; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
867 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
868 convo = find_conversation_by_id(gc, channel->id); |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
869 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
870 remove_chat_buddy(convo, u_nick); |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
871 |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
872 templist = templist->next; |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
873 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
874 } |
cac3efeb4d9c
[gaim-migrate @ 1514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
875 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
876 if ((strstr(buf, " PART ")) && (buf[0] == ':') && (!strstr(buf, " NOTICE "))) { |
1011 | 877 |
878 gchar u_channel[128]; | |
879 gchar u_nick[128]; | |
880 | |
1021 | 881 struct irc_channel *channel; |
1011 | 882 int id; |
883 int j; | |
884 GList *test = NULL; | |
885 | |
886 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
887 u_nick[j] = buf[i]; | |
888 } | |
889 u_nick[j] = '\0'; | |
890 | |
891 i++; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
892 |
1011 | 893 for (j = 0; buf[i] != '#'; j++, i++) { |
894 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
895 |
1011 | 896 i++; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
897 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
898 strcpy(u_channel, buf + i); |
1011 | 899 |
900 | |
1014 | 901 /* Now, lets check to see if it was US that was leaving. |
902 * If so, do the correct thing by closing up all of our | |
903 * old channel stuff. Otherwise, | |
1011 | 904 * we should just print that someone left */ |
905 | |
1014 | 906 channel = find_channel_by_name(gc, u_channel); |
907 | |
908 if (!channel) { | |
909 return; | |
910 } | |
911 | |
1011 | 912 if (g_strcasecmp(u_nick, gc->username) == 0) { |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
913 |
1014 | 914 /* Looks like we're going to leave the channel for |
915 * real now. Let's create a valid channel structure | |
916 * and add it to our list */ | |
1011 | 917 |
918 serv_got_chat_left(gc, channel->id); | |
919 | |
920 idata->channels = g_list_remove(idata->channels, channel); | |
1014 | 921 } else { |
922 struct conversation *convo = NULL; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
923 |
1014 | 924 /* Find their conversation window */ |
925 convo = find_conversation_by_id(gc, channel->id); | |
926 | |
927 if (!convo) { | |
928 /* Some how the window doesn't exist. | |
929 * Let's get out of here */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
930 return; |
1014 | 931 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
932 |
1014 | 933 /* And remove their name */ |
934 remove_chat_buddy(convo, u_nick); | |
935 | |
1011 | 936 } |
937 | |
1014 | 938 /* Go Home! */ |
1011 | 939 return; |
940 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
941 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
942 if ((strstr(buf, " NOTICE ")) && (buf[0] == ':')) { |
1178 | 943 gchar u_nick[128]; |
944 gchar u_host[255]; | |
945 gchar u_command[32]; | |
946 gchar u_channel[128]; | |
947 gchar u_message[IRC_BUF_LEN]; | |
948 int j; | |
949 int msgcode = 0; | |
950 | |
951 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
952 u_nick[j] = buf[i]; | |
953 } | |
954 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
955 u_nick[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
956 i++; |
1178 | 957 |
958 for (j = 0; buf[i] != ' '; j++, i++) { | |
959 u_host[j] = buf[i]; | |
960 } | |
961 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
962 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
963 i++; |
1178 | 964 |
965 for (j = 0; buf[i] != ' '; j++, i++) { | |
966 u_command[j] = buf[i]; | |
967 } | |
968 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
969 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
970 i++; |
1178 | 971 |
972 for (j = 0; buf[i] != ':'; j++, i++) { | |
973 u_channel[j] = buf[i]; | |
974 } | |
975 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
976 u_channel[j - 1] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
977 i++; |
1178 | 978 |
979 | |
980 /* Now that everything is parsed, the rest of this baby must be our message */ | |
981 strncpy(u_message, buf + i, IRC_BUF_LEN); | |
982 | |
983 /* Now, lets check the message to see if there's anything special in it */ | |
984 if (u_message[0] == '\001') { | |
985 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { | |
986 /* Someone's triyng to ping us. Let's respond */ | |
987 gchar u_arg[24]; | |
988 gchar u_buf[200]; | |
1393 | 989 unsigned long tend= time((time_t *)NULL); |
990 unsigned long tstart; | |
991 | |
992 printf("LA: %s\n", buf); | |
1178 | 993 |
994 strcpy(u_arg, u_message + 6); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
995 u_arg[strlen(u_arg) - 1] = '\0'; |
1178 | 996 |
1393 | 997 tstart = atol(u_arg); |
998 | |
999 g_snprintf(u_buf, sizeof(u_buf), "Ping Reply From %s: [%ld seconds]", u_nick, tend-tstart); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1000 |
1178 | 1001 do_error_dialog(u_buf, "Gaim IRC - Ping Reply"); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1002 |
1178 | 1003 return; |
1004 } | |
1005 } | |
1006 | |
1007 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1008 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1009 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1010 if ((strstr(buf, " PRIVMSG ")) && (buf[0] == ':')) { |
1011 | 1011 gchar u_nick[128]; |
1012 gchar u_host[255]; | |
1013 gchar u_command[32]; | |
1014 gchar u_channel[128]; | |
1015 gchar u_message[IRC_BUF_LEN]; | |
1016 int j; | |
1017 int msgcode = 0; | |
1018 | |
1019 for (j = 0, i = 1; buf[i] != '!'; j++, i++) { | |
1020 u_nick[j] = buf[i]; | |
1021 } | |
1022 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1023 u_nick[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1024 i++; |
1011 | 1025 |
1026 for (j = 0; buf[i] != ' '; j++, i++) { | |
1027 u_host[j] = buf[i]; | |
1028 } | |
1029 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1030 u_host[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1031 i++; |
1011 | 1032 |
1033 for (j = 0; buf[i] != ' '; j++, i++) { | |
1034 u_command[j] = buf[i]; | |
1035 } | |
1036 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1037 u_command[j] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1038 i++; |
1011 | 1039 |
1040 for (j = 0; buf[i] != ':'; j++, i++) { | |
1041 u_channel[j] = buf[i]; | |
1042 } | |
1043 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1044 u_channel[j - 1] = '\0'; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1045 i++; |
1011 | 1046 |
1047 | |
1048 /* Now that everything is parsed, the rest of this baby must be our message */ | |
1049 strncpy(u_message, buf + i, IRC_BUF_LEN); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1050 |
1011 | 1051 /* Now, lets check the message to see if there's anything special in it */ |
1052 if (u_message[0] == '\001') { | |
1017 | 1053 if (g_strncasecmp(u_message, "\001VERSION", 8) == 0) { |
1054 /* Looks like we have a version request. Let | |
1055 * us handle it thusly */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1056 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1057 g_snprintf(buf, IRC_BUF_LEN, |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1058 "NOTICE %s :%cVERSION GAIM %s:The Pimpin Penguin AIM Clone:www.marko.net/gaim%c\n", |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1059 u_nick, '\001', VERSION, '\001'); |
1017 | 1060 |
1061 write(idata->fd, buf, strlen(buf)); | |
1062 | |
1063 /* And get the heck out of dodge */ | |
1064 return; | |
1065 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1066 |
1017 | 1067 if ((g_strncasecmp(u_message, "\001PING ", 6) == 0) && (strlen(u_message) > 6)) { |
1068 /* Someone's triyng to ping us. Let's respond */ | |
1069 gchar u_arg[24]; | |
1070 | |
1071 strcpy(u_arg, u_message + 6); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1072 u_arg[strlen(u_arg) - 1] = '\0'; |
1017 | 1073 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1074 g_snprintf(buf, IRC_BUF_LEN, "NOTICE %s :%cPING %s%c\n", u_nick, '\001', |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1075 u_arg, '\001'); |
1017 | 1076 |
1077 write(idata->fd, buf, strlen(buf)); | |
1078 | |
1079 /* And get the heck out of dodge */ | |
1080 return; | |
1081 } | |
1082 | |
1011 | 1083 if (g_strncasecmp(u_message, "\001ACTION ", 8) == 0) { |
1084 /* Looks like we have an action. Let's parse it a little */ | |
1085 strcpy(buf, u_message); | |
1086 | |
1087 strcpy(u_message, "/me "); | |
1088 for (j = 4, i = 8; buf[i] != '\001'; i++, j++) { | |
1089 u_message[j] = buf[i]; | |
1090 } | |
1091 u_message[j] = '\0'; | |
1092 } | |
1093 } | |
1094 | |
1095 | |
1096 /* Let's check to see if we have a channel on our hands */ | |
1097 if (u_channel[0] == '#') { | |
1098 /* Yup. We have a channel */ | |
1099 int id; | |
1100 | |
1101 id = find_id_by_name(gc, u_channel); | |
1102 if (id != -1) { | |
1764 | 1103 serv_got_chat_in(gc, id, u_nick, 0, u_message, time((time_t)NULL)); |
1011 | 1104 } |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1105 } else { |
1011 | 1106 /* Nope. Let's treat it as a private message */ |
1764 | 1107 serv_got_im(gc, u_nick, u_message, 0, time((time_t)NULL)); |
1011 | 1108 } |
1109 | |
1110 return; | |
1111 } | |
1112 | |
1113 /* Let's parse PING requests so that we wont get booted for inactivity */ | |
1114 | |
1115 if (strncmp(buf, "PING :", 6) == 0) { | |
1116 buf2 = g_strsplit(buf, ":", 1); | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1117 |
1011 | 1118 /* Let's build a new response */ |
1119 g_snprintf(buf, IRC_BUF_LEN, "PONG :%s\n", buf2[1]); | |
1120 write(idata->fd, buf, strlen(buf)); | |
1121 | |
1122 /* And clean up after ourselves */ | |
1123 g_strfreev(buf2); | |
1124 | |
1125 return; | |
1126 } | |
1127 | |
1128 } | |
1129 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1130 static void irc_close(struct gaim_connection *gc) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1131 { |
1011 | 1132 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1021 | 1133 GList *chats = idata->channels; |
1134 struct irc_channel *cc; | |
1135 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1136 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN); |
1011 | 1137 |
1021 | 1138 g_snprintf(buf, IRC_BUF_LEN, "QUIT :Download GAIM [www.marko.net/gaim]\n"); |
1011 | 1139 write(idata->fd, buf, strlen(buf)); |
1140 | |
1141 g_free(buf); | |
1021 | 1142 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1143 if (idata->timer) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1144 gtk_timeout_remove(idata->timer); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1145 |
1021 | 1146 while (chats) { |
1147 cc = (struct irc_channel *)chats->data; | |
1148 g_free(cc->name); | |
1149 chats = g_list_remove(chats, cc); | |
1150 g_free(cc); | |
1151 } | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1152 |
1021 | 1153 if (gc->inpa) |
1154 gdk_input_remove(gc->inpa); | |
1155 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1156 if (idata->inpa) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1157 gdk_input_remove(idata->inpa); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1158 |
1011 | 1159 close(idata->fd); |
1160 g_free(gc->proto_data); | |
1161 } | |
1162 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1163 static void irc_chat_leave(struct gaim_connection *gc, int id) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1164 { |
1011 | 1165 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
1166 struct irc_channel *channel; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1167 gchar *buf = (gchar *) g_malloc(IRC_BUF_LEN + 1); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1168 |
1011 | 1169 channel = find_channel_by_id(gc, id); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1170 |
1011 | 1171 if (!channel) { |
1172 return; | |
1173 } | |
1174 | |
1175 g_snprintf(buf, IRC_BUF_LEN, "PART #%s\n", channel->name); | |
1176 write(idata->fd, buf, strlen(buf)); | |
1177 | |
1178 g_free(buf); | |
1179 } | |
1180 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1181 static void irc_login_callback(gpointer data, gint source, GdkInputCondition condition) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1182 { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1183 struct gaim_connection *gc = data; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1184 struct irc_data *idata = gc->proto_data; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1185 char buf[4096]; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1186 int len, error = ETIMEDOUT; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1187 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1188 len = sizeof(error); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1189 if (getsockopt(idata->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1190 error = errno; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1191 if (error) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1192 hide_login_progress(gc, "Couldn't connect"); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1193 signoff(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1194 return; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1195 } |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1196 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1197 fcntl(idata->fd, F_SETFL, 0); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1198 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1199 g_snprintf(buf, 4096, "NICK %s\n USER %s localhost %s :GAIM (www.marko.net/gaim)\n", |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1200 gc->username, g_get_user_name(), gc->user->proto_opt[0]); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1201 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1202 if (write(idata->fd, buf, strlen(buf)) < 0) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1203 hide_login_progress(gc, "Write error"); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1204 signoff(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1205 return; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1206 } |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1207 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1208 gdk_input_remove(idata->inpa); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1209 idata->inpa = 0; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1210 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1211 /* Now lets sign ourselves on */ |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1212 account_online(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1213 serv_finish_login(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1214 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1215 if (bud_list_cache_exists(gc)) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1216 do_import(NULL, gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1217 |
1269
677e2c9e8baf
[gaim-migrate @ 1279]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1266
diff
changeset
|
1218 /* we don't call this now because otherwise some IRC servers might not like us */ |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1219 idata->timer = gtk_timeout_add(20000, (GtkFunction)irc_request_buddy_update, gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1220 } |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1221 |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1222 static void irc_login(struct aim_user *user) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1223 { |
1011 | 1224 int fd; |
1225 struct hostent *host; | |
1226 struct sockaddr_in site; | |
1227 char buf[4096]; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1228 |
1089
f0f5c10cce63
[gaim-migrate @ 1099]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1075
diff
changeset
|
1229 struct gaim_connection *gc = new_gaim_conn(user); |
1011 | 1230 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); |
1231 char c; | |
1232 int i; | |
1233 int status; | |
1234 | |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1235 host = gethostbyname(user->proto_opt[0]); |
1011 | 1236 if (!host) { |
1237 hide_login_progress(gc, "Unable to resolve hostname"); | |
1115
114cd406b022
[gaim-migrate @ 1125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1105
diff
changeset
|
1238 signoff(gc); |
1011 | 1239 return; |
1240 } | |
1241 | |
1242 site.sin_family = AF_INET; | |
1243 site.sin_addr.s_addr = *(long *)(host->h_addr); | |
1304 | 1244 |
1245 if (user->proto_opt[1][0]) | |
1246 site.sin_port = htons(atoi(user->proto_opt[1])); | |
1247 else { | |
1248 site.sin_port = htons(6667); | |
1249 g_snprintf(user->proto_opt[1], 5, "6667"); | |
1250 } | |
1011 | 1251 |
1252 fd = socket(AF_INET, SOCK_STREAM, 0); | |
1253 if (fd < 0) { | |
1254 hide_login_progress(gc, "Unable to create socket"); | |
1115
114cd406b022
[gaim-migrate @ 1125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1105
diff
changeset
|
1255 signoff(gc); |
1011 | 1256 return; |
1257 } | |
1258 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1259 fcntl(fd, F_SETFL, O_NONBLOCK); |
1011 | 1260 if (connect(fd, (struct sockaddr *)&site, sizeof(site)) < 0) { |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1261 if ((errno == EINPROGRESS) || (errno == EINTR)) { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1262 idata->inpa = gdk_input_add(idata->fd, GDK_INPUT_WRITE, irc_login_callback, gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1263 } else { |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1264 hide_login_progress(gc, "Unable to connect."); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1265 signoff(gc); |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1266 return; |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1267 } |
1011 | 1268 } |
1269 | |
1270 idata->fd = fd; | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1271 |
1011 | 1272 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
1273 set_login_progress(gc, 2, buf); | |
1274 | |
1275 /* This is where we will attempt to sign on */ | |
1276 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1277 if (!idata->inpa) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1278 irc_login_callback(gc, idata->fd, GDK_INPUT_READ); |
1022 | 1279 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1280 gc->inpa = gdk_input_add(idata->fd, GDK_INPUT_READ, irc_callback, gc); |
1011 | 1281 } |
1008 | 1282 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1283 static void irc_print_option(GtkEntry * entry, struct aim_user *user) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1284 { |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1285 if (gtk_object_get_user_data(GTK_OBJECT(entry))) { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1286 g_snprintf(user->proto_opt[1], sizeof(user->proto_opt[1]), "%s", |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1287 gtk_entry_get_text(entry)); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1288 } else { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1289 g_snprintf(user->proto_opt[0], sizeof(user->proto_opt[0]), "%s", |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1290 gtk_entry_get_text(entry)); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1291 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1292 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1293 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1294 static void irc_user_opts(GtkWidget * book, struct aim_user *user) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1295 { |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1296 /* so here, we create the new notebook page */ |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1297 GtkWidget *vbox; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1298 GtkWidget *hbox; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1299 GtkWidget *label; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1300 GtkWidget *entry; |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1301 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1302 vbox = gtk_vbox_new(FALSE, 0); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1303 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("IRC Options")); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1304 gtk_widget_show(vbox); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1305 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1306 hbox = gtk_hbox_new(FALSE, 0); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1307 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1308 gtk_widget_show(hbox); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1309 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1310 label = gtk_label_new("Server:"); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1311 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1312 gtk_widget_show(label); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1313 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1314 entry = gtk_entry_new(); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1315 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1316 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(irc_print_option), user); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1317 if (user->proto_opt[0][0]) { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1318 debug_printf("setting text %s\n", user->proto_opt[0]); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1319 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[0]); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1320 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1321 gtk_widget_show(entry); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1322 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1323 hbox = gtk_hbox_new(FALSE, 0); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1324 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1325 gtk_widget_show(hbox); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1326 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1327 label = gtk_label_new("Port:"); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1328 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1329 gtk_widget_show(label); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1330 |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1331 entry = gtk_entry_new(); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1332 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 5); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1333 if (user->proto_opt[1][0]) { |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1334 debug_printf("setting text %s\n", user->proto_opt[1]); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1335 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[1]); |
1304 | 1336 } else { |
1337 gtk_entry_set_text(GTK_ENTRY(entry), "6667"); | |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1338 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1339 gtk_object_set_user_data(GTK_OBJECT(entry), user); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1340 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(irc_print_option), user); |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1341 gtk_widget_show(entry); |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1342 } |
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1343 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1344 static char **irc_list_icon(int uc) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1345 { |
1178 | 1346 return free_icon_xpm; |
1347 } | |
1348 | |
1349 /* Send out a ping request to the specified user */ | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1350 static void irc_send_ping(GtkObject * w, char *who) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1351 { |
1178 | 1352 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); |
1353 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1354 char buf[BUF_LEN]; | |
1355 | |
1393 | 1356 g_snprintf(buf, BUF_LEN, "PRIVMSG %s :%cPING %ld%c\n", who, '\001', time((time_t *)NULL), '\001'); |
1178 | 1357 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1358 write(idata->fd, buf, strlen(buf)); |
1178 | 1359 } |
1360 | |
1673 | 1361 /* Do a whois check on someone :-) */ |
1362 static void irc_get_info(struct gaim_connection *gc, char *who) | |
1363 { | |
1364 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1365 char buf[BUF_LEN]; | |
1366 | |
1367 if ((who[0] == '@') || (who[0] == '+') && (strlen(who)>1)) | |
1368 g_snprintf(buf, BUF_LEN, "WHOIS %s\n", who+1); | |
1369 else | |
1370 g_snprintf(buf, BUF_LEN, "WHOIS %s\n", who); | |
1371 write(idata->fd, buf, strlen(buf)); | |
1372 } | |
1373 | |
1374 static void irc_send_whois(GtkObject * w, char *who) | |
1375 { | |
1376 struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); | |
1377 irc_get_info(gc, who); | |
1378 } | |
1178 | 1379 |
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1443
diff
changeset
|
1380 static void irc_buddy_menu(GtkWidget * menu, struct gaim_connection *gc, char *who) |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1381 { |
1178 | 1382 GtkWidget *button; |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1383 |
1178 | 1384 button = gtk_menu_item_new_with_label("Ping"); |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1385 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_ping), who); |
1178 | 1386 gtk_object_set_user_data(GTK_OBJECT(button), gc); |
1387 gtk_menu_append(GTK_MENU(menu), button); | |
1388 gtk_widget_show(button); | |
1673 | 1389 |
1390 button = gtk_menu_item_new_with_label("Whois"); | |
1391 gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_whois), who); | |
1392 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
1393 gtk_menu_append(GTK_MENU(menu), button); | |
1394 gtk_widget_show(button); | |
1178 | 1395 } |
1396 | |
1397 | |
1676 | 1398 static void irc_set_away(struct gaim_connection *gc, char *state, char *msg) |
1399 { | |
1400 struct irc_data *idata = (struct irc_data *)gc->proto_data; | |
1401 char buf[BUF_LEN]; | |
1402 | |
1403 if (msg) | |
1404 g_snprintf(buf, BUF_LEN, "AWAY :%s\n", msg); | |
1405 else | |
1406 g_snprintf(buf, BUF_LEN, "AWAY\n"); | |
1407 | |
1408 write(idata->fd, buf, strlen(buf)); | |
1409 } | |
1410 | |
1678 | 1411 static void irc_fake_buddy(struct gaim_connection *gc, char *who) |
1412 { | |
1413 /* Heh, there is no buddy list. We fake it. | |
1414 * I just need this here so the add and remove buttons will | |
1415 * show up */ | |
1416 } | |
1417 | |
1418 | |
1419 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1420 static struct prpl *my_protocol = NULL; |
987 | 1421 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1422 static void irc_init(struct prpl *ret) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1423 { |
1008 | 1424 ret->protocol = PROTO_IRC; |
1425 ret->name = irc_name; | |
1178 | 1426 ret->list_icon = irc_list_icon; |
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1443
diff
changeset
|
1427 ret->buddy_menu = irc_buddy_menu; |
1075
2fe18b2d6105
[gaim-migrate @ 1085]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1056
diff
changeset
|
1428 ret->user_opts = irc_user_opts; |
1008 | 1429 ret->login = irc_login; |
1011 | 1430 ret->close = irc_close; |
1431 ret->send_im = irc_send_im; | |
1432 ret->join_chat = irc_join_chat; | |
1433 ret->chat_leave = irc_chat_leave; | |
1434 ret->chat_send = irc_chat_send; | |
1673 | 1435 ret->get_info = irc_get_info; |
1676 | 1436 ret->set_away = irc_set_away; |
1678 | 1437 ret->add_buddy = irc_fake_buddy; |
1438 ret->remove_buddy = irc_fake_buddy; | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1439 |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1440 my_protocol = ret; |
987 | 1441 } |
1442 | |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1443 char *gaim_plugin_init(GModule * handle) |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1444 { |
1443
336fc98b7f90
[gaim-migrate @ 1453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1394
diff
changeset
|
1445 load_protocol(irc_init, sizeof(struct prpl)); |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1446 return NULL; |
987 | 1447 } |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1448 |
1266
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1449 void gaim_plugin_remove() |
aac04affc65d
[gaim-migrate @ 1276]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1265
diff
changeset
|
1450 { |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1451 struct prpl *p = find_prpl(PROTO_IRC); |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1452 if (p == my_protocol) |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1453 unload_protocol(p); |
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1046
diff
changeset
|
1454 } |