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