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