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