[81e04e1] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* Some glue to put the IRC and the IM stuff together. */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 23 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "bitlbee.h" |
---|
[17a6ee9] | 27 | #include "dcc.h" |
---|
[d860a8d] | 28 | |
---|
[e4816ea] | 29 | /* IM->IRC callbacks: Simple IM/buddy-related stuff. */ |
---|
[d860a8d] | 30 | |
---|
[81e04e1] | 31 | static const struct irc_user_funcs irc_user_im_funcs; |
---|
| 32 | |
---|
[5c7b45c] | 33 | static void bee_irc_imc_connected( struct im_connection *ic ) |
---|
| 34 | { |
---|
| 35 | irc_t *irc = (irc_t*) ic->bee->ui_data; |
---|
| 36 | |
---|
| 37 | irc_channel_auto_joins( irc, ic->acc ); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | static void bee_irc_imc_disconnected( struct im_connection *ic ) |
---|
| 41 | { |
---|
| 42 | /* Maybe try to send /QUITs here instead of later on. */ |
---|
| 43 | } |
---|
| 44 | |
---|
[81e04e1] | 45 | static gboolean bee_irc_user_new( bee_t *bee, bee_user_t *bu ) |
---|
| 46 | { |
---|
| 47 | irc_user_t *iu; |
---|
[92c8d41] | 48 | irc_t *irc = (irc_t*) bee->ui_data; |
---|
[81e04e1] | 49 | char nick[MAX_NICK_LENGTH+1], *s; |
---|
| 50 | |
---|
| 51 | memset( nick, 0, MAX_NICK_LENGTH + 1 ); |
---|
[b1f818b] | 52 | strcpy( nick, nick_get( bu ) ); |
---|
[81e04e1] | 53 | |
---|
[92c8d41] | 54 | bu->ui_data = iu = irc_user_new( irc, nick ); |
---|
[d860a8d] | 55 | iu->bu = bu; |
---|
[81e04e1] | 56 | |
---|
| 57 | if( ( s = strchr( bu->handle, '@' ) ) ) |
---|
| 58 | { |
---|
| 59 | iu->host = g_strdup( s + 1 ); |
---|
| 60 | iu->user = g_strndup( bu->handle, s - bu->handle ); |
---|
| 61 | } |
---|
| 62 | else if( bu->ic->acc->server ) |
---|
| 63 | { |
---|
| 64 | iu->host = g_strdup( bu->ic->acc->server ); |
---|
| 65 | iu->user = g_strdup( bu->handle ); |
---|
| 66 | |
---|
| 67 | /* s/ /_/ ... important for AOL screennames */ |
---|
| 68 | for( s = iu->user; *s; s ++ ) |
---|
| 69 | if( *s == ' ' ) |
---|
| 70 | *s = '_'; |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | iu->host = g_strdup( bu->ic->acc->prpl->name ); |
---|
| 75 | iu->user = g_strdup( bu->handle ); |
---|
| 76 | } |
---|
| 77 | |
---|
[ad404ab] | 78 | if( bu->flags & BEE_USER_LOCAL ) |
---|
| 79 | { |
---|
| 80 | char *s = set_getstr( &bee->set, "handle_unknown" ); |
---|
| 81 | |
---|
| 82 | if( strcmp( s, "add_private" ) == 0 ) |
---|
[92c8d41] | 83 | iu->last_channel = NULL; |
---|
[ad404ab] | 84 | else if( strcmp( s, "add_channel" ) == 0 ) |
---|
[92c8d41] | 85 | iu->last_channel = irc->default_channel; |
---|
[ad404ab] | 86 | } |
---|
| 87 | |
---|
[81e04e1] | 88 | iu->f = &irc_user_im_funcs; |
---|
| 89 | |
---|
| 90 | return TRUE; |
---|
| 91 | } |
---|
| 92 | |
---|
[d860a8d] | 93 | static gboolean bee_irc_user_free( bee_t *bee, bee_user_t *bu ) |
---|
| 94 | { |
---|
[eabc9d2] | 95 | return irc_user_free( bee->ui_data, (irc_user_t *) bu->ui_data ); |
---|
[d860a8d] | 96 | } |
---|
[81e04e1] | 97 | |
---|
[d860a8d] | 98 | static gboolean bee_irc_user_status( bee_t *bee, bee_user_t *bu, bee_user_t *old ) |
---|
| 99 | { |
---|
[231b08b] | 100 | irc_t *irc = bee->ui_data; |
---|
[003a12b] | 101 | irc_user_t *iu = bu->ui_data; |
---|
[231b08b] | 102 | |
---|
[eb50495] | 103 | /* Do this outside the if below since away state can change without |
---|
| 104 | the online state changing. */ |
---|
| 105 | iu->flags &= ~IRC_USER_AWAY; |
---|
| 106 | if( bu->flags & BEE_USER_AWAY || !( bu->flags & BEE_USER_ONLINE ) ) |
---|
| 107 | iu->flags |= IRC_USER_AWAY; |
---|
| 108 | |
---|
[231b08b] | 109 | if( ( bu->flags & BEE_USER_ONLINE ) != ( old->flags & BEE_USER_ONLINE ) ) |
---|
| 110 | { |
---|
| 111 | if( bu->flags & BEE_USER_ONLINE ) |
---|
[003a12b] | 112 | { |
---|
| 113 | if( g_hash_table_lookup( irc->watches, iu->key ) ) |
---|
| 114 | irc_send_num( irc, 600, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 115 | iu->host, (int) time( NULL ), "logged online" ); |
---|
| 116 | } |
---|
[231b08b] | 117 | else |
---|
[003a12b] | 118 | { |
---|
| 119 | if( g_hash_table_lookup( irc->watches, iu->key ) ) |
---|
| 120 | irc_send_num( irc, 601, "%s %s %s %d :%s", iu->nick, iu->user, |
---|
| 121 | iu->host, (int) time( NULL ), "logged offline" ); |
---|
[0bd948e] | 122 | |
---|
| 123 | /* Send a QUIT since those will also show up in any |
---|
| 124 | query windows the user may have, plus it's only |
---|
| 125 | one QUIT instead of possibly many (in case of |
---|
| 126 | multiple control chans). If there's a channel that |
---|
| 127 | shows offline people, a JOIN will follow. */ |
---|
| 128 | if( set_getbool( &bee->set, "offline_user_quits" ) ) |
---|
| 129 | irc_user_quit( iu, "Leaving..." ); |
---|
[003a12b] | 130 | } |
---|
[231b08b] | 131 | } |
---|
| 132 | |
---|
[1c8e5f7] | 133 | /* Reset this one since the info may have changed. */ |
---|
| 134 | iu->away_reply_timeout = 0; |
---|
| 135 | |
---|
[13c1a9f] | 136 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 137 | |
---|
[d860a8d] | 138 | return TRUE; |
---|
| 139 | } |
---|
[81e04e1] | 140 | |
---|
[13c1a9f] | 141 | void bee_irc_channel_update( irc_t *irc, irc_channel_t *ic, irc_user_t *iu ) |
---|
| 142 | { |
---|
| 143 | GSList *l; |
---|
| 144 | |
---|
| 145 | if( ic == NULL ) |
---|
| 146 | { |
---|
| 147 | for( l = irc->channels; l; l = l->next ) |
---|
| 148 | { |
---|
| 149 | ic = l->data; |
---|
| 150 | /* TODO: Just add a type flag or so.. */ |
---|
[9052bc1] | 151 | if( ic->f == irc->default_channel->f && |
---|
| 152 | ( ic->flags & IRC_CHANNEL_JOINED ) ) |
---|
[13c1a9f] | 153 | bee_irc_channel_update( irc, ic, iu ); |
---|
| 154 | } |
---|
| 155 | return; |
---|
| 156 | } |
---|
| 157 | if( iu == NULL ) |
---|
| 158 | { |
---|
| 159 | for( l = irc->users; l; l = l->next ) |
---|
| 160 | { |
---|
| 161 | iu = l->data; |
---|
| 162 | if( iu->bu ) |
---|
| 163 | bee_irc_channel_update( irc, ic, l->data ); |
---|
| 164 | } |
---|
| 165 | return; |
---|
| 166 | } |
---|
| 167 | |
---|
[ac2717b] | 168 | if( !irc_channel_wants_user( ic, iu ) ) |
---|
[13c1a9f] | 169 | { |
---|
[006a84f] | 170 | irc_channel_del_user( ic, iu, IRC_CDU_PART, NULL ); |
---|
[13c1a9f] | 171 | } |
---|
| 172 | else |
---|
| 173 | { |
---|
[ac2717b] | 174 | struct irc_control_channel *icc = ic->data; |
---|
[94d5da9c] | 175 | int mode = 0; |
---|
[13c1a9f] | 176 | |
---|
[94d5da9c] | 177 | if( !( iu->bu->flags & BEE_USER_ONLINE ) ) |
---|
| 178 | mode = icc->modes[0]; |
---|
| 179 | else if( iu->bu->flags & BEE_USER_AWAY ) |
---|
| 180 | mode = icc->modes[1]; |
---|
[0e8b3e8] | 181 | else |
---|
[94d5da9c] | 182 | mode = icc->modes[2]; |
---|
| 183 | |
---|
| 184 | if( !mode ) |
---|
| 185 | irc_channel_del_user( ic, iu, IRC_CDU_PART, NULL ); |
---|
| 186 | else |
---|
| 187 | { |
---|
| 188 | irc_channel_add_user( ic, iu ); |
---|
| 189 | irc_channel_user_set_mode( ic, iu, mode ); |
---|
| 190 | } |
---|
[13c1a9f] | 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
[934db064] | 194 | static gboolean bee_irc_user_msg( bee_t *bee, bee_user_t *bu, const char *msg_, time_t sent_at ) |
---|
[f012a9f] | 195 | { |
---|
| 196 | irc_t *irc = bee->ui_data; |
---|
| 197 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 198 | char *dst, *prefix = NULL; |
---|
[21c87a7] | 199 | char *wrapped, *ts = NULL; |
---|
[2fe5eb9] | 200 | irc_channel_t *ic = NULL; |
---|
[934db064] | 201 | char *msg = g_strdup( msg_ ); |
---|
| 202 | GSList *l; |
---|
[21c87a7] | 203 | |
---|
| 204 | if( sent_at > 0 && set_getbool( &irc->b->set, "display_timestamps" ) ) |
---|
| 205 | ts = irc_format_timestamp( irc, sent_at ); |
---|
[f012a9f] | 206 | |
---|
[f7ca587] | 207 | /* Too similar to irc_usermsg()... */ |
---|
[92c8d41] | 208 | if( iu->last_channel ) |
---|
[f012a9f] | 209 | { |
---|
[2fe5eb9] | 210 | if( iu->last_channel->flags & IRC_CHANNEL_JOINED ) |
---|
| 211 | ic = iu->last_channel; |
---|
| 212 | else if( irc->default_channel->flags & IRC_CHANNEL_JOINED ) |
---|
| 213 | ic = irc->default_channel; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | if( ic ) |
---|
| 217 | { |
---|
| 218 | dst = ic->name; |
---|
[92c8d41] | 219 | prefix = g_strdup_printf( "%s%s%s", irc->user->nick, set_getstr( &bee->set, "to_char" ), ts ? : "" ); |
---|
[f012a9f] | 220 | } |
---|
| 221 | else |
---|
| 222 | { |
---|
[92c8d41] | 223 | dst = irc->user->nick; |
---|
| 224 | prefix = ts; |
---|
| 225 | ts = NULL; |
---|
[f012a9f] | 226 | } |
---|
| 227 | |
---|
[934db064] | 228 | for( l = irc_plugins; l; l = l->next ) |
---|
| 229 | { |
---|
| 230 | irc_plugin_t *p = l->data; |
---|
| 231 | if( p->filter_msg_in ) |
---|
| 232 | { |
---|
| 233 | char *s = p->filter_msg_in( iu, msg, 0 ); |
---|
| 234 | if( s ) |
---|
| 235 | { |
---|
| 236 | if( s != msg ) |
---|
| 237 | g_free( msg ); |
---|
| 238 | msg = s; |
---|
| 239 | } |
---|
| 240 | else |
---|
| 241 | { |
---|
| 242 | /* Modules can swallow messages. */ |
---|
| 243 | return TRUE; |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | if( ( g_strcasecmp( set_getstr( &bee->set, "strip_html" ), "always" ) == 0 ) || |
---|
| 249 | ( ( bu->ic->flags & OPT_DOES_HTML ) && set_getbool( &bee->set, "strip_html" ) ) ) |
---|
| 250 | { |
---|
| 251 | char *s = g_strdup( msg ); |
---|
| 252 | strip_html( s ); |
---|
| 253 | g_free( msg ); |
---|
| 254 | msg = s; |
---|
| 255 | } |
---|
| 256 | |
---|
[f012a9f] | 257 | wrapped = word_wrap( msg, 425 ); |
---|
| 258 | irc_send_msg( iu, "PRIVMSG", dst, wrapped, prefix ); |
---|
| 259 | |
---|
| 260 | g_free( wrapped ); |
---|
| 261 | g_free( prefix ); |
---|
[934db064] | 262 | g_free( msg ); |
---|
[21c87a7] | 263 | g_free( ts ); |
---|
[f012a9f] | 264 | |
---|
| 265 | return TRUE; |
---|
| 266 | } |
---|
| 267 | |
---|
[573dab0] | 268 | static gboolean bee_irc_user_typing( bee_t *bee, bee_user_t *bu, uint32_t flags ) |
---|
| 269 | { |
---|
| 270 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
| 271 | |
---|
| 272 | if( set_getbool( &bee->set, "typing_notice" ) ) |
---|
| 273 | irc_send_msg_f( (irc_user_t *) bu->ui_data, "PRIVMSG", irc->user->nick, |
---|
| 274 | "\001TYPING %d\001", ( flags >> 8 ) & 3 ); |
---|
| 275 | else |
---|
| 276 | return FALSE; |
---|
| 277 | |
---|
| 278 | return TRUE; |
---|
| 279 | } |
---|
| 280 | |
---|
[badd148] | 281 | static gboolean bee_irc_user_nick_update( irc_user_t *iu ); |
---|
[6ef9065] | 282 | |
---|
[1d39159] | 283 | static gboolean bee_irc_user_fullname( bee_t *bee, bee_user_t *bu ) |
---|
| 284 | { |
---|
| 285 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 286 | char *s; |
---|
| 287 | |
---|
| 288 | if( iu->fullname != iu->nick ) |
---|
| 289 | g_free( iu->fullname ); |
---|
| 290 | iu->fullname = g_strdup( bu->fullname ); |
---|
| 291 | |
---|
| 292 | /* Strip newlines (unlikely, but IRC-unfriendly so they must go) |
---|
| 293 | TODO(wilmer): Do the same with away msgs again! */ |
---|
| 294 | for( s = iu->fullname; *s; s ++ ) |
---|
| 295 | if( isspace( *s ) ) *s = ' '; |
---|
| 296 | |
---|
| 297 | if( ( bu->ic->flags & OPT_LOGGED_IN ) && set_getbool( &bee->set, "display_namechanges" ) ) |
---|
| 298 | { |
---|
[fda55fa] | 299 | /* People don't like this /NOTICE. Meh, let's go back to the old one. |
---|
[1d39159] | 300 | char *msg = g_strdup_printf( "<< \002BitlBee\002 - Changed name to `%s' >>", iu->fullname ); |
---|
| 301 | irc_send_msg( iu, "NOTICE", irc->user->nick, msg, NULL ); |
---|
[fda55fa] | 302 | */ |
---|
| 303 | imcb_log( bu->ic, "User `%s' changed name to `%s'", iu->nick, iu->fullname ); |
---|
[1d39159] | 304 | } |
---|
| 305 | |
---|
[badd148] | 306 | bee_irc_user_nick_update( iu ); |
---|
[1d39159] | 307 | |
---|
| 308 | return TRUE; |
---|
| 309 | } |
---|
| 310 | |
---|
[6ef9065] | 311 | static gboolean bee_irc_user_nick_hint( bee_t *bee, bee_user_t *bu, const char *hint ) |
---|
| 312 | { |
---|
[badd148] | 313 | bee_irc_user_nick_update( (irc_user_t*) bu->ui_data ); |
---|
| 314 | |
---|
| 315 | return TRUE; |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | static gboolean bee_irc_user_group( bee_t *bee, bee_user_t *bu ) |
---|
| 319 | { |
---|
| 320 | irc_user_t *iu = (irc_user_t *) bu->ui_data; |
---|
| 321 | irc_t *irc = (irc_t *) bee->ui_data; |
---|
[51a3d12] | 322 | bee_user_flags_t online; |
---|
| 323 | |
---|
| 324 | /* Take the user offline temporarily so we can change the nick (if necessary). */ |
---|
| 325 | if( ( online = bu->flags & BEE_USER_ONLINE ) ) |
---|
| 326 | bu->flags &= ~BEE_USER_ONLINE; |
---|
[badd148] | 327 | |
---|
| 328 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 329 | bee_irc_user_nick_update( iu ); |
---|
| 330 | |
---|
[51a3d12] | 331 | if( online ) |
---|
| 332 | { |
---|
| 333 | bu->flags |= online; |
---|
| 334 | bee_irc_channel_update( irc, NULL, iu ); |
---|
| 335 | } |
---|
| 336 | |
---|
[badd148] | 337 | return TRUE; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | static gboolean bee_irc_user_nick_update( irc_user_t *iu ) |
---|
| 341 | { |
---|
| 342 | bee_user_t *bu = iu->bu; |
---|
| 343 | char *newnick; |
---|
[6ef9065] | 344 | |
---|
| 345 | if( bu->flags & BEE_USER_ONLINE ) |
---|
| 346 | /* Ignore if the user is visible already. */ |
---|
| 347 | return TRUE; |
---|
| 348 | |
---|
[b1f818b] | 349 | if( nick_saved( bu ) ) |
---|
[6ef9065] | 350 | /* The user already assigned a nickname to this person. */ |
---|
| 351 | return TRUE; |
---|
| 352 | |
---|
[badd148] | 353 | newnick = nick_get( bu ); |
---|
[6ef9065] | 354 | |
---|
| 355 | if( strcmp( iu->nick, newnick ) != 0 ) |
---|
| 356 | { |
---|
[b1f818b] | 357 | nick_dedupe( bu, newnick ); |
---|
[6ef9065] | 358 | irc_user_set_nick( iu, newnick ); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | return TRUE; |
---|
| 362 | } |
---|
| 363 | |
---|
[e4816ea] | 364 | /* IRC->IM calls */ |
---|
| 365 | |
---|
[619dd18] | 366 | static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); |
---|
| 367 | |
---|
[e4816ea] | 368 | static gboolean bee_irc_user_privmsg( irc_user_t *iu, const char *msg ) |
---|
| 369 | { |
---|
[1c8e5f7] | 370 | const char *away; |
---|
| 371 | |
---|
[619dd18] | 372 | if( iu->bu == NULL ) |
---|
[e4816ea] | 373 | return FALSE; |
---|
[1c8e5f7] | 374 | |
---|
| 375 | if( ( away = irc_user_get_away( iu ) ) && |
---|
| 376 | time( NULL ) >= iu->away_reply_timeout ) |
---|
| 377 | { |
---|
| 378 | irc_send_num( iu->irc, 301, "%s :%s", iu->nick, away ); |
---|
| 379 | iu->away_reply_timeout = time( NULL ) + |
---|
| 380 | set_getint( &iu->irc->b->set, "away_reply_timeout" ); |
---|
| 381 | } |
---|
| 382 | |
---|
[934db064] | 383 | if( iu->pastebuf == NULL ) |
---|
| 384 | iu->pastebuf = g_string_new( msg ); |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | b_event_remove( iu->pastebuf_timer ); |
---|
| 388 | g_string_append_printf( iu->pastebuf, "\n%s", msg ); |
---|
| 389 | } |
---|
| 390 | |
---|
[1c8e5f7] | 391 | if( set_getbool( &iu->irc->b->set, "paste_buffer" ) ) |
---|
[619dd18] | 392 | { |
---|
| 393 | int delay; |
---|
| 394 | |
---|
| 395 | if( ( delay = set_getint( &iu->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) |
---|
| 396 | delay *= 1000; |
---|
| 397 | |
---|
| 398 | iu->pastebuf_timer = b_timeout_add( delay, bee_irc_user_privmsg_cb, iu ); |
---|
| 399 | |
---|
| 400 | return TRUE; |
---|
| 401 | } |
---|
| 402 | else |
---|
[934db064] | 403 | { |
---|
| 404 | bee_irc_user_privmsg_cb( iu, 0, 0 ); |
---|
| 405 | |
---|
| 406 | return TRUE; |
---|
| 407 | } |
---|
[619dd18] | 408 | } |
---|
| 409 | |
---|
| 410 | static gboolean bee_irc_user_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) |
---|
| 411 | { |
---|
| 412 | irc_user_t *iu = data; |
---|
[934db064] | 413 | char *msg = g_string_free( iu->pastebuf, FALSE ); |
---|
| 414 | GSList *l; |
---|
| 415 | |
---|
| 416 | for( l = irc_plugins; l; l = l->next ) |
---|
| 417 | { |
---|
| 418 | irc_plugin_t *p = l->data; |
---|
| 419 | if( p->filter_msg_out ) |
---|
| 420 | { |
---|
| 421 | char *s = p->filter_msg_out( iu, msg, 0 ); |
---|
| 422 | if( s ) |
---|
| 423 | { |
---|
| 424 | if( s != msg ) |
---|
| 425 | g_free( msg ); |
---|
| 426 | msg = s; |
---|
| 427 | } |
---|
| 428 | else |
---|
| 429 | { |
---|
| 430 | /* Modules can swallow messages. */ |
---|
| 431 | iu->pastebuf = NULL; |
---|
| 432 | g_free( msg ); |
---|
| 433 | return FALSE; |
---|
| 434 | } |
---|
| 435 | } |
---|
| 436 | } |
---|
[619dd18] | 437 | |
---|
[934db064] | 438 | bee_user_msg( iu->irc->b, iu->bu, msg, 0 ); |
---|
[619dd18] | 439 | |
---|
[934db064] | 440 | g_free( msg ); |
---|
| 441 | iu->pastebuf = NULL; |
---|
[619dd18] | 442 | iu->pastebuf_timer = 0; |
---|
| 443 | |
---|
| 444 | return FALSE; |
---|
[e4816ea] | 445 | } |
---|
| 446 | |
---|
| 447 | static gboolean bee_irc_user_ctcp( irc_user_t *iu, char *const *ctcp ) |
---|
| 448 | { |
---|
| 449 | if( ctcp[1] && g_strcasecmp( ctcp[0], "DCC" ) == 0 |
---|
| 450 | && g_strcasecmp( ctcp[1], "SEND" ) == 0 ) |
---|
| 451 | { |
---|
| 452 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->transfer_request ) |
---|
| 453 | { |
---|
| 454 | file_transfer_t *ft = dcc_request( iu->bu->ic, ctcp ); |
---|
| 455 | if ( ft ) |
---|
| 456 | iu->bu->ic->acc->prpl->transfer_request( iu->bu->ic, ft, iu->bu->handle ); |
---|
| 457 | |
---|
| 458 | return TRUE; |
---|
| 459 | } |
---|
| 460 | } |
---|
| 461 | else if( g_strcasecmp( ctcp[0], "TYPING" ) == 0 ) |
---|
| 462 | { |
---|
| 463 | if( iu->bu && iu->bu->ic && iu->bu->ic->acc->prpl->send_typing && ctcp[1] ) |
---|
| 464 | { |
---|
| 465 | int st = ctcp[1][0]; |
---|
| 466 | if( st >= '0' && st <= '2' ) |
---|
| 467 | { |
---|
| 468 | st <<= 8; |
---|
| 469 | iu->bu->ic->acc->prpl->send_typing( iu->bu->ic, iu->bu->handle, st ); |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | return TRUE; |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | return FALSE; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | static const struct irc_user_funcs irc_user_im_funcs = { |
---|
| 480 | bee_irc_user_privmsg, |
---|
| 481 | bee_irc_user_ctcp, |
---|
| 482 | }; |
---|
| 483 | |
---|
[aea8b68] | 484 | |
---|
[e4816ea] | 485 | /* IM->IRC: Groupchats */ |
---|
[5a75d15] | 486 | const struct irc_channel_funcs irc_channel_im_chat_funcs; |
---|
[a87754b] | 487 | |
---|
| 488 | static gboolean bee_irc_chat_new( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 489 | { |
---|
| 490 | irc_t *irc = bee->ui_data; |
---|
| 491 | irc_channel_t *ic; |
---|
| 492 | char *topic; |
---|
[eb37735] | 493 | GSList *l; |
---|
[aea8b68] | 494 | int i; |
---|
| 495 | |
---|
[eb37735] | 496 | /* Try to find a channel that expects to receive a groupchat. |
---|
[52a2521] | 497 | This flag is set earlier in our current call trace. */ |
---|
[eb37735] | 498 | for( l = irc->channels; l; l = l->next ) |
---|
| 499 | { |
---|
| 500 | ic = l->data; |
---|
| 501 | if( ic->flags & IRC_CHANNEL_CHAT_PICKME ) |
---|
| 502 | break; |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | /* If we found none, just generate some stupid name. */ |
---|
| 506 | if( l == NULL ) for( i = 0; i <= 999; i ++ ) |
---|
[aea8b68] | 507 | { |
---|
| 508 | char name[16]; |
---|
[5a75d15] | 509 | sprintf( name, "#chat_%03d", i ); |
---|
[aea8b68] | 510 | if( ( ic = irc_channel_new( irc, name ) ) ) |
---|
| 511 | break; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | if( ic == NULL ) |
---|
| 515 | return FALSE; |
---|
| 516 | |
---|
| 517 | c->ui_data = ic; |
---|
| 518 | ic->data = c; |
---|
| 519 | |
---|
| 520 | topic = g_strdup_printf( "BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", c->title ); |
---|
| 521 | irc_channel_set_topic( ic, topic, irc->root ); |
---|
| 522 | g_free( topic ); |
---|
| 523 | |
---|
| 524 | return TRUE; |
---|
| 525 | } |
---|
| 526 | |
---|
[a87754b] | 527 | static gboolean bee_irc_chat_free( bee_t *bee, struct groupchat *c ) |
---|
[aea8b68] | 528 | { |
---|
| 529 | irc_channel_t *ic = c->ui_data; |
---|
| 530 | |
---|
[b1af3e8] | 531 | if( ic == NULL ) |
---|
| 532 | return FALSE; |
---|
| 533 | |
---|
[aea8b68] | 534 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 535 | irc_channel_printf( ic, "Cleaning up channel, bye!" ); |
---|
| 536 | |
---|
[5a75d15] | 537 | ic->data = NULL; |
---|
[006a84f] | 538 | irc_channel_del_user( ic, ic->irc->user, IRC_CDU_KICK, "Chatroom closed by server" ); |
---|
[aea8b68] | 539 | |
---|
| 540 | return TRUE; |
---|
| 541 | } |
---|
| 542 | |
---|
[a87754b] | 543 | static gboolean bee_irc_chat_log( bee_t *bee, struct groupchat *c, const char *text ) |
---|
[aea8b68] | 544 | { |
---|
[27e2c66] | 545 | irc_channel_t *ic = c->ui_data; |
---|
| 546 | |
---|
[b1af3e8] | 547 | if( ic == NULL ) |
---|
| 548 | return FALSE; |
---|
| 549 | |
---|
[27e2c66] | 550 | irc_channel_printf( ic, "%s", text ); |
---|
[b17ce85] | 551 | |
---|
| 552 | return TRUE; |
---|
[aea8b68] | 553 | } |
---|
| 554 | |
---|
[a87754b] | 555 | static gboolean bee_irc_chat_msg( bee_t *bee, struct groupchat *c, bee_user_t *bu, const char *msg, time_t sent_at ) |
---|
[aea8b68] | 556 | { |
---|
[27e2c66] | 557 | irc_t *irc = bee->ui_data; |
---|
| 558 | irc_user_t *iu = bu->ui_data; |
---|
| 559 | irc_channel_t *ic = c->ui_data; |
---|
| 560 | char *ts = NULL; |
---|
| 561 | |
---|
[b1af3e8] | 562 | if( ic == NULL ) |
---|
| 563 | return FALSE; |
---|
| 564 | |
---|
[27e2c66] | 565 | if( sent_at > 0 && set_getbool( &bee->set, "display_timestamps" ) ) |
---|
| 566 | ts = irc_format_timestamp( irc, sent_at ); |
---|
| 567 | |
---|
| 568 | irc_send_msg( iu, "PRIVMSG", ic->name, msg, ts ); |
---|
| 569 | g_free( ts ); |
---|
| 570 | |
---|
| 571 | return TRUE; |
---|
[aea8b68] | 572 | } |
---|
| 573 | |
---|
[a87754b] | 574 | static gboolean bee_irc_chat_add_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 575 | { |
---|
| 576 | irc_t *irc = bee->ui_data; |
---|
[b1af3e8] | 577 | irc_channel_t *ic = c->ui_data; |
---|
[aea8b68] | 578 | |
---|
[b1af3e8] | 579 | if( ic == NULL ) |
---|
| 580 | return FALSE; |
---|
| 581 | |
---|
| 582 | irc_channel_add_user( ic, bu == bee->user ? irc->user : bu->ui_data ); |
---|
[b17ce85] | 583 | |
---|
| 584 | return TRUE; |
---|
[aea8b68] | 585 | } |
---|
| 586 | |
---|
[a87754b] | 587 | static gboolean bee_irc_chat_remove_user( bee_t *bee, struct groupchat *c, bee_user_t *bu ) |
---|
[aea8b68] | 588 | { |
---|
[b17ce85] | 589 | irc_t *irc = bee->ui_data; |
---|
[b1af3e8] | 590 | irc_channel_t *ic = c->ui_data; |
---|
| 591 | |
---|
[d6657ce] | 592 | if( ic == NULL || bu == NULL ) |
---|
[b1af3e8] | 593 | return FALSE; |
---|
[b17ce85] | 594 | |
---|
[1c40aa7] | 595 | /* TODO: Possible bug here: If a module removes $user here instead of just |
---|
| 596 | using imcb_chat_free() and the channel was IRC_CHANNEL_TEMP, we get into |
---|
| 597 | a broken state around here. */ |
---|
[b1af3e8] | 598 | irc_channel_del_user( ic, bu == bee->user ? irc->user : bu->ui_data, IRC_CDU_PART, NULL ); |
---|
[b17ce85] | 599 | |
---|
| 600 | return TRUE; |
---|
[aea8b68] | 601 | } |
---|
| 602 | |
---|
[9e27f18] | 603 | static gboolean bee_irc_chat_topic( bee_t *bee, struct groupchat *c, const char *new, bee_user_t *bu ) |
---|
| 604 | { |
---|
[b1af3e8] | 605 | irc_channel_t *ic = c->ui_data; |
---|
[9e27f18] | 606 | irc_t *irc = bee->ui_data; |
---|
| 607 | irc_user_t *iu; |
---|
| 608 | |
---|
[b1af3e8] | 609 | if( ic == NULL ) |
---|
| 610 | return FALSE; |
---|
| 611 | |
---|
[9e27f18] | 612 | if( bu == NULL ) |
---|
| 613 | iu = irc->root; |
---|
| 614 | else if( bu == bee->user ) |
---|
| 615 | iu = irc->user; |
---|
| 616 | else |
---|
| 617 | iu = bu->ui_data; |
---|
| 618 | |
---|
[b1af3e8] | 619 | irc_channel_set_topic( ic, new, iu ); |
---|
[9e27f18] | 620 | |
---|
| 621 | return TRUE; |
---|
| 622 | } |
---|
| 623 | |
---|
[d343eaa] | 624 | static gboolean bee_irc_chat_name_hint( bee_t *bee, struct groupchat *c, const char *name ) |
---|
| 625 | { |
---|
| 626 | irc_t *irc = bee->ui_data; |
---|
[52a2521] | 627 | irc_channel_t *ic = c->ui_data, *oic; |
---|
[d343eaa] | 628 | char stripped[MAX_NICK_LENGTH+1], *full_name; |
---|
| 629 | |
---|
[b1af3e8] | 630 | if( ic == NULL ) |
---|
| 631 | return FALSE; |
---|
| 632 | |
---|
[d343eaa] | 633 | /* Don't rename a channel if the user's in it already. */ |
---|
| 634 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 635 | return FALSE; |
---|
| 636 | |
---|
| 637 | strncpy( stripped, name, MAX_NICK_LENGTH ); |
---|
| 638 | stripped[MAX_NICK_LENGTH] = '\0'; |
---|
[134a02c] | 639 | irc_channel_name_strip( stripped ); |
---|
[d343eaa] | 640 | if( set_getbool( &bee->set, "lcnicks" ) ) |
---|
| 641 | nick_lc( stripped ); |
---|
| 642 | |
---|
[52a2521] | 643 | if( stripped[0] == '\0' ) |
---|
| 644 | return FALSE; |
---|
[d343eaa] | 645 | |
---|
[52a2521] | 646 | full_name = g_strdup_printf( "#%s", stripped ); |
---|
| 647 | if( ( oic = irc_channel_by_name( irc, full_name ) ) ) |
---|
[d343eaa] | 648 | { |
---|
[52a2521] | 649 | char *type, *chat_type; |
---|
| 650 | |
---|
| 651 | type = set_getstr( &oic->set, "type" ); |
---|
| 652 | chat_type = set_getstr( &oic->set, "chat_type" ); |
---|
| 653 | |
---|
| 654 | if( type && chat_type && oic->data == FALSE && |
---|
| 655 | strcmp( type, "chat" ) == 0 && |
---|
| 656 | strcmp( chat_type, "groupchat" ) == 0 ) |
---|
| 657 | { |
---|
| 658 | /* There's a channel with this name already, but it looks |
---|
| 659 | like it's not in use yet. Most likely the IRC client |
---|
| 660 | rejoined the channel after a reconnect. Remove it so |
---|
| 661 | we can reuse its name. */ |
---|
| 662 | irc_channel_free( oic ); |
---|
| 663 | } |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | g_free( full_name ); |
---|
| 667 | return FALSE; |
---|
| 668 | } |
---|
[d343eaa] | 669 | } |
---|
| 670 | |
---|
[52a2521] | 671 | g_free( ic->name ); |
---|
| 672 | ic->name = full_name; |
---|
| 673 | |
---|
[d343eaa] | 674 | return TRUE; |
---|
| 675 | } |
---|
| 676 | |
---|
[1aa74f55] | 677 | static gboolean bee_irc_chat_invite( bee_t *bee, bee_user_t *bu, const char *name, const char *msg ) |
---|
| 678 | { |
---|
| 679 | char *channel, *s; |
---|
| 680 | irc_t *irc = bee->ui_data; |
---|
| 681 | irc_user_t *iu = bu->ui_data; |
---|
| 682 | irc_channel_t *chan; |
---|
| 683 | |
---|
| 684 | if( strchr( CTYPES, name[0] ) ) |
---|
| 685 | channel = g_strdup( name ); |
---|
| 686 | else |
---|
| 687 | channel = g_strdup_printf( "#%s", name ); |
---|
| 688 | |
---|
| 689 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 690 | *s = '\0'; |
---|
| 691 | |
---|
| 692 | if( strlen( channel ) > MAX_NICK_LENGTH ) |
---|
| 693 | { |
---|
| 694 | /* If the channel name is very long (like those insane GTalk |
---|
| 695 | UUID names), try if we can use the inviter's nick. */ |
---|
| 696 | s = g_strdup_printf( "#%s", iu->nick ); |
---|
| 697 | if( irc_channel_by_name( irc, s ) == NULL ) |
---|
| 698 | { |
---|
| 699 | g_free( channel ); |
---|
| 700 | channel = s; |
---|
| 701 | } |
---|
| 702 | } |
---|
| 703 | |
---|
| 704 | if( ( chan = irc_channel_new( irc, channel ) ) && |
---|
| 705 | set_setstr( &chan->set, "type", "chat" ) && |
---|
| 706 | set_setstr( &chan->set, "chat_type", "room" ) && |
---|
| 707 | set_setstr( &chan->set, "account", bu->ic->acc->tag ) && |
---|
| 708 | set_setstr( &chan->set, "room", (char*) name ) ) |
---|
| 709 | { |
---|
| 710 | /* I'm assuming that if the user didn't "chat add" the room |
---|
| 711 | himself but got invited, it's temporary, so make this a |
---|
| 712 | temporary mapping that is removed as soon as we /PART. */ |
---|
| 713 | chan->flags |= IRC_CHANNEL_TEMP; |
---|
| 714 | } |
---|
| 715 | else |
---|
| 716 | { |
---|
| 717 | irc_channel_free( chan ); |
---|
| 718 | chan = NULL; |
---|
| 719 | } |
---|
| 720 | g_free( channel ); |
---|
| 721 | |
---|
| 722 | irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "<< \002BitlBee\002 - Invitation to chatroom %s >>", name ); |
---|
| 723 | if( msg ) |
---|
| 724 | irc_send_msg( iu, "PRIVMSG", irc->user->nick, msg, NULL ); |
---|
| 725 | if( chan ) |
---|
| 726 | { |
---|
| 727 | irc_send_msg_f( iu, "PRIVMSG", irc->user->nick, "To join the room, just /join %s", chan->name ); |
---|
| 728 | irc_send_invite( iu, chan ); |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | return TRUE; |
---|
| 732 | } |
---|
| 733 | |
---|
[a87754b] | 734 | /* IRC->IM */ |
---|
[619dd18] | 735 | static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ); |
---|
| 736 | |
---|
[a87754b] | 737 | static gboolean bee_irc_channel_chat_privmsg( irc_channel_t *ic, const char *msg ) |
---|
| 738 | { |
---|
| 739 | struct groupchat *c = ic->data; |
---|
[69b896b] | 740 | char *trans = NULL, *s; |
---|
[a87754b] | 741 | |
---|
[5a75d15] | 742 | if( c == NULL ) |
---|
| 743 | return FALSE; |
---|
[69b896b] | 744 | |
---|
| 745 | if( set_getbool( &ic->set, "translate_to_nicks" ) ) |
---|
| 746 | { |
---|
| 747 | char nick[MAX_NICK_LENGTH+1]; |
---|
| 748 | irc_user_t *iu; |
---|
| 749 | |
---|
| 750 | strncpy( nick, msg, MAX_NICK_LENGTH ); |
---|
| 751 | nick[MAX_NICK_LENGTH] = '\0'; |
---|
| 752 | if( ( s = strchr( nick, ':' ) ) || ( s = strchr( nick, ',' ) ) ) |
---|
| 753 | { |
---|
| 754 | *s = '\0'; |
---|
[4c737ebd] | 755 | if( ( iu = irc_user_by_name( ic->irc, nick ) ) && iu->bu && |
---|
[69b896b] | 756 | iu->bu->nick && irc_channel_has_user( ic, iu ) ) |
---|
| 757 | { |
---|
| 758 | trans = g_strconcat( iu->bu->nick, msg + ( s - nick ), NULL ); |
---|
| 759 | msg = trans; |
---|
| 760 | } |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | |
---|
| 764 | if( set_getbool( &ic->irc->b->set, "paste_buffer" ) ) |
---|
[619dd18] | 765 | { |
---|
| 766 | int delay; |
---|
| 767 | |
---|
| 768 | if( ic->pastebuf == NULL ) |
---|
| 769 | ic->pastebuf = g_string_new( msg ); |
---|
| 770 | else |
---|
| 771 | { |
---|
| 772 | b_event_remove( ic->pastebuf_timer ); |
---|
| 773 | g_string_append_printf( ic->pastebuf, "\n%s", msg ); |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | if( ( delay = set_getint( &ic->irc->b->set, "paste_buffer_delay" ) ) <= 5 ) |
---|
| 777 | delay *= 1000; |
---|
| 778 | |
---|
| 779 | ic->pastebuf_timer = b_timeout_add( delay, bee_irc_channel_chat_privmsg_cb, ic ); |
---|
| 780 | |
---|
[69b896b] | 781 | g_free( trans ); |
---|
[619dd18] | 782 | return TRUE; |
---|
| 783 | } |
---|
| 784 | else |
---|
| 785 | bee_chat_msg( ic->irc->b, c, msg, 0 ); |
---|
[a87754b] | 786 | |
---|
[69b896b] | 787 | g_free( trans ); |
---|
[a87754b] | 788 | return TRUE; |
---|
[5a75d15] | 789 | } |
---|
| 790 | |
---|
[619dd18] | 791 | static gboolean bee_irc_channel_chat_privmsg_cb( gpointer data, gint fd, b_input_condition cond ) |
---|
| 792 | { |
---|
| 793 | irc_channel_t *ic = data; |
---|
| 794 | |
---|
| 795 | bee_chat_msg( ic->irc->b, ic->data, ic->pastebuf->str, 0 ); |
---|
| 796 | |
---|
| 797 | g_string_free( ic->pastebuf, TRUE ); |
---|
| 798 | ic->pastebuf = 0; |
---|
| 799 | ic->pastebuf_timer = 0; |
---|
| 800 | |
---|
| 801 | return FALSE; |
---|
| 802 | } |
---|
| 803 | |
---|
[5a75d15] | 804 | static gboolean bee_irc_channel_chat_join( irc_channel_t *ic ) |
---|
| 805 | { |
---|
| 806 | char *acc_s, *room; |
---|
| 807 | account_t *acc; |
---|
[a87754b] | 808 | |
---|
[5a75d15] | 809 | if( strcmp( set_getstr( &ic->set, "chat_type" ), "room" ) != 0 ) |
---|
| 810 | return TRUE; |
---|
| 811 | |
---|
| 812 | if( ( acc_s = set_getstr( &ic->set, "account" ) ) && |
---|
| 813 | ( room = set_getstr( &ic->set, "room" ) ) && |
---|
| 814 | ( acc = account_get( ic->irc->b, acc_s ) ) && |
---|
| 815 | acc->ic && acc->prpl->chat_join ) |
---|
| 816 | { |
---|
| 817 | char *nick; |
---|
| 818 | |
---|
| 819 | if( !( nick = set_getstr( &ic->set, "nick" ) ) ) |
---|
| 820 | nick = ic->irc->user->nick; |
---|
| 821 | |
---|
| 822 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
[03f3828] | 823 | acc->prpl->chat_join( acc->ic, room, nick, NULL, &ic->set ); |
---|
[5a75d15] | 824 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
| 825 | |
---|
| 826 | return FALSE; |
---|
| 827 | } |
---|
| 828 | else |
---|
| 829 | { |
---|
| 830 | irc_send_num( ic->irc, 403, "%s :Can't join channel, account offline?", ic->name ); |
---|
| 831 | return FALSE; |
---|
| 832 | } |
---|
[a87754b] | 833 | } |
---|
| 834 | |
---|
[bfb99ee] | 835 | static gboolean bee_irc_channel_chat_part( irc_channel_t *ic, const char *msg ) |
---|
| 836 | { |
---|
| 837 | struct groupchat *c = ic->data; |
---|
| 838 | |
---|
[5a75d15] | 839 | if( c && c->ic->acc->prpl->chat_leave ) |
---|
[bfb99ee] | 840 | c->ic->acc->prpl->chat_leave( c ); |
---|
| 841 | |
---|
| 842 | return TRUE; |
---|
| 843 | } |
---|
| 844 | |
---|
[9e27f18] | 845 | static gboolean bee_irc_channel_chat_topic( irc_channel_t *ic, const char *new ) |
---|
| 846 | { |
---|
[4469e7e] | 847 | struct groupchat *c = ic->data; |
---|
[5a75d15] | 848 | |
---|
| 849 | if( c == NULL ) |
---|
| 850 | return FALSE; |
---|
[4469e7e] | 851 | |
---|
| 852 | if( c->ic->acc->prpl->chat_topic == NULL ) |
---|
| 853 | irc_send_num( ic->irc, 482, "%s :IM network does not support channel topics", ic->name ); |
---|
| 854 | else |
---|
| 855 | { |
---|
[5a75d15] | 856 | /* TODO: Need more const goodness here, sigh */ |
---|
| 857 | char *topic = g_strdup( new ); |
---|
[4469e7e] | 858 | c->ic->acc->prpl->chat_topic( c, topic ); |
---|
[5a75d15] | 859 | g_free( topic ); |
---|
[4469e7e] | 860 | } |
---|
| 861 | |
---|
[41e0c00] | 862 | /* Whatever happened, the IM module should ack the topic change. */ |
---|
[4469e7e] | 863 | return FALSE; |
---|
[9e27f18] | 864 | } |
---|
| 865 | |
---|
[66b9e36a] | 866 | static gboolean bee_irc_channel_chat_invite( irc_channel_t *ic, irc_user_t *iu ) |
---|
| 867 | { |
---|
| 868 | struct groupchat *c = ic->data; |
---|
[5a75d15] | 869 | bee_user_t *bu = iu->bu; |
---|
| 870 | |
---|
| 871 | if( bu == NULL ) |
---|
| 872 | return FALSE; |
---|
[66b9e36a] | 873 | |
---|
[5a75d15] | 874 | if( c ) |
---|
| 875 | { |
---|
| 876 | if( iu->bu->ic != c->ic ) |
---|
| 877 | irc_send_num( ic->irc, 482, "%s :Can't mix different IM networks in one groupchat", ic->name ); |
---|
| 878 | else if( c->ic->acc->prpl->chat_invite ) |
---|
| 879 | c->ic->acc->prpl->chat_invite( c, iu->bu->handle, NULL ); |
---|
| 880 | else |
---|
| 881 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
| 882 | } |
---|
| 883 | else if( bu->ic->acc->prpl->chat_with && |
---|
| 884 | strcmp( set_getstr( &ic->set, "chat_type" ), "groupchat" ) == 0 ) |
---|
| 885 | { |
---|
| 886 | ic->flags |= IRC_CHANNEL_CHAT_PICKME; |
---|
| 887 | iu->bu->ic->acc->prpl->chat_with( bu->ic, bu->handle ); |
---|
| 888 | ic->flags &= ~IRC_CHANNEL_CHAT_PICKME; |
---|
| 889 | } |
---|
[66b9e36a] | 890 | else |
---|
[5a75d15] | 891 | { |
---|
[66b9e36a] | 892 | irc_send_num( ic->irc, 482, "%s :IM protocol does not support room invitations", ic->name ); |
---|
[5a75d15] | 893 | } |
---|
[66b9e36a] | 894 | |
---|
| 895 | return TRUE; |
---|
| 896 | } |
---|
| 897 | |
---|
[5a75d15] | 898 | static char *set_eval_room_account( set_t *set, char *value ); |
---|
[1c40aa7] | 899 | static char *set_eval_chat_type( set_t *set, char *value ); |
---|
[5a75d15] | 900 | |
---|
| 901 | static gboolean bee_irc_channel_init( irc_channel_t *ic ) |
---|
| 902 | { |
---|
| 903 | set_add( &ic->set, "account", NULL, set_eval_room_account, ic ); |
---|
[1c40aa7] | 904 | set_add( &ic->set, "chat_type", "groupchat", set_eval_chat_type, ic ); |
---|
[5a75d15] | 905 | set_add( &ic->set, "nick", NULL, NULL, ic ); |
---|
| 906 | set_add( &ic->set, "room", NULL, NULL, ic ); |
---|
[69b896b] | 907 | set_add( &ic->set, "translate_to_nicks", "true", set_eval_bool, ic ); |
---|
[5a75d15] | 908 | |
---|
[1c40aa7] | 909 | /* chat_type == groupchat */ |
---|
| 910 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
| 911 | |
---|
[5a75d15] | 912 | return TRUE; |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | static char *set_eval_room_account( set_t *set, char *value ) |
---|
| 916 | { |
---|
| 917 | struct irc_channel *ic = set->data; |
---|
[03f3828] | 918 | account_t *acc, *oa; |
---|
[5a75d15] | 919 | |
---|
| 920 | if( !( acc = account_get( ic->irc->b, value ) ) ) |
---|
| 921 | return SET_INVALID; |
---|
| 922 | else if( !acc->prpl->chat_join ) |
---|
| 923 | { |
---|
| 924 | irc_usermsg( ic->irc, "Named chatrooms not supported on that account." ); |
---|
| 925 | return SET_INVALID; |
---|
| 926 | } |
---|
| 927 | |
---|
[03f3828] | 928 | if( set->value && ( oa = account_get( ic->irc->b, set->value ) ) && |
---|
| 929 | oa->prpl->chat_free_settings ) |
---|
| 930 | oa->prpl->chat_free_settings( oa, &ic->set ); |
---|
| 931 | |
---|
| 932 | if( acc->prpl->chat_add_settings ) |
---|
| 933 | acc->prpl->chat_add_settings( acc, &ic->set ); |
---|
| 934 | |
---|
[e135cd09] | 935 | return g_strdup( acc->tag ); |
---|
[5a75d15] | 936 | } |
---|
| 937 | |
---|
[1c40aa7] | 938 | static char *set_eval_chat_type( set_t *set, char *value ) |
---|
| 939 | { |
---|
| 940 | struct irc_channel *ic = set->data; |
---|
| 941 | |
---|
| 942 | if( strcmp( value, "groupchat" ) == 0 ) |
---|
| 943 | ic->flags |= IRC_CHANNEL_TEMP; |
---|
| 944 | else if( strcmp( value, "room" ) == 0 ) |
---|
| 945 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
| 946 | else |
---|
| 947 | return NULL; |
---|
| 948 | |
---|
| 949 | return value; |
---|
| 950 | } |
---|
| 951 | |
---|
[5a75d15] | 952 | static gboolean bee_irc_channel_free( irc_channel_t *ic ) |
---|
| 953 | { |
---|
[b1af3e8] | 954 | struct groupchat *c = ic->data; |
---|
| 955 | |
---|
[5a75d15] | 956 | set_del( &ic->set, "account" ); |
---|
| 957 | set_del( &ic->set, "chat_type" ); |
---|
| 958 | set_del( &ic->set, "nick" ); |
---|
| 959 | set_del( &ic->set, "room" ); |
---|
[69b896b] | 960 | set_del( &ic->set, "translate_to_nicks" ); |
---|
[5a75d15] | 961 | |
---|
[1c40aa7] | 962 | ic->flags &= ~IRC_CHANNEL_TEMP; |
---|
| 963 | |
---|
[b1af3e8] | 964 | /* That one still points at this channel. Don't. */ |
---|
| 965 | if( c ) |
---|
| 966 | c->ui_data = NULL; |
---|
| 967 | |
---|
[5a75d15] | 968 | return TRUE; |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | const struct irc_channel_funcs irc_channel_im_chat_funcs = { |
---|
[a87754b] | 972 | bee_irc_channel_chat_privmsg, |
---|
[5a75d15] | 973 | bee_irc_channel_chat_join, |
---|
[bfb99ee] | 974 | bee_irc_channel_chat_part, |
---|
[9e27f18] | 975 | bee_irc_channel_chat_topic, |
---|
[66b9e36a] | 976 | bee_irc_channel_chat_invite, |
---|
[5a75d15] | 977 | |
---|
| 978 | bee_irc_channel_init, |
---|
| 979 | bee_irc_channel_free, |
---|
[a87754b] | 980 | }; |
---|
| 981 | |
---|
[aea8b68] | 982 | |
---|
[e4816ea] | 983 | /* IM->IRC: File transfers */ |
---|
[17a6ee9] | 984 | static file_transfer_t *bee_irc_ft_in_start( bee_t *bee, bee_user_t *bu, const char *file_name, size_t file_size ) |
---|
| 985 | { |
---|
| 986 | return dccs_send_start( bu->ic, (irc_user_t *) bu->ui_data, file_name, file_size ); |
---|
| 987 | } |
---|
| 988 | |
---|
[a87754b] | 989 | static gboolean bee_irc_ft_out_start( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 990 | { |
---|
| 991 | return dccs_recv_start( ft ); |
---|
| 992 | } |
---|
| 993 | |
---|
[a87754b] | 994 | static void bee_irc_ft_close( struct im_connection *ic, file_transfer_t *ft ) |
---|
[17a6ee9] | 995 | { |
---|
| 996 | return dcc_close( ft ); |
---|
| 997 | } |
---|
| 998 | |
---|
[a87754b] | 999 | static void bee_irc_ft_finished( struct im_connection *ic, file_transfer_t *file ) |
---|
[17a6ee9] | 1000 | { |
---|
| 1001 | dcc_file_transfer_t *df = file->priv; |
---|
| 1002 | |
---|
| 1003 | if( file->bytes_transferred >= file->file_size ) |
---|
| 1004 | dcc_finish( file ); |
---|
| 1005 | else |
---|
| 1006 | df->proto_finished = TRUE; |
---|
| 1007 | } |
---|
| 1008 | |
---|
[d860a8d] | 1009 | const struct bee_ui_funcs irc_ui_funcs = { |
---|
[5c7b45c] | 1010 | bee_irc_imc_connected, |
---|
| 1011 | bee_irc_imc_disconnected, |
---|
| 1012 | |
---|
[81e04e1] | 1013 | bee_irc_user_new, |
---|
[d860a8d] | 1014 | bee_irc_user_free, |
---|
[1d39159] | 1015 | bee_irc_user_fullname, |
---|
[6ef9065] | 1016 | bee_irc_user_nick_hint, |
---|
[7e83e8e4] | 1017 | bee_irc_user_group, |
---|
[d860a8d] | 1018 | bee_irc_user_status, |
---|
[f012a9f] | 1019 | bee_irc_user_msg, |
---|
[573dab0] | 1020 | bee_irc_user_typing, |
---|
[17a6ee9] | 1021 | |
---|
[aea8b68] | 1022 | bee_irc_chat_new, |
---|
| 1023 | bee_irc_chat_free, |
---|
[27e2c66] | 1024 | bee_irc_chat_log, |
---|
| 1025 | bee_irc_chat_msg, |
---|
[aea8b68] | 1026 | bee_irc_chat_add_user, |
---|
[b17ce85] | 1027 | bee_irc_chat_remove_user, |
---|
[9e27f18] | 1028 | bee_irc_chat_topic, |
---|
[d343eaa] | 1029 | bee_irc_chat_name_hint, |
---|
[1aa74f55] | 1030 | bee_irc_chat_invite, |
---|
[aea8b68] | 1031 | |
---|
[17a6ee9] | 1032 | bee_irc_ft_in_start, |
---|
| 1033 | bee_irc_ft_out_start, |
---|
| 1034 | bee_irc_ft_close, |
---|
| 1035 | bee_irc_ft_finished, |
---|
[81e04e1] | 1036 | }; |
---|