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