Mercurial > pidgin
annotate src/protocols/irc/irc.c @ 3812:f8b01fcefe0d
[gaim-migrate @ 3959]
fixes a warning in conversations. thanks deryni
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Mon, 28 Oct 2002 02:39:50 +0000 |
parents | ed3e19143373 |
children | 43e396e94095 |
rev | line source |
---|---|
2086 | 1 /* |
2 * gaim - IRC Protocol Plugin | |
3 * | |
4 * Copyright (C) 2000-2001, Rob Flynn <rob@tgflinux.com> | |
5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
2290
23c06449ae8e
[gaim-migrate @ 2300]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
6 * |
23c06449ae8e
[gaim-migrate @ 2300]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
7 * A large portion of this was copied more or less directly from X-Chat, |
23c06449ae8e
[gaim-migrate @ 2300]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
8 * the world's most rocking IRC client. http://www.xchat.org/ |
2086 | 9 * |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 */ | |
25 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
26 #include <config.h> |
2086 | 27 |
3630 | 28 #ifndef _WIN32 |
29 #include <unistd.h> | |
30 #else | |
31 #include <winsock.h> | |
32 #endif | |
33 | |
3029 | 34 #include <fcntl.h> |
2086 | 35 #include <errno.h> |
36 #include <string.h> | |
37 #include <stdlib.h> | |
38 #include <stdio.h> | |
39 #include <time.h> | |
40 #include <sys/stat.h> | |
41 #include <ctype.h> | |
42 #include "multi.h" | |
43 #include "prpl.h" | |
44 #include "gaim.h" | |
45 #include "proxy.h" | |
46 | |
3630 | 47 #ifdef _WIN32 |
48 #include "win32dep.h" | |
49 #endif | |
50 | |
3580 | 51 #include "pixmaps/protocols/irc/irc_icon.xpm" |
2086 | 52 |
53 #define IRC_BUF_LEN 4096 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
54 #define PDIWORDS 32 |
2086 | 55 |
56 #define USEROPT_SERV 0 | |
57 #define USEROPT_PORT 1 | |
3751 | 58 #define USEROPT_CHARSET 2 |
2086 | 59 |
3630 | 60 /* for win32 compatability */ |
61 G_MODULE_IMPORT GSList *connections; | |
62 | |
63 | |
3751 | 64 /* Datastructs */ |
3029 | 65 struct dcc_chat |
66 { | |
67 struct gaim_connection *gc; | |
68 char ip_address[12]; | |
69 int port; | |
70 int fd; | |
71 int inpa; | |
72 char nick[80]; | |
73 }; | |
74 | |
3616 | 75 struct irc_file_transfer { |
3708 | 76 enum { IFT_SENDFILE_IN, IFT_SENDFILE_OUT } type; |
77 struct file_transfer *xfer; | |
78 char *sn; | |
79 char *name; | |
80 int len; | |
81 int watcher; | |
82 int awatcher; | |
83 char ip[12]; | |
84 int port; | |
85 int fd; | |
86 int cur; | |
87 struct gaim_connection *gc; | |
3616 | 88 }; |
89 | |
2086 | 90 struct irc_data { |
91 int fd; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
92 gboolean online; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
93 guint32 timer; |
2086 | 94 |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
95 char *rxqueue; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
96 int rxlen; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
97 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
98 GString *str; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
99 int bc; |
2086 | 100 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
101 char *chantypes; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
102 char *chanmodes; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
103 char *nickmodes; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
104 gboolean six_modes; |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
105 |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
106 gboolean in_whois; |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
107 gboolean in_list; |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
108 GString *liststr; |
3616 | 109 GSList *file_transfers; |
2086 | 110 }; |
111 | |
3751 | 112 /* Prototypes */ |
113 static void irc_start_chat(struct gaim_connection *gc, char *who); | |
114 static void irc_ctcp_clientinfo(struct gaim_connection *gc, char *who); | |
115 static void irc_ctcp_userinfo(struct gaim_connection *gc, char *who); | |
116 static void irc_ctcp_version(struct gaim_connection *gc, char *who); | |
117 static void irc_ctcp_ping(struct gaim_connection *gc, char *who); | |
118 | |
119 static void irc_send_privmsg(struct gaim_connection *gc, char *who, char *what, gboolean fragment); | |
120 static void irc_send_notice(struct gaim_connection *gc, char *who, char *what); | |
121 | |
122 static char *irc_send_convert(struct gaim_connection *gc, char *string, int maxlen, int *done); | |
123 static char *irc_recv_convert(struct gaim_connection *gc, char *string); | |
124 static void irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, | |
125 char *word[], char *word_eol[]); | |
126 static void irc_parse_join(struct gaim_connection *gc, char *nick, | |
127 char *word[], char *word_eol[]); | |
128 static gboolean irc_parse_part(struct gaim_connection *gc, char *nick, char *cmd, | |
129 char *word[], char *word_eol[]); | |
130 static void irc_parse_topic(struct gaim_connection *gc, char *nick, | |
131 char *word[], char *word_eol[]); | |
132 | |
133 static void dcc_chat_cancel(struct dcc_chat *); | |
134 | |
135 /* Global variables */ | |
136 GSList *dcc_chat_list = NULL; | |
137 | |
3029 | 138 struct dcc_chat * |
139 find_dcc_chat (struct gaim_connection *gc, char *nick) | |
140 { | |
141 GSList *tmp; | |
142 struct dcc_chat *data; | |
143 tmp = dcc_chat_list; | |
144 while (tmp != NULL) | |
145 { | |
146 data = (struct dcc_chat *) (tmp)->data; | |
147 if (data | |
148 && data->nick | |
149 && strcmp (nick, data->nick) == 0 | |
150 && gc == data->gc) | |
151 { | |
152 return data; | |
153 } | |
154 tmp = tmp->next; | |
155 } | |
156 return NULL; | |
157 } | |
158 | |
3751 | 159 static int |
160 irc_write(int fd, char *data, int len) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
161 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
162 debug_printf("IRC C: %s", data); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
163 return write(fd, data, len); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
164 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
165 |
3751 | 166 static char * |
167 irc_send_convert(struct gaim_connection *gc, char *string, int maxlen, int *done) | |
168 { | |
169 char *converted = g_malloc(maxlen + 1); | |
170 gchar *inptr = string, *outptr = converted; | |
171 int inleft = strlen(string), outleft = maxlen; | |
172 GIConv conv; | |
173 | |
174 conv = g_iconv_open(gc->user->proto_opt[USEROPT_CHARSET], "UTF-8"); | |
175 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) { | |
176 debug_printf("IRC charset conversion error\n"); | |
177 debug_printf("Sending as UTF-8 (this is a hack!)\n"); | |
178 g_free(converted); | |
179 *done = maxlen; | |
180 return(g_strndup(string, maxlen)); | |
181 } | |
182 | |
183 *done = strlen(string) - inleft; | |
184 *outptr = '\0'; | |
185 return(converted); | |
186 } | |
187 | |
188 static char * | |
189 irc_recv_convert(struct gaim_connection *gc, char *string) | |
190 { | |
191 char *utf8; | |
192 GError *err = NULL; | |
193 | |
194 utf8 = g_convert(string, strlen(string), "UTF-8", | |
195 gc->user->proto_opt[USEROPT_CHARSET], NULL, NULL, &err); | |
196 if (err) { | |
197 debug_printf("IRC recv conversion error: %s\n", err->message); | |
198 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); | |
199 } | |
200 | |
201 return (utf8); | |
202 } | |
203 | |
204 static struct conversation * | |
205 irc_find_chat(struct gaim_connection *gc, char *name) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
206 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
207 GSList *bcs = gc->buddy_chats; |
2086 | 208 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
209 while (bcs) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
210 struct conversation *b = bcs->data; |
2331
1ea2792b6004
[gaim-migrate @ 2343]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2328
diff
changeset
|
211 if (!g_strcasecmp(b->name, name)) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
212 return b; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
213 bcs = bcs->next; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
214 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
215 return NULL; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
216 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
217 |
3751 | 218 static struct conversation * |
219 irc_find_chat_by_id(struct gaim_connection *gc, int id) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
220 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
221 GSList *bcs = gc->buddy_chats; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
222 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
223 while (bcs) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
224 struct conversation *b = bcs->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
225 if (b->id == id) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
226 return b; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
227 bcs = bcs->next; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
228 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
229 return NULL; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
230 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
231 |
3751 | 232 static void |
233 process_data_init(char *buf, char *cmd, char *word[], char *eol[], gboolean quotes) | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
234 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
235 int wordcount = 2; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
236 gboolean space = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
237 gboolean quote = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
238 int j = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
239 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
240 word[1] = cmd; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
241 eol[1] = buf; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
242 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
243 while (TRUE) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
244 switch (*cmd) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
245 case 0: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
246 buf[j] = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
247 for (j = wordcount; j < PDIWORDS; j++) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
248 word[j] = "\000\000"; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
249 eol[j] = "\000\000"; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
250 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
251 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
252 case '"': |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
253 if (!quotes) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
254 space = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
255 buf[j++] = *cmd; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
256 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
257 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
258 quote = !quote; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
259 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
260 case ' ': |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
261 if (quote) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
262 space = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
263 buf[j++] = *cmd; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
264 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
265 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
266 if (space) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
267 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
268 buf[j++] = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
269 word[wordcount] = &buf[j]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
270 eol[wordcount++] = cmd + 1; |
2294
b6c6603a8915
[gaim-migrate @ 2304]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2293
diff
changeset
|
271 if (wordcount == PDIWORDS - 1) { |
b6c6603a8915
[gaim-migrate @ 2304]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2293
diff
changeset
|
272 buf[j] = 0; |
b6c6603a8915
[gaim-migrate @ 2304]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2293
diff
changeset
|
273 return; |
b6c6603a8915
[gaim-migrate @ 2304]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2293
diff
changeset
|
274 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
275 space = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
276 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
277 default: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
278 space = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
279 buf[j++] = *cmd; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
280 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
281 cmd++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
282 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
283 } |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
284 |
3751 | 285 static void |
286 handle_005(struct gaim_connection *gc, char *word[], char *word_eol[]) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
287 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
288 int w = 4; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
289 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
290 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
291 while (w < PDIWORDS && *word[w]) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
292 if (!strncmp(word[w], "MODES=", 5)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
293 if (atoi(word[w] + 6) >= 6) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
294 id->six_modes = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
295 } else if (!strncmp(word[w], "CHANTYPES=", 10)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
296 g_free(id->chantypes); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
297 id->chantypes = g_strdup(word[w] + 10); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
298 } else if (!strncmp(word[w], "CHANMODES=", 10)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
299 g_free(id->chanmodes); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
300 id->chanmodes = g_strdup(word[w] + 10); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
301 } else if (!strncmp(word[w], "PREFIX=", 7)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
302 char *pre = strchr(word[w] + 7, ')'); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
303 if (pre) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
304 *pre = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
305 g_free(id->nickmodes); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
306 id->nickmodes = g_strdup(word[w] + 8); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
307 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
308 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
309 w++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
310 } |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
311 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
312 |
3751 | 313 static char * |
314 int_to_col(int c) | |
2086 | 315 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
316 switch(c) { |
3708 | 317 case 1: |
318 return "#ffffff"; | |
319 case 2: | |
320 return "#000066"; | |
321 case 3: | |
322 return "#006600"; | |
323 case 4: | |
324 return "#ff0000"; | |
325 case 5: | |
326 return "#660000"; | |
327 case 6: | |
328 return "#660066"; | |
329 case 7: | |
330 return "#666600"; | |
331 case 8: | |
332 return "#cccc00"; | |
333 case 9: | |
334 return "#33cc33"; | |
335 case 10: | |
336 return "#00acac"; | |
337 case 11: | |
338 return "#00ccac"; | |
339 case 12: | |
340 return "#0000ff"; | |
341 case 13: | |
342 return "#cc00cc"; | |
343 case 14: | |
344 return "#666666"; | |
345 case 15: | |
346 return "#00ccac"; | |
347 default: | |
348 return "#000000"; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
349 } |
2086 | 350 } |
351 | |
3751 | 352 static GString * |
353 encode_html(char *msg) | |
3029 | 354 { |
355 GString *str = g_string_new(""); | |
356 char *cur = msg, *end = msg; | |
357 gboolean bold = FALSE, underline = FALSE, italics = FALSE; | |
358 | |
359 while ((end = strchr(cur, '<'))) { | |
360 *end = 0; | |
361 str = g_string_append(str, cur); | |
362 cur = ++end; | |
363 if (!g_strncasecmp(cur, "B>", 2)) { | |
3063 | 364 if (!bold) { |
365 bold = TRUE; | |
366 str = g_string_append_c(str, '\2'); | |
367 } | |
3029 | 368 cur = cur + 2; |
369 } else if (!g_strncasecmp(cur, "I>", 2)) { /* use bold for italics too */ | |
3063 | 370 if (!italics) { |
371 italics = TRUE; | |
372 str = g_string_append_c(str, '\2'); | |
373 } | |
3029 | 374 cur = cur + 2; |
375 } else if (!g_strncasecmp(cur, "U>", 2)) { | |
3063 | 376 if (!underline) { |
377 underline = TRUE; | |
378 str = g_string_append_c(str, '\37'); | |
379 } | |
3029 | 380 cur = cur + 2; |
3063 | 381 } else if (!g_strncasecmp(cur, "/B>", 3)) { |
382 if (bold) { | |
383 bold = FALSE; | |
384 str = g_string_append_c(str, '\2'); | |
385 } | |
3029 | 386 cur = cur + 3; |
3063 | 387 } else if (!g_strncasecmp(cur, "/I>", 3)) { |
388 if (italics) { | |
389 italics = FALSE; | |
390 str = g_string_append_c(str, '\2'); | |
391 } | |
3029 | 392 cur = cur + 3; |
3063 | 393 } else if (!g_strncasecmp(cur, "/U>", 3)) { |
394 if (underline) { | |
395 underline = FALSE; | |
396 str = g_string_append_c(str, '\37'); | |
397 } | |
3029 | 398 cur = cur + 3; |
3063 | 399 } else { |
400 str = g_string_append_c(str, '<'); | |
3029 | 401 } |
3063 | 402 |
3029 | 403 } |
404 str = g_string_append(str, cur); | |
405 return str; | |
406 } | |
407 | |
3751 | 408 static GString * |
409 decode_html(char *msg) | |
2086 | 410 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
411 GString /* oo la la */ *str = g_string_new(""); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
412 char *cur = msg, *end = msg; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
413 gboolean bold = FALSE, underline = FALSE, fg = FALSE, bg = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
414 int fore, back; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
415 while (*end) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
416 switch (*end) { |
3708 | 417 case 02: /* ^B */ |
418 *end = 0; | |
419 str = g_string_append(str, cur); | |
420 if (bold) | |
421 str = g_string_append(str, "</B>"); | |
422 else | |
423 str = g_string_append(str, "<B>"); | |
424 bold = !bold; | |
425 cur = end + 1; | |
426 break; | |
427 case 03: /* ^C */ | |
428 *end++ = 0; | |
429 str = g_string_append(str, cur); | |
430 fore = back = -1; | |
431 if (isdigit(*end)) { | |
432 fore = *end++ - '0'; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
433 if (isdigit(*end)) { |
3708 | 434 fore *= 10; |
435 fore += *end++ - '0'; | |
436 } | |
437 if (*end == ',' && isdigit(end[1])) { | |
438 end++; | |
439 back = *end++ - '0'; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
440 if (isdigit(*end)) { |
3708 | 441 back *= 10; |
442 back += *end++ - '0'; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
443 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
444 } |
3708 | 445 } |
446 if (fore == -1) { | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
447 if (fg) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
448 str = g_string_append(str, "</FONT>"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
449 if (bg) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
450 str = g_string_append(str, "</FONT>"); |
3708 | 451 fg = bg = FALSE; |
452 } else { | |
453 fore %= 16; | |
454 if (fg) | |
455 str = g_string_append(str, "</FONT>"); | |
456 if (back != -1) { | |
457 if (bg) | |
458 str = g_string_append(str, "</FONT>"); | |
459 back %= 16; | |
460 str = g_string_append(str, "<FONT BACK="); | |
461 str = g_string_append(str, int_to_col(back)); | |
462 str = g_string_append_c(str, '>'); | |
463 bg = TRUE; | |
464 } | |
465 str = g_string_append(str, "<FONT COLOR="); | |
466 str = g_string_append(str, int_to_col(fore)); | |
467 str = g_string_append_c(str, '>'); | |
468 fg = TRUE; | |
469 } | |
470 cur = end--; | |
471 break; | |
472 case 017: /* ^O */ | |
473 if (!bold && !underline && !fg && !bg) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
474 break; |
3708 | 475 *end = 0; |
476 str = g_string_append(str, cur); | |
477 if (bold) | |
478 str = g_string_append(str, "</B>"); | |
479 if (underline) | |
480 str = g_string_append(str, "</U>"); | |
481 if (fg) | |
482 str = g_string_append(str, "</FONT>"); | |
483 if (bg) | |
484 str = g_string_append(str, "</FONT>"); | |
485 bold = underline = fg = bg = FALSE; | |
486 cur = end + 1; | |
487 break; | |
488 case 037: /* ^_ */ | |
489 *end = 0; | |
490 str = g_string_append(str, cur); | |
491 if (underline) | |
492 str = g_string_append(str, "</U>"); | |
493 else | |
494 str = g_string_append(str, "<U>"); | |
495 underline = !underline; | |
496 cur = end + 1; | |
497 break; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
498 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
499 end++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
500 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
501 if (*cur) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
502 str = g_string_append(str, cur); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
503 return str; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
504 } |
2086 | 505 |
3751 | 506 static void |
507 irc_got_im(struct gaim_connection *gc, char *who, char *what, int flags, time_t t) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
508 { |
3751 | 509 char *utf8 = irc_recv_convert(gc, what); |
510 GString *str = decode_html(utf8); | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2847
diff
changeset
|
511 serv_got_im(gc, who, str->str, flags, t, -1); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
512 g_string_free(str, TRUE); |
3751 | 513 g_free(utf8); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
514 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
515 |
3751 | 516 static void |
517 dcc_chat_cancel(struct dcc_chat *); | |
3029 | 518 |
519 void | |
520 dcc_chat_in (gpointer data, gint source, GaimInputCondition condition) | |
521 { | |
522 struct dcc_chat *chat = data; | |
523 gchar buffer[IRC_BUF_LEN]; | |
524 gchar buf[128]; | |
3793 | 525 int n = 0; |
3029 | 526 struct conversation *convo; |
527 debug_printf("THIS IS TOO MUCH EFFORT\n"); | |
528 n = read (chat->fd, buffer, IRC_BUF_LEN); | |
3707 | 529 if (n > 0) { |
530 | |
531 buffer[n] = 0; | |
532 g_strstrip(buffer); | |
533 | |
534 /* Convert to HTML */ | |
535 if (strlen(buffer)) { | |
536 debug_printf ("DCC Message from: %s\n", chat->nick); | |
537 irc_got_im(chat->gc, chat->nick, buffer, 0, | |
538 time(NULL)); | |
539 } | |
540 } | |
3029 | 541 else { |
542 g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), | |
543 chat->nick); | |
544 convo = new_conversation (chat->nick); | |
545 write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, | |
546 time ((time_t) NULL), -1); | |
3730 | 547 dcc_chat_cancel (chat); |
3029 | 548 } |
549 } | |
550 | |
3751 | 551 static void |
552 irc_file_transfer_do(struct gaim_connection *gc, struct irc_file_transfer *ift) { | |
3616 | 553 /* Ok, we better be receiving some crap here boyeee */ |
554 if (transfer_in_do(ift->xfer, ift->fd, ift->name, ift->len)) { | |
3708 | 555 gaim_input_remove(ift->watcher); |
556 ift->watcher = 0; | |
3616 | 557 } |
558 } | |
559 | |
560 | |
3751 | 561 void |
562 irc_read_dcc_ack (gpointer data, gint source, GaimInputCondition condition) { | |
3708 | 563 /* Read ACK Here */ |
3633 | 564 |
3630 | 565 } |
566 | |
3751 | 567 void |
568 dcc_send_callback (gpointer data, gint source, GaimInputCondition condition) { | |
3708 | 569 struct irc_file_transfer *ift = data; |
570 struct sockaddr_in addr; | |
571 int len = sizeof(addr); | |
3622 | 572 |
3708 | 573 addr.sin_family = AF_INET; |
574 addr.sin_port = htons(ift->port); | |
575 addr.sin_addr.s_addr = INADDR_ANY; | |
3622 | 576 |
3708 | 577 ift->fd = accept(ift->fd, (struct sockaddr *)&addr, &len); |
578 if (!ift->fd) { | |
579 /* FIXME: Handle this gracefully XXX */ | |
580 printf("Something bad happened here, bubba!\n"); | |
581 return; | |
582 } | |
3622 | 583 |
3633 | 584 /* ift->awatcher = gaim_input_add(ift->fd, GAIM_INPUT_READ, irc_read_dcc_ack, ift); */ |
3630 | 585 |
3708 | 586 if (transfer_out_do(ift->xfer, ift->fd, 0)) { |
587 gaim_input_remove(ift->watcher); | |
588 ift->watcher = 0; | |
589 } | |
3622 | 590 } |
591 | |
3751 | 592 void |
593 dcc_recv_callback (gpointer data, gint source, GaimInputCondition condition) { | |
3708 | 594 struct irc_file_transfer *ift = data; |
595 | |
596 ift->fd = source; | |
597 irc_file_transfer_do(ift->gc, ift); | |
3616 | 598 } |
599 | |
3751 | 600 void |
601 dcc_chat_callback (gpointer data, gint source, GaimInputCondition condition) { | |
3029 | 602 struct dcc_chat *chat = data; |
603 struct conversation *convo = new_conversation (chat->nick); | |
604 char buf[IRC_BUF_LEN]; | |
605 chat->fd = source; | |
606 g_snprintf (buf, sizeof buf, | |
607 "DCC Chat with %s established", | |
608 chat->nick); | |
609 write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, | |
610 time ((time_t) NULL), -1); | |
611 debug_printf ("Chat with %s established\n", chat->nick); | |
612 dcc_chat_list = g_slist_append (dcc_chat_list, chat); | |
613 gaim_input_remove(chat->inpa); | |
614 chat->inpa = gaim_input_add(source, GAIM_INPUT_READ, dcc_chat_in, chat); | |
615 } | |
616 | |
3751 | 617 static void |
618 irc_got_chat_in(struct gaim_connection *gc, int id, char *who, int whisper, char *msg, time_t t) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
619 { |
3751 | 620 char *utf8 = irc_recv_convert(gc, msg); |
621 GString *str = decode_html(utf8); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
622 serv_got_chat_in(gc, id, who, whisper, str->str, t); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
623 g_string_free(str, TRUE); |
3751 | 624 g_free(utf8); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
625 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
626 |
3751 | 627 static void |
628 handle_list(struct gaim_connection *gc, char *list) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
629 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
630 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
631 GSList *gr; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
632 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
633 id->str = g_string_append_c(id->str, ' '); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
634 id->str = g_string_append(id->str, list); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
635 id->bc--; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
636 if (id->bc) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
637 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
638 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
639 g_strdown(id->str->str); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
640 gr = gc->groups; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
641 while (gr) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
642 GSList *m = ((struct group *)gr->data)->members; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
643 while (m) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
644 struct buddy *b = m->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
645 char *tmp = g_strdup(b->name); |
3028 | 646 char *x, *l; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
647 g_strdown(tmp); |
2310
b2db2a76dcec
[gaim-migrate @ 2320]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2305
diff
changeset
|
648 x = strstr(id->str->str, tmp); |
3028 | 649 l = x + strlen(b->name); |
650 if (x && (*l != ' ' && *l != 0)) | |
651 x = 0; | |
2310
b2db2a76dcec
[gaim-migrate @ 2320]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2305
diff
changeset
|
652 if (!b->present && x) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
653 serv_got_update(gc, b->name, 1, 0, 0, 0, 0, 0); |
2310
b2db2a76dcec
[gaim-migrate @ 2320]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2305
diff
changeset
|
654 else if (b->present && !x) |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
655 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
656 g_free(tmp); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
657 m = m->next; |
2086 | 658 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
659 gr = gr->next; |
2086 | 660 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
661 g_string_free(id->str, TRUE); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
662 id->str = g_string_new(""); |
2086 | 663 } |
664 | |
3751 | 665 static gboolean |
666 irc_request_buddy_update(gpointer data) | |
2086 | 667 { |
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
668 struct gaim_connection *gc = data; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
669 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
670 char buf[500]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
671 int n = g_snprintf(buf, sizeof(buf), "ISON"); |
2086 | 672 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
673 GSList *gr = gc->groups; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
674 if (!gr || id->bc) |
2137
18722ae5b882
[gaim-migrate @ 2147]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2131
diff
changeset
|
675 return TRUE; |
2086 | 676 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
677 while (gr) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
678 struct group *g = gr->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
679 GSList *m = g->members; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
680 while (m) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
681 struct buddy *b = m->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
682 if (n + strlen(b->name) + 2 > sizeof(buf)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
683 g_snprintf(buf + n, sizeof(buf) - n, "\r\n"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
684 irc_write(id->fd, buf, n); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
685 id->bc++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
686 n = g_snprintf(buf, sizeof(buf), "ISON"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
687 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
688 n += g_snprintf(buf + n, sizeof(buf) - n, " %s", b->name); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
689 m = m->next; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
690 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
691 gr = gr->next; |
2086 | 692 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
693 g_snprintf(buf + n, sizeof(buf) - n, "\r\n"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
694 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
695 id->bc++; |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
696 return TRUE; |
2086 | 697 } |
698 | |
3751 | 699 static void |
700 handle_names(struct gaim_connection *gc, char *chan, char *names) | |
2086 | 701 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
702 struct conversation *c = irc_find_chat(gc, chan); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
703 char **buf, **tmp; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
704 if (!c) return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
705 if (*names == ':') names++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
706 buf = g_strsplit(names, " ", -1); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
707 for (tmp = buf; *tmp; tmp++) |
3708 | 708 add_chat_buddy(c, *tmp, NULL); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
709 g_strfreev(buf); |
2086 | 710 } |
711 | |
3751 | 712 static void |
713 handle_notopic(struct gaim_connection *gc, char *text) | |
3707 | 714 { |
715 struct conversation *c; | |
716 if ((c = irc_find_chat(gc, text))) { | |
717 char buf[IRC_BUF_LEN]; | |
718 g_snprintf(buf, sizeof(buf), _("No topic is set")); | |
719 chat_set_topic(c, NULL, buf); | |
720 } | |
721 } | |
722 | |
3751 | 723 static void |
724 handle_topic(struct gaim_connection *gc, char *text) | |
2086 | 725 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
726 struct conversation *c; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
727 char *po = strchr(text, ' '); |
2086 | 728 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
729 if (!po) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
730 return; |
2086 | 731 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
732 *po = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
733 po += 2; |
2086 | 734 |
2328
14c8df9cc75f
[gaim-migrate @ 2338]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2312
diff
changeset
|
735 if ((c = irc_find_chat(gc, text))) { |
14c8df9cc75f
[gaim-migrate @ 2338]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2312
diff
changeset
|
736 char buf[IRC_BUF_LEN]; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
737 chat_set_topic(c, NULL, po); |
2328
14c8df9cc75f
[gaim-migrate @ 2338]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2312
diff
changeset
|
738 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"), |
3708 | 739 text, po); |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2847
diff
changeset
|
740 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); |
2328
14c8df9cc75f
[gaim-migrate @ 2338]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2312
diff
changeset
|
741 } |
2086 | 742 } |
743 | |
3751 | 744 static gboolean |
745 mode_has_arg(struct gaim_connection *gc, char sign, char mode) | |
2086 | 746 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
747 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
748 char *cm = id->chanmodes; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
749 int type = 0; |
2086 | 750 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
751 if (strchr(id->nickmodes, mode)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
752 return TRUE; |
2086 | 753 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
754 while (*cm) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
755 if (*cm == ',') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
756 type++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
757 else if (*cm == mode) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
758 switch (type) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
759 case 0: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
760 case 1: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
761 return TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
762 case 2: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
763 if (sign == '+') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
764 return TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
765 case 3: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
766 return FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
767 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
768 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
769 cm++; |
2086 | 770 } |
771 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
772 return FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
773 } |
2086 | 774 |
3751 | 775 static void |
776 irc_chan_mode(struct gaim_connection *gc, char *room, char sign, char mode, char *argstr, char *who) | |
3452 | 777 { |
778 struct conversation *c = irc_find_chat(gc, room); | |
779 char buf[IRC_BUF_LEN]; | |
780 char *nick = g_strndup(who, strchr(who, '!') - who); | |
781 | |
3707 | 782 g_snprintf(buf, sizeof(buf), "-:- mode/%s [%c%c %s] by %s", |
783 room, sign, mode, strlen(argstr) ? argstr : "", | |
784 nick); | |
3452 | 785 g_free(nick); |
786 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time((time_t)NULL), -1); | |
787 } | |
788 | |
3751 | 789 static void |
790 irc_user_mode(struct gaim_connection *gc, char *room, char sign, char mode, char *nick) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
791 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
792 struct conversation *c = irc_find_chat(gc, room); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
793 GList *r; |
2086 | 794 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
795 if (mode != 'o' && mode != 'v') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
796 return; |
2086 | 797 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
798 if (!c) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
799 return; |
2086 | 800 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
801 r = c->in_room; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
802 while (r) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
803 gboolean op = FALSE, voice = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
804 char *who = r->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
805 if (*who == '@') { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
806 op = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
807 who++; |
2086 | 808 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
809 if (*who == '+') { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
810 voice = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
811 who++; |
2086 | 812 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
813 if (!strcmp(who, nick)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
814 char *tmp, buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
815 if (mode == 'o') { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
816 if (sign == '-') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
817 op = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
818 else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
819 op = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
820 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
821 if (mode == 'v') { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
822 if (sign == '-') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
823 voice = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
824 else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
825 voice = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
826 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
827 tmp = g_strdup(r->data); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
828 g_snprintf(buf, sizeof(buf), "%s%s%s", op ? "@" : "", |
3708 | 829 voice ? "+" : "", nick); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
830 rename_chat_buddy(c, tmp, buf); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
831 g_free(tmp); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
832 return; |
2086 | 833 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
834 r = r->next; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
835 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
836 } |
2086 | 837 |
3751 | 838 static void |
839 handle_mode(struct gaim_connection *gc, char *word[], char *word_eol[], gboolean n324) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
840 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
841 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
842 int offset = n324 ? 4 : 3; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
843 char *chan = word[offset]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
844 struct conversation *c = irc_find_chat(gc, chan); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
845 char *modes = word[offset + 1]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
846 int len = strlen(word_eol[offset]) - 1; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
847 char sign = *modes++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
848 int arg = 1; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
849 char *argstr; |
3452 | 850 char *who = word[1]; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
851 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
852 if (!c) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
853 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
854 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
855 if (word_eol[offset][len] == ' ') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
856 word_eol[offset][len] = 0; |
2086 | 857 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
858 while (TRUE) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
859 switch (*modes) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
860 case 0: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
861 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
862 case '+': |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
863 case '-': |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
864 sign = *modes; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
865 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
866 default: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
867 if (mode_has_arg(gc, sign, *modes)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
868 argstr = word[++arg + offset]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
869 else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
870 argstr = ""; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
871 if (strchr(id->nickmodes, *modes)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
872 irc_user_mode(gc, chan, sign, *modes, argstr); |
3452 | 873 else if (strchr(who, '!')) |
874 irc_chan_mode(gc, chan, sign, *modes, argstr, who); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
875 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
876 modes++; |
2086 | 877 } |
878 } | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
879 |
3751 | 880 static void |
881 handle_version(struct gaim_connection *gc, char *word[], char *word_eol[], int num) | |
3452 | 882 { |
883 struct irc_data *id = gc->proto_data; | |
884 GString *str; | |
885 | |
886 id->liststr = g_string_new(""); | |
887 | |
888 id->liststr = g_string_append(id->liststr, "<b>Version: </b>"); | |
889 id->liststr = g_string_append(id->liststr, word_eol[4]); | |
890 | |
891 str = decode_html(id->liststr->str); | |
892 g_show_info_text(gc, NULL, 2, str->str, NULL); | |
893 g_string_free(str, TRUE); | |
894 g_string_free(id->liststr, TRUE); | |
895 id->liststr = NULL; | |
896 } | |
897 | |
3751 | 898 static void |
899 handle_who(struct gaim_connection *gc, char *word[], char *word_eol[], int num) | |
3452 | 900 { |
901 struct irc_data *id = gc->proto_data; | |
902 char buf[IRC_BUF_LEN]; | |
903 | |
904 if (!id->in_whois) { | |
905 id->in_whois = TRUE; | |
906 id->liststr = g_string_new(""); | |
907 } | |
908 | |
909 switch (num) { | |
910 case 352: | |
911 g_snprintf(buf, sizeof(buf), "<b>%s</b> (%s@%s): %s<br>", | |
912 word[8], word[5], word[6], word_eol[11]); | |
913 id->liststr = g_string_append(id->liststr, buf); | |
914 break; | |
915 } | |
916 } | |
917 | |
2648 | 918 /* Handle our whois stuff here. You know what, I have a sore throat. You know |
919 * what I think about that? I'm not too pleased with it. Perhaps I should take | |
920 * some medicine, or perhaps I should go to bed? Blah!! */ | |
921 | |
3751 | 922 static void |
923 handle_whois(struct gaim_connection *gc, char *word[], char *word_eol[], int num) | |
2648 | 924 { |
925 struct irc_data *id = gc->proto_data; | |
926 char tmp[1024]; | |
927 | |
928 if (!id->in_whois) { | |
929 id->in_whois = TRUE; | |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
930 id->liststr = g_string_new(""); |
2648 | 931 } else { |
932 /* I can't decide if we should have one break or two */ | |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
933 id->liststr = g_string_append(id->liststr, "<BR>"); |
2648 | 934 id->in_whois = TRUE; |
935 } | |
936 | |
937 switch (num) { | |
3707 | 938 case 311: |
939 id->liststr = g_string_append(id->liststr, "<b>User: </b>"); | |
940 break; | |
941 case 312: | |
942 id->liststr = g_string_append(id->liststr, "<b>Server: </b>"); | |
943 break; | |
944 case 313: | |
945 g_snprintf(tmp, sizeof(tmp), "<b>IRC Operator:</b> %s ", word[4]); | |
946 id->liststr = g_string_append(id->liststr, tmp); | |
947 break; | |
948 case 314: | |
949 id->liststr = g_string_append(id->liststr, "<b>User: </b>"); | |
950 g_snprintf(tmp, sizeof(tmp), "<b>%s</b> (%s@%s) %s", | |
951 word[4], word[5], word[6], word_eol[8]); | |
952 id->liststr = g_string_append(id->liststr, tmp); | |
953 return; | |
954 case 317: | |
955 id->liststr = g_string_append(id->liststr, "<b>Idle Time: </b>"); | |
956 break; | |
957 case 319: | |
958 id->liststr = g_string_append(id->liststr, "<b>Channels: </b>"); | |
959 break; | |
960 default: | |
961 break; | |
2648 | 962 } |
3452 | 963 |
2651
f84dcbcfba4b
[gaim-migrate @ 2664]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2650
diff
changeset
|
964 if (word_eol[5][0] == ':') |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
965 id->liststr = g_string_append(id->liststr, word_eol[5] + 1); |
3452 | 966 /* Nicer idle time output, by jonas@birme.se */ |
967 else if (isdigit(word_eol[5][0])) { | |
968 time_t idle = atol(word_eol[5]); | |
969 time_t signon = atol(strchr(word_eol[5], ' ')); | |
970 | |
971 g_snprintf(tmp, sizeof(tmp), | |
972 "%ld seconds [signon: %s]", (idle / 1000), ctime(&signon)); | |
973 id->liststr = g_string_append(id->liststr, tmp); | |
974 } | |
2651
f84dcbcfba4b
[gaim-migrate @ 2664]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2650
diff
changeset
|
975 else |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
976 id->liststr = g_string_append(id->liststr, word_eol[5]); |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
977 } |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
978 |
3751 | 979 static void |
980 handle_roomlist(struct gaim_connection *gc, char *word[], char *word_eol[]) | |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
981 { |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
982 struct irc_data *id = gc->proto_data; |
2648 | 983 |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
984 if (!id->in_list) { |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
985 id->in_list = TRUE; |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
986 id->liststr = g_string_new(""); |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
987 } else { |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
988 id->liststr = g_string_append(id->liststr, "<BR>"); |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
989 id->in_list = TRUE; |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
990 } |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
991 |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
992 id->liststr = g_string_append(id->liststr, word_eol[4]); |
2648 | 993 } |
994 | |
3751 | 995 static void |
996 irc_change_nick(void *a, char *b) { | |
3511 | 997 struct gaim_connection *gc = a; |
998 struct irc_data *id = gc->proto_data; | |
999 char buf[IRC_BUF_LEN]; | |
1000 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", b); | |
1001 irc_write(id->fd, buf, strlen(buf)); | |
1002 } | |
1003 | |
3751 | 1004 static void |
1005 process_numeric(struct gaim_connection *gc, char *word[], char *word_eol[]) | |
2086 | 1006 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1007 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1008 char *text = word_eol[3]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1009 int n = atoi(word[2]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1010 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1011 if (!g_strncasecmp(gc->displayname, text, strlen(gc->displayname))) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1012 text += strlen(gc->displayname) + 1; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1013 if (*text == ':') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1014 text++; |
2086 | 1015 |
3707 | 1016 /* RPL_ and ERR_ */ |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1017 switch (n) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1018 case 4: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1019 if (!strncmp(word[5], "u2.10", 5)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1020 id->six_modes = TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1021 else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1022 id->six_modes = FALSE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1023 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1024 case 5: |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1025 handle_005(gc, word, word_eol); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1026 break; |
3707 | 1027 case 301: /* RPL_AWAY */ |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1028 if (id->in_whois) { |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1029 id->liststr = g_string_append(id->liststr, "<BR><b>Away: </b>"); |
2651
f84dcbcfba4b
[gaim-migrate @ 2664]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2650
diff
changeset
|
1030 |
f84dcbcfba4b
[gaim-migrate @ 2664]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2650
diff
changeset
|
1031 if (word_eol[5][0] == ':') |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1032 id->liststr = g_string_append(id->liststr, word_eol[5] + 1); |
2651
f84dcbcfba4b
[gaim-migrate @ 2664]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2650
diff
changeset
|
1033 else |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1034 id->liststr = g_string_append(id->liststr, word_eol[5]); |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1035 } else |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1036 irc_got_im(gc, word[4], word_eol[5], IM_FLAG_AWAY, time(NULL)); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1037 break; |
3707 | 1038 case 303: /* RPL_ISON */ |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1039 handle_list(gc, &word_eol[4][1]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1040 break; |
3707 | 1041 case 311: /* RPL_WHOISUSER */ |
1042 case 312: /* RPL_WHOISSERVER */ | |
1043 case 313: /* RPL_WHOISOPERATOR */ | |
1044 case 314: /* RPL_WHOWASUSER */ | |
1045 case 317: /* RPL_WHOISIDLE */ | |
1046 case 319: /* RPL_WHOISCHANNELS */ | |
2648 | 1047 handle_whois(gc, word, word_eol, n); |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1048 break; |
3707 | 1049 case 322: /* RPL_LIST */ |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1050 handle_roomlist(gc, word, word_eol); |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1051 break; |
3707 | 1052 case 315: /* RPL_ENDOFWHO */ |
1053 case 318: /* RPL_ENDOFWHOIS */ | |
1054 case 323: /* RPL_LISTEND */ | |
1055 case 369: /* RPL_ENDOFWHOWAS */ | |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1056 if ((id->in_whois || id->in_list) && id->liststr) { |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1057 GString *str = decode_html(id->liststr->str); |
2791
8f6365332a05
[gaim-migrate @ 2804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2782
diff
changeset
|
1058 g_show_info_text(gc, NULL, 2, str->str, NULL); |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1059 g_string_free(str, TRUE); |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1060 g_string_free(id->liststr, TRUE); |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1061 id->liststr = NULL; |
2652
65a602693286
[gaim-migrate @ 2665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2651
diff
changeset
|
1062 id->in_whois = FALSE; |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1063 id->in_list = FALSE; |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1064 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1065 break; |
3707 | 1066 case 324: /* RPL_CHANNELMODEIS */ |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1067 handle_mode(gc, word, word_eol, TRUE); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1068 break; |
3707 | 1069 case 331: /* RPL_NOTOPIC */ |
1070 handle_notopic(gc, text); | |
1071 break; | |
1072 case 332: /* RPL_TOPIC */ | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1073 handle_topic(gc, text); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1074 break; |
3707 | 1075 case 351: /* RPL_VERSION */ |
3452 | 1076 handle_version(gc, word, word_eol, n); |
1077 break; | |
3707 | 1078 case 352: /* RPL_WHOREPLY */ |
3708 | 1079 handle_who(gc, word, word_eol, n); |
1080 break; | |
3707 | 1081 case 353: /* RPL_NAMREPLY */ |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1082 handle_names(gc, word[5], word_eol[6]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1083 break; |
3707 | 1084 case 376: /* RPL_ENDOFMOTD */ |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1085 irc_request_buddy_update(gc); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1086 break; |
3707 | 1087 case 382: /* RPL_REHASHING */ |
1088 do_error_dialog(_("Rehashing server"), _("IRC Operator"), GAIM_ERROR); | |
1089 break; | |
1090 case 401: /* ERR_NOSUCHNICK */ | |
1091 do_error_dialog(_("No such nick/channel"), _("IRC Error"), GAIM_ERROR); | |
2652
65a602693286
[gaim-migrate @ 2665]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2651
diff
changeset
|
1092 break; |
3707 | 1093 case 402: /* ERR_NOSUCHSERVER */ |
1094 do_error_dialog(_("No such server"), _("IRC Error"), GAIM_ERROR); | |
1095 case 431: /* ERR_NONICKNAMEGIVEN */ | |
1096 do_error_dialog(_("No nickname given"), _("IRC Error"), GAIM_ERROR); | |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
1097 break; |
3707 | 1098 case 481: /* ERR_NOPRIVILEGES */ |
1099 do_error_dialog(_("You're not an IRC operator!"), _("IRC Error"), GAIM_ERROR); | |
1100 break; | |
3511 | 1101 case 433: |
1102 do_prompt_dialog(_("That nick is already in use. Please enter a new nick"), gc->displayname, gc, irc_change_nick, NULL); | |
3605 | 1103 break; |
3452 | 1104 default: |
3707 | 1105 /* Other error messages */ |
3452 | 1106 if (n > 400 && n < 502) { |
1107 char errmsg[IRC_BUF_LEN]; | |
1108 char *errmsg1 = strrchr(text, ':'); | |
1109 g_snprintf(errmsg, sizeof(errmsg), "IRC Error %d", n); | |
1110 if (errmsg) | |
3536 | 1111 do_error_dialog(errmsg, errmsg1 ? errmsg1+1 : NULL, GAIM_ERROR); |
3452 | 1112 } |
1113 break; | |
2086 | 1114 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1115 } |
2086 | 1116 |
3751 | 1117 static gboolean |
1118 is_channel(struct gaim_connection *gc, char *name) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1119 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1120 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1121 if (strchr(id->chantypes, *name)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1122 return TRUE; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1123 return FALSE; |
2086 | 1124 } |
1125 | |
3751 | 1126 static void |
1127 irc_rem_chat_bud(struct gaim_connection *gc, char *nick, char *reason) | |
2086 | 1128 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1129 GSList *bcs = gc->buddy_chats; |
2086 | 1130 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1131 while (bcs) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1132 struct conversation *b = bcs->data; |
2086 | 1133 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1134 GList *r = b->in_room; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1135 while (r) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1136 char *who = r->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1137 if (*who == '@') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1138 who++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1139 if (*who == '+') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1140 who++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1141 if (!g_strcasecmp(who, nick)) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1142 char *tmp = g_strdup(r->data); |
2820
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1143 remove_chat_buddy(b, tmp, reason); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1144 g_free(tmp); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1145 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1146 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1147 r = r->next; |
2086 | 1148 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1149 bcs = bcs->next; |
2086 | 1150 } |
1151 } | |
1152 | |
3751 | 1153 static void |
1154 irc_change_name(struct gaim_connection *gc, char *old, char *new) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1155 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1156 GSList *bcs = gc->buddy_chats; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1157 char buf[IRC_BUF_LEN]; |
2086 | 1158 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1159 while (bcs) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1160 struct conversation *b = bcs->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1161 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1162 GList *r = b->in_room; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1163 while (r) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1164 char *who = r->data; |
2292
6625d0755c51
[gaim-migrate @ 2302]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2291
diff
changeset
|
1165 int n = 0; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1166 if (*who == '@') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1167 buf[n++] = *who++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1168 if (*who == '+') |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1169 buf[n++] = *who++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1170 g_snprintf(buf + n, sizeof(buf) - n, "%s", new); |
2312
766603034af8
[gaim-migrate @ 2322]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2310
diff
changeset
|
1171 if (!strcmp(who, old)) { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1172 char *tmp = g_strdup(r->data); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1173 rename_chat_buddy(b, tmp, buf); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1174 r = b->in_room; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1175 g_free(tmp); |
2725
f3c094e78609
[gaim-migrate @ 2738]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2687
diff
changeset
|
1176 break; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1177 } else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1178 r = r->next; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1179 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1180 bcs = bcs->next; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1181 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1182 } |
2086 | 1183 |
3751 | 1184 static void |
1185 handle_privmsg(struct gaim_connection *gc, char *to, char *nick, char *msg) | |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1186 { |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1187 if (is_channel(gc, to)) { |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1188 struct conversation *c = irc_find_chat(gc, to); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1189 if (!c) |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1190 return; |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1191 irc_got_chat_in(gc, c->id, nick, 0, msg, time(NULL)); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1192 } else { |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1193 char *tmp = g_malloc(strlen(nick) + 2); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1194 g_snprintf(tmp, strlen(nick) + 2, "@%s", nick); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1195 if (find_conversation(tmp)) |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1196 irc_got_im(gc, tmp, msg, 0, time(NULL)); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1197 else { |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1198 *tmp = '+'; |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1199 if (find_conversation(tmp)) |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1200 irc_got_im(gc, tmp, msg, 0, time(NULL)); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1201 else |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1202 irc_got_im(gc, nick, msg, 0, time(NULL)); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1203 } |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1204 g_free(tmp); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1205 } |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1206 } |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1207 |
3751 | 1208 static void |
1209 dcc_chat_init(struct dcc_chat *data) { | |
3730 | 1210 proxy_connect(data->ip_address, data->port, dcc_chat_callback, data); |
3029 | 1211 } |
1212 | |
3751 | 1213 static void |
1214 dcc_chat_cancel(struct dcc_chat *data){ | |
3029 | 1215 if (find_dcc_chat(data->gc, data->nick)) { |
1216 dcc_chat_list = g_slist_remove(dcc_chat_list, data); | |
1217 gaim_input_remove (data->inpa); | |
1218 close (data->fd); | |
1219 } | |
1220 g_free(data); | |
1221 } | |
1222 | |
3751 | 1223 static void |
1224 irc_convo_closed(struct gaim_connection *gc, char *who) | |
3029 | 1225 { |
1226 struct dcc_chat *dchat = find_dcc_chat(gc, who); | |
1227 if (!dchat) | |
1228 return; | |
1229 | |
3730 | 1230 dcc_chat_cancel(dchat); |
3029 | 1231 } |
1232 | |
3751 | 1233 static void |
1234 handle_ctcp(struct gaim_connection *gc, char *to, char *nick, | |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1235 char *msg, char *word[], char *word_eol[]) |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1236 { |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1237 struct irc_data *id = gc->proto_data; |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1238 char buf[IRC_BUF_LEN]; |
3735 | 1239 char out[IRC_BUF_LEN]; |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1240 |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1241 if (!g_strncasecmp(msg, "VERSION", 7)) { |
3735 | 1242 g_snprintf(buf, sizeof(buf), "\001VERSION Gaim " VERSION ": The Penguin Pimpin' " |
1243 "Multi-protocol Messaging Client: " WEBSITE "\001"); | |
1244 irc_send_notice (gc, nick, buf); | |
1245 g_snprintf(out, sizeof(out), ">> CTCP VERSION requested from %s", nick); | |
1246 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1247 } |
3707 | 1248 if (!g_strncasecmp(msg, "CLIENTINFO", 10)) { |
3735 | 1249 g_snprintf(buf, sizeof(buf), "\001CLIENTINFO USERINFO CLIENTINFO VERSION\001"); |
1250 irc_send_notice (gc, nick, buf); | |
1251 g_snprintf(out, sizeof(out), ">> CTCP CLIENTINFO requested from %s", nick); | |
1252 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
3707 | 1253 } |
1254 if (!g_strncasecmp(msg, "USERINFO", 8)) { | |
3735 | 1255 g_snprintf(buf, sizeof(buf), "\001USERINFO Alias: %s\001", gc->user->alias); |
1256 irc_send_notice (gc, nick, buf); | |
1257 g_snprintf(out, sizeof(out), ">> CTCP USERINFO requested from %s", nick); | |
1258 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
3707 | 1259 } |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1260 if (!g_strncasecmp(msg, "ACTION", 6)) { |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1261 char *po = strchr(msg + 6, 1); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1262 char *tmp; |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1263 if (po) *po = 0; |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1264 tmp = g_strconcat("/me", msg + 6, NULL); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1265 handle_privmsg(gc, to, nick, tmp); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1266 g_free(tmp); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1267 } |
3735 | 1268 if (!g_strncasecmp(msg, "PING", 4)) { |
1269 g_snprintf(buf, sizeof(buf), "\001%s\001", msg); | |
1270 irc_send_notice (gc, nick, buf); | |
1271 g_snprintf(out, sizeof(out), ">> CTCP PING requested from %s", nick); | |
1272 do_error_dialog(out, _("IRC CTCP info"), GAIM_INFO); | |
1273 } | |
3029 | 1274 if (!g_strncasecmp(msg, "DCC CHAT", 8)) { |
1275 char **chat_args = g_strsplit(msg, " ", 5); | |
1276 char ask[1024]; | |
3707 | 1277 struct dcc_chat *dccchat = g_new0(struct dcc_chat, 1); |
3029 | 1278 dccchat->gc = gc; |
1279 g_snprintf(dccchat->ip_address, sizeof(dccchat->ip_address), chat_args[3]); | |
3616 | 1280 printf("DCC CHAT DEBUG CRAP: %s\n", dccchat->ip_address); |
3029 | 1281 dccchat->port=atoi(chat_args[4]); |
1282 g_snprintf(dccchat->nick, sizeof(dccchat->nick), nick); | |
3730 | 1283 g_snprintf(ask, sizeof(ask), _("%s would like to establish a DCC chat"), nick); |
1284 do_ask_dialog(ask, _("This requires a direct connection to be established between the two computers. Messages sent will not pass through the IRC server"), dccchat, _("Connect"), dcc_chat_init, _("Cancel"), dcc_chat_cancel); | |
3029 | 1285 } |
3616 | 1286 |
1287 | |
1288 if (!g_strncasecmp(msg, "DCC SEND", 8)) { | |
3708 | 1289 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); |
1290 char **send_args = g_strsplit(msg, " ", 6); | |
1291 send_args[5][strlen(send_args[5])-1] = 0; | |
3616 | 1292 |
3708 | 1293 ift->type = IFT_SENDFILE_IN; |
1294 ift->sn = g_strdup(nick); | |
1295 ift->gc = gc; | |
1296 g_snprintf(ift->ip, sizeof(ift->ip), send_args[3]); | |
1297 ift->port = atoi(send_args[4]); | |
1298 ift->len = atoi(send_args[5]); | |
1299 ift->name = g_strdup(send_args[2]); | |
1300 ift->cur = 0; | |
3616 | 1301 |
3708 | 1302 id->file_transfers = g_slist_append(id->file_transfers, ift); |
3616 | 1303 |
3708 | 1304 ift->xfer = transfer_in_add(gc, nick, ift->name, ift->len, 1, NULL); |
3616 | 1305 } |
3735 | 1306 |
1307 /*write_to_conv(c, out, WFLAG_SYSTEM, NULL, time(NULL), -1);*/ | |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1308 } |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1309 |
3751 | 1310 static gboolean |
1311 irc_parse(struct gaim_connection *gc, char *buf) | |
2086 | 1312 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1313 struct irc_data *idata = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1314 gchar outbuf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1315 char *word[PDIWORDS], *word_eol[PDIWORDS]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1316 char pdibuf[522]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1317 char *ex, ip[128], nick[128]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1318 char *cmd; |
2086 | 1319 |
1320 /* Check for errors */ | |
3452 | 1321 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1322 if (*buf != ':') { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1323 if (!strncmp(buf, "NOTICE ", 7)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1324 buf += 7; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1325 if (!strncmp(buf, "PING ", 5)) { |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1326 int r = FALSE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1327 g_snprintf(outbuf, sizeof(outbuf), "PONG %s\r\n", buf + 5); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1328 if (irc_write(idata->fd, outbuf, strlen(outbuf)) < 0) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1329 hide_login_progress(gc, _("Unable to write")); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1330 signoff(gc); |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1331 r = TRUE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1332 } |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1333 return r; |
2086 | 1334 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1335 /* XXX doesn't handle ERROR */ |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1336 return FALSE; |
2086 | 1337 } |
1338 | |
2782
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1339 if (!idata->online) { |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1340 /* Now lets sign ourselves on */ |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1341 account_online(gc); |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1342 serv_finish_login(gc); |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1343 |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1344 if (bud_list_cache_exists(gc)) |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1345 do_import(gc, NULL); |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1346 |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1347 /* we don't call this now because otherwise some IRC servers might not like us */ |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1348 idata->timer = g_timeout_add(20000, irc_request_buddy_update, gc); |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1349 idata->online = TRUE; |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1350 } |
428bd24c18c6
[gaim-migrate @ 2795]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
1351 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1352 buf++; |
2086 | 1353 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1354 process_data_init(pdibuf, buf, word, word_eol, FALSE); |
2086 | 1355 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1356 if (atoi(word[2])) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1357 if (*word_eol[3]) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1358 process_numeric(gc, word, word_eol); |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1359 return FALSE; |
2086 | 1360 } |
1361 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1362 cmd = word[2]; |
2086 | 1363 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1364 ex = strchr(pdibuf, '!'); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1365 if (!ex) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1366 strncpy(ip, pdibuf, sizeof(ip)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1367 ip[sizeof(ip)-1] = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1368 strncpy(nick, pdibuf, sizeof(nick)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1369 nick[sizeof(nick)-1] = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1370 } else { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1371 strncpy(ip, ex + 1, sizeof(ip)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1372 ip[sizeof(ip)-1] = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1373 strncpy(nick, pdibuf, sizeof(nick)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1374 nick[sizeof(nick)-1] = 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1375 if ((ex - pdibuf) < sizeof (nick)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1376 nick[ex - pdibuf] = 0; /* cut the buffer at the '!' */ |
2086 | 1377 } |
1378 | |
2847
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1379 if (!strcmp(cmd, "INVITE")) { |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1380 char *chan = g_strdup(word[4]); |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1381 serv_got_chat_invite(gc, chan + 1, nick, NULL, g_list_append(NULL, chan)); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1382 } else if (!strcmp(cmd, "JOIN")) { |
3751 | 1383 irc_parse_join(gc, nick, word, word_eol); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1384 } else if (!strcmp(cmd, "KICK")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1385 if (!strcmp(gc->displayname, word[4])) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1386 struct conversation *c = irc_find_chat(gc, word[3]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1387 if (!c) |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1388 return FALSE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1389 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1390 c->gc = NULL; |
3707 | 1391 g_snprintf(outbuf, sizeof(outbuf), _("You have been kicked from %s: %s"), |
1392 word[3], *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]); | |
1393 do_error_dialog(outbuf, _("IRC Error"), GAIM_ERROR); | |
2820
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1394 } else { |
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1395 char *reason = *word_eol[5] == ':' ? word_eol[5] + 1 : word_eol[5]; |
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1396 char *msg = g_strdup_printf(_("Kicked by %s: %s"), nick, reason); |
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1397 irc_rem_chat_bud(gc, word[4], msg); |
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1398 g_free(msg); |
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1399 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1400 } else if (!strcmp(cmd, "KILL")) { /* */ |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1401 } else if (!strcmp(cmd, "MODE")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1402 handle_mode(gc, word, word_eol, FALSE); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1403 } else if (!strcmp(cmd, "NICK")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1404 char *new = *word_eol[3] == ':' ? word_eol[3] + 1 : word_eol[3]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1405 if (!strcmp(gc->displayname, nick)) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1406 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", new); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1407 irc_change_name(gc, nick, new); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1408 } else if (!strcmp(cmd, "NOTICE")) { |
3751 | 1409 irc_parse_notice(gc, nick, ex, word, word_eol); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1410 } else if (!strcmp(cmd, "PART")) { |
3751 | 1411 if (!irc_parse_part(gc, nick, cmd, word, word_eol)) |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1412 return FALSE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1413 } else if (!strcmp(cmd, "PRIVMSG")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1414 char *to, *msg; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1415 if (!*word[3]) |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1416 return FALSE; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1417 to = word[3]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1418 msg = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1419 if (msg[0] == 1 && msg[strlen (msg) - 1] == 1) { /* ctcp */ |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1420 if (!g_strncasecmp(msg + 1, "DCC ", 4)) |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1421 process_data_init(pdibuf, buf, word, word_eol, TRUE); |
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1422 handle_ctcp(gc, to, nick, msg + 1, word, word_eol); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1423 } else { |
2339
9bda60d2d2e6
[gaim-migrate @ 2352]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2331
diff
changeset
|
1424 handle_privmsg(gc, to, nick, msg); |
2086 | 1425 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1426 } else if (!strcmp(cmd, "PONG")) { /* */ |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1427 } else if (!strcmp(cmd, "QUIT")) { |
2820
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2801
diff
changeset
|
1428 irc_rem_chat_bud(gc, nick, *word_eol[3] == ':' ? word_eol[3] + 1 : word_eol[3]); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1429 } else if (!strcmp(cmd, "TOPIC")) { |
3751 | 1430 irc_parse_topic(gc, nick, word, word_eol); |
3707 | 1431 } else if (!strcmp(cmd, "WALLOPS")) { /* Don't know if a dialog box is the right way? */ |
1432 char *msg = strrchr(word_eol[0], ':'); | |
1433 if (msg) | |
1434 do_error_dialog(msg+1, _("IRC Operator"), GAIM_ERROR); | |
2086 | 1435 } |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1436 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1437 return FALSE; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1438 } |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1439 |
3751 | 1440 /* CTCP by jonas@birme.se */ |
1441 static void | |
1442 irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, | |
1443 char *word[], char *word_eol[]) | |
1444 { | |
1445 char buf[IRC_BUF_LEN]; | |
1446 | |
1447 if (!g_strcasecmp(word[4], ":\001CLIENTINFO")) { | |
1448 char *p = g_strrstr(word_eol[5], "\001"); | |
1449 *p = 0; | |
1450 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", | |
1451 word_eol[5]); | |
1452 do_error_dialog(buf, _("CTCP ClientInfo"), GAIM_INFO); | |
1453 } else if (!g_strcasecmp(word[4], ":\001USERINFO")) { | |
1454 char *p = g_strrstr(word_eol[5], "\001"); | |
1455 *p = 0; | |
1456 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", | |
1457 word_eol[5]); | |
1458 do_error_dialog(buf, _("CTCP UserInfo"), GAIM_INFO); | |
1459 } else if (!g_strcasecmp(word[4], ":\001VERSION")) { | |
1460 char *p = g_strrstr(word_eol[5], "\001"); | |
1461 *p = 0; | |
1462 g_snprintf(buf, sizeof(buf), "CTCP Answer: %s", | |
1463 word_eol[5]); | |
1464 do_error_dialog(buf, _("CTCP Version"), GAIM_INFO); | |
1465 } else if (!g_strcasecmp(word[4], ":\001PING")) { | |
1466 char *p = g_strrstr(word_eol[5], "\001"); | |
1467 struct timeval ping_time; | |
1468 struct timeval now; | |
1469 gchar **vector; | |
1470 if (p) | |
1471 *p = 0; | |
1472 vector = g_strsplit(word_eol[5], " ", 2); | |
1473 if (gettimeofday(&now, NULL) == 0 && vector != NULL) { | |
1474 if (now.tv_usec - atol(vector[1]) < 0) { | |
1475 ping_time.tv_sec = now.tv_sec - atol(vector[0]) - 1; | |
1476 ping_time.tv_usec = now.tv_usec - atol(vector[1]) + 1000000; | |
1477 } else { | |
1478 ping_time.tv_sec = now.tv_sec - atol(vector[0]); | |
1479 ping_time.tv_usec = now.tv_usec - atol(vector[1]); | |
1480 } | |
1481 g_snprintf(buf, sizeof(buf), | |
1482 "CTCP Ping reply from %s: %lu.%.03lu seconds", | |
1483 nick, ping_time.tv_sec, (ping_time.tv_usec/1000)); | |
1484 do_error_dialog(buf, _("CTCP Ping"), GAIM_INFO); | |
1485 g_strfreev(vector); | |
1486 } | |
1487 } else { | |
1488 if (*word_eol[4] == ':') word_eol[4]++; | |
1489 if (ex) | |
1490 irc_got_im(gc, nick, word_eol[4], 0, | |
1491 time(NULL)); | |
1492 } | |
1493 | |
1494 } | |
1495 | |
1496 static void | |
1497 irc_parse_join(struct gaim_connection *gc, char *nick, | |
1498 char *word[], char *word_eol[]) | |
1499 { | |
1500 char *chan = *word[3] == ':' ? word[3] + 1 : word[3]; | |
1501 static int id = 1; | |
1502 struct conversation *c; | |
1503 char *hostmask, *p; | |
1504 | |
1505 if (!g_strcasecmp(gc->displayname, nick)) { | |
1506 serv_got_joined_chat(gc, id++, chan); | |
1507 } else { | |
1508 c = irc_find_chat(gc, chan); | |
1509 if (c) { | |
1510 hostmask = g_strdup(word[1]); | |
1511 p = strchr(hostmask, '!'); | |
1512 if (p) { | |
1513 char *pend = strchr(p, ' '); | |
1514 if (pend) { | |
1515 *pend = 0; | |
1516 } | |
1517 add_chat_buddy(c, nick, p+1); | |
1518 g_free(hostmask); | |
1519 } | |
1520 } | |
1521 } | |
1522 } | |
1523 | |
1524 static void | |
1525 irc_parse_topic(struct gaim_connection *gc, char *nick, | |
1526 char *word[], char *word_eol[]) | |
1527 { | |
1528 struct conversation *c = irc_find_chat(gc, word[3]); | |
1529 char *topic = *word_eol[4] == ':' ? word_eol[4] + 1 : word_eol[4]; | |
1530 char buf[IRC_BUF_LEN]; | |
1531 | |
1532 if (c) { | |
1533 chat_set_topic(c, nick, topic); | |
1534 g_snprintf(buf, sizeof(buf), _("<B>%s has changed the topic to: %s</B>"), | |
1535 nick, topic); | |
1536 write_to_conv(c, buf, WFLAG_SYSTEM, NULL, time(NULL), -1); | |
1537 } | |
1538 } | |
1539 | |
1540 static gboolean | |
1541 irc_parse_part(struct gaim_connection *gc, char *nick, char *cmd, | |
1542 char *word[], char *word_eol[]) | |
1543 { | |
1544 char *chan = cmd + 5; | |
1545 struct conversation *c; | |
1546 char *reason = word_eol[4]; | |
1547 GList *r; | |
1548 | |
1549 if (*chan == ':') | |
1550 chan++; | |
1551 if (*reason == ':') | |
1552 reason++; | |
1553 if (!(c = irc_find_chat(gc, chan))) | |
1554 return FALSE; | |
1555 if (!strcmp(nick, gc->displayname)) { | |
1556 serv_got_chat_left(gc, c->id); | |
1557 return FALSE; | |
1558 } | |
1559 r = c->in_room; | |
1560 while (r) { | |
1561 char *who = r->data; | |
1562 if (*who == '@') | |
1563 who++; | |
1564 if (*who == '+') | |
1565 who++; | |
1566 if (!g_strcasecmp(who, nick)) { | |
1567 char *tmp = g_strdup(r->data); | |
1568 remove_chat_buddy(c, tmp, reason); | |
1569 g_free(tmp); | |
1570 break; | |
1571 } | |
1572 r = r->next; | |
1573 } | |
1574 } | |
1575 | |
1576 static void | |
1577 irc_callback(gpointer data, gint source, | |
1578 GaimInputCondition condition) | |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1579 { |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1580 struct gaim_connection *gc = data; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1581 struct irc_data *idata = gc->proto_data; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1582 int i = 0; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1583 gchar buf[1024]; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1584 gboolean off; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1585 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1586 i = read(idata->fd, buf, 1024); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1587 if (i <= 0) { |
3074 | 1588 hide_login_progress_error(gc, "Read error"); |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1589 signoff(gc); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1590 return; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1591 } |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1592 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1593 idata->rxqueue = g_realloc(idata->rxqueue, i + idata->rxlen + 1); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1594 memcpy(idata->rxqueue + idata->rxlen, buf, i); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1595 idata->rxlen += i; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1596 idata->rxqueue[idata->rxlen] = 0; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1597 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1598 while (1) { |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1599 char *d, *e; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1600 int len; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1601 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1602 if (!idata->rxqueue || ((e = strchr(idata->rxqueue, '\n')) == NULL)) |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1603 return; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1604 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1605 len = e - idata->rxqueue + 1; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1606 d = g_strndup(idata->rxqueue, len); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1607 g_strchomp(d); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1608 debug_printf("IRC S: %s\n", d); |
3707 | 1609 |
3708 | 1610 /* REMOVE ME BEFORE SUBMIT! */ |
3751 | 1611 /*fprintf(stderr, "IRC S: %s\n", d);*/ |
3708 | 1612 |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1613 idata->rxlen -= len; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1614 if (idata->rxlen) { |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1615 char *tmp = g_strdup(e + 1); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1616 g_free(idata->rxqueue); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1617 idata->rxqueue = tmp; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1618 } else { |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1619 g_free(idata->rxqueue); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1620 idata->rxqueue = NULL; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1621 } |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1622 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1623 off = irc_parse(gc, d); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1624 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1625 g_free(d); |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1626 |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1627 if (off) |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1628 return; |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1629 } |
2086 | 1630 } |
1631 | |
3751 | 1632 static void |
1633 irc_login_callback(gpointer data, gint source, GaimInputCondition condition) | |
2086 | 1634 { |
1635 struct gaim_connection *gc = data; | |
1636 struct irc_data *idata; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1637 char hostname[256]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1638 char buf[IRC_BUF_LEN]; |
3751 | 1639 char *test; |
1640 GError *err = NULL; | |
1641 | |
2086 | 1642 if (!g_slist_find(connections, gc)) { |
1643 close(source); | |
1644 return; | |
1645 } | |
1646 | |
1647 idata = gc->proto_data; | |
1648 | |
1649 if (source == -1) { | |
1650 hide_login_progress(gc, "Write error"); | |
1651 signoff(gc); | |
1652 return; | |
1653 } | |
1654 | |
3751 | 1655 |
1656 /* Try a quick conversion to see if the specified encoding is OK */ | |
1657 test = g_convert("test", strlen("test"), gc->user->proto_opt[USEROPT_CHARSET], | |
1658 "UTF-8", NULL, NULL, &err); | |
1659 if (err) { | |
1660 debug_printf("Couldn't initialize %s for IRC charset conversion, using ISO-8859-1\n", | |
1661 gc->user->proto_opt[USEROPT_CHARSET]); | |
1662 strcpy(gc->user->proto_opt[USEROPT_CHARSET], "ISO-8859-1"); | |
1663 } | |
1664 | |
2086 | 1665 if (idata->fd != source) |
1666 idata->fd = source; | |
1667 | |
2574
3526c5581f92
[gaim-migrate @ 2587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
1668 gethostname(hostname, sizeof(hostname) - 1); |
3526c5581f92
[gaim-migrate @ 2587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
1669 hostname[sizeof(hostname) - 1] = 0; |
3526c5581f92
[gaim-migrate @ 2587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
1670 if (!*hostname) |
3526c5581f92
[gaim-migrate @ 2587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
1671 g_snprintf(hostname, sizeof(hostname), "localhost"); |
3789 | 1672 |
1673 if (*gc->user->password) { | |
1674 g_snprintf(buf, sizeof(buf), "PASS %s\r\n", gc->user->password); | |
1675 | |
1676 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { | |
1677 hide_login_progress(gc, "Write error"); | |
1678 signoff(gc); | |
1679 return; | |
1680 } | |
1681 } | |
1682 | |
3562 | 1683 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n", |
3452 | 1684 g_get_user_name(), hostname, |
1685 gc->user->proto_opt[USEROPT_SERV], | |
3575 | 1686 gc->user->alias && strlen(gc->user->alias) ? gc->user->alias : "gaim"); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1687 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1688 hide_login_progress(gc, "Write error"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1689 signoff(gc); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1690 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1691 } |
2086 | 1692 |
2574
3526c5581f92
[gaim-migrate @ 2587]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2536
diff
changeset
|
1693 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gc->username); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1694 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
2086 | 1695 hide_login_progress(gc, "Write error"); |
1696 signoff(gc); | |
1697 return; | |
1698 } | |
1699 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1700 gc->inpa = gaim_input_add(idata->fd, GAIM_INPUT_READ, irc_callback, gc); |
2086 | 1701 } |
1702 | |
3751 | 1703 static void |
1704 irc_login(struct aim_user *user) | |
2086 | 1705 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1706 char buf[IRC_BUF_LEN]; |
2086 | 1707 |
1708 struct gaim_connection *gc = new_gaim_conn(user); | |
1709 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); | |
1710 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1711 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", gc->username); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1712 |
2086 | 1713 g_snprintf(buf, sizeof(buf), "Signon: %s", gc->username); |
1714 set_login_progress(gc, 2, buf); | |
1715 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1716 idata->chantypes = g_strdup("#&!+"); |
3452 | 1717 idata->chanmodes = g_strdup("beI,k,lnt"); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1718 idata->nickmodes = g_strdup("ohv"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1719 idata->str = g_string_new(""); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1720 |
2086 | 1721 idata->fd = proxy_connect(user->proto_opt[USEROPT_SERV], |
1722 user->proto_opt[USEROPT_PORT][0] ? atoi(user-> | |
1723 proto_opt[USEROPT_PORT]) : | |
1724 6667, irc_login_callback, gc); | |
1725 if (!user->gc || (idata->fd < 0)) { | |
1726 hide_login_progress(gc, "Unable to create socket"); | |
1727 signoff(gc); | |
1728 return; | |
1729 } | |
1730 } | |
1731 | |
3751 | 1732 static void |
1733 irc_close(struct gaim_connection *gc) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1734 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1735 struct irc_data *idata = (struct irc_data *)gc->proto_data; |
3618 | 1736 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1737 gchar buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1738 |
3452 | 1739 if (idata->str->len > 0) { |
1740 g_snprintf(buf, sizeof(buf), "QUIT :%s\r\n", idata->str->str); | |
1741 } else { | |
1742 g_snprintf(buf, sizeof(buf), | |
1743 "QUIT :Download Gaim [%s]\r\n", WEBSITE); | |
1744 } | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1745 irc_write(idata->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1746 |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1747 if (idata->rxqueue) |
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1748 g_free(idata->rxqueue); |
3618 | 1749 |
3619 | 1750 idata->rxqueue = NULL; |
1751 idata->rxlen = 0; | |
1752 | |
3618 | 1753 /* Kill any existing transfers */ |
1754 while (idata->file_transfers) { | |
3708 | 1755 struct irc_file_transfer *ift = (struct irc_file_transfer *)idata->file_transfers->data; |
3618 | 1756 |
3708 | 1757 g_free(ift->sn); |
1758 g_free(ift->name); | |
1759 gaim_input_remove(ift->watcher); | |
3618 | 1760 |
3708 | 1761 close(ift->fd); |
3618 | 1762 |
3708 | 1763 idata->file_transfers = idata->file_transfers->next; |
3618 | 1764 } |
3619 | 1765 idata->file_transfers = NULL; |
3618 | 1766 |
2687
2d544f48146d
[gaim-migrate @ 2700]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1767 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1768 g_free(idata->chantypes); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1769 g_free(idata->chanmodes); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1770 g_free(idata->nickmodes); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1771 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1772 g_string_free(idata->str, TRUE); |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1773 if (idata->liststr) |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
1774 g_string_free(idata->liststr, TRUE); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1775 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1776 if (idata->timer) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1777 g_source_remove(idata->timer); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1778 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1779 if (gc->inpa) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1780 gaim_input_remove(gc->inpa); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1781 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1782 close(idata->fd); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1783 g_free(gc->proto_data); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1784 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1785 |
3751 | 1786 static void |
1787 set_mode_3(struct gaim_connection *gc, char *who, int sign, int mode, | |
3708 | 1788 int start, int end, char *word[]) |
2086 | 1789 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1790 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1791 char buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1792 int left; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1793 int i = start; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1794 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1795 while (1) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1796 left = end - i; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1797 switch (left) { |
3708 | 1798 case 0: |
1799 return; | |
1800 case 1: | |
1801 g_snprintf(buf, sizeof(buf), "MODE %s %c%c %s\r\n", | |
1802 who, sign, mode, word[i]); | |
1803 i += 1; | |
1804 break; | |
1805 case 2: | |
1806 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c %s %s\r\n", | |
1807 who, sign, mode, mode, word[i], word[i + 1]); | |
1808 i += 2; | |
1809 break; | |
1810 default: | |
1811 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c %s %s %s\r\n", | |
1812 who, sign, mode, mode, mode, | |
1813 word[i], word[i + 1], word[i + 2]); | |
1814 i += 2; | |
1815 break; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1816 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1817 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1818 if (left < 3) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1819 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1820 } |
2086 | 1821 } |
1822 | |
3751 | 1823 static void |
1824 set_mode_6(struct gaim_connection *gc, char *who, int sign, int mode, | |
3708 | 1825 int start, int end, char *word[]) |
2086 | 1826 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1827 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1828 char buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1829 int left; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1830 int i = start; |
2086 | 1831 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1832 while (1) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1833 left = end - i; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1834 switch (left) { |
3708 | 1835 case 0: |
1836 return; | |
1837 case 1: | |
1838 g_snprintf(buf, sizeof(buf), "MODE %s %c%c %s\r\n", | |
1839 who, sign, mode, word[i]); | |
1840 i += 1; | |
1841 break; | |
1842 case 2: | |
1843 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c %s %s\r\n", | |
1844 who, sign, mode, mode, word[i], word[i + 1]); | |
1845 i += 2; | |
1846 break; | |
1847 case 3: | |
1848 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c %s %s %s\r\n", | |
1849 who, sign, mode, mode, mode, | |
1850 word[i], word[i + 1], word[i + 2]); | |
1851 i += 3; | |
1852 break; | |
1853 case 4: | |
1854 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c %s %s %s %s\r\n", | |
1855 who, sign, mode, mode, mode, mode, | |
1856 word[i], word[i + 1], word[i + 2], word[i + 3]); | |
1857 i += 4; | |
1858 break; | |
1859 case 5: | |
1860 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c%c %s %s %s %s %s\r\n", | |
1861 who, sign, mode, mode, mode, mode, mode, | |
1862 word[i], word[i + 1], word[i + 2], | |
1863 word[i + 3], word[i + 4]); | |
1864 i += 5; | |
1865 break; | |
1866 default: | |
1867 g_snprintf(buf, sizeof(buf), "MODE %s %c%c%c%c%c%c%c %s %s %s %s %s %s\r\n", | |
1868 who, sign, mode, mode, mode, mode, mode, mode, | |
1869 word[i], word[i + 1], word[i + 2], | |
1870 word[i + 3], word[i + 4], word[i + 5]); | |
1871 i += 6; | |
1872 break; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1873 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1874 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1875 if (left < 6) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1876 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1877 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1878 } |
2086 | 1879 |
3751 | 1880 static void |
1881 set_mode(struct gaim_connection *gc, char *who, int sign, int mode, char *word[]) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1882 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1883 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1884 int i = 2; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1885 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1886 while (1) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1887 if (!*word[i]) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1888 if (i == 2) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1889 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1890 if (id->six_modes) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1891 set_mode_6(gc, who, sign, mode, 2, i, word); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1892 else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1893 set_mode_3(gc, who, sign, mode, 2, i, word); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1894 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1895 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1896 i++; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1897 } |
2086 | 1898 } |
1899 | |
3751 | 1900 static void |
1901 set_chan_mode(struct gaim_connection *gc, char *chan, char *mode_str) | |
3452 | 1902 { |
1903 struct irc_data *id = gc->proto_data; | |
1904 char buf[IRC_BUF_LEN]; | |
1905 | |
1906 if ((mode_str[0] == '-') || (mode_str[0] == '+')) { | |
1907 g_snprintf(buf, sizeof(buf), "MODE %s %s\r\n", chan, mode_str); | |
1908 irc_write(id->fd, buf, strlen(buf)); | |
1909 } | |
1910 } | |
1911 | |
3751 | 1912 static int |
1913 handle_command(struct gaim_connection *gc, char *who, char *what) | |
2086 | 1914 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1915 char buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1916 char pdibuf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1917 char *word[PDIWORDS], *word_eol[PDIWORDS]; |
3029 | 1918 char *tmp = g_strdup(what); |
1919 GString *str = encode_html(tmp); | |
3751 | 1920 char *intl; |
1921 int len; | |
3029 | 1922 struct dcc_chat *dccchat = find_dcc_chat(gc, who); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1923 struct irc_data *id = gc->proto_data; |
3029 | 1924 g_free(tmp); |
3030 | 1925 what = str->str; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1926 if (*what != '/') { |
3029 | 1927 if (dccchat) { |
3751 | 1928 intl = irc_send_convert(gc, what, sizeof(buf), &len); |
1929 g_snprintf(buf, sizeof(buf), "%s\r\n", intl); | |
1930 g_free(intl); | |
3029 | 1931 irc_write(dccchat->fd, buf, strlen(buf)); |
1932 g_string_free(str, TRUE); | |
1933 return 1; | |
1934 } | |
3751 | 1935 irc_send_privmsg (gc, who, what, TRUE); |
3029 | 1936 g_string_free(str, TRUE); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
1937 return 1; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1938 } |
3029 | 1939 |
3033 | 1940 process_data_init(pdibuf, what + 1, word, word_eol, TRUE); |
1941 g_string_free(str, FALSE); | |
3029 | 1942 if (!g_strcasecmp(pdibuf, "ME")) { |
1943 if (dccchat) { | |
3751 | 1944 intl = irc_send_convert(gc, word_eol[2], sizeof(buf), &len); |
1945 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001\r\n", intl); | |
1946 g_free(intl); | |
3029 | 1947 irc_write(dccchat->fd, buf, strlen(buf)); |
3033 | 1948 g_free(what); |
3029 | 1949 return 1; |
1950 } | |
3735 | 1951 g_snprintf(buf, sizeof(buf), "\001ACTION %s\001", word_eol[2]); |
3751 | 1952 irc_send_privmsg (gc, who, buf, FALSE); |
3033 | 1953 g_free(what); |
2304
15fb364935ec
[gaim-migrate @ 2314]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
1954 return 1; |
2847
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1955 } else if (!g_strcasecmp(pdibuf, "INVITE")) { |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1956 char buf[IRC_BUF_LEN]; |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1957 g_snprintf(buf, sizeof(buf), "INVITE %s\r\n", word_eol[2]); |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
1958 irc_write(id->fd, buf, strlen(buf)); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1959 } else if (!g_strcasecmp(pdibuf, "TOPIC")) { |
3033 | 1960 if (!*word_eol[2]) { |
3501 | 1961 struct conversation *c; |
1962 c = irc_find_chat(gc, who); | |
1963 g_snprintf(buf, sizeof(buf), _("Topic for %s is %s"), who, c->topic ? c->topic : "(no topic set)"); | |
1964 write_to_conv(c, buf, WFLAG_SYSTEM | WFLAG_NOLOG, NULL, time(NULL), -1); | |
1965 } else { | |
3751 | 1966 /* This could be too long */ |
1967 intl = irc_send_convert(gc, word_eol[2], sizeof(buf), &len); | |
1968 g_snprintf(buf, sizeof(buf), "TOPIC %s :%s\r\n", who, intl); | |
1969 g_free(intl); | |
3501 | 1970 irc_write(id->fd, buf, strlen(buf)); |
3033 | 1971 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1972 } else if (!g_strcasecmp(pdibuf, "NICK")) { |
3033 | 1973 if (!*word_eol[2]) { |
1974 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
1975 return -EINVAL; |
3033 | 1976 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1977 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", word_eol[2]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1978 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1979 } else if (!g_strcasecmp(pdibuf, "OP")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1980 set_mode(gc, who, '+', 'o', word); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1981 } else if (!g_strcasecmp(pdibuf, "DEOP")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1982 set_mode(gc, who, '-', 'o', word); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1983 } else if (!g_strcasecmp(pdibuf, "VOICE")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1984 set_mode(gc, who, '+', 'v', word); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1985 } else if (!g_strcasecmp(pdibuf, "DEVOICE")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1986 set_mode(gc, who, '-', 'v', word); |
3452 | 1987 } else if (!g_strcasecmp(pdibuf, "MODE")) { |
1988 char *chan = who; | |
1989 set_chan_mode(gc, chan, word_eol[2]); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1990 } else if (!g_strcasecmp(pdibuf, "QUOTE")) { |
3033 | 1991 if (!*word_eol[2]) { |
1992 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
1993 return -EINVAL; |
3033 | 1994 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1995 g_snprintf(buf, sizeof(buf), "%s\r\n", word_eol[2]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1996 irc_write(id->fd, buf, strlen(buf)); |
2301
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
1997 } else if (!g_strcasecmp(pdibuf, "SAY")) { |
3033 | 1998 if (!*word_eol[2]) { |
1999 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2000 return -EINVAL; |
3033 | 2001 } |
3751 | 2002 irc_send_privmsg (gc, who, word_eol[2], TRUE); |
2305
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2003 return 1; |
2302
722a912562a0
[gaim-migrate @ 2312]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2301
diff
changeset
|
2004 } else if (!g_strcasecmp(pdibuf, "MSG")) { |
3033 | 2005 if (!*word[2]) { |
2006 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2007 return -EINVAL; |
3033 | 2008 } |
2009 if (!*word_eol[3]) { | |
2010 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2011 return -EINVAL; |
3033 | 2012 } |
3751 | 2013 irc_send_privmsg (gc, word[2], word_eol[3], TRUE); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2014 } else if (!g_strcasecmp(pdibuf, "KICK")) { |
3033 | 2015 if (!*word[2]) { |
2016 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2017 return -EINVAL; |
3033 | 2018 } |
3751 | 2019 if (*word_eol[3]) { |
2020 intl = irc_send_convert(gc, word_eol[3], sizeof(buf), &len); | |
2021 g_snprintf(buf, sizeof(buf), "KICK %s %s :%s\r\n", who, word[2], intl); | |
2022 g_free(intl); | |
2023 } else | |
2298
57da45349e50
[gaim-migrate @ 2308]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2295
diff
changeset
|
2024 g_snprintf(buf, sizeof(buf), "KICK %s %s\r\n", who, word[2]); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2025 irc_write(id->fd, buf, strlen(buf)); |
2801 | 2026 } else if (!g_strcasecmp(pdibuf, "JOIN") || !g_strcasecmp(pdibuf, "J")) { |
3033 | 2027 if (!*word[2]) { |
2028 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2029 return -EINVAL; |
3033 | 2030 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2031 if (*word[3]) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2032 g_snprintf(buf, sizeof(buf), "JOIN %s %s\r\n", word[2], word[3]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2033 else |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2034 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", word[2]); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2035 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2036 } else if (!g_strcasecmp(pdibuf, "PART")) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2037 char *chan = *word[2] ? word[2] : who; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2038 char *reason = word_eol[3]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2039 struct conversation *c; |
3033 | 2040 if (!is_channel(gc, chan)) { |
2041 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2042 return -EINVAL; |
3033 | 2043 } |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2044 c = irc_find_chat(gc, chan); |
3751 | 2045 if (*reason) { |
2046 intl = irc_send_convert(gc, reason, sizeof(buf), &len); | |
2047 g_snprintf(buf, sizeof(buf), "PART %s :%s\r\n", chan, intl); | |
2048 g_free(intl); | |
2049 } else | |
2050 g_snprintf(buf, sizeof(buf), "PART %s\r\n", chan); | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2051 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2052 if (c) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2053 gc->buddy_chats = g_slist_remove(gc->buddy_chats, c); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2054 c->gc = NULL; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2055 g_snprintf(buf, sizeof(buf), _("You have left %s"), chan); |
3707 | 2056 do_error_dialog(buf, _("IRC Part"), GAIM_INFO); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2057 } |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2058 } else if (!g_strcasecmp(pdibuf, "WHOIS")) { |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2059 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", word_eol[2]); |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2060 irc_write(id->fd, buf, strlen(buf)); |
3707 | 2061 } else if (!g_strcasecmp(pdibuf, "WHOWAS")) { |
2062 g_snprintf(buf, sizeof(buf), "WHOWAS %s\r\n", word_eol[2]); | |
2063 irc_write(id->fd, buf, strlen(buf)); | |
2829
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
2064 } else if (!g_strcasecmp(pdibuf, "LIST")) { |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
2065 g_snprintf(buf, sizeof(buf), "LIST\r\n"); |
e3f98544eae0
[gaim-migrate @ 2842]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
2066 irc_write(id->fd, buf, strlen(buf)); |
3452 | 2067 } else if (!g_strcasecmp(pdibuf, "QUIT")) { |
2068 char *reason = word_eol[2]; | |
2069 id->str = g_string_insert(id->str, 0, reason); | |
2070 do_quit(); | |
2071 } else if (!g_strcasecmp(pdibuf, "VERSION")) { | |
2072 g_snprintf(buf, sizeof(buf), "VERSION\r\n"); | |
2073 irc_write(id->fd, buf, strlen(buf)); | |
2074 } else if (!g_strcasecmp(pdibuf, "W")) { | |
2075 g_snprintf(buf, sizeof(buf), "WHO *\r\n"); | |
2076 irc_write(id->fd, buf, strlen(buf)); | |
3707 | 2077 } else if (!g_strcasecmp(pdibuf, "REHASH")) { |
2078 g_snprintf(buf, sizeof(buf), "REHASH\r\n"); | |
2079 irc_write(id->fd, buf, strlen(buf)); | |
2080 } else if (!g_strcasecmp(pdibuf, "RESTART")) { | |
2081 g_snprintf(buf, sizeof(buf), "RESTART\r\n"); | |
2082 irc_write(id->fd, buf, strlen(buf)); | |
2083 } else if (!g_strcasecmp(pdibuf, "CTCP")) { | |
2084 if (!g_strcasecmp(word[2], "CLIENTINFO")) { | |
2085 if (word[3]) | |
2086 irc_ctcp_clientinfo(gc, word[3]); | |
2087 } else if (!g_strcasecmp(word[2], "USERINFO")) { | |
2088 if (word[3]) | |
2089 irc_ctcp_userinfo(gc, word[3]); | |
2090 } else if (!g_strcasecmp(word[2], "VERSION")) { | |
2091 if (word[3]) | |
2092 irc_ctcp_version(gc, word[3]); | |
3735 | 2093 |
2094 } else if (!g_strcasecmp(word[2], "PING")) { | |
2095 if (word[3]) | |
2096 irc_ctcp_ping(gc, word[3]); | |
3707 | 2097 } |
2098 } else if (!g_strcasecmp(pdibuf, "DCC")) { | |
2099 struct conversation *c = NULL; | |
2100 if (!g_strcasecmp(word[2], "CHAT")) { | |
2101 if (word[3]) | |
2102 irc_start_chat(gc, word[3]); | |
2103 | |
2104 if (is_channel(gc, who)) { | |
2105 c = irc_find_chat(gc, who); | |
2106 } else { | |
2107 c = find_conversation(who); | |
2108 } | |
2109 if (c) { | |
2110 write_to_conv(c, "<I>Requesting DCC CHAT</I>", | |
2111 WFLAG_SYSTEM, NULL, | |
2112 time(NULL), -1); | |
2113 } | |
2114 } | |
2301
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2115 } else if (!g_strcasecmp(pdibuf, "HELP")) { |
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2116 struct conversation *c = NULL; |
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2117 if (is_channel(gc, who)) { |
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2118 c = irc_find_chat(gc, who); |
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2119 } else { |
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2120 c = find_conversation(who); |
171d11fb37b9
[gaim-migrate @ 2311]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2299
diff
changeset
|
2121 } |
3033 | 2122 if (!c) { |
2123 g_free(what); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2124 return -EINVAL; |
3033 | 2125 } |
3707 | 2126 if (!g_strcasecmp(word[2], "OPER")) { |
2127 write_to_conv(c, "<B>Operator commands:<BR>" | |
2128 "REHASH RESTART</B>", | |
2129 WFLAG_NOLOG, NULL, time(NULL), -1); | |
2130 } else if (!g_strcasecmp(word[2], "CTCP")) { | |
2131 write_to_conv(c, "<B>CTCP commands:<BR>" | |
2132 "CLIENTINFO <nick><BR>" | |
2133 "USERINFO <nick><BR>" | |
3735 | 2134 "VERSION <nick><BR>" |
2135 "PING <nick></B><BR>", | |
3707 | 2136 WFLAG_NOLOG, NULL, time(NULL), -1); |
2137 } else if (!g_strcasecmp(word[2], "DCC")) { | |
2138 write_to_conv(c, "<B>DCC commands:<BR>" | |
2139 "CHAT <nick></B>", | |
2140 WFLAG_NOLOG, NULL, time(NULL), -1); | |
2141 } else { | |
2142 write_to_conv(c, "<B>Currently supported commands:<BR>" | |
2143 "WHOIS INVITE NICK LIST<BR>" | |
2144 "JOIN PART TOPIC KICK<BR>" | |
2145 "OP DEOP VOICE DEVOICE<BR>" | |
2146 "ME MSG QUOTE SAY QUIT<BR>" | |
3735 | 2147 "MODE VERSION W WHOWAS<BR>" |
3707 | 2148 "Type /HELP OPER for operator commands<BR>" |
2149 "Type /HELP CTCP for CTCP commands<BR>" | |
2150 "Type /HELP DCC for DCC commands", | |
2151 WFLAG_NOLOG, NULL, time(NULL), -1); | |
2152 } | |
2305
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2153 } else { |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2154 struct conversation *c = NULL; |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2155 if (is_channel(gc, who)) { |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2156 c = irc_find_chat(gc, who); |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2157 } else { |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2158 c = find_conversation(who); |
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2159 } |
3033 | 2160 if (!c) { |
2161 g_free(what); | |
2305
0371b905baef
[gaim-migrate @ 2315]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2304
diff
changeset
|
2162 return -EINVAL; |
3033 | 2163 } |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2847
diff
changeset
|
2164 write_to_conv(c, "<B>Unknown command</B>", WFLAG_NOLOG, NULL, time(NULL), -1); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2165 } |
3033 | 2166 g_free(what); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2167 return 0; |
2086 | 2168 } |
2169 | |
3751 | 2170 static int |
2171 send_msg(struct gaim_connection *gc, char *who, char *what) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2172 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2173 char *cr = strchr(what, '\n'); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2174 if (cr) { |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2175 int ret = 0; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2176 while (TRUE) { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2177 if (cr) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2178 *cr = 0; |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2179 ret = handle_command(gc, who, what); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2180 if (!cr) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2181 break; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2182 what = cr + 1; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2183 if (!*what) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2184 break; |
2295
24dc9ce95127
[gaim-migrate @ 2305]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2294
diff
changeset
|
2185 *cr = '\n'; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2186 cr = strchr(what, '\n'); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2187 } |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2188 return ret; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2189 } else |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2190 return handle_command(gc, who, what); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2191 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2192 |
3751 | 2193 static void |
2194 irc_chat_invite(struct gaim_connection *gc, int idn, const char *message, const char *name) { | |
2847
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2195 char buf[IRC_BUF_LEN]; |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2196 struct irc_data *id = gc->proto_data; |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2197 struct conversation *c = irc_find_chat_by_id(gc, idn); |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2198 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name); |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2199 irc_write(id->fd, buf, strlen(buf)); |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2200 } |
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2201 |
3751 | 2202 static int |
2203 irc_send_im(struct gaim_connection *gc, char *who, char *what, int len, int flags) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2204 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2205 if (*who == '@' || *who == '+') |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2206 return send_msg(gc, who + 1, what); |
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2207 return send_msg(gc, who, what); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2208 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2209 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2210 /* IRC doesn't have a buddy list, but we can still figure out who's online with ISON */ |
3751 | 2211 static void |
2212 irc_add_buddy(struct gaim_connection *gc, const char *who) {} | |
2213 static void | |
2214 irc_remove_buddy(struct gaim_connection *gc, char *who, char *group) {} | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2215 |
3751 | 2216 static GList * |
2217 irc_chat_info(struct gaim_connection *gc) | |
2086 | 2218 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2219 GList *m = NULL; |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2220 struct proto_chat_entry *pce; |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2221 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2222 pce = g_new0(struct proto_chat_entry, 1); |
2466
f8eb5f120603
[gaim-migrate @ 2479]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2459
diff
changeset
|
2223 pce->label = _("Channel:"); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2224 m = g_list_append(m, pce); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2225 |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2226 pce = g_new0(struct proto_chat_entry, 1); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2227 pce->label = _("Password:"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2228 m = g_list_append(m, pce); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2229 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
2230 return m; |
2086 | 2231 } |
2232 | |
3751 | 2233 static void |
2234 irc_join_chat(struct gaim_connection *gc, GList *data) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2235 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2236 struct irc_data *id = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2237 char buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2238 char *name, *pass; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2239 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2240 if (!data) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2241 return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2242 name = data->data; |
2299
b5b7dece5249
[gaim-migrate @ 2309]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2298
diff
changeset
|
2243 if (data->next) { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2244 pass = data->next->data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2245 g_snprintf(buf, sizeof(buf), "JOIN %s %s\r\n", name, pass); |
2299
b5b7dece5249
[gaim-migrate @ 2309]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2298
diff
changeset
|
2246 } else |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2247 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", name); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2248 irc_write(id->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2249 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2250 |
3751 | 2251 static void |
2252 irc_chat_leave(struct gaim_connection *gc, int id) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2253 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2254 struct irc_data *idata = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2255 struct conversation *c = irc_find_chat_by_id(gc, id); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2256 char buf[IRC_BUF_LEN]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2257 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2258 if (!c) return; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2259 |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2260 g_snprintf(buf, sizeof(buf), "PART %s\r\n", c->name); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2261 irc_write(idata->fd, buf, strlen(buf)); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2262 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2263 |
3751 | 2264 static int |
2265 irc_chat_send(struct gaim_connection *gc, int id, char *what) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2266 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2267 struct conversation *c = irc_find_chat_by_id(gc, id); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2268 if (!c) |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2269 return -EINVAL; |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2270 if (send_msg(gc, c->name, what) > 0) |
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2302
diff
changeset
|
2271 serv_got_chat_in(gc, c->id, gc->displayname, 0, what, time(NULL)); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2272 return 0; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2273 } |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2274 |
3751 | 2275 static GList * |
2276 irc_away_states(struct gaim_connection *gc) | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2277 { |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2278 return g_list_append(NULL, GAIM_AWAY_CUSTOM); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2279 } |
2086 | 2280 |
3751 | 2281 static void |
2282 irc_set_away(struct gaim_connection *gc, char *state, char *msg) | |
2086 | 2283 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2284 struct irc_data *idata = gc->proto_data; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2285 char buf[IRC_BUF_LEN]; |
2086 | 2286 |
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
2287 if (gc->away) |
2394
579f8d4347ad
[gaim-migrate @ 2407]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
2288 gc->away = NULL; |
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
2289 |
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
2290 if (msg) { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2291 g_snprintf(buf, sizeof(buf), "AWAY :%s\r\n", msg); |
2394
579f8d4347ad
[gaim-migrate @ 2407]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
2292 gc->away = ""; |
2393
a7ecfd3f7714
[gaim-migrate @ 2406]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
2293 } else |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2294 g_snprintf(buf, sizeof(buf), "AWAY\r\n"); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2295 irc_write(idata->fd, buf, strlen(buf)); |
2086 | 2296 } |
2297 | |
3751 | 2298 static char ** |
2299 irc_list_icon(int uc) | |
2086 | 2300 { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2301 return irc_icon_xpm; |
2086 | 2302 } |
2303 | |
3751 | 2304 static int |
2305 getlocalip(char *ip) /* Thanks, libfaim */ | |
3029 | 2306 { |
2307 struct hostent *hptr; | |
2308 char localhost[129]; | |
2309 long unsigned add; | |
2310 | |
2311 /* XXX if available, use getaddrinfo() */ | |
2312 /* XXX allow client to specify which IP to use for multihomed boxes */ | |
2313 | |
2314 if (gethostname(localhost, 128) < 0) | |
2315 return -1; | |
2316 | |
2317 if (!(hptr = gethostbyname(localhost))) | |
2318 return -1; | |
2319 | |
2320 memcpy(&add, hptr->h_addr_list[0], 4); | |
2321 add = htonl(add); | |
2322 g_snprintf(ip, 11, "%lu", add); | |
2323 | |
2324 return 0; | |
2325 } | |
2326 | |
3751 | 2327 static void |
2328 dcc_chat_connected(gpointer data, gint source, GdkInputCondition condition) | |
3029 | 2329 { |
2330 struct dcc_chat *chat = data; | |
2331 struct conversation *convo; | |
2332 char buf[128]; | |
2333 struct sockaddr_in addr; | |
2334 int addrlen = sizeof (addr); | |
2335 addr.sin_family = AF_INET; | |
2336 addr.sin_port = htons (chat->port); | |
2337 addr.sin_addr.s_addr = INADDR_ANY; | |
2338 chat->fd = accept (chat->fd, (struct sockaddr *) (&addr), &addrlen); | |
3707 | 2339 if (!chat->fd) { |
3730 | 2340 dcc_chat_cancel (chat); |
3707 | 2341 convo = new_conversation (chat->nick); |
2342 g_snprintf (buf, sizeof buf, _("DCC Chat with %s closed"), | |
2343 chat->nick); | |
2344 write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, | |
2345 time ((time_t) NULL), -1); | |
2346 return; | |
2347 } | |
3029 | 2348 chat->inpa = |
2349 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_in, chat); | |
2350 convo = new_conversation (chat->nick); | |
2351 g_snprintf (buf, sizeof buf, "DCC Chat with %s established", | |
2352 chat->nick); | |
2353 write_to_conv (convo, buf, WFLAG_SYSTEM, NULL, time ((time_t) NULL), -1); | |
2354 debug_printf ("Chat with %s established\n", chat->nick); | |
2355 dcc_chat_list = g_slist_append (dcc_chat_list, chat); | |
2356 } | |
3665
7cb6cf20ed7d
[gaim-migrate @ 3794]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3633
diff
changeset
|
2357 #if 0 |
3751 | 2358 static void |
2359 irc_ask_send_file(struct gaim_connection *gc, char *destsn) { | |
3708 | 2360 struct irc_data *id = (struct irc_data *)gc->proto_data; |
2361 struct irc_file_transfer *ift = g_new0(struct irc_file_transfer, 1); | |
2362 char *localip = (char *)malloc(12); | |
3622 | 2363 |
3708 | 2364 if (getlocalip(localip) == -1) { |
2365 free(localip); | |
2366 return; | |
2367 } | |
3616 | 2368 |
3708 | 2369 ift->type = IFT_SENDFILE_OUT; |
2370 ift->sn = g_strdup(destsn); | |
2371 ift->gc = gc; | |
2372 snprintf(ift->ip, sizeof(ift->ip), "%s", localip); | |
2373 id->file_transfers = g_slist_append(id->file_transfers, ift); | |
3622 | 2374 |
3708 | 2375 ift->xfer = transfer_out_add(gc, ift->sn); |
3616 | 2376 } |
3665
7cb6cf20ed7d
[gaim-migrate @ 3794]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3633
diff
changeset
|
2377 #endif |
3751 | 2378 static struct |
2379 irc_file_transfer *find_ift_by_xfer(struct gaim_connection *gc, | |
3708 | 2380 struct file_transfer *xfer) { |
3616 | 2381 |
3708 | 2382 GSList *g = ((struct irc_data *)gc->proto_data)->file_transfers; |
2383 struct irc_file_transfer *f = NULL; | |
3616 | 2384 |
3708 | 2385 while (g) { |
2386 f = (struct irc_file_transfer *)g->data; | |
2387 if (f->xfer == xfer) | |
2388 break; | |
2389 g = g->next; | |
2390 f = NULL; | |
2391 } | |
3616 | 2392 |
3708 | 2393 return f; |
3616 | 2394 } |
2395 | |
3751 | 2396 static void |
2397 irc_file_transfer_data_chunk(struct gaim_connection *gc, struct file_transfer *xfer, const char *data, int len) { | |
3616 | 2398 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); |
2399 guint32 pos; | |
2400 | |
2401 ift->cur += len; | |
2402 pos = htonl(ift->cur); | |
2403 write(ift->fd, (char *)&pos, 4); | |
2404 | |
3623 | 2405 // FIXME: You should check to verify that they received the data when |
2406 // you are sending a file ... | |
3616 | 2407 } |
2408 | |
3751 | 2409 static void |
2410 irc_file_transfer_cancel (struct gaim_connection *gc, struct file_transfer *xfer) { | |
3616 | 2411 struct irc_data *id = (struct irc_data *)gc->proto_data; |
2412 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | |
2413 | |
2414 printf("Our shit got canceled, yo!\n"); | |
2415 | |
2416 /* Remove the FT from our list of transfers */ | |
2417 id->file_transfers = g_slist_remove(id->file_transfers, ift); | |
2418 | |
2419 gaim_input_remove(ift->watcher); | |
2420 | |
2421 /* Close our FT because we're done */ | |
2422 close(ift->fd); | |
2423 | |
2424 g_free(ift->sn); | |
2425 g_free(ift->name); | |
2426 | |
2427 g_free(ift); | |
2428 } | |
2429 | |
3751 | 2430 static void |
2431 irc_file_transfer_done(struct gaim_connection *gc, struct file_transfer *xfer) { | |
3616 | 2432 struct irc_data *id = (struct irc_data *)gc->proto_data; |
2433 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | |
2434 | |
2435 | |
2436 printf("Our shit be done, yo.\n"); | |
2437 | |
2438 /* Remove the FT from our list of transfers */ | |
2439 id->file_transfers = g_slist_remove(id->file_transfers, ift); | |
2440 | |
2441 gaim_input_remove(ift->watcher); | |
2442 | |
2443 /* Close our FT because we're done */ | |
2444 close(ift->fd); | |
2445 | |
2446 g_free(ift->sn); | |
2447 g_free(ift->name); | |
2448 | |
2449 g_free(ift); | |
2450 } | |
2451 | |
3751 | 2452 static void |
2453 irc_file_transfer_out (struct gaim_connection *gc, struct file_transfer *xfer, const char *name, int totfiles, int totsize) { | |
3622 | 2454 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); |
2455 struct sockaddr_in addr; | |
2456 char buf[IRC_BUF_LEN]; | |
2457 int len; | |
2458 | |
2459 | |
2460 ift->fd = socket (AF_INET, SOCK_STREAM, 0); | |
2461 addr.sin_family = AF_INET; | |
2462 addr.sin_port = 0; | |
2463 addr.sin_addr.s_addr = INADDR_ANY; | |
2464 bind (ift->fd, (struct sockaddr *) &addr, sizeof(addr)); | |
2465 listen(ift->fd, 1); | |
2466 | |
2467 len = sizeof(addr); | |
2468 getsockname (ift->fd, (struct sockaddr *) &addr, &len); | |
2469 | |
2470 ift->port = ntohs(addr.sin_port); | |
2471 | |
2472 ift->watcher = gaim_input_add (ift->fd, GAIM_INPUT_READ, dcc_send_callback, ift); | |
3633 | 2473 printf("watcher is %d\n", ift->watcher); |
3622 | 2474 |
2475 snprintf(buf, sizeof(buf), "\001DCC SEND %s %s %d %d\001\n", name, ift->ip, ift->port, totsize); | |
2476 printf("Trying: %s\n", buf); | |
2477 irc_send_im (gc, ift->sn, buf, -1, 0); | |
2478 } | |
2479 | |
3751 | 2480 static void |
2481 irc_file_transfer_in(struct gaim_connection *gc, | |
3708 | 2482 struct file_transfer *xfer, int offset) { |
3616 | 2483 |
2484 struct irc_file_transfer *ift = find_ift_by_xfer(gc, xfer); | |
2485 | |
2486 ift->xfer = xfer; | |
2487 proxy_connect(ift->ip, ift->port, dcc_recv_callback, ift); | |
2488 } | |
2489 | |
3751 | 2490 static void |
2491 irc_ctcp_clientinfo(struct gaim_connection *gc, char *who) | |
2492 { | |
2493 char buf[IRC_BUF_LEN]; | |
2494 | |
2495 snprintf (buf, sizeof buf, "\001CLIENTINFO\001"); | |
2496 irc_send_privmsg(gc, who, buf, FALSE); | |
2497 } | |
2498 | |
2499 static void | |
2500 irc_ctcp_userinfo(struct gaim_connection *gc, char *who) | |
3707 | 2501 { |
3735 | 2502 char buf[IRC_BUF_LEN]; |
2503 | |
3751 | 2504 snprintf (buf, sizeof buf, "\001USERINFO\001"); |
2505 irc_send_privmsg(gc, who, buf, FALSE); | |
3707 | 2506 } |
2507 | |
3751 | 2508 static void |
2509 irc_ctcp_version(struct gaim_connection *gc, char *who) | |
3707 | 2510 { |
3735 | 2511 char buf[IRC_BUF_LEN]; |
2512 | |
3751 | 2513 snprintf (buf, sizeof buf, "\001VERSION\001"); |
2514 irc_send_privmsg(gc, who, buf, FALSE); | |
3707 | 2515 } |
2516 | |
3751 | 2517 static void |
2518 irc_ctcp_ping(struct gaim_connection *gc, char *who) | |
3707 | 2519 { |
3735 | 2520 char buf[IRC_BUF_LEN]; |
2521 | |
3751 | 2522 g_snprintf (buf, sizeof(buf), "\001PING %ul\001", time(NULL)); |
2523 irc_send_privmsg(gc, who, buf, FALSE); | |
3735 | 2524 } |
2525 | |
3751 | 2526 static void |
2527 irc_send_notice(struct gaim_connection *gc, char *who, char *what) | |
3735 | 2528 { |
3751 | 2529 char buf[IRC_BUF_LEN], *intl; |
3735 | 2530 struct irc_data *id = gc->proto_data; |
3751 | 2531 int len; |
2532 | |
2533 intl = irc_send_convert(gc, what, 501, &len); | |
2534 g_snprintf(buf, sizeof(buf), "NOTICE %s :%s\r\n", who, intl); | |
2535 g_free(intl); | |
3735 | 2536 irc_write(id->fd, buf, strlen(buf)); |
2537 } | |
2538 | |
3751 | 2539 /* Don't call this guy with fragment = 1 for anything but straight |
2540 * up privmsgs. (no CTCP/whatever) It's still dangerous for CTCPs | |
2541 * (it might not include the trailing \001), but I think this behavior | |
2542 * is generally better than not fragmenting at all on lots of our | |
2543 * packets. */ | |
2544 /* From RFC2812: | |
2545 * IRC messages are always lines of characters terminated with a CR-LF | |
2546 * (Carriage Return - Line Feed) pair, and these messages SHALL NOT | |
2547 * exceed 512 characters in length, counting all characters including | |
2548 * the trailing CR-LF. Thus, there are 510 characters maximum allowed | |
2549 * for the command and its parameters. */ | |
2550 /* So apparently that includes all the inter-server crap, which is up | |
2551 * to NINETY-THREE chars on dancer, which seems to be a pretty liberal | |
2552 * ircd. My rough calculation for now is ":<nick>!~<user>@<host> ", | |
2553 * where <host> is a max of an (uncalculated) 63 chars. Thanks to | |
2554 * trelane and #freenode for giving a hand here. */ | |
2555 static void | |
2556 irc_send_privmsg(struct gaim_connection *gc, char *who, char *what, gboolean fragment) | |
3735 | 2557 { |
3751 | 2558 char buf[IRC_BUF_LEN], *intl; |
3735 | 2559 struct irc_data *id = gc->proto_data; |
3751 | 2560 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */ |
2561 int nicklen = (gc->user->alias && strlen(gc->user->alias)) ? strlen(gc->user->alias) : 4; | |
2562 int max = 444 - strlen(who) - strlen(g_get_user_name()) - nicklen; | |
2563 | |
2564 int len; | |
2565 | |
2566 do { | |
2567 /* the \001 on CTCPs may cause a problem here for some | |
2568 * charsets, but probably not ones people use for IRC. */ | |
2569 intl = irc_send_convert(gc, what, max, &len); | |
2570 g_snprintf(buf, sizeof(buf), "PRIVMSG %s :%s\r\n", who, intl); | |
2571 g_free(intl); | |
2572 irc_write(id->fd, buf, strlen(buf)); | |
2573 what += len; | |
2574 } while (fragment && strlen(what)); | |
3707 | 2575 } |
2576 | |
3751 | 2577 static void |
2578 irc_start_chat(struct gaim_connection *gc, char *who) { | |
3029 | 2579 struct dcc_chat *chat; |
2580 int len; | |
2581 struct sockaddr_in addr; | |
3735 | 2582 char buf[IRC_BUF_LEN]; |
3029 | 2583 |
2584 /* Create a socket */ | |
2585 chat = g_new0 (struct dcc_chat, 1); | |
2586 chat->fd = socket (AF_INET, SOCK_STREAM, 0); | |
2587 chat->gc = gc; | |
2588 g_snprintf (chat->nick, sizeof (chat->nick), "%s", who); | |
2589 if (chat->fd < 0) { | |
3730 | 2590 dcc_chat_cancel (chat); |
3708 | 2591 return; |
3029 | 2592 } |
2593 addr.sin_family = AF_INET; | |
2594 addr.sin_port = 0; | |
2595 addr.sin_addr.s_addr = INADDR_ANY; | |
2596 bind (chat->fd, (struct sockaddr *) &addr, sizeof (addr)); | |
2597 listen (chat->fd, 1); | |
2598 len = sizeof (addr); | |
2599 getsockname (chat->fd, (struct sockaddr *) &addr, &len); | |
2600 chat->port = ntohs (addr.sin_port); | |
2601 getlocalip(chat->ip_address); | |
2602 chat->inpa = | |
2603 gaim_input_add (chat->fd, GAIM_INPUT_READ, dcc_chat_connected, | |
3708 | 2604 chat); |
3630 | 2605 g_snprintf (buf, sizeof buf, "\001DCC CHAT chat %s %d\001\n", |
3708 | 2606 chat->ip_address, chat->port); |
3033 | 2607 irc_send_im (gc, who, buf, -1, 0); |
3029 | 2608 } |
2609 | |
3751 | 2610 static void |
2611 irc_get_info(struct gaim_connection *gc, char *who) | |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2612 { |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2613 struct irc_data *idata = gc->proto_data; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2614 char buf[IRC_BUF_LEN]; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2615 |
2633
b740a33875c3
[gaim-migrate @ 2646]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2620
diff
changeset
|
2616 if (*who == '@') |
b740a33875c3
[gaim-migrate @ 2646]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2620
diff
changeset
|
2617 who++; |
b740a33875c3
[gaim-migrate @ 2646]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2620
diff
changeset
|
2618 if (*who == '+') |
b740a33875c3
[gaim-migrate @ 2646]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2620
diff
changeset
|
2619 who++; |
b740a33875c3
[gaim-migrate @ 2646]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2620
diff
changeset
|
2620 |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2621 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", who); |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2622 irc_write(idata->fd, buf, strlen(buf)); |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2623 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2624 |
3751 | 2625 static GList * |
2626 irc_buddy_menu(struct gaim_connection *gc, char *who) | |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2627 { |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2628 GList *m = NULL; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2629 struct proto_buddy_menu *pbm; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2630 |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2631 pbm = g_new0(struct proto_buddy_menu, 1); |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2632 pbm->label = _("Get Info"); |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2633 pbm->callback = irc_get_info; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2634 pbm->gc = gc; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2635 m = g_list_append(m, pbm); |
3616 | 2636 |
3029 | 2637 pbm = g_new0(struct proto_buddy_menu, 1); |
2638 pbm->label = _("DCC Chat"); | |
2639 pbm->callback = irc_start_chat; | |
2640 pbm->gc = gc; | |
2641 m = g_list_append(m, pbm); | |
3708 | 2642 /* |
2643 pbm = g_new0(struct proto_buddy_menu, 1); | |
2644 pbm->label = _("DCC Send"); | |
2645 pbm->callback = irc_ask_send_file; | |
2646 pbm->gc = gc; | |
2647 m = g_list_append(m, pbm); | |
2648 */ | |
3707 | 2649 |
2650 pbm = g_new0(struct proto_buddy_menu, 1); | |
2651 pbm->label = _("CTCP ClientInfo"); | |
2652 pbm->callback = irc_ctcp_clientinfo; | |
2653 pbm->gc = gc; | |
2654 m = g_list_append(m, pbm); | |
2655 | |
2656 pbm = g_new0(struct proto_buddy_menu, 1); | |
2657 pbm->label = _("CTCP UserInfo"); | |
2658 pbm->callback = irc_ctcp_userinfo; | |
2659 pbm->gc = gc; | |
2660 m = g_list_append(m, pbm); | |
2661 | |
2662 pbm = g_new0(struct proto_buddy_menu, 1); | |
2663 pbm->label = _("CTCP Version"); | |
2664 pbm->callback = irc_ctcp_version; | |
2665 pbm->gc = gc; | |
2666 m = g_list_append(m, pbm); | |
2667 | |
3735 | 2668 pbm = g_new0(struct proto_buddy_menu, 1); |
2669 pbm->label = _("CTCP Ping"); | |
2670 pbm->callback = irc_ctcp_ping; | |
2671 pbm->gc = gc; | |
2672 m = g_list_append(m, pbm); | |
2673 | |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2674 return m; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2675 } |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2676 |
2086 | 2677 static struct prpl *my_protocol = NULL; |
2678 | |
3751 | 2679 G_MODULE_EXPORT void |
2680 irc_init(struct prpl *ret) | |
2086 | 2681 { |
3572 | 2682 struct proto_user_opt *puo; |
2086 | 2683 ret->protocol = PROTO_IRC; |
3789 | 2684 ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL; |
3572 | 2685 ret->name = g_strdup("IRC"); |
2086 | 2686 ret->list_icon = irc_list_icon; |
2687 ret->login = irc_login; | |
2688 ret->close = irc_close; | |
2689 ret->send_im = irc_send_im; | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2652
diff
changeset
|
2690 ret->add_buddy = irc_add_buddy; |
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2652
diff
changeset
|
2691 ret->remove_buddy = irc_remove_buddy; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2171
diff
changeset
|
2692 ret->chat_info = irc_chat_info; |
2086 | 2693 ret->join_chat = irc_join_chat; |
2694 ret->chat_leave = irc_chat_leave; | |
2695 ret->chat_send = irc_chat_send; | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2696 ret->away_states = irc_away_states; |
2086 | 2697 ret->set_away = irc_set_away; |
2619
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2698 ret->get_info = irc_get_info; |
536198196dc6
[gaim-migrate @ 2632]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2617
diff
changeset
|
2699 ret->buddy_menu = irc_buddy_menu; |
2847
e49bd1479edd
[gaim-migrate @ 2860]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2831
diff
changeset
|
2700 ret->chat_invite = irc_chat_invite; |
3029 | 2701 ret->convo_closed = irc_convo_closed; |
3622 | 2702 ret->file_transfer_out = irc_file_transfer_out; |
3616 | 2703 ret->file_transfer_in = irc_file_transfer_in; |
2704 ret->file_transfer_data_chunk = irc_file_transfer_data_chunk; | |
2705 ret->file_transfer_done = irc_file_transfer_done; | |
2706 ret->file_transfer_cancel =irc_file_transfer_cancel; | |
3572 | 2707 |
2708 puo = g_new0(struct proto_user_opt, 1); | |
2709 puo->label = g_strdup("Server:"); | |
2710 puo->def = g_strdup("irc.openprojects.net"); | |
2711 puo->pos = USEROPT_SERV; | |
2712 ret->user_opts = g_list_append(ret->user_opts, puo); | |
2713 | |
2714 puo = g_new0(struct proto_user_opt, 1); | |
2715 puo->label = g_strdup("Port:"); | |
2716 puo->def = g_strdup("6667"); | |
2717 puo->pos = USEROPT_PORT; | |
2718 ret->user_opts = g_list_append(ret->user_opts, puo); | |
2719 | |
3751 | 2720 puo = g_new0(struct proto_user_opt, 1); |
2721 puo->label = g_strdup("Encoding:"); | |
2722 puo->def = g_strdup("ISO-8859-1"); | |
2723 puo->pos = USEROPT_CHARSET; | |
2724 ret->user_opts = g_list_append(ret->user_opts, puo); | |
2725 | |
3616 | 2726 my_protocol = ret; |
2086 | 2727 } |
2728 | |
2729 #ifndef STATIC | |
3751 | 2730 G_MODULE_EXPORT void |
2731 gaim_prpl_init(struct prpl* prpl) | |
2086 | 2732 { |
3572 | 2733 irc_init(prpl); |
2734 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 2735 } |
2736 | |
2737 #endif |