Sat, 25 Mar 2000 17:15:50 +0000
[gaim-migrate @ 49]
Moved back to gnome/. Don't ask.
| 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 | */ | |
| 25 | 582 | g_free(who); //FIXME |
| 1 | 583 | break; |
| 584 | } | |
| 585 | cnv = cnv->next; | |
| 586 | } | |
| 25 | 587 | g_free(who); //FIXME |
| 1 | 588 | g_snprintf(b->name, sizeof(b->name), "%s", name); |
| 589 | /*gtk_label_set_text(GTK_LABEL(b->label), b->name);*/ | |
| 590 | ||
| 591 | /* okay lets save the new config... */ | |
| 592 | ||
| 593 | } | |
| 594 | ||
| 595 | b->idle = idle; | |
| 596 | b->evil = evil; | |
| 597 | b->uc = type; | |
| 598 | ||
| 599 | b->signon = signon; | |
| 600 | ||
| 601 | if (loggedin) { | |
| 602 | if (!b->present) { | |
| 603 | b->present = 1; | |
| 604 | do_pounce(b->name); | |
| 605 | } | |
| 606 | } else | |
| 607 | b->present = 0; | |
| 608 | ||
| 609 | set_buddy(b); | |
| 610 | } | |
| 611 | ||
| 612 | static | |
| 613 | void close_warned(GtkWidget *w, GtkWidget *w2) | |
| 614 | { | |
| 615 | gtk_widget_destroy(w2); | |
| 616 | } | |
| 617 | ||
| 618 | ||
| 619 | ||
| 620 | void serv_got_eviled(char *name, int lev) | |
| 621 | { | |
| 622 | char *buf2 = g_malloc(1024); | |
| 623 | GtkWidget *d, *label, *close; | |
| 624 | ||
| 625 | ||
| 626 | g_snprintf(buf2, 1023, "You have just been warned by %s.\nYour new warning level is %d./%%", | |
| 627 | ((name == NULL) ? "an anonymous person" : name) , lev); | |
| 628 | ||
| 629 | ||
| 630 | d = gtk_dialog_new(); | |
| 631 | gtk_widget_realize(d); | |
| 632 | aol_icon(d->window); | |
| 633 | ||
| 634 | label = gtk_label_new(buf2); | |
| 635 | gtk_widget_show(label); | |
| 636 | close = gtk_button_new_with_label("Close"); | |
| 637 | gtk_widget_show(close); | |
| 638 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), | |
| 639 | label, FALSE, FALSE, 5); | |
| 640 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
| 641 | close, FALSE, FALSE, 5); | |
| 642 | ||
| 643 | gtk_window_set_title(GTK_WINDOW(d), "Warned"); | |
| 644 | gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(close_warned), d); | |
| 645 | gtk_widget_show(d); | |
| 646 | } | |
| 647 | ||
| 648 | ||
| 649 | ||
| 650 | static void close_invite(GtkWidget *w, GtkWidget *w2) | |
| 651 | { | |
| 652 | gtk_widget_destroy(w2); | |
| 653 | } | |
| 654 | ||
| 655 | static void chat_invite_callback(GtkWidget *w, GtkWidget *w2) | |
| 656 | { | |
| 657 | int i = (int)gtk_object_get_user_data(GTK_OBJECT(w2)); | |
| 658 | serv_accept_chat(i); | |
| 659 | gtk_widget_destroy(w2); | |
| 660 | } | |
| 661 | ||
| 662 | ||
| 663 | ||
| 664 | void serv_got_chat_invite(char *name, int id, char *who, char *message) | |
| 665 | { | |
| 666 | GtkWidget *d; | |
| 667 | GtkWidget *label; | |
| 668 | GtkWidget *yesbtn; | |
| 669 | GtkWidget *nobtn; | |
| 670 | ||
| 671 | char buf2[BUF_LONG]; | |
| 672 | ||
| 673 | ||
| 674 | g_snprintf(buf2, sizeof(buf2), "User '%s' invites you to buddy chat room: '%s'\n%s", who, name, message); | |
| 675 | ||
| 676 | d = gtk_dialog_new(); | |
| 677 | gtk_widget_realize(d); | |
| 678 | aol_icon(d->window); | |
| 679 | ||
| 680 | ||
| 681 | label = gtk_label_new(buf2); | |
| 682 | gtk_widget_show(label); | |
| 683 | yesbtn = gtk_button_new_with_label("Yes"); | |
| 684 | gtk_widget_show(yesbtn); | |
| 685 | nobtn = gtk_button_new_with_label("No"); | |
| 686 | gtk_widget_show(nobtn); | |
| 687 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), | |
| 688 | label, FALSE, FALSE, 5); | |
| 689 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
| 690 | yesbtn, FALSE, FALSE, 5); | |
| 691 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), | |
| 692 | nobtn, FALSE, FALSE, 5); | |
| 693 | ||
| 694 | ||
| 695 | /* gtk_widget_set_usize(d, 200, 110); */ | |
| 696 | gtk_object_set_user_data(GTK_OBJECT(d), (void *)id); | |
| 697 | ||
| 698 | ||
| 699 | gtk_window_set_title(GTK_WINDOW(d), "Buddy chat invite"); | |
| 700 | gtk_signal_connect(GTK_OBJECT(nobtn), "clicked", GTK_SIGNAL_FUNC(close_invite), d); | |
| 701 | gtk_signal_connect(GTK_OBJECT(yesbtn), "clicked", GTK_SIGNAL_FUNC(chat_invite_callback), d); | |
| 702 | ||
| 703 | ||
| 704 | gtk_widget_show(d); | |
| 705 | } | |
| 706 | ||
| 707 | void serv_got_joined_chat(int id, char *name) | |
| 708 | { | |
| 709 | struct buddy_chat *b; | |
| 710 | ||
| 711 | b = (struct buddy_chat *)g_new0(struct buddy_chat, 1); | |
| 712 | buddy_chats = g_list_append(buddy_chats, b); | |
| 713 | ||
| 714 | b->ignored = NULL; | |
| 715 | b->in_room = NULL; | |
| 716 | b->id = id; | |
| 717 | g_snprintf(b->name, 80, "%s", name); | |
| 718 | show_new_buddy_chat(b); | |
| 719 | } | |
| 720 | ||
| 721 | void serv_got_chat_left(int id) | |
| 722 | { | |
| 723 | GList *bcs = buddy_chats; | |
| 724 | struct buddy_chat *b = NULL; | |
| 725 | ||
| 726 | ||
| 727 | while(bcs) { | |
| 728 | b = (struct buddy_chat *)bcs->data; | |
| 729 | if (id == b->id) { | |
| 730 | break; | |
| 731 | } | |
| 732 | b = NULL; | |
| 733 | bcs = bcs->next; | |
| 734 | } | |
| 735 | ||
| 736 | if (!b) | |
| 737 | return; | |
| 738 | ||
| 739 | if (b->window) | |
| 740 | gtk_widget_destroy(GTK_WIDGET(b->window)); | |
| 741 | ||
| 742 | buddy_chats = g_list_remove(buddy_chats, b); | |
| 743 | ||
| 744 | g_free(b); | |
| 745 | } | |
| 746 | ||
| 747 | void serv_got_chat_in(int id, char *who, int whisper, char *message) | |
| 748 | { | |
| 749 | int w; | |
| 750 | GList *bcs = buddy_chats; | |
| 751 | struct buddy_chat *b = NULL; | |
| 752 | ||
| 753 | while(bcs) { | |
| 754 | b = (struct buddy_chat *)bcs->data; | |
| 755 | if (id == b->id) | |
| 756 | break; | |
| 757 | bcs = bcs->next; | |
| 758 | b = NULL; | |
| 759 | ||
| 760 | } | |
| 761 | if (!b) | |
| 762 | return; | |
| 763 | ||
| 764 | if (whisper) | |
| 765 | w = WFLAG_WHISPER; | |
| 766 | else | |
| 767 | w = 0; | |
| 768 | ||
| 769 | chat_write(b, who, w, message); | |
| 770 | } | |
| 771 | ||
| 772 |