[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2004 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* |
---|
| 8 | * nogaim |
---|
| 9 | * |
---|
| 10 | * Gaim without gaim - for BitlBee |
---|
| 11 | * |
---|
| 12 | * This file contains functions called by the Gaim IM-modules. It's written |
---|
| 13 | * from scratch for BitlBee and doesn't contain any code from Gaim anymore |
---|
| 14 | * (except for the function names). |
---|
| 15 | * |
---|
[84c1a0a] | 16 | * Copyright 2002-2006 Wilmer van der Gaast <wilmer@gaast.net> and others |
---|
[b7d3cc34] | 17 | */ |
---|
| 18 | |
---|
| 19 | /* |
---|
| 20 | This program is free software; you can redistribute it and/or modify |
---|
| 21 | it under the terms of the GNU General Public License as published by |
---|
| 22 | the Free Software Foundation; either version 2 of the License, or |
---|
| 23 | (at your option) any later version. |
---|
| 24 | |
---|
| 25 | This program is distributed in the hope that it will be useful, |
---|
| 26 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 27 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 28 | GNU General Public License for more details. |
---|
| 29 | |
---|
| 30 | You should have received a copy of the GNU General Public License with |
---|
| 31 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 32 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 33 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #define BITLBEE_CORE |
---|
| 37 | #include "nogaim.h" |
---|
| 38 | #include <ctype.h> |
---|
| 39 | |
---|
[19a6c75] | 40 | static char *proto_away_alias[8][5] = |
---|
[b7d3cc34] | 41 | { |
---|
| 42 | { "Away from computer", "Away", "Extended away", NULL }, |
---|
| 43 | { "NA", "N/A", "Not available", NULL }, |
---|
| 44 | { "Busy", "Do not disturb", "DND", "Occupied", NULL }, |
---|
| 45 | { "Be right back", "BRB", NULL }, |
---|
| 46 | { "On the phone", "Phone", "On phone", NULL }, |
---|
| 47 | { "Out to lunch", "Lunch", "Food", NULL }, |
---|
[19a6c75] | 48 | { "Invisible", "Hidden" }, |
---|
[b7d3cc34] | 49 | { NULL } |
---|
| 50 | }; |
---|
| 51 | static char *proto_away_alias_find( GList *gcm, char *away ); |
---|
| 52 | |
---|
| 53 | static int remove_chat_buddy_silent( struct conversation *b, char *handle ); |
---|
| 54 | |
---|
| 55 | GSList *connections; |
---|
| 56 | |
---|
[65e2ce1] | 57 | #ifdef WITH_PLUGINS |
---|
[7b23afd] | 58 | gboolean load_plugin(char *path) |
---|
| 59 | { |
---|
| 60 | void (*init_function) (void); |
---|
| 61 | |
---|
| 62 | GModule *mod = g_module_open(path, G_MODULE_BIND_LAZY); |
---|
| 63 | |
---|
| 64 | if(!mod) { |
---|
| 65 | log_message(LOGLVL_ERROR, "Can't find `%s', not loading", path); |
---|
| 66 | return FALSE; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | if(!g_module_symbol(mod,"init_plugin",(gpointer *) &init_function)) { |
---|
| 70 | log_message(LOGLVL_WARNING, "Can't find function `init_plugin' in `%s'\n", path); |
---|
| 71 | return FALSE; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | init_function(); |
---|
| 75 | |
---|
| 76 | return TRUE; |
---|
| 77 | } |
---|
[b7d3cc34] | 78 | |
---|
[65e2ce1] | 79 | void load_plugins(void) |
---|
| 80 | { |
---|
| 81 | GDir *dir; |
---|
| 82 | GError *error = NULL; |
---|
| 83 | |
---|
[4bfca70] | 84 | dir = g_dir_open(global.conf->plugindir, 0, &error); |
---|
[65e2ce1] | 85 | |
---|
| 86 | if (dir) { |
---|
| 87 | const gchar *entry; |
---|
| 88 | char *path; |
---|
| 89 | |
---|
| 90 | while ((entry = g_dir_read_name(dir))) { |
---|
[4bfca70] | 91 | path = g_build_filename(global.conf->plugindir, entry, NULL); |
---|
[65e2ce1] | 92 | if(!path) { |
---|
| 93 | log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); |
---|
| 94 | continue; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | load_plugin(path); |
---|
| 98 | |
---|
| 99 | g_free(path); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | g_dir_close(dir); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | #endif |
---|
[b7d3cc34] | 106 | |
---|
| 107 | /* nogaim.c */ |
---|
| 108 | |
---|
[7b23afd] | 109 | GList *protocols = NULL; |
---|
| 110 | |
---|
| 111 | void register_protocol (struct prpl *p) |
---|
| 112 | { |
---|
| 113 | protocols = g_list_append(protocols, p); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | struct prpl *find_protocol(const char *name) |
---|
| 118 | { |
---|
| 119 | GList *gl; |
---|
| 120 | for (gl = protocols; gl; gl = gl->next) |
---|
| 121 | { |
---|
| 122 | struct prpl *proto = gl->data; |
---|
| 123 | if(!g_strcasecmp(proto->name, name)) |
---|
| 124 | return proto; |
---|
| 125 | } |
---|
| 126 | return NULL; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /* nogaim.c */ |
---|
[b7d3cc34] | 130 | void nogaim_init() |
---|
| 131 | { |
---|
[65e2ce1] | 132 | extern void msn_init(); |
---|
| 133 | extern void oscar_init(); |
---|
| 134 | extern void byahoo_init(); |
---|
| 135 | extern void jabber_init(); |
---|
[7b23afd] | 136 | |
---|
[b7d3cc34] | 137 | #ifdef WITH_MSN |
---|
[7b23afd] | 138 | msn_init(); |
---|
[b7d3cc34] | 139 | #endif |
---|
| 140 | |
---|
| 141 | #ifdef WITH_OSCAR |
---|
[7b23afd] | 142 | oscar_init(); |
---|
[b7d3cc34] | 143 | #endif |
---|
| 144 | |
---|
| 145 | #ifdef WITH_YAHOO |
---|
[7b23afd] | 146 | byahoo_init(); |
---|
[b7d3cc34] | 147 | #endif |
---|
| 148 | |
---|
| 149 | #ifdef WITH_JABBER |
---|
[7b23afd] | 150 | jabber_init(); |
---|
[b7d3cc34] | 151 | #endif |
---|
[7b23afd] | 152 | |
---|
[65e2ce1] | 153 | #ifdef WITH_PLUGINS |
---|
| 154 | load_plugins(); |
---|
[b7d3cc34] | 155 | #endif |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | GSList *get_connections() { return connections; } |
---|
| 159 | |
---|
| 160 | int proto_away( struct gaim_connection *gc, char *away ) |
---|
| 161 | { |
---|
| 162 | GList *m, *ms; |
---|
| 163 | char *s; |
---|
| 164 | |
---|
| 165 | if( !away ) away = ""; |
---|
| 166 | ms = m = gc->prpl->away_states( gc ); |
---|
| 167 | |
---|
| 168 | while( m ) |
---|
| 169 | { |
---|
| 170 | if( *away ) |
---|
| 171 | { |
---|
| 172 | if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) |
---|
| 173 | break; |
---|
| 174 | } |
---|
| 175 | else |
---|
| 176 | { |
---|
| 177 | if( g_strcasecmp( m->data, "Available" ) == 0 ) |
---|
| 178 | break; |
---|
| 179 | if( g_strcasecmp( m->data, "Online" ) == 0 ) |
---|
| 180 | break; |
---|
| 181 | } |
---|
| 182 | m = m->next; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | if( m ) |
---|
| 186 | { |
---|
| 187 | gc->prpl->set_away( gc, m->data, *away ? away : NULL ); |
---|
| 188 | } |
---|
| 189 | else |
---|
| 190 | { |
---|
| 191 | s = proto_away_alias_find( ms, away ); |
---|
| 192 | if( s ) |
---|
| 193 | { |
---|
| 194 | gc->prpl->set_away( gc, s, away ); |
---|
| 195 | if( set_getint( gc->irc, "debug" ) ) |
---|
[5c09a59] | 196 | serv_got_crap( gc, "Setting away state to %s", s ); |
---|
[b7d3cc34] | 197 | } |
---|
| 198 | else |
---|
| 199 | gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | g_list_free( ms ); |
---|
| 203 | |
---|
| 204 | return( 1 ); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | static char *proto_away_alias_find( GList *gcm, char *away ) |
---|
| 208 | { |
---|
| 209 | GList *m; |
---|
| 210 | int i, j; |
---|
| 211 | |
---|
| 212 | for( i = 0; *proto_away_alias[i]; i ++ ) |
---|
| 213 | { |
---|
| 214 | for( j = 0; proto_away_alias[i][j]; j ++ ) |
---|
| 215 | if( g_strncasecmp( away, proto_away_alias[i][j], strlen( proto_away_alias[i][j] ) ) == 0 ) |
---|
| 216 | break; |
---|
| 217 | |
---|
| 218 | if( !proto_away_alias[i][j] ) /* If we reach the end, this row */ |
---|
| 219 | continue; /* is not what we want. Next! */ |
---|
| 220 | |
---|
| 221 | /* Now find an entry in this row which exists in gcm */ |
---|
| 222 | for( j = 0; proto_away_alias[i][j]; j ++ ) |
---|
| 223 | { |
---|
| 224 | m = gcm; |
---|
| 225 | while( m ) |
---|
| 226 | { |
---|
| 227 | if( g_strcasecmp( proto_away_alias[i][j], m->data ) == 0 ) |
---|
| 228 | return( proto_away_alias[i][j] ); |
---|
| 229 | m = m->next; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | return( NULL ); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /* multi.c */ |
---|
| 238 | |
---|
| 239 | struct gaim_connection *new_gaim_conn( struct aim_user *user ) |
---|
| 240 | { |
---|
| 241 | struct gaim_connection *gc; |
---|
| 242 | account_t *a; |
---|
| 243 | |
---|
| 244 | gc = g_new0( struct gaim_connection, 1 ); |
---|
| 245 | |
---|
[7b23afd] | 246 | gc->prpl = user->prpl; |
---|
[b7d3cc34] | 247 | g_snprintf( gc->username, sizeof( gc->username ), "%s", user->username ); |
---|
| 248 | g_snprintf( gc->password, sizeof( gc->password ), "%s", user->password ); |
---|
| 249 | /* [MD] BUGFIX: don't set gc->irc to the global IRC, but use the one from the struct aim_user. |
---|
| 250 | * This fixes daemon mode breakage where IRC doesn't point to the currently active connection. |
---|
| 251 | */ |
---|
| 252 | gc->irc=user->irc; |
---|
| 253 | |
---|
| 254 | connections = g_slist_append( connections, gc ); |
---|
| 255 | |
---|
| 256 | user->gc = gc; |
---|
| 257 | gc->user = user; |
---|
| 258 | |
---|
| 259 | // Find the account_t so we can set its gc pointer |
---|
| 260 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
| 261 | if( ( struct aim_user * ) a->gc == user ) |
---|
| 262 | { |
---|
| 263 | a->gc = gc; |
---|
| 264 | break; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | return( gc ); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | void destroy_gaim_conn( struct gaim_connection *gc ) |
---|
| 271 | { |
---|
| 272 | account_t *a; |
---|
| 273 | |
---|
| 274 | /* Destroy the pointer to this connection from the account list */ |
---|
| 275 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
| 276 | if( a->gc == gc ) |
---|
| 277 | { |
---|
| 278 | a->gc = NULL; |
---|
| 279 | break; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | connections = g_slist_remove( connections, gc ); |
---|
| 283 | g_free( gc->user ); |
---|
| 284 | g_free( gc ); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | void set_login_progress( struct gaim_connection *gc, int step, char *msg ) |
---|
| 288 | { |
---|
[5c09a59] | 289 | serv_got_crap( gc, "Logging in: %s", msg ); |
---|
[b7d3cc34] | 290 | } |
---|
| 291 | |
---|
| 292 | /* Errors *while* logging in */ |
---|
| 293 | void hide_login_progress( struct gaim_connection *gc, char *msg ) |
---|
| 294 | { |
---|
[5c09a59] | 295 | serv_got_crap( gc, "Login error: %s", msg ); |
---|
[b7d3cc34] | 296 | } |
---|
| 297 | |
---|
| 298 | /* Errors *after* logging in */ |
---|
| 299 | void hide_login_progress_error( struct gaim_connection *gc, char *msg ) |
---|
| 300 | { |
---|
[5c09a59] | 301 | serv_got_crap( gc, "Logged out: %s", msg ); |
---|
[b7d3cc34] | 302 | } |
---|
| 303 | |
---|
| 304 | void serv_got_crap( struct gaim_connection *gc, char *format, ... ) |
---|
| 305 | { |
---|
| 306 | va_list params; |
---|
[e27661d] | 307 | char *text; |
---|
[dfde8e0] | 308 | account_t *a; |
---|
[b7d3cc34] | 309 | |
---|
| 310 | va_start( params, format ); |
---|
[e27661d] | 311 | text = g_strdup_vprintf( format, params ); |
---|
[b7d3cc34] | 312 | va_end( params ); |
---|
| 313 | |
---|
[c572dd6] | 314 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
| 315 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
[e27661d] | 316 | strip_html( text ); |
---|
[b7d3cc34] | 317 | |
---|
[dfde8e0] | 318 | /* Try to find a different connection on the same protocol. */ |
---|
| 319 | for( a = gc->irc->accounts; a; a = a->next ) |
---|
[b20b32f] | 320 | if( a->prpl == gc->prpl && a->gc != gc ) |
---|
[dfde8e0] | 321 | break; |
---|
| 322 | |
---|
[e27661d] | 323 | /* If we found one, include the screenname in the message. */ |
---|
[dfde8e0] | 324 | if( a ) |
---|
[e27661d] | 325 | irc_usermsg( gc->irc, "%s(%s) - %s", gc->prpl->name, gc->username, text ); |
---|
[dfde8e0] | 326 | else |
---|
[e27661d] | 327 | irc_usermsg( gc->irc, "%s - %s", gc->prpl->name, text ); |
---|
[7b07dc6] | 328 | |
---|
[e27661d] | 329 | g_free( text ); |
---|
[b7d3cc34] | 330 | } |
---|
| 331 | |
---|
| 332 | static gboolean send_keepalive( gpointer d ) |
---|
| 333 | { |
---|
| 334 | struct gaim_connection *gc = d; |
---|
| 335 | |
---|
| 336 | if( gc->prpl && gc->prpl->keepalive ) |
---|
| 337 | gc->prpl->keepalive( gc ); |
---|
| 338 | |
---|
| 339 | return TRUE; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | void account_online( struct gaim_connection *gc ) |
---|
| 343 | { |
---|
| 344 | user_t *u; |
---|
| 345 | |
---|
| 346 | /* MSN servers sometimes redirect you to a different server and do |
---|
[84c1a0a] | 347 | the whole login sequence again, so these "late" calls to this |
---|
[b7d3cc34] | 348 | function should be handled correctly. (IOW, ignored) */ |
---|
| 349 | if( gc->flags & OPT_LOGGED_IN ) |
---|
| 350 | return; |
---|
| 351 | |
---|
| 352 | u = user_find( gc->irc, gc->irc->nick ); |
---|
| 353 | |
---|
[5c09a59] | 354 | serv_got_crap( gc, "Logged in" ); |
---|
[b7d3cc34] | 355 | |
---|
| 356 | gc->keepalive = g_timeout_add( 60000, send_keepalive, gc ); |
---|
| 357 | gc->flags |= OPT_LOGGED_IN; |
---|
| 358 | |
---|
[61dddd0] | 359 | /* Also necessary when we're not away, at least for some of the |
---|
| 360 | protocols. */ |
---|
| 361 | proto_away( gc, u->away ); |
---|
[b7d3cc34] | 362 | } |
---|
| 363 | |
---|
| 364 | gboolean auto_reconnect( gpointer data ) |
---|
| 365 | { |
---|
| 366 | account_t *a = data; |
---|
| 367 | |
---|
| 368 | a->reconnect = 0; |
---|
| 369 | account_on( a->irc, a ); |
---|
| 370 | |
---|
| 371 | return( FALSE ); /* Only have to run the timeout once */ |
---|
| 372 | } |
---|
| 373 | |
---|
| 374 | void cancel_auto_reconnect( account_t *a ) |
---|
| 375 | { |
---|
| 376 | while( g_source_remove_by_user_data( (gpointer) a ) ); |
---|
| 377 | a->reconnect = 0; |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | void signoff( struct gaim_connection *gc ) |
---|
| 381 | { |
---|
| 382 | irc_t *irc = gc->irc; |
---|
| 383 | user_t *t, *u = irc->users; |
---|
| 384 | account_t *a; |
---|
| 385 | |
---|
[5c09a59] | 386 | serv_got_crap( gc, "Signing off.." ); |
---|
[b7d3cc34] | 387 | |
---|
| 388 | gaim_input_remove( gc->keepalive ); |
---|
| 389 | gc->keepalive = 0; |
---|
| 390 | gc->prpl->close( gc ); |
---|
| 391 | gaim_input_remove( gc->inpa ); |
---|
| 392 | |
---|
| 393 | while( u ) |
---|
| 394 | { |
---|
| 395 | if( u->gc == gc ) |
---|
| 396 | { |
---|
| 397 | t = u->next; |
---|
| 398 | user_del( irc, u->nick ); |
---|
| 399 | u = t; |
---|
| 400 | } |
---|
| 401 | else |
---|
| 402 | u = u->next; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | query_del_by_gc( gc->irc, gc ); |
---|
| 406 | |
---|
| 407 | for( a = irc->accounts; a; a = a->next ) |
---|
| 408 | if( a->gc == gc ) |
---|
| 409 | break; |
---|
| 410 | |
---|
| 411 | if( !a ) |
---|
| 412 | { |
---|
| 413 | /* Uhm... This is very sick. */ |
---|
| 414 | } |
---|
| 415 | else if( !gc->wants_to_die && set_getint( irc, "auto_reconnect" ) ) |
---|
| 416 | { |
---|
| 417 | int delay = set_getint( irc, "auto_reconnect_delay" ); |
---|
[5c09a59] | 418 | serv_got_crap( gc, "Reconnecting in %d seconds..", delay ); |
---|
[b7d3cc34] | 419 | |
---|
| 420 | a->reconnect = 1; |
---|
| 421 | g_timeout_add( delay * 1000, auto_reconnect, a ); |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | destroy_gaim_conn( gc ); |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | |
---|
| 428 | /* dialogs.c */ |
---|
| 429 | |
---|
| 430 | void do_error_dialog( struct gaim_connection *gc, char *msg, char *title ) |
---|
| 431 | { |
---|
[25d1be7] | 432 | if( msg && title ) |
---|
| 433 | serv_got_crap( gc, "Error: %s: %s", title, msg ); |
---|
| 434 | else if( msg ) |
---|
| 435 | serv_got_crap( gc, "Error: %s", msg ); |
---|
| 436 | else if( title ) |
---|
| 437 | serv_got_crap( gc, "Error: %s", title ); |
---|
| 438 | else |
---|
| 439 | serv_got_crap( gc, "Error" ); |
---|
[b7d3cc34] | 440 | } |
---|
| 441 | |
---|
| 442 | void do_ask_dialog( struct gaim_connection *gc, char *msg, void *data, void *doit, void *dont ) |
---|
| 443 | { |
---|
| 444 | query_add( gc->irc, gc, msg, doit, dont, data ); |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | |
---|
| 448 | /* list.c */ |
---|
| 449 | |
---|
| 450 | void add_buddy( struct gaim_connection *gc, char *group, char *handle, char *realname ) |
---|
| 451 | { |
---|
| 452 | user_t *u; |
---|
| 453 | char nick[MAX_NICK_LENGTH+1]; |
---|
| 454 | char *s; |
---|
| 455 | irc_t *irc = gc->irc; |
---|
| 456 | |
---|
| 457 | if( set_getint( irc, "debug" ) && 0 ) /* This message is too useless */ |
---|
[5c09a59] | 458 | serv_got_crap( gc, "Receiving user add from handle: %s", handle ); |
---|
[b7d3cc34] | 459 | |
---|
| 460 | if( user_findhandle( gc, handle ) ) |
---|
| 461 | { |
---|
| 462 | if( set_getint( irc, "debug" ) ) |
---|
[5c09a59] | 463 | serv_got_crap( gc, "User already exists, ignoring add request: %s", handle ); |
---|
[b7d3cc34] | 464 | |
---|
| 465 | return; |
---|
| 466 | |
---|
| 467 | /* Buddy seems to exist already. Let's ignore this request then... */ |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
[7b23afd] | 471 | strcpy( nick, nick_get( gc->irc, handle, gc->prpl, realname ) ); |
---|
[b7d3cc34] | 472 | |
---|
| 473 | u = user_add( gc->irc, nick ); |
---|
| 474 | |
---|
| 475 | if( !realname || !*realname ) realname = nick; |
---|
| 476 | u->realname = g_strdup( realname ); |
---|
| 477 | |
---|
| 478 | if( ( s = strchr( handle, '@' ) ) ) |
---|
| 479 | { |
---|
| 480 | u->host = g_strdup( s + 1 ); |
---|
| 481 | u->user = g_strndup( handle, s - handle ); |
---|
| 482 | } |
---|
| 483 | else if( gc->user->proto_opt[0] && *gc->user->proto_opt[0] ) |
---|
| 484 | { |
---|
| 485 | u->host = g_strdup( gc->user->proto_opt[0] ); |
---|
| 486 | u->user = g_strdup( handle ); |
---|
| 487 | |
---|
| 488 | /* s/ /_/ ... important for AOL screennames */ |
---|
| 489 | for( s = u->user; *s; s ++ ) |
---|
| 490 | if( *s == ' ' ) |
---|
| 491 | *s = '_'; |
---|
| 492 | } |
---|
| 493 | else |
---|
| 494 | { |
---|
[7b23afd] | 495 | u->host = g_strdup( gc->user->prpl->name ); |
---|
[b7d3cc34] | 496 | u->user = g_strdup( handle ); |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | u->gc = gc; |
---|
| 500 | u->handle = g_strdup( handle ); |
---|
[9b8a38b] | 501 | if( group ) u->group = g_strdup( group ); |
---|
[b7d3cc34] | 502 | u->send_handler = buddy_send_handler; |
---|
| 503 | u->last_typing_notice = 0; |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | struct buddy *find_buddy( struct gaim_connection *gc, char *handle ) |
---|
| 507 | { |
---|
| 508 | static struct buddy b[1]; |
---|
| 509 | user_t *u; |
---|
| 510 | |
---|
| 511 | u = user_findhandle( gc, handle ); |
---|
| 512 | |
---|
| 513 | if( !u ) |
---|
| 514 | return( NULL ); |
---|
| 515 | |
---|
| 516 | memset( b, 0, sizeof( b ) ); |
---|
| 517 | strncpy( b->name, handle, 80 ); |
---|
| 518 | strncpy( b->show, u->realname, BUDDY_ALIAS_MAXLEN ); |
---|
| 519 | b->present = u->online; |
---|
| 520 | b->gc = u->gc; |
---|
| 521 | |
---|
| 522 | return( b ); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | void signoff_blocked( struct gaim_connection *gc ) |
---|
| 526 | { |
---|
| 527 | return; /* Make all blocked users look invisible (TODO?) */ |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | |
---|
| 531 | void serv_buddy_rename( struct gaim_connection *gc, char *handle, char *realname ) |
---|
| 532 | { |
---|
| 533 | user_t *u = user_findhandle( gc, handle ); |
---|
| 534 | |
---|
| 535 | if( !u ) return; |
---|
| 536 | |
---|
[e27661d] | 537 | if( g_strcasecmp( u->realname, realname ) != 0 ) |
---|
[b7d3cc34] | 538 | { |
---|
| 539 | if( u->realname != u->nick ) g_free( u->realname ); |
---|
| 540 | |
---|
[e27661d] | 541 | u->realname = g_strdup( realname ); |
---|
[b7d3cc34] | 542 | |
---|
| 543 | if( ( gc->flags & OPT_LOGGED_IN ) && set_getint( gc->irc, "display_namechanges" ) ) |
---|
[5c09a59] | 544 | serv_got_crap( gc, "User `%s' changed name to `%s'", u->nick, u->realname ); |
---|
[b7d3cc34] | 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | |
---|
| 549 | /* prpl.c */ |
---|
| 550 | |
---|
[7bf0f5f0] | 551 | struct show_got_added_data |
---|
| 552 | { |
---|
| 553 | struct gaim_connection *gc; |
---|
| 554 | char *handle; |
---|
| 555 | }; |
---|
| 556 | |
---|
| 557 | void show_got_added_no( gpointer w, struct show_got_added_data *data ) |
---|
| 558 | { |
---|
| 559 | g_free( data->handle ); |
---|
| 560 | g_free( data ); |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | void show_got_added_yes( gpointer w, struct show_got_added_data *data ) |
---|
| 564 | { |
---|
| 565 | data->gc->prpl->add_buddy( data->gc, data->handle ); |
---|
| 566 | add_buddy( data->gc, NULL, data->handle, data->handle ); |
---|
| 567 | |
---|
| 568 | return show_got_added_no( w, data ); |
---|
| 569 | } |
---|
| 570 | |
---|
[e6d6047] | 571 | void show_got_added( struct gaim_connection *gc, char *handle, const char *realname ) |
---|
[b7d3cc34] | 572 | { |
---|
[7bf0f5f0] | 573 | struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); |
---|
| 574 | char *s; |
---|
| 575 | |
---|
| 576 | /* TODO: Make a setting for this! */ |
---|
| 577 | if( user_findhandle( gc, handle ) != NULL ) |
---|
| 578 | return; |
---|
| 579 | |
---|
| 580 | s = g_strdup_printf( "The user %s is not in your buddy list yet. Do you want to add him/her now?", handle ); |
---|
| 581 | |
---|
| 582 | data->gc = gc; |
---|
| 583 | data->handle = g_strdup( handle ); |
---|
| 584 | query_add( gc->irc, gc, s, show_got_added_yes, show_got_added_no, data ); |
---|
[b7d3cc34] | 585 | } |
---|
| 586 | |
---|
| 587 | |
---|
| 588 | /* server.c */ |
---|
| 589 | |
---|
| 590 | void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps ) |
---|
| 591 | { |
---|
| 592 | user_t *u; |
---|
| 593 | int oa, oo; |
---|
| 594 | |
---|
| 595 | u = user_findhandle( gc, handle ); |
---|
| 596 | |
---|
| 597 | if( !u ) |
---|
| 598 | { |
---|
| 599 | if( g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "add" ) == 0 ) |
---|
| 600 | { |
---|
| 601 | add_buddy( gc, NULL, handle, NULL ); |
---|
| 602 | u = user_findhandle( gc, handle ); |
---|
| 603 | } |
---|
| 604 | else |
---|
| 605 | { |
---|
| 606 | if( set_getint( gc->irc, "debug" ) || g_strcasecmp( set_getstr( gc->irc, "handle_unknown" ), "ignore" ) != 0 ) |
---|
| 607 | { |
---|
[5c09a59] | 608 | serv_got_crap( gc, "serv_got_update() for handle %s:", handle ); |
---|
| 609 | serv_got_crap( gc, "loggedin = %d, type = %d", loggedin, type ); |
---|
[b7d3cc34] | 610 | } |
---|
| 611 | |
---|
| 612 | return; |
---|
| 613 | } |
---|
| 614 | return; |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | oa = u->away != NULL; |
---|
| 618 | oo = u->online; |
---|
| 619 | |
---|
| 620 | if( u->away ) |
---|
| 621 | { |
---|
| 622 | g_free( u->away ); |
---|
| 623 | u->away = NULL; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | if( loggedin && !u->online ) |
---|
| 627 | { |
---|
| 628 | irc_spawn( gc->irc, u ); |
---|
| 629 | u->online = 1; |
---|
| 630 | } |
---|
| 631 | else if( !loggedin && u->online ) |
---|
| 632 | { |
---|
| 633 | struct conversation *c; |
---|
| 634 | |
---|
| 635 | irc_kill( gc->irc, u ); |
---|
| 636 | u->online = 0; |
---|
| 637 | |
---|
| 638 | /* Remove him/her from the conversations to prevent PART messages after he/she QUIT already */ |
---|
| 639 | for( c = gc->conversations; c; c = c->next ) |
---|
| 640 | remove_chat_buddy_silent( c, handle ); |
---|
| 641 | } |
---|
| 642 | |
---|
[7b23afd] | 643 | if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "oscar") || !strcmp(gc->prpl->name, "icq")) ) |
---|
[b7d3cc34] | 644 | { |
---|
| 645 | u->away = g_strdup( "Away" ); |
---|
| 646 | } |
---|
[7b23afd] | 647 | else if( ( type & UC_UNAVAILABLE ) && ( !strcmp(gc->prpl->name, "jabber") ) ) |
---|
[b7d3cc34] | 648 | { |
---|
| 649 | if( type & UC_DND ) |
---|
| 650 | u->away = g_strdup( "Do Not Disturb" ); |
---|
| 651 | else if( type & UC_XA ) |
---|
| 652 | u->away = g_strdup( "Extended Away" ); |
---|
| 653 | else // if( type & UC_AWAY ) |
---|
| 654 | u->away = g_strdup( "Away" ); |
---|
| 655 | } |
---|
| 656 | else if( ( type & UC_UNAVAILABLE ) && gc->prpl->get_status_string ) |
---|
| 657 | { |
---|
| 658 | u->away = g_strdup( gc->prpl->get_status_string( gc, type ) ); |
---|
| 659 | } |
---|
| 660 | else |
---|
| 661 | u->away = NULL; |
---|
| 662 | |
---|
| 663 | /* LISPy... */ |
---|
| 664 | if( ( set_getint( gc->irc, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ |
---|
| 665 | ( u->online ) && /* Don't touch offline people */ |
---|
| 666 | ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ |
---|
| 667 | ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ |
---|
| 668 | { |
---|
| 669 | irc_write( gc->irc, ":%s!%s@%s MODE %s %cv %s", gc->irc->mynick, gc->irc->mynick, gc->irc->myhost, |
---|
| 670 | gc->irc->channel, u->away?'-':'+', u->nick ); |
---|
| 671 | } |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 flags, time_t mtime, gint len ) |
---|
| 675 | { |
---|
| 676 | irc_t *irc = gc->irc; |
---|
| 677 | user_t *u; |
---|
| 678 | |
---|
| 679 | u = user_findhandle( gc, handle ); |
---|
| 680 | |
---|
| 681 | if( !u ) |
---|
| 682 | { |
---|
| 683 | char *h = set_getstr( irc, "handle_unknown" ); |
---|
| 684 | |
---|
| 685 | if( g_strcasecmp( h, "ignore" ) == 0 ) |
---|
| 686 | { |
---|
| 687 | if( set_getint( irc, "debug" ) ) |
---|
[5c09a59] | 688 | serv_got_crap( gc, "Ignoring message from unknown handle %s", handle ); |
---|
[b7d3cc34] | 689 | |
---|
| 690 | return; |
---|
| 691 | } |
---|
| 692 | else if( g_strncasecmp( h, "add", 3 ) == 0 ) |
---|
| 693 | { |
---|
| 694 | int private = set_getint( irc, "private" ); |
---|
| 695 | |
---|
| 696 | if( h[3] ) |
---|
| 697 | { |
---|
| 698 | if( g_strcasecmp( h + 3, "_private" ) == 0 ) |
---|
| 699 | private = 1; |
---|
| 700 | else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) |
---|
| 701 | private = 0; |
---|
| 702 | } |
---|
| 703 | |
---|
| 704 | add_buddy( gc, NULL, handle, NULL ); |
---|
| 705 | u = user_findhandle( gc, handle ); |
---|
| 706 | u->is_private = private; |
---|
| 707 | } |
---|
| 708 | else |
---|
| 709 | { |
---|
[5c09a59] | 710 | serv_got_crap( gc, "Message from unknown handle %s:", handle ); |
---|
[b7d3cc34] | 711 | u = user_find( irc, irc->mynick ); |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | |
---|
[c572dd6] | 715 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
| 716 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
[b7d3cc34] | 717 | strip_html( msg ); |
---|
| 718 | |
---|
[30f248a] | 719 | while( strlen( msg ) > 425 ) |
---|
[b7d3cc34] | 720 | { |
---|
| 721 | char tmp, *nl; |
---|
| 722 | |
---|
[30f248a] | 723 | tmp = msg[425]; |
---|
| 724 | msg[425] = 0; |
---|
[b7d3cc34] | 725 | |
---|
[30f248a] | 726 | /* If there's a newline/space in this string, split up there, |
---|
| 727 | looks a bit prettier. */ |
---|
[f1df064] | 728 | if( ( nl = strrchr( msg, '\n' ) ) || ( nl = strrchr( msg, ' ' ) ) ) |
---|
[30f248a] | 729 | { |
---|
| 730 | msg[425] = tmp; |
---|
| 731 | tmp = *nl; |
---|
[b7d3cc34] | 732 | *nl = 0; |
---|
[30f248a] | 733 | } |
---|
[b7d3cc34] | 734 | |
---|
| 735 | irc_msgfrom( irc, u->nick, msg ); |
---|
| 736 | |
---|
| 737 | /* Move on. */ |
---|
| 738 | if( nl ) |
---|
| 739 | { |
---|
[30f248a] | 740 | *nl = tmp; |
---|
[b7d3cc34] | 741 | msg = nl + 1; |
---|
| 742 | } |
---|
| 743 | else |
---|
| 744 | { |
---|
[30f248a] | 745 | msg[425] = tmp; |
---|
| 746 | msg += 425; |
---|
[b7d3cc34] | 747 | } |
---|
| 748 | } |
---|
| 749 | irc_msgfrom( irc, u->nick, msg ); |
---|
| 750 | } |
---|
| 751 | |
---|
[e7f46c5] | 752 | void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int type ) |
---|
[b7d3cc34] | 753 | { |
---|
| 754 | user_t *u; |
---|
| 755 | |
---|
| 756 | if( !set_getint( gc->irc, "typing_notice" ) ) |
---|
| 757 | return; |
---|
| 758 | |
---|
[e7f46c5] | 759 | if( ( u = user_findhandle( gc, handle ) ) ) { |
---|
| 760 | /* If type is: |
---|
| 761 | * 0: user has stopped typing |
---|
| 762 | * 1: user is actively typing |
---|
| 763 | * 2: user has entered text, but is not actively typing |
---|
| 764 | */ |
---|
| 765 | if (type == 0 || type == 1 || type == 2) { |
---|
| 766 | char buf[256]; |
---|
| 767 | g_snprintf(buf, 256, "\1TYPING %d\1", type); |
---|
| 768 | irc_privmsg( gc->irc, u, "PRIVMSG", gc->irc->nick, NULL, buf ); |
---|
| 769 | } |
---|
| 770 | } |
---|
[b7d3cc34] | 771 | } |
---|
| 772 | |
---|
| 773 | void serv_got_chat_left( struct gaim_connection *gc, int id ) |
---|
| 774 | { |
---|
| 775 | struct conversation *c, *l = NULL; |
---|
| 776 | GList *ir; |
---|
| 777 | |
---|
| 778 | if( set_getint( gc->irc, "debug" ) ) |
---|
[5c09a59] | 779 | serv_got_crap( gc, "You were removed from conversation %d", (int) id ); |
---|
[b7d3cc34] | 780 | |
---|
| 781 | for( c = gc->conversations; c && c->id != id; c = (l=c)->next ); |
---|
| 782 | |
---|
| 783 | if( c ) |
---|
| 784 | { |
---|
| 785 | if( c->joined ) |
---|
| 786 | { |
---|
| 787 | user_t *u, *r; |
---|
| 788 | |
---|
| 789 | r = user_find( gc->irc, gc->irc->mynick ); |
---|
| 790 | irc_privmsg( gc->irc, r, "PRIVMSG", c->channel, "", "Cleaning up channel, bye!" ); |
---|
| 791 | |
---|
| 792 | u = user_find( gc->irc, gc->irc->nick ); |
---|
| 793 | irc_kick( gc->irc, u, c->channel, r ); |
---|
| 794 | /* irc_part( gc->irc, u, c->channel ); */ |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | if( l ) |
---|
| 798 | l->next = c->next; |
---|
| 799 | else |
---|
| 800 | gc->conversations = c->next; |
---|
| 801 | |
---|
| 802 | for( ir = c->in_room; ir; ir = ir->next ) |
---|
| 803 | g_free( ir->data ); |
---|
| 804 | g_list_free( c->in_room ); |
---|
| 805 | g_free( c->channel ); |
---|
| 806 | g_free( c->title ); |
---|
| 807 | g_free( c ); |
---|
| 808 | } |
---|
| 809 | } |
---|
| 810 | |
---|
| 811 | void serv_got_chat_in( struct gaim_connection *gc, int id, char *who, int whisper, char *msg, time_t mtime ) |
---|
| 812 | { |
---|
| 813 | struct conversation *c; |
---|
| 814 | user_t *u; |
---|
| 815 | |
---|
| 816 | /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ |
---|
| 817 | if( g_strcasecmp( who, gc->user->username ) == 0 ) |
---|
| 818 | return; |
---|
| 819 | |
---|
| 820 | u = user_findhandle( gc, who ); |
---|
| 821 | for( c = gc->conversations; c && c->id != id; c = c->next ); |
---|
| 822 | |
---|
[c572dd6] | 823 | if( ( g_strcasecmp( set_getstr( gc->irc, "strip_html" ), "always" ) == 0 ) || |
---|
| 824 | ( ( gc->flags & OPT_CONN_HTML ) && set_getint( gc->irc, "strip_html" ) ) ) |
---|
[b7d3cc34] | 825 | strip_html( msg ); |
---|
| 826 | |
---|
| 827 | if( c && u ) |
---|
| 828 | irc_privmsg( gc->irc, u, "PRIVMSG", c->channel, "", msg ); |
---|
| 829 | else |
---|
[5c09a59] | 830 | serv_got_crap( gc, "Message from/to conversation %s@%d (unknown conv/user): %s", who, id, msg ); |
---|
[b7d3cc34] | 831 | } |
---|
| 832 | |
---|
| 833 | struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, char *handle ) |
---|
| 834 | { |
---|
| 835 | struct conversation *c; |
---|
| 836 | char *s; |
---|
| 837 | |
---|
| 838 | /* This one just creates the conversation structure, user won't see anything yet */ |
---|
| 839 | |
---|
| 840 | if( gc->conversations ) |
---|
| 841 | { |
---|
| 842 | for( c = gc->conversations; c->next; c = c->next ); |
---|
| 843 | c = c->next = g_new0( struct conversation, 1 ); |
---|
| 844 | } |
---|
| 845 | else |
---|
| 846 | gc->conversations = c = g_new0( struct conversation, 1); |
---|
| 847 | |
---|
| 848 | c->id = id; |
---|
| 849 | c->gc = gc; |
---|
| 850 | c->title = g_strdup( handle ); |
---|
| 851 | |
---|
| 852 | s = g_new( char, 16 ); |
---|
[94281ef] | 853 | sprintf( s, "&chat_%03d", gc->irc->c_id++ ); |
---|
[b7d3cc34] | 854 | c->channel = g_strdup( s ); |
---|
| 855 | g_free( s ); |
---|
| 856 | |
---|
| 857 | if( set_getint( gc->irc, "debug" ) ) |
---|
[5c09a59] | 858 | serv_got_crap( gc, "Creating new conversation: (id=%d,handle=%s)", id, handle ); |
---|
[b7d3cc34] | 859 | |
---|
| 860 | return( c ); |
---|
| 861 | } |
---|
| 862 | |
---|
| 863 | |
---|
| 864 | /* buddy_chat.c */ |
---|
| 865 | |
---|
| 866 | void add_chat_buddy( struct conversation *b, char *handle ) |
---|
| 867 | { |
---|
| 868 | user_t *u = user_findhandle( b->gc, handle ); |
---|
| 869 | int me = 0; |
---|
| 870 | |
---|
| 871 | if( set_getint( b->gc->irc, "debug" ) ) |
---|
[5c09a59] | 872 | serv_got_crap( b->gc, "User %s added to conversation %d", handle, b->id ); |
---|
[b7d3cc34] | 873 | |
---|
| 874 | /* It might be yourself! */ |
---|
[9cb9868] | 875 | if( b->gc->prpl->cmp_buddynames( handle, b->gc->user->username ) == 0 ) |
---|
[b7d3cc34] | 876 | { |
---|
| 877 | u = user_find( b->gc->irc, b->gc->irc->nick ); |
---|
| 878 | if( !b->joined ) |
---|
| 879 | irc_join( b->gc->irc, u, b->channel ); |
---|
| 880 | b->joined = me = 1; |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | /* Most protocols allow people to join, even when they're not in |
---|
| 884 | your contact list. Try to handle that here */ |
---|
| 885 | if( !u ) |
---|
| 886 | { |
---|
| 887 | add_buddy( b->gc, NULL, handle, NULL ); |
---|
| 888 | u = user_findhandle( b->gc, handle ); |
---|
| 889 | } |
---|
| 890 | |
---|
| 891 | /* Add the handle to the room userlist, if it's not 'me' */ |
---|
| 892 | if( !me ) |
---|
| 893 | { |
---|
| 894 | if( b->joined ) |
---|
| 895 | irc_join( b->gc->irc, u, b->channel ); |
---|
| 896 | b->in_room = g_list_append( b->in_room, g_strdup( handle ) ); |
---|
| 897 | } |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | void remove_chat_buddy( struct conversation *b, char *handle, char *reason ) |
---|
| 901 | { |
---|
| 902 | user_t *u; |
---|
| 903 | int me = 0; |
---|
| 904 | |
---|
| 905 | if( set_getint( b->gc->irc, "debug" ) ) |
---|
[5c09a59] | 906 | serv_got_crap( b->gc, "User %s removed from conversation %d (%s)", handle, b->id, reason ? reason : "" ); |
---|
[b7d3cc34] | 907 | |
---|
| 908 | /* It might be yourself! */ |
---|
| 909 | if( g_strcasecmp( handle, b->gc->user->username ) == 0 ) |
---|
| 910 | { |
---|
| 911 | u = user_find( b->gc->irc, b->gc->irc->nick ); |
---|
| 912 | b->joined = 0; |
---|
| 913 | me = 1; |
---|
| 914 | } |
---|
| 915 | else |
---|
| 916 | { |
---|
| 917 | u = user_findhandle( b->gc, handle ); |
---|
| 918 | } |
---|
| 919 | |
---|
| 920 | if( remove_chat_buddy_silent( b, handle ) ) |
---|
| 921 | if( ( b->joined || me ) && u ) |
---|
| 922 | irc_part( b->gc->irc, u, b->channel ); |
---|
| 923 | } |
---|
| 924 | |
---|
| 925 | static int remove_chat_buddy_silent( struct conversation *b, char *handle ) |
---|
| 926 | { |
---|
| 927 | GList *i; |
---|
| 928 | |
---|
| 929 | /* Find the handle in the room userlist and shoot it */ |
---|
| 930 | i = b->in_room; |
---|
| 931 | while( i ) |
---|
| 932 | { |
---|
| 933 | if( g_strcasecmp( handle, i->data ) == 0 ) |
---|
| 934 | { |
---|
| 935 | g_free( i->data ); |
---|
| 936 | b->in_room = g_list_remove( b->in_room, i->data ); |
---|
| 937 | return( 1 ); |
---|
| 938 | } |
---|
| 939 | |
---|
| 940 | i = i->next; |
---|
| 941 | } |
---|
| 942 | |
---|
| 943 | return( 0 ); |
---|
| 944 | } |
---|
| 945 | |
---|
| 946 | |
---|
| 947 | /* Misc. BitlBee stuff which shouldn't really be here */ |
---|
| 948 | |
---|
| 949 | struct conversation *conv_findchannel( char *channel ) |
---|
| 950 | { |
---|
| 951 | struct gaim_connection *gc; |
---|
| 952 | struct conversation *c; |
---|
| 953 | GSList *l; |
---|
| 954 | |
---|
| 955 | /* This finds the connection which has a conversation which belongs to this channel */ |
---|
| 956 | for( l = connections; l; l = l->next ) |
---|
| 957 | { |
---|
| 958 | gc = l->data; |
---|
| 959 | for( c = gc->conversations; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next ); |
---|
| 960 | if( c ) |
---|
| 961 | return( c ); |
---|
| 962 | } |
---|
| 963 | |
---|
| 964 | return( NULL ); |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | char *set_eval_away_devoice( irc_t *irc, set_t *set, char *value ) |
---|
| 968 | { |
---|
| 969 | int st; |
---|
| 970 | |
---|
| 971 | if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) ) |
---|
| 972 | st = 1; |
---|
| 973 | else if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) ) |
---|
| 974 | st = 0; |
---|
| 975 | else if( sscanf( value, "%d", &st ) != 1 ) |
---|
| 976 | return( NULL ); |
---|
| 977 | |
---|
| 978 | st = st != 0; |
---|
| 979 | |
---|
| 980 | /* Horror.... */ |
---|
| 981 | |
---|
| 982 | if( st != set_getint( irc, "away_devoice" ) ) |
---|
| 983 | { |
---|
| 984 | char list[80] = ""; |
---|
| 985 | user_t *u = irc->users; |
---|
| 986 | int i = 0, count = 0; |
---|
| 987 | char pm; |
---|
| 988 | char v[80]; |
---|
| 989 | |
---|
| 990 | if( st ) |
---|
| 991 | pm = '+'; |
---|
| 992 | else |
---|
| 993 | pm = '-'; |
---|
| 994 | |
---|
| 995 | while( u ) |
---|
| 996 | { |
---|
| 997 | if( u->gc && u->online && !u->away ) |
---|
| 998 | { |
---|
| 999 | if( ( strlen( list ) + strlen( u->nick ) ) >= 79 ) |
---|
| 1000 | { |
---|
| 1001 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
| 1002 | irc_write( irc, ":%s!%s@%s MODE %s %c%s%s", |
---|
| 1003 | irc->mynick, irc->mynick, irc->myhost, |
---|
| 1004 | irc->channel, pm, v, list ); |
---|
| 1005 | |
---|
| 1006 | *list = 0; |
---|
| 1007 | count = 0; |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | sprintf( list + strlen( list ), " %s", u->nick ); |
---|
| 1011 | count ++; |
---|
| 1012 | } |
---|
| 1013 | u = u->next; |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | /* $v = 'v' x $i */ |
---|
| 1017 | for( i = 0; i < count; v[i++] = 'v' ); v[i] = 0; |
---|
| 1018 | irc_write( irc, ":%s!%s@%s MODE %s %c%s%s", irc->mynick, irc->mynick, irc->myhost, |
---|
| 1019 | irc->channel, pm, v, list ); |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | return( set_eval_bool( irc, set, value ) ); |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags ) |
---|
| 1026 | { |
---|
[e27661d] | 1027 | char *buf = NULL; |
---|
| 1028 | int st; |
---|
[b7d3cc34] | 1029 | |
---|
[c572dd6] | 1030 | if( ( u->gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
| 1031 | { |
---|
[e27661d] | 1032 | buf = escape_html( msg ); |
---|
[c572dd6] | 1033 | msg = buf; |
---|
[b7d3cc34] | 1034 | } |
---|
| 1035 | |
---|
[e27661d] | 1036 | st = ((struct gaim_connection *)u->gc)->prpl->send_im( u->gc, u->handle, msg, strlen( msg ), flags ); |
---|
| 1037 | g_free( buf ); |
---|
| 1038 | |
---|
| 1039 | return st; |
---|
[b7d3cc34] | 1040 | } |
---|
| 1041 | |
---|
| 1042 | int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg ) |
---|
| 1043 | { |
---|
[e27661d] | 1044 | char *buf = NULL; |
---|
| 1045 | int st; |
---|
[b7d3cc34] | 1046 | |
---|
[e27661d] | 1047 | if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) |
---|
| 1048 | { |
---|
| 1049 | buf = escape_html( msg ); |
---|
[b7d3cc34] | 1050 | msg = buf; |
---|
| 1051 | } |
---|
| 1052 | |
---|
[e27661d] | 1053 | st = gc->prpl->chat_send( gc, id, msg ); |
---|
| 1054 | g_free( buf ); |
---|
| 1055 | |
---|
| 1056 | return st; |
---|
[b7d3cc34] | 1057 | } |
---|