Mercurial > pidgin.yaz
annotate src/server.c @ 241:452993e3cdd2
[gaim-migrate @ 251]
I didnt mean to commit that pixmap giggle
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sat, 20 May 2000 06:17:50 +0000 |
parents | 6ced2f1c8b24 |
children | 14fc16f579c8 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #include <time.h> | |
23 #include <stdio.h> | |
24 #include <string.h> | |
25 #include <sys/types.h> | |
26 #include <sys/stat.h> | |
27 #include <sys/time.h> | |
28 #include <unistd.h> | |
29 #include <gtk/gtk.h> | |
30 #ifdef USE_OSCAR | |
31 #include "../libfaim/aim.h" | |
32 #endif | |
33 #include "gaim.h" | |
34 | |
35 static int idle_timer = -1; | |
36 static time_t lastsent = 0; | |
37 static time_t login_time = 0; | |
38 static struct timeval lag_tv; | |
39 static int is_idle = 0; | |
40 | |
41 int correction_time = 0; | |
42 | |
43 int serv_login(char *username, char *password) | |
44 { | |
45 #ifndef USE_OSCAR | |
46 return toc_login(username, password); | |
47 #else | |
48 return oscar_login(username, password); | |
49 #endif | |
50 } | |
51 | |
52 void serv_close() | |
53 { | |
54 #ifndef USE_OSCAR | |
55 toc_close(); | |
56 #endif | |
57 gtk_timeout_remove(idle_timer); | |
58 idle_timer = -1; | |
59 } | |
60 | |
61 | |
62 void serv_touch_idle() | |
63 { | |
64 /* Are we idle? If so, not anymore */ | |
65 if (is_idle > 0) { | |
66 is_idle = 0; | |
67 serv_set_idle(0); | |
68 } | |
69 time(&lastsent); | |
70 } | |
71 | |
72 | |
73 static gint check_idle() | |
74 { | |
75 time_t t; | |
76 | |
77 /* Not idle, really... :) */ | |
78 update_all_buddies(); | |
79 | |
80 time(&t); | |
81 | |
82 gettimeofday(&lag_tv, NULL); | |
171
789c792ed14b
[gaim-migrate @ 181]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
145
diff
changeset
|
83 if (general_options & OPT_GEN_SHOW_LAGMETER) |
181
f2d631f867a3
[gaim-migrate @ 191]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
171
diff
changeset
|
84 serv_send_im(current_user->username, LAGOMETER_STR, 1); |
1 | 85 |
86 if (report_idle != IDLE_GAIM) | |
87 return TRUE; | |
88 | |
89 | |
90 if (is_idle) | |
91 return TRUE; | |
92 | |
93 if ((t - lastsent) > 600) { /* 15 minutes! */ | |
94 serv_set_idle((int)t - lastsent); | |
95 is_idle = 1; | |
96 } | |
97 | |
115
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
98 #ifdef GAIM_PLUGINS |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
99 { |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
100 GList *c = callbacks; |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
101 struct gaim_callback *g; |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
102 void (*function)(void *); |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
103 while (c) { |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
104 g = (struct gaim_callback *)c->data; |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
105 if (g->event == event_blist_update && |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
106 g->function != NULL) { |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
107 function = g->function; |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
108 (*function)(g->data); |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
109 } |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
110 c = c->next; |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
111 } |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
112 } |
890cfb7d8fdb
[gaim-migrate @ 125]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
101
diff
changeset
|
113 #endif |
1 | 114 |
115 return TRUE; | |
116 | |
117 } | |
118 | |
119 | |
120 void serv_finish_login() | |
121 { | |
122 char *buf; | |
123 | |
124 if (strlen(current_user->user_info)) { | |
79 | 125 buf = g_malloc(strlen(current_user->user_info) * 4); |
1 | 126 strcpy(buf, current_user->user_info); |
127 escape_text(buf); | |
128 serv_set_info(buf); | |
129 g_free(buf); | |
130 } | |
131 | |
132 if (idle_timer != -1) | |
133 gtk_timeout_remove(idle_timer); | |
134 | |
135 idle_timer = gtk_timeout_add(20000, (GtkFunction)check_idle, NULL); | |
136 serv_touch_idle(); | |
137 | |
138 time(&login_time); | |
139 | |
140 serv_add_buddy(current_user->username); | |
141 | |
142 if (!(general_options & OPT_GEN_REGISTERED)) | |
143 { | |
144 show_register_dialog(); | |
145 save_prefs(); | |
146 } | |
147 } | |
148 | |
149 | |
150 | |
151 void serv_send_im(char *name, char *message, int away) | |
152 { | |
153 char buf[MSG_LEN - 7]; | |
94
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
154 |
1 | 155 #ifndef USE_OSCAR |
156 g_snprintf(buf, MSG_LEN - 8, "toc_send_im %s \"%s\"%s", normalize(name), | |
157 message, ((away) ? " auto" : "")); | |
158 sflap_send(buf, strlen(buf), TYPE_DATA); | |
159 #else | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
160 oscar_send_im(name, message, away); |
1 | 161 #endif |
162 if (!away) | |
163 serv_touch_idle(); | |
164 } | |
165 | |
166 void serv_get_info(char *name) | |
167 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
168 char buf[MSG_LEN]; |
1 | 169 #ifndef USE_OSCAR |
170 g_snprintf(buf, MSG_LEN, "toc_get_info %s", normalize(name)); | |
171 sflap_send(buf, -1, TYPE_DATA); | |
172 #endif | |
173 } | |
174 | |
175 void serv_get_dir(char *name) | |
176 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
177 char buf[MSG_LEN]; |
1 | 178 #ifndef USE_OSCAR |
179 g_snprintf(buf, MSG_LEN, "toc_get_dir %s", normalize(name)); | |
180 sflap_send(buf, -1, TYPE_DATA); | |
181 #endif | |
182 } | |
183 | |
184 void serv_set_dir(char *first, char *middle, char *last, char *maiden, | |
185 char *city, char *state, char *country, int web) | |
186 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
187 char buf2[BUF_LEN*4], buf[BUF_LEN]; |
1 | 188 #ifndef USE_OSCAR |
189 g_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%s:%s:%s:%s:%s", first, | |
190 middle, last, maiden, city, state, country, | |
191 (web == 1) ? "Y" : ""); | |
192 escape_text(buf2); | |
193 g_snprintf(buf, sizeof(buf), "toc_set_dir %s", buf2); | |
194 sflap_send(buf, -1, TYPE_DATA); | |
195 #endif | |
196 } | |
197 | |
198 void serv_dir_search(char *first, char *middle, char *last, char *maiden, | |
199 char *city, char *state, char *country, char *email) | |
200 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
201 char buf[BUF_LONG]; |
1 | 202 #ifndef USE_OSCAR |
203 g_snprintf(buf, sizeof(buf)/2, "toc_dir_search %s:%s:%s:%s:%s:%s:%s:%s", first, middle, last, maiden, city, state, country, email); | |
204 sprintf(debug_buff,"Searching for: %s,%s,%s,%s,%s,%s,%s\n", first, middle, last, maiden, city, state, country); | |
205 debug_print(debug_buff); | |
206 sflap_send(buf, -1, TYPE_DATA); | |
207 #endif | |
208 } | |
209 | |
210 | |
211 void serv_set_away(char *message) | |
212 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
213 char buf[MSG_LEN]; |
1 | 214 #ifndef USE_OSCAR |
215 if (message) | |
216 g_snprintf(buf, MSG_LEN, "toc_set_away \"%s\"", message); | |
217 else | |
200
bc117fbcf527
[gaim-migrate @ 210]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
181
diff
changeset
|
218 g_snprintf(buf, MSG_LEN, "toc_set_away \"\""); |
1 | 219 sflap_send(buf, -1, TYPE_DATA); |
220 #endif | |
221 } | |
222 | |
223 void serv_set_info(char *info) | |
224 { | |
225 char buf[MSG_LEN]; | |
226 #ifndef USE_OSCAR | |
227 g_snprintf(buf, sizeof(buf), "toc_set_info \"%s\n\"", info); | |
228 sflap_send(buf, -1, TYPE_DATA); | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
229 #endif |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
230 } |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
231 |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
232 void serv_change_passwd(char *orig, char *new) { |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
233 #ifndef USE_OSCAR |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
234 char *buf = g_malloc(BUF_LONG); |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
235 g_snprintf(buf, BUF_LONG, "toc_change_passwd %s %s", orig, new); |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
236 sflap_send(buf, strlen(buf), TYPE_DATA); |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
237 g_free(buf); |
1 | 238 #endif |
239 } | |
240 | |
241 void serv_add_buddy(char *name) | |
242 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
243 char buf[1024]; |
1 | 244 #ifndef USE_OSCAR |
245 g_snprintf(buf, sizeof(buf), "toc_add_buddy %s", normalize(name)); | |
246 sflap_send(buf, -1, TYPE_DATA); | |
247 #endif | |
248 } | |
249 | |
250 void serv_add_buddies(GList *buddies) | |
251 { | |
252 char buf[MSG_LEN]; | |
253 int n, num = 0; | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
254 |
1 | 255 #ifndef USE_OSCAR |
256 n = g_snprintf(buf, sizeof(buf), "toc_add_buddy"); | |
257 while(buddies) { | |
258 if (num == 20) { | |
259 sflap_send(buf, -1, TYPE_DATA); | |
260 n = g_snprintf(buf, sizeof(buf), "toc_add_buddy"); | |
261 num = 0; | |
262 } | |
263 ++num; | |
264 n += g_snprintf(buf + n, sizeof(buf) - n, " %s", normalize(buddies->data)); | |
265 buddies = buddies->next; | |
266 } | |
267 sflap_send(buf, -1, TYPE_DATA); | |
268 #endif | |
269 } | |
270 | |
271 | |
272 void serv_remove_buddy(char *name) | |
273 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
274 char buf[1024]; |
1 | 275 #ifndef USE_OSCAR |
276 g_snprintf(buf, sizeof(buf), "toc_remove_buddy %s", normalize(name)); | |
277 sflap_send(buf, -1, TYPE_DATA); | |
278 #endif | |
279 } | |
280 | |
281 void serv_add_permit(char *name) | |
282 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
283 char buf[1024]; |
1 | 284 #ifndef USE_OSCAR |
285 g_snprintf(buf, sizeof(buf), "toc_add_permit %s", normalize(name)); | |
286 sflap_send(buf, -1, TYPE_DATA); | |
287 #endif | |
288 } | |
289 | |
290 | |
291 | |
292 void serv_add_deny(char *name) | |
293 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
294 char buf[1024]; |
1 | 295 #ifndef USE_OSCAR |
296 g_snprintf(buf, sizeof(buf), "toc_add_deny %s", normalize(name)); | |
297 sflap_send(buf, -1, TYPE_DATA); | |
298 #endif | |
299 } | |
300 | |
301 | |
302 | |
303 void serv_set_permit_deny() | |
304 { | |
305 char buf[MSG_LEN]; | |
306 int at; | |
307 GList *list; | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
308 |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
309 #ifndef USE_OSCAR |
1 | 310 /* FIXME! We flash here. */ |
311 if (permdeny == 1 || permdeny == 3) { | |
312 g_snprintf(buf, sizeof(buf), "toc_add_permit"); | |
313 sflap_send(buf, -1, TYPE_DATA); | |
314 } else { | |
315 g_snprintf(buf, sizeof(buf), "toc_add_deny"); | |
316 sflap_send(buf, -1, TYPE_DATA); | |
317 } | |
318 | |
319 | |
320 at = g_snprintf(buf, sizeof(buf), "toc_add_permit"); | |
321 list = permit; | |
322 while(list) { | |
323 at += g_snprintf(&buf[at], sizeof(buf) - at, " %s", normalize(list->data)); | |
324 list = list->next; | |
325 } | |
326 buf[at] = 0; | |
327 sflap_send(buf, -1, TYPE_DATA); | |
328 | |
329 at = g_snprintf(buf, sizeof(buf), "toc_add_deny"); | |
330 list = deny; | |
331 while(list) { | |
332 at += g_snprintf(&buf[at], sizeof(buf) - at, " %s", normalize(list->data)); | |
333 list = list->next; | |
334 } | |
335 buf[at] = 0; | |
336 sflap_send(buf, -1, TYPE_DATA); | |
337 #endif | |
338 } | |
339 | |
340 void serv_set_idle(int time) | |
341 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
342 char buf[256]; |
1 | 343 #ifndef USE_OSCAR |
344 g_snprintf(buf, sizeof(buf), "toc_set_idle %d", time); | |
345 sflap_send(buf, -1, TYPE_DATA); | |
346 #endif | |
347 } | |
348 | |
349 | |
350 void serv_warn(char *name, int anon) | |
351 { | |
352 #ifndef USE_OSCAR | |
353 char *send = g_malloc(256); | |
354 g_snprintf(send, 255, "toc_evil %s %s", name, | |
355 ((anon) ? "anon" : "norm")); | |
356 sflap_send(send, -1, TYPE_DATA); | |
357 g_free(send); | |
358 #endif | |
359 } | |
360 | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
361 void serv_build_config(char *buf, int len) { |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
362 #ifndef USE_OSCAR |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
363 toc_build_config(buf, len); |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
364 #endif |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
365 } |
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
366 |
1 | 367 |
368 void serv_save_config() | |
369 { | |
370 #ifndef USE_OSCAR | |
371 char *buf = g_malloc(BUF_LONG); | |
372 char *buf2 = g_malloc(MSG_LEN); | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
373 serv_build_config(buf, BUF_LONG / 2); |
1 | 374 g_snprintf(buf2, MSG_LEN, "toc_set_config {%s}", buf); |
375 sflap_send(buf2, -1, TYPE_DATA); | |
376 g_free(buf2); | |
377 g_free(buf); | |
378 #endif | |
379 } | |
380 | |
381 | |
382 void serv_accept_chat(int i) | |
383 { | |
384 #ifndef USE_OSCAR | |
385 char *buf = g_malloc(256); | |
386 g_snprintf(buf, 255, "toc_chat_accept %d", i); | |
387 sflap_send(buf, -1, TYPE_DATA); | |
388 g_free(buf); | |
389 #endif | |
390 } | |
391 | |
392 void serv_join_chat(int exchange, char *name) | |
393 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
394 char buf[BUF_LONG]; |
1 | 395 #ifndef USE_OSCAR |
396 g_snprintf(buf, sizeof(buf)/2, "toc_chat_join %d \"%s\"", exchange, name); | |
397 sflap_send(buf, -1, TYPE_DATA); | |
398 #endif | |
399 } | |
400 | |
401 void serv_chat_invite(int id, char *message, char *name) | |
402 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
403 char buf[BUF_LONG]; |
1 | 404 #ifndef USE_OSCAR |
405 g_snprintf(buf, sizeof(buf)/2, "toc_chat_invite %d \"%s\" %s", id, message, normalize(name)); | |
406 sflap_send(buf, -1, TYPE_DATA); | |
407 #endif | |
408 } | |
409 | |
410 void serv_chat_leave(int id) | |
411 { | |
412 #ifndef USE_OSCAR | |
413 char *buf = g_malloc(256); | |
414 g_snprintf(buf, 255, "toc_chat_leave %d", id); | |
415 sflap_send(buf, -1, TYPE_DATA); | |
416 g_free(buf); | |
417 #endif | |
418 } | |
419 | |
420 void serv_chat_whisper(int id, char *who, char *message) | |
421 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
422 char buf2[MSG_LEN]; |
1 | 423 #ifndef USE_OSCAR |
424 g_snprintf(buf2, sizeof(buf2), "toc_chat_whisper %d %s \"%s\"", id, who, message); | |
425 sflap_send(buf2, -1, TYPE_DATA); | |
426 #endif | |
427 } | |
428 | |
429 void serv_chat_send(int id, char *message) | |
430 { | |
237
6ced2f1c8b24
[gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
200
diff
changeset
|
431 char buf[MSG_LEN]; |
1 | 432 #ifndef USE_OSCAR |
433 g_snprintf(buf, sizeof(buf), "toc_chat_send %d \"%s\"",id, message); | |
434 sflap_send(buf, -1, TYPE_DATA); | |
435 #endif | |
436 } | |
437 | |
438 | |
439 | |
440 | |
441 void serv_got_im(char *name, char *message, int away) | |
442 { | |
443 struct conversation *cnv; | |
444 int is_idle = -1; | |
445 int new_conv = 0; | |
446 char *nname; | |
447 | |
94
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
448 #ifdef GAIM_PLUGINS |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
449 GList *c = callbacks; |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
450 struct gaim_callback *g; |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
451 void (*function)(char **, char **, void *); |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
452 while (c) { |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
453 g = (struct gaim_callback *)c->data; |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
454 if (g->event == event_im_recv && g->function != NULL) { |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
455 function = g->function; |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
456 /* I can guarantee you this is wrong */ |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
457 (*function)(&name, &message, g->data); |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
458 } |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
459 c = c->next; |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
460 } |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
461 /* make sure no evil plugin is trying to crash gaim */ |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
462 if (message == NULL) |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
463 return; |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
464 #endif |
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
465 |
1 | 466 nname = g_strdup(normalize(name)); |
467 | |
171
789c792ed14b
[gaim-migrate @ 181]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
145
diff
changeset
|
468 if (!strcasecmp(normalize(current_user->username), nname)) { |
1 | 469 if (!strcmp(message, LAGOMETER_STR)) { |
470 struct timeval tv; | |
471 int ms; | |
472 | |
473 gettimeofday(&tv, NULL); | |
474 | |
475 ms = 1000000 * (tv.tv_sec - lag_tv.tv_sec); | |
476 | |
477 ms += tv.tv_usec - lag_tv.tv_usec; | |
478 | |
479 update_lagometer(ms); | |
480 g_free(nname); | |
481 return; | |
482 } | |
14 | 483 } |
1 | 484 g_free(nname); |
485 | |
486 cnv = find_conversation(name); | |
145
41bd1cd48571
[gaim-migrate @ 155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
487 if (away) away = WFLAG_AUTO; |
1 | 488 |
489 if (awaymessage != NULL) { | |
490 if (!(general_options & OPT_GEN_DISCARD_WHEN_AWAY)) { | |
491 if (cnv == NULL) { | |
492 new_conv = 1; | |
493 cnv = new_conversation(name); | |
494 } | |
495 } | |
496 if (cnv != NULL) { | |
497 if (sound_options & OPT_SOUND_WHEN_AWAY) | |
498 play_sound(AWAY); | |
145
41bd1cd48571
[gaim-migrate @ 155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
499 write_to_conv(cnv, message, away | WFLAG_RECV); |
1 | 500 } |
501 | |
502 } else { | |
503 if (cnv == NULL) { | |
504 new_conv = 1; | |
505 cnv = new_conversation(name); | |
506 } | |
507 if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) { | |
508 play_sound(FIRST_RECEIVE); | |
509 } else { | |
510 if (cnv->makesound && (sound_options & OPT_SOUND_RECV)) | |
511 play_sound(RECEIVE); | |
512 } | |
145
41bd1cd48571
[gaim-migrate @ 155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
513 write_to_conv(cnv, message, away | WFLAG_RECV); |
1 | 514 } |
515 | |
516 | |
517 | |
518 | |
519 if (awaymessage != NULL) { | |
520 time_t t; | |
521 | |
522 time(&t); | |
523 | |
524 | |
525 if ((cnv == NULL) || (t - cnv->sent_away) < 120) | |
526 return; | |
527 | |
528 cnv->sent_away = t; | |
529 | |
530 if (is_idle) | |
531 is_idle = -1; | |
532 | |
533 serv_send_im(name, awaymessage->message, 1); | |
534 | |
535 if (is_idle == -1) | |
536 is_idle = 1; | |
537 | |
538 if (cnv != NULL) | |
539 write_to_conv(cnv, awaymessage->message, WFLAG_SEND | WFLAG_AUTO); | |
540 } | |
541 } | |
542 | |
543 | |
544 | |
545 void serv_got_update(char *name, int loggedin, int evil, time_t signon, time_t idle, int type) | |
546 { | |
547 struct buddy *b; | |
548 char *nname; | |
549 | |
550 b = find_buddy(name); | |
551 | |
552 nname = g_strdup(normalize(name)); | |
553 if (!strcasecmp(nname, normalize(current_user->username))) { | |
554 correction_time = (int)(signon - login_time); | |
555 update_all_buddies(); | |
25 | 556 if (!b) { |
557 g_free(nname); | |
1 | 558 return; |
25 | 559 } |
1 | 560 } |
561 | |
25 | 562 g_free(nname); |
1 | 563 |
564 if (!b) { | |
565 sprintf(debug_buff,"Error, no such person\n"); | |
566 debug_print(debug_buff); | |
567 return; | |
568 } | |
569 | |
570 /* This code will 'align' the name from the TOC */ | |
571 /* server with what's in our record. We want to */ | |
572 /* store things how THEY want it... */ | |
573 if (strcmp(name, b->name)) { | |
574 GList *cnv = conversations; | |
575 struct conversation *cv; | |
576 | |
577 char *who = g_malloc(80); | |
578 | |
579 strcpy(who, normalize(name)); | |
580 | |
581 while(cnv) { | |
582 cv = (struct conversation *)cnv->data; | |
583 if (!strcasecmp(who, normalize(cv->name))) { | |
584 g_snprintf(cv->name, sizeof(cv->name), "%s", name); | |
585 if (find_log_info(name) || (general_options & OPT_GEN_LOG_ALL)) | |
586 g_snprintf(who, 63, LOG_CONVERSATION_TITLE, name); | |
587 else | |
588 g_snprintf(who, 63, CONVERSATION_TITLE, name); | |
589 gtk_window_set_title(GTK_WINDOW(cv->window), who); | |
79 | 590 /* was g_free(buf), but break gives us that |
591 * and freeing twice is not good --Sumner */ | |
1 | 592 break; |
593 } | |
594 cnv = cnv->next; | |
595 } | |
45 | 596 g_free(who); |
1 | 597 g_snprintf(b->name, sizeof(b->name), "%s", name); |
598 /*gtk_label_set_text(GTK_LABEL(b->label), b->name);*/ | |
599 | |
600 /* okay lets save the new config... */ | |
601 | |
602 } | |
603 | |
604 b->idle = idle; | |
605 b->evil = evil; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
606 #ifdef GAIM_PLUGINS |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
607 if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
608 GList *c = callbacks; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
609 struct gaim_callback *g; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
610 void (*function)(char *, void *); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
611 while (c) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
612 g = (struct gaim_callback *)c->data; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
613 if (g->event == event_buddy_back && |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
614 g->function != NULL) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
615 function = g->function; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
616 (*function)(b->name, g->data); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
617 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
618 c = c->next; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
619 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
620 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
621 #endif |
1 | 622 b->uc = type; |
623 | |
624 b->signon = signon; | |
625 | |
626 if (loggedin) { | |
627 if (!b->present) { | |
628 b->present = 1; | |
629 do_pounce(b->name); | |
630 } | |
631 } else | |
632 b->present = 0; | |
633 | |
634 set_buddy(b); | |
635 } | |
636 | |
637 static | |
638 void close_warned(GtkWidget *w, GtkWidget *w2) | |
639 { | |
640 gtk_widget_destroy(w2); | |
641 } | |
642 | |
643 | |
644 | |
645 void serv_got_eviled(char *name, int lev) | |
646 { | |
647 char *buf2 = g_malloc(1024); | |
648 GtkWidget *d, *label, *close; | |
649 | |
650 | |
651 g_snprintf(buf2, 1023, "You have just been warned by %s.\nYour new warning level is %d./%%", | |
652 ((name == NULL) ? "an anonymous person" : name) , lev); | |
653 | |
654 | |
655 d = gtk_dialog_new(); | |
656 gtk_widget_realize(d); | |
657 aol_icon(d->window); | |
658 | |
659 label = gtk_label_new(buf2); | |
660 gtk_widget_show(label); | |
661 close = gtk_button_new_with_label("Close"); | |
662 gtk_widget_show(close); | |
663 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), | |
664 label, FALSE, FALSE, 5); | |
665 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
666 close, FALSE, FALSE, 5); | |
667 | |
668 gtk_window_set_title(GTK_WINDOW(d), "Warned"); | |
669 gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(close_warned), d); | |
670 gtk_widget_show(d); | |
671 } | |
672 | |
673 | |
674 | |
675 static void close_invite(GtkWidget *w, GtkWidget *w2) | |
676 { | |
677 gtk_widget_destroy(w2); | |
678 } | |
679 | |
680 static void chat_invite_callback(GtkWidget *w, GtkWidget *w2) | |
681 { | |
682 int i = (int)gtk_object_get_user_data(GTK_OBJECT(w2)); | |
683 serv_accept_chat(i); | |
684 gtk_widget_destroy(w2); | |
685 } | |
686 | |
687 | |
688 | |
689 void serv_got_chat_invite(char *name, int id, char *who, char *message) | |
690 { | |
691 GtkWidget *d; | |
692 GtkWidget *label; | |
693 GtkWidget *yesbtn; | |
694 GtkWidget *nobtn; | |
695 | |
696 char buf2[BUF_LONG]; | |
697 | |
698 | |
699 g_snprintf(buf2, sizeof(buf2), "User '%s' invites you to buddy chat room: '%s'\n%s", who, name, message); | |
700 | |
701 d = gtk_dialog_new(); | |
702 gtk_widget_realize(d); | |
703 aol_icon(d->window); | |
704 | |
705 | |
706 label = gtk_label_new(buf2); | |
707 gtk_widget_show(label); | |
708 yesbtn = gtk_button_new_with_label("Yes"); | |
709 gtk_widget_show(yesbtn); | |
710 nobtn = gtk_button_new_with_label("No"); | |
711 gtk_widget_show(nobtn); | |
712 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), | |
713 label, FALSE, FALSE, 5); | |
714 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
715 yesbtn, FALSE, FALSE, 5); | |
716 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
717 nobtn, FALSE, FALSE, 5); | |
718 | |
719 | |
720 /* gtk_widget_set_usize(d, 200, 110); */ | |
721 gtk_object_set_user_data(GTK_OBJECT(d), (void *)id); | |
722 | |
723 | |
724 gtk_window_set_title(GTK_WINDOW(d), "Buddy chat invite"); | |
725 gtk_signal_connect(GTK_OBJECT(nobtn), "clicked", GTK_SIGNAL_FUNC(close_invite), d); | |
726 gtk_signal_connect(GTK_OBJECT(yesbtn), "clicked", GTK_SIGNAL_FUNC(chat_invite_callback), d); | |
727 | |
728 | |
729 gtk_widget_show(d); | |
730 } | |
731 | |
732 void serv_got_joined_chat(int id, char *name) | |
733 { | |
734 struct buddy_chat *b; | |
735 | |
736 b = (struct buddy_chat *)g_new0(struct buddy_chat, 1); | |
737 buddy_chats = g_list_append(buddy_chats, b); | |
738 | |
739 b->ignored = NULL; | |
740 b->in_room = NULL; | |
741 b->id = id; | |
742 g_snprintf(b->name, 80, "%s", name); | |
743 show_new_buddy_chat(b); | |
744 } | |
745 | |
746 void serv_got_chat_left(int id) | |
747 { | |
748 GList *bcs = buddy_chats; | |
749 struct buddy_chat *b = NULL; | |
750 | |
751 | |
752 while(bcs) { | |
753 b = (struct buddy_chat *)bcs->data; | |
754 if (id == b->id) { | |
755 break; | |
756 } | |
757 b = NULL; | |
758 bcs = bcs->next; | |
759 } | |
760 | |
761 if (!b) | |
762 return; | |
763 | |
764 if (b->window) | |
765 gtk_widget_destroy(GTK_WIDGET(b->window)); | |
766 | |
767 buddy_chats = g_list_remove(buddy_chats, b); | |
768 | |
769 g_free(b); | |
770 } | |
771 | |
772 void serv_got_chat_in(int id, char *who, int whisper, char *message) | |
773 { | |
774 int w; | |
775 GList *bcs = buddy_chats; | |
776 struct buddy_chat *b = NULL; | |
777 | |
778 while(bcs) { | |
779 b = (struct buddy_chat *)bcs->data; | |
780 if (id == b->id) | |
781 break; | |
782 bcs = bcs->next; | |
783 b = NULL; | |
784 | |
785 } | |
786 if (!b) | |
787 return; | |
788 | |
789 if (whisper) | |
790 w = WFLAG_WHISPER; | |
791 else | |
792 w = 0; | |
793 | |
794 chat_write(b, who, w, message); | |
795 } | |
796 | |
797 |