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