Mercurial > pidgin.yaz
annotate src/server.c @ 145:41bd1cd48571
[gaim-migrate @ 155]
Modified how the "<AUTO-REPLY>" thing works. Works better now, IMHO.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 21 Apr 2000 01:25:44 +0000 |
parents | 4e91b92f91a7 |
children | 789c792ed14b |
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); | |
14 | 85 if (!(general_options & OPT_GEN_SHOW_LAGMETER)) |
94
9f6ce50ffb78
[gaim-migrate @ 104]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
79
diff
changeset
|
86 serv_send_im(current_user->username, LAGOMETER_STR, 0); |
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 | |
491 if (!strcasecmp(normalize(name), nname)) { | |
14 | 492 if (!(general_options & OPT_GEN_SHOW_LAGMETER)) |
493 { | |
1 | 494 if (!strcmp(message, LAGOMETER_STR)) { |
495 struct timeval tv; | |
496 int ms; | |
497 | |
498 gettimeofday(&tv, NULL); | |
499 | |
500 ms = 1000000 * (tv.tv_sec - lag_tv.tv_sec); | |
501 | |
502 ms += tv.tv_usec - lag_tv.tv_usec; | |
503 | |
504 update_lagometer(ms); | |
505 g_free(nname); | |
506 return; | |
507 } | |
14 | 508 } |
1 | 509 } |
510 g_free(nname); | |
511 | |
512 cnv = find_conversation(name); | |
145
41bd1cd48571
[gaim-migrate @ 155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
513 if (away) away = WFLAG_AUTO; |
1 | 514 |
515 if (awaymessage != NULL) { | |
516 if (!(general_options & OPT_GEN_DISCARD_WHEN_AWAY)) { | |
517 if (cnv == NULL) { | |
518 new_conv = 1; | |
519 cnv = new_conversation(name); | |
520 } | |
521 } | |
522 if (cnv != NULL) { | |
523 if (sound_options & OPT_SOUND_WHEN_AWAY) | |
524 play_sound(AWAY); | |
145
41bd1cd48571
[gaim-migrate @ 155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
525 write_to_conv(cnv, message, away | WFLAG_RECV); |
1 | 526 } |
527 | |
528 } else { | |
529 if (cnv == NULL) { | |
530 new_conv = 1; | |
531 cnv = new_conversation(name); | |
532 } | |
533 if (new_conv && (sound_options & OPT_SOUND_FIRST_RCV)) { | |
534 play_sound(FIRST_RECEIVE); | |
535 } else { | |
536 if (cnv->makesound && (sound_options & OPT_SOUND_RECV)) | |
537 play_sound(RECEIVE); | |
538 } | |
145
41bd1cd48571
[gaim-migrate @ 155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
136
diff
changeset
|
539 write_to_conv(cnv, message, away | WFLAG_RECV); |
1 | 540 } |
541 | |
542 | |
543 | |
544 | |
545 if (awaymessage != NULL) { | |
546 time_t t; | |
547 | |
548 time(&t); | |
549 | |
550 | |
551 if ((cnv == NULL) || (t - cnv->sent_away) < 120) | |
552 return; | |
553 | |
554 cnv->sent_away = t; | |
555 | |
556 if (is_idle) | |
557 is_idle = -1; | |
558 | |
559 serv_send_im(name, awaymessage->message, 1); | |
560 | |
561 if (is_idle == -1) | |
562 is_idle = 1; | |
563 | |
564 if (cnv != NULL) | |
565 write_to_conv(cnv, awaymessage->message, WFLAG_SEND | WFLAG_AUTO); | |
566 } | |
567 } | |
568 | |
569 | |
570 | |
571 void serv_got_update(char *name, int loggedin, int evil, time_t signon, time_t idle, int type) | |
572 { | |
573 struct buddy *b; | |
574 char *nname; | |
575 | |
576 b = find_buddy(name); | |
577 | |
578 nname = g_strdup(normalize(name)); | |
579 if (!strcasecmp(nname, normalize(current_user->username))) { | |
580 correction_time = (int)(signon - login_time); | |
581 update_all_buddies(); | |
25 | 582 if (!b) { |
583 g_free(nname); | |
1 | 584 return; |
25 | 585 } |
1 | 586 } |
587 | |
25 | 588 g_free(nname); |
1 | 589 |
590 if (!b) { | |
591 sprintf(debug_buff,"Error, no such person\n"); | |
592 debug_print(debug_buff); | |
593 return; | |
594 } | |
595 | |
596 /* This code will 'align' the name from the TOC */ | |
597 /* server with what's in our record. We want to */ | |
598 /* store things how THEY want it... */ | |
599 if (strcmp(name, b->name)) { | |
600 GList *cnv = conversations; | |
601 struct conversation *cv; | |
602 | |
603 char *who = g_malloc(80); | |
604 | |
605 strcpy(who, normalize(name)); | |
606 | |
607 while(cnv) { | |
608 cv = (struct conversation *)cnv->data; | |
609 if (!strcasecmp(who, normalize(cv->name))) { | |
610 g_snprintf(cv->name, sizeof(cv->name), "%s", name); | |
611 if (find_log_info(name) || (general_options & OPT_GEN_LOG_ALL)) | |
612 g_snprintf(who, 63, LOG_CONVERSATION_TITLE, name); | |
613 else | |
614 g_snprintf(who, 63, CONVERSATION_TITLE, name); | |
615 gtk_window_set_title(GTK_WINDOW(cv->window), who); | |
79 | 616 /* was g_free(buf), but break gives us that |
617 * and freeing twice is not good --Sumner */ | |
1 | 618 break; |
619 } | |
620 cnv = cnv->next; | |
621 } | |
45 | 622 g_free(who); |
1 | 623 g_snprintf(b->name, sizeof(b->name), "%s", name); |
624 /*gtk_label_set_text(GTK_LABEL(b->label), b->name);*/ | |
625 | |
626 /* okay lets save the new config... */ | |
627 | |
628 } | |
629 | |
630 b->idle = idle; | |
631 b->evil = evil; | |
136
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
632 #ifdef GAIM_PLUGINS |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
633 if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
634 GList *c = callbacks; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
635 struct gaim_callback *g; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
636 void (*function)(char *, void *); |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
637 while (c) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
638 g = (struct gaim_callback *)c->data; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
639 if (g->event == event_buddy_back && |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
640 g->function != NULL) { |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
641 function = g->function; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
642 (*function)(b->name, g->data); |
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 c = c->next; |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
645 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
646 } |
4e91b92f91a7
[gaim-migrate @ 146]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
115
diff
changeset
|
647 #endif |
1 | 648 b->uc = type; |
649 | |
650 b->signon = signon; | |
651 | |
652 if (loggedin) { | |
653 if (!b->present) { | |
654 b->present = 1; | |
655 do_pounce(b->name); | |
656 } | |
657 } else | |
658 b->present = 0; | |
659 | |
660 set_buddy(b); | |
661 } | |
662 | |
663 static | |
664 void close_warned(GtkWidget *w, GtkWidget *w2) | |
665 { | |
666 gtk_widget_destroy(w2); | |
667 } | |
668 | |
669 | |
670 | |
671 void serv_got_eviled(char *name, int lev) | |
672 { | |
673 char *buf2 = g_malloc(1024); | |
674 GtkWidget *d, *label, *close; | |
675 | |
676 | |
677 g_snprintf(buf2, 1023, "You have just been warned by %s.\nYour new warning level is %d./%%", | |
678 ((name == NULL) ? "an anonymous person" : name) , lev); | |
679 | |
680 | |
681 d = gtk_dialog_new(); | |
682 gtk_widget_realize(d); | |
683 aol_icon(d->window); | |
684 | |
685 label = gtk_label_new(buf2); | |
686 gtk_widget_show(label); | |
687 close = gtk_button_new_with_label("Close"); | |
688 gtk_widget_show(close); | |
689 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), | |
690 label, FALSE, FALSE, 5); | |
691 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
692 close, FALSE, FALSE, 5); | |
693 | |
694 gtk_window_set_title(GTK_WINDOW(d), "Warned"); | |
695 gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(close_warned), d); | |
696 gtk_widget_show(d); | |
697 } | |
698 | |
699 | |
700 | |
701 static void close_invite(GtkWidget *w, GtkWidget *w2) | |
702 { | |
703 gtk_widget_destroy(w2); | |
704 } | |
705 | |
706 static void chat_invite_callback(GtkWidget *w, GtkWidget *w2) | |
707 { | |
708 int i = (int)gtk_object_get_user_data(GTK_OBJECT(w2)); | |
709 serv_accept_chat(i); | |
710 gtk_widget_destroy(w2); | |
711 } | |
712 | |
713 | |
714 | |
715 void serv_got_chat_invite(char *name, int id, char *who, char *message) | |
716 { | |
717 GtkWidget *d; | |
718 GtkWidget *label; | |
719 GtkWidget *yesbtn; | |
720 GtkWidget *nobtn; | |
721 | |
722 char buf2[BUF_LONG]; | |
723 | |
724 | |
725 g_snprintf(buf2, sizeof(buf2), "User '%s' invites you to buddy chat room: '%s'\n%s", who, name, message); | |
726 | |
727 d = gtk_dialog_new(); | |
728 gtk_widget_realize(d); | |
729 aol_icon(d->window); | |
730 | |
731 | |
732 label = gtk_label_new(buf2); | |
733 gtk_widget_show(label); | |
734 yesbtn = gtk_button_new_with_label("Yes"); | |
735 gtk_widget_show(yesbtn); | |
736 nobtn = gtk_button_new_with_label("No"); | |
737 gtk_widget_show(nobtn); | |
738 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), | |
739 label, FALSE, FALSE, 5); | |
740 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
741 yesbtn, FALSE, FALSE, 5); | |
742 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
743 nobtn, FALSE, FALSE, 5); | |
744 | |
745 | |
746 /* gtk_widget_set_usize(d, 200, 110); */ | |
747 gtk_object_set_user_data(GTK_OBJECT(d), (void *)id); | |
748 | |
749 | |
750 gtk_window_set_title(GTK_WINDOW(d), "Buddy chat invite"); | |
751 gtk_signal_connect(GTK_OBJECT(nobtn), "clicked", GTK_SIGNAL_FUNC(close_invite), d); | |
752 gtk_signal_connect(GTK_OBJECT(yesbtn), "clicked", GTK_SIGNAL_FUNC(chat_invite_callback), d); | |
753 | |
754 | |
755 gtk_widget_show(d); | |
756 } | |
757 | |
758 void serv_got_joined_chat(int id, char *name) | |
759 { | |
760 struct buddy_chat *b; | |
761 | |
762 b = (struct buddy_chat *)g_new0(struct buddy_chat, 1); | |
763 buddy_chats = g_list_append(buddy_chats, b); | |
764 | |
765 b->ignored = NULL; | |
766 b->in_room = NULL; | |
767 b->id = id; | |
768 g_snprintf(b->name, 80, "%s", name); | |
769 show_new_buddy_chat(b); | |
770 } | |
771 | |
772 void serv_got_chat_left(int id) | |
773 { | |
774 GList *bcs = buddy_chats; | |
775 struct buddy_chat *b = NULL; | |
776 | |
777 | |
778 while(bcs) { | |
779 b = (struct buddy_chat *)bcs->data; | |
780 if (id == b->id) { | |
781 break; | |
782 } | |
783 b = NULL; | |
784 bcs = bcs->next; | |
785 } | |
786 | |
787 if (!b) | |
788 return; | |
789 | |
790 if (b->window) | |
791 gtk_widget_destroy(GTK_WIDGET(b->window)); | |
792 | |
793 buddy_chats = g_list_remove(buddy_chats, b); | |
794 | |
795 g_free(b); | |
796 } | |
797 | |
798 void serv_got_chat_in(int id, char *who, int whisper, char *message) | |
799 { | |
800 int w; | |
801 GList *bcs = buddy_chats; | |
802 struct buddy_chat *b = NULL; | |
803 | |
804 while(bcs) { | |
805 b = (struct buddy_chat *)bcs->data; | |
806 if (id == b->id) | |
807 break; | |
808 bcs = bcs->next; | |
809 b = NULL; | |
810 | |
811 } | |
812 if (!b) | |
813 return; | |
814 | |
815 if (whisper) | |
816 w = WFLAG_WHISPER; | |
817 else | |
818 w = 0; | |
819 | |
820 chat_write(b, who, w, message); | |
821 } | |
822 | |
823 |