[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[0baed0d] | 4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
[b7d3cc34] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* User manager (root) commands */ |
---|
| 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 | #define BITLBEE_CORE |
---|
| 27 | #include "commands.h" |
---|
| 28 | #include "bitlbee.h" |
---|
| 29 | #include "help.h" |
---|
[f1c2b21] | 30 | #include "ipc.h" |
---|
[764c7d1] | 31 | #include "otr.h" |
---|
[b7d3cc34] | 32 | |
---|
[280c56a] | 33 | void root_command_string( irc_t *irc, char *command ) |
---|
[7e563ed] | 34 | { |
---|
[24b8bbb] | 35 | root_command( irc, split_command_parts( command ) ); |
---|
[7e563ed] | 36 | } |
---|
| 37 | |
---|
[3b99524] | 38 | #define MIN_ARGS( x, y... ) \ |
---|
| 39 | do \ |
---|
| 40 | { \ |
---|
[07054a5] | 41 | int blaat; \ |
---|
| 42 | for( blaat = 0; blaat <= x; blaat ++ ) \ |
---|
| 43 | if( cmd[blaat] == NULL ) \ |
---|
[3b99524] | 44 | { \ |
---|
| 45 | irc_usermsg( irc, "Not enough parameters given (need %d).", x ); \ |
---|
| 46 | return y; \ |
---|
| 47 | } \ |
---|
| 48 | } while( 0 ) |
---|
| 49 | |
---|
[f73b969] | 50 | void root_command( irc_t *irc, char *cmd[] ) |
---|
[7e563ed] | 51 | { |
---|
[6c56f42] | 52 | int i, len; |
---|
[7e563ed] | 53 | |
---|
| 54 | if( !cmd[0] ) |
---|
[f73b969] | 55 | return; |
---|
[7e563ed] | 56 | |
---|
[6c56f42] | 57 | len = strlen( cmd[0] ); |
---|
[7e563ed] | 58 | for( i = 0; commands[i].command; i++ ) |
---|
[6c56f42] | 59 | if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 ) |
---|
[7e563ed] | 60 | { |
---|
[6c56f42] | 61 | if( commands[i+1].command && |
---|
| 62 | g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 ) |
---|
| 63 | /* Only match on the first letters if the match is unique. */ |
---|
| 64 | break; |
---|
| 65 | |
---|
[3b99524] | 66 | MIN_ARGS( commands[i].required_parameters ); |
---|
| 67 | |
---|
[7e563ed] | 68 | commands[i].execute( irc, cmd ); |
---|
[f73b969] | 69 | return; |
---|
[7e563ed] | 70 | } |
---|
| 71 | |
---|
| 72 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
| 73 | } |
---|
| 74 | |
---|
[f73b969] | 75 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 76 | { |
---|
| 77 | char param[80]; |
---|
| 78 | int i; |
---|
| 79 | char *s; |
---|
| 80 | |
---|
| 81 | memset( param, 0, sizeof(param) ); |
---|
| 82 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
| 83 | if ( i != 1 ) // prepend space except for the first parameter |
---|
| 84 | strcat(param, " "); |
---|
| 85 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | s = help_get( &(global.help), param ); |
---|
| 89 | if( !s ) s = help_get( &(global.help), "" ); |
---|
| 90 | |
---|
| 91 | if( s ) |
---|
| 92 | { |
---|
| 93 | irc_usermsg( irc, "%s", s ); |
---|
| 94 | g_free( s ); |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
[90bbb0e] | 102 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
[180ab31] | 103 | static void bitlbee_whatsnew( irc_t *irc ); |
---|
[90bbb0e] | 104 | |
---|
[f73b969] | 105 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 106 | { |
---|
[92cb8c4] | 107 | storage_status_t status; |
---|
| 108 | gboolean load = TRUE; |
---|
| 109 | char *password = cmd[1]; |
---|
[b7d3cc34] | 110 | |
---|
[92cb8c4] | 111 | if( irc->status & USTATUS_IDENTIFIED ) |
---|
[e9cf291] | 112 | { |
---|
| 113 | irc_usermsg( irc, "You're already logged in." ); |
---|
| 114 | return; |
---|
| 115 | } |
---|
| 116 | |
---|
[92cb8c4] | 117 | if( strncmp( cmd[1], "-no", 3 ) == 0 ) |
---|
| 118 | { |
---|
| 119 | load = FALSE; |
---|
| 120 | password = cmd[2]; |
---|
| 121 | } |
---|
| 122 | else if( strncmp( cmd[1], "-force", 6 ) == 0 ) |
---|
| 123 | { |
---|
| 124 | password = cmd[2]; |
---|
| 125 | } |
---|
| 126 | else if( irc->b->accounts != NULL ) |
---|
| 127 | { |
---|
| 128 | irc_usermsg( irc, |
---|
| 129 | "You're trying to identify yourself, but already have " |
---|
| 130 | "at least one IM account set up. " |
---|
| 131 | "Use \x02identify -noload\x02 or \x02identify -force\x02 " |
---|
| 132 | "instead (see \x02help identify\x02)." ); |
---|
| 133 | return; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | if( password == NULL ) |
---|
| 137 | { |
---|
| 138 | MIN_ARGS( 2 ); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if( load ) |
---|
| 142 | status = storage_load( irc, password ); |
---|
| 143 | else |
---|
| 144 | status = storage_check_pass( irc->user->nick, password ); |
---|
| 145 | |
---|
[09adf08] | 146 | switch (status) { |
---|
| 147 | case STORAGE_INVALID_PASSWORD: |
---|
[b7d3cc34] | 148 | irc_usermsg( irc, "Incorrect password" ); |
---|
[09adf08] | 149 | break; |
---|
| 150 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 151 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
[09adf08] | 152 | break; |
---|
| 153 | case STORAGE_OK: |
---|
[92cb8c4] | 154 | irc_usermsg( irc, "Password accepted%s", |
---|
| 155 | load ? ", settings and accounts loaded" : "" ); |
---|
| 156 | irc_setpass( irc, password ); |
---|
[3183c21] | 157 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 158 | irc_umode_set( irc, "+R", 1 ); |
---|
[6c2404e] | 159 | |
---|
[180ab31] | 160 | bitlbee_whatsnew( irc ); |
---|
| 161 | |
---|
[e92c4f4] | 162 | /* The following code is a bit hairy now. With takeover |
---|
| 163 | support, we shouldn't immediately auto_connect in case |
---|
| 164 | we're going to offer taking over an existing session. |
---|
| 165 | Do it in 200ms since that should give the parent process |
---|
| 166 | enough time to come back to us. */ |
---|
| 167 | if( load ) |
---|
[6c2404e] | 168 | { |
---|
[e92c4f4] | 169 | irc_channel_auto_joins( irc, NULL ); |
---|
[fe4f28f] | 170 | if( !set_getbool( &irc->default_channel->set, "auto_join" ) ) |
---|
| 171 | irc_channel_del_user( irc->default_channel, irc->user, |
---|
| 172 | IRC_CDU_PART, "auto_join disabled " |
---|
| 173 | "for this channel." ); |
---|
[e92c4f4] | 174 | if( set_getbool( &irc->b->set, "auto_connect" ) ) |
---|
[6c2404e] | 175 | irc->login_source_id = b_timeout_add( 200, |
---|
| 176 | cmd_identify_finish, irc ); |
---|
| 177 | } |
---|
[e92c4f4] | 178 | |
---|
| 179 | /* If ipc_child_identify() returns FALSE, it means we're |
---|
| 180 | already sure that there's no takeover target (only |
---|
| 181 | possible in 1-process daemon mode). Start auto_connect |
---|
| 182 | immediately. */ |
---|
| 183 | if( !ipc_child_identify( irc ) && load && |
---|
| 184 | set_getbool( &irc->b->set, "auto_connect" ) ) |
---|
[6c2404e] | 185 | cmd_identify_finish( irc, 0, 0 ); |
---|
| 186 | |
---|
[09adf08] | 187 | break; |
---|
[c121f89] | 188 | case STORAGE_OTHER_ERROR: |
---|
[09adf08] | 189 | default: |
---|
[c121f89] | 190 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
[09adf08] | 191 | break; |
---|
[b7d3cc34] | 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
[6c2404e] | 195 | gboolean cmd_identify_finish( gpointer data, gint fd, b_input_condition cond ) |
---|
| 196 | { |
---|
| 197 | char *account_on[] = { "account", "on", NULL }; |
---|
| 198 | irc_t *irc = data; |
---|
| 199 | |
---|
| 200 | cmd_account( irc, account_on ); |
---|
| 201 | |
---|
[af9f2ca] | 202 | b_event_remove( irc->login_source_id ); |
---|
[f545372] | 203 | irc->login_source_id = -1; |
---|
[6c2404e] | 204 | return FALSE; |
---|
| 205 | } |
---|
| 206 | |
---|
[f73b969] | 207 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 208 | { |
---|
| 209 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
| 210 | { |
---|
| 211 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
[f73b969] | 212 | return; |
---|
[b7d3cc34] | 213 | } |
---|
[1ee6c18] | 214 | |
---|
[3183c21] | 215 | switch( storage_save( irc, cmd[1], FALSE ) ) { |
---|
[a1f17d4] | 216 | case STORAGE_ALREADY_EXISTS: |
---|
| 217 | irc_usermsg( irc, "Nick is already registered" ); |
---|
| 218 | break; |
---|
| 219 | |
---|
| 220 | case STORAGE_OK: |
---|
[0383943] | 221 | irc_usermsg( irc, "Account successfully created" ); |
---|
[3183c21] | 222 | irc_setpass( irc, cmd[1] ); |
---|
[79e826a] | 223 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 224 | irc_umode_set( irc, "+R", 1 ); |
---|
[a1f17d4] | 225 | break; |
---|
| 226 | |
---|
| 227 | default: |
---|
| 228 | irc_usermsg( irc, "Error registering" ); |
---|
| 229 | break; |
---|
[b7d3cc34] | 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
[f73b969] | 233 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 234 | { |
---|
[a1f17d4] | 235 | storage_status_t status; |
---|
| 236 | |
---|
[1f92a58] | 237 | status = storage_remove (irc->user->nick, cmd[1]); |
---|
[a1f17d4] | 238 | switch (status) { |
---|
| 239 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 240 | irc_usermsg( irc, "That account does not exist" ); |
---|
[f73b969] | 241 | break; |
---|
[a1f17d4] | 242 | case STORAGE_INVALID_PASSWORD: |
---|
[1ee6c18] | 243 | irc_usermsg( irc, "Password invalid" ); |
---|
[f73b969] | 244 | break; |
---|
[a1f17d4] | 245 | case STORAGE_OK: |
---|
[7cad7b4] | 246 | irc_setpass( irc, NULL ); |
---|
[79e826a] | 247 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[238f828] | 248 | irc_umode_set( irc, "-R", 1 ); |
---|
[1f92a58] | 249 | irc_usermsg( irc, "Account `%s' removed", irc->user->nick ); |
---|
[f73b969] | 250 | break; |
---|
[a1f17d4] | 251 | default: |
---|
[30ce1ce] | 252 | irc_usermsg( irc, "Error: `%d'", status ); |
---|
[f73b969] | 253 | break; |
---|
[b7d3cc34] | 254 | } |
---|
| 255 | } |
---|
[1f92a58] | 256 | |
---|
| 257 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
| 258 | { |
---|
| 259 | if( ( irc->status & USTATUS_IDENTIFIED ) == 0 ) |
---|
| 260 | irc_usermsg( irc, "Please create an account first" ); |
---|
| 261 | else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK ) |
---|
| 262 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 263 | else |
---|
| 264 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 265 | } |
---|
[b7d3cc34] | 266 | |
---|
[f536a99] | 267 | static void cmd_showset( irc_t *irc, set_t **head, char *key ) |
---|
[f3579fd] | 268 | { |
---|
[f536a99] | 269 | char *val; |
---|
[f3579fd] | 270 | |
---|
[f536a99] | 271 | if( ( val = set_getstr( head, key ) ) ) |
---|
| 272 | irc_usermsg( irc, "%s = `%s'", key, val ); |
---|
[5613af7] | 273 | else if( !set_find( head, key ) ) |
---|
| 274 | { |
---|
| 275 | irc_usermsg( irc, "Setting `%s' does not exist.", key ); |
---|
| 276 | if( *head == irc->b->set ) |
---|
| 277 | irc_usermsg( irc, "It might be an account or channel setting. " |
---|
| 278 | "See \x02help account set\x02 and \x02help channel set\x02." ); |
---|
| 279 | } |
---|
[f3579fd] | 280 | else |
---|
[f536a99] | 281 | irc_usermsg( irc, "%s is empty", key ); |
---|
[f3579fd] | 282 | } |
---|
| 283 | |
---|
[e7bc722] | 284 | typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); |
---|
[c05eb5b] | 285 | typedef int (*cmd_set_checkflags)( irc_t*, set_t *set ); |
---|
[e7bc722] | 286 | |
---|
[e907683] | 287 | static int cmd_set_real( irc_t *irc, char **cmd, set_t **head, cmd_set_checkflags checkflags ) |
---|
[e7bc722] | 288 | { |
---|
[e907683] | 289 | char *set_name = NULL, *value = NULL; |
---|
| 290 | gboolean del = FALSE; |
---|
[e7bc722] | 291 | |
---|
| 292 | if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
[d4810df] | 293 | { |
---|
| 294 | MIN_ARGS( 2, 0 ); |
---|
[e907683] | 295 | set_name = cmd[2]; |
---|
| 296 | del = TRUE; |
---|
[d4810df] | 297 | } |
---|
[e7bc722] | 298 | else |
---|
| 299 | { |
---|
[e907683] | 300 | set_name = cmd[1]; |
---|
| 301 | value = cmd[2]; |
---|
[e7bc722] | 302 | } |
---|
| 303 | |
---|
[e907683] | 304 | if( set_name && ( value || del ) ) |
---|
[e7bc722] | 305 | { |
---|
| 306 | set_t *s = set_find( head, set_name ); |
---|
| 307 | int st; |
---|
| 308 | |
---|
[8a08d92] | 309 | if( s && checkflags && checkflags( irc, s ) == 0 ) |
---|
[e7bc722] | 310 | return 0; |
---|
| 311 | |
---|
[e907683] | 312 | if( del ) |
---|
[e7bc722] | 313 | st = set_reset( head, set_name ); |
---|
| 314 | else |
---|
[e907683] | 315 | st = set_setstr( head, set_name, value ); |
---|
[e7bc722] | 316 | |
---|
[5613af7] | 317 | if( set_getstr( head, set_name ) == NULL && |
---|
| 318 | set_find( head, set_name ) ) |
---|
[e7bc722] | 319 | { |
---|
[e907683] | 320 | /* This happens when changing the passwd, for example. |
---|
| 321 | Showing these msgs instead gives slightly clearer |
---|
| 322 | feedback. */ |
---|
[e7bc722] | 323 | if( st ) |
---|
| 324 | irc_usermsg( irc, "Setting changed successfully" ); |
---|
| 325 | else |
---|
| 326 | irc_usermsg( irc, "Failed to change setting" ); |
---|
| 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
| 330 | cmd_showset( irc, head, set_name ); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | else if( set_name ) |
---|
| 334 | { |
---|
| 335 | cmd_showset( irc, head, set_name ); |
---|
| 336 | } |
---|
| 337 | else |
---|
| 338 | { |
---|
| 339 | set_t *s = *head; |
---|
| 340 | while( s ) |
---|
| 341 | { |
---|
[180ab31] | 342 | if( !( s->flags & SET_HIDDEN ) ) |
---|
| 343 | cmd_showset( irc, &s, s->key ); |
---|
[e7bc722] | 344 | s = s->next; |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | return 1; |
---|
| 349 | } |
---|
| 350 | |
---|
[c05eb5b] | 351 | static int cmd_account_set_checkflags( irc_t *irc, set_t *s ) |
---|
| 352 | { |
---|
| 353 | account_t *a = s->data; |
---|
| 354 | |
---|
| 355 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
| 356 | { |
---|
| 357 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 358 | return 0; |
---|
| 359 | } |
---|
| 360 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
| 361 | { |
---|
| 362 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
| 363 | return 0; |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | return 1; |
---|
| 367 | } |
---|
| 368 | |
---|
[f73b969] | 369 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 370 | { |
---|
| 371 | account_t *a; |
---|
[c7eb771] | 372 | int len; |
---|
[b7d3cc34] | 373 | |
---|
[3af70b0] | 374 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 375 | { |
---|
| 376 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 377 | return; |
---|
[b7d3cc34] | 378 | } |
---|
| 379 | |
---|
[c7eb771] | 380 | len = strlen( cmd[1] ); |
---|
| 381 | |
---|
| 382 | if( len >= 1 && g_strncasecmp( cmd[1], "add", len ) == 0 ) |
---|
[b7d3cc34] | 383 | { |
---|
[7b23afd] | 384 | struct prpl *prpl; |
---|
[b7d3cc34] | 385 | |
---|
[3b99524] | 386 | MIN_ARGS( 4 ); |
---|
[b7d3cc34] | 387 | |
---|
[a9a7287] | 388 | prpl = find_protocol( cmd[2] ); |
---|
[b7d3cc34] | 389 | |
---|
[7b23afd] | 390 | if( prpl == NULL ) |
---|
[b7d3cc34] | 391 | { |
---|
| 392 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 393 | return; |
---|
[b7d3cc34] | 394 | } |
---|
[593971d] | 395 | |
---|
| 396 | for( a = irc->b->accounts; a; a = a->next ) |
---|
| 397 | if( a->prpl == prpl && prpl->handle_cmp( a->user, cmd[3] ) == 0 ) |
---|
| 398 | irc_usermsg( irc, "Warning: You already have an account with " |
---|
| 399 | "protocol `%s' and username `%s'. Are you accidentally " |
---|
| 400 | "trying to add it twice?", prpl->name, cmd[3] ); |
---|
| 401 | |
---|
[d860a8d] | 402 | a = account_add( irc->b, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 403 | if( cmd[5] ) |
---|
[30ce1ce] | 404 | { |
---|
| 405 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
| 406 | "is now deprecated. Use `account set' instead." ); |
---|
[5100caa] | 407 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[30ce1ce] | 408 | } |
---|
[b7d3cc34] | 409 | |
---|
| 410 | irc_usermsg( irc, "Account successfully added" ); |
---|
[e907683] | 411 | |
---|
| 412 | return; |
---|
[b7d3cc34] | 413 | } |
---|
[c7eb771] | 414 | else if( len >= 1 && g_strncasecmp( cmd[1], "list", len ) == 0 ) |
---|
[b7d3cc34] | 415 | { |
---|
| 416 | int i = 0; |
---|
| 417 | |
---|
[e6e1f18] | 418 | if( strchr( irc->umode, 'b' ) ) |
---|
| 419 | irc_usermsg( irc, "Account list:" ); |
---|
| 420 | |
---|
[d860a8d] | 421 | for( a = irc->b->accounts; a; a = a->next ) |
---|
[b7d3cc34] | 422 | { |
---|
| 423 | char *con; |
---|
| 424 | |
---|
[0da65d5] | 425 | if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) |
---|
[b7d3cc34] | 426 | con = " (connected)"; |
---|
[0da65d5] | 427 | else if( a->ic ) |
---|
[b7d3cc34] | 428 | con = " (connecting)"; |
---|
| 429 | else if( a->reconnect ) |
---|
| 430 | con = " (awaiting reconnect)"; |
---|
| 431 | else |
---|
| 432 | con = ""; |
---|
| 433 | |
---|
[40e6dac] | 434 | irc_usermsg( irc, "%2d (%s): %s, %s%s", i, a->tag, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 435 | |
---|
| 436 | i ++; |
---|
| 437 | } |
---|
| 438 | irc_usermsg( irc, "End of account list" ); |
---|
[e907683] | 439 | |
---|
| 440 | return; |
---|
| 441 | } |
---|
| 442 | else if( cmd[2] ) |
---|
| 443 | { |
---|
| 444 | /* Try the following two only if cmd[2] == NULL */ |
---|
[b7d3cc34] | 445 | } |
---|
[c7eb771] | 446 | else if( len >= 2 && g_strncasecmp( cmd[1], "on", len ) == 0 ) |
---|
[b7d3cc34] | 447 | { |
---|
[e907683] | 448 | if ( irc->b->accounts ) |
---|
[b7d3cc34] | 449 | { |
---|
[e907683] | 450 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 451 | |
---|
| 452 | for( a = irc->b->accounts; a; a = a->next ) |
---|
| 453 | if( !a->ic && a->auto_connect ) |
---|
[d860a8d] | 454 | account_on( irc->b, a ); |
---|
[e907683] | 455 | } |
---|
[b7d3cc34] | 456 | else |
---|
| 457 | { |
---|
[e907683] | 458 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
[b7d3cc34] | 459 | } |
---|
[e907683] | 460 | |
---|
| 461 | return; |
---|
[b7d3cc34] | 462 | } |
---|
[c7eb771] | 463 | else if( len >= 2 && g_strncasecmp( cmd[1], "off", len ) == 0 ) |
---|
[b7d3cc34] | 464 | { |
---|
[e907683] | 465 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 466 | |
---|
| 467 | for( a = irc->b->accounts; a; a = a->next ) |
---|
[b7d3cc34] | 468 | { |
---|
[0da65d5] | 469 | if( a->ic ) |
---|
[d860a8d] | 470 | account_off( irc->b, a ); |
---|
[b7d3cc34] | 471 | else if( a->reconnect ) |
---|
| 472 | cancel_auto_reconnect( a ); |
---|
[e907683] | 473 | } |
---|
| 474 | |
---|
| 475 | return; |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | MIN_ARGS( 2 ); |
---|
[c7eb771] | 479 | len = strlen( cmd[2] ); |
---|
[e907683] | 480 | |
---|
| 481 | /* At least right now, don't accept on/off/set/del as account IDs even |
---|
| 482 | if they're a proper match, since people not familiar with the new |
---|
| 483 | syntax yet may get a confusing/nasty surprise. */ |
---|
| 484 | if( g_strcasecmp( cmd[1], "on" ) == 0 || |
---|
| 485 | g_strcasecmp( cmd[1], "off" ) == 0 || |
---|
| 486 | g_strcasecmp( cmd[1], "set" ) == 0 || |
---|
| 487 | g_strcasecmp( cmd[1], "del" ) == 0 || |
---|
| 488 | ( a = account_get( irc->b, cmd[1] ) ) == NULL ) |
---|
| 489 | { |
---|
| 490 | irc_usermsg( irc, "Could not find account `%s'. Note that the syntax " |
---|
| 491 | "of the account command changed, see \x02help account\x02.", cmd[1] ); |
---|
| 492 | |
---|
| 493 | return; |
---|
| 494 | } |
---|
| 495 | |
---|
[c7eb771] | 496 | if( len >= 1 && g_strncasecmp( cmd[2], "del", len ) == 0 ) |
---|
[e907683] | 497 | { |
---|
| 498 | if( a->ic ) |
---|
| 499 | { |
---|
| 500 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
[b7d3cc34] | 501 | } |
---|
| 502 | else |
---|
| 503 | { |
---|
[e907683] | 504 | account_del( irc->b, a ); |
---|
| 505 | irc_usermsg( irc, "Account deleted" ); |
---|
[b7d3cc34] | 506 | } |
---|
| 507 | } |
---|
[c7eb771] | 508 | else if( len >= 2 && g_strncasecmp( cmd[2], "on", len ) == 0 ) |
---|
[5100caa] | 509 | { |
---|
[e907683] | 510 | if( a->ic ) |
---|
| 511 | irc_usermsg( irc, "Account already online" ); |
---|
| 512 | else |
---|
| 513 | account_on( irc->b, a ); |
---|
| 514 | } |
---|
[c7eb771] | 515 | else if( len >= 2 && g_strncasecmp( cmd[2], "off", len ) == 0 ) |
---|
[e907683] | 516 | { |
---|
| 517 | if( a->ic ) |
---|
| 518 | { |
---|
| 519 | account_off( irc->b, a ); |
---|
| 520 | } |
---|
| 521 | else if( a->reconnect ) |
---|
| 522 | { |
---|
| 523 | cancel_auto_reconnect( a ); |
---|
| 524 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 525 | } |
---|
| 526 | else |
---|
| 527 | { |
---|
| 528 | irc_usermsg( irc, "Account already offline" ); |
---|
| 529 | } |
---|
| 530 | } |
---|
[c7eb771] | 531 | else if( len >= 1 && g_strncasecmp( cmd[2], "set", len ) == 0 ) |
---|
[e907683] | 532 | { |
---|
| 533 | cmd_set_real( irc, cmd + 2, &a->set, cmd_account_set_checkflags ); |
---|
[5100caa] | 534 | } |
---|
[b7d3cc34] | 535 | else |
---|
| 536 | { |
---|
[e907683] | 537 | irc_usermsg( irc, "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[2] ); |
---|
[b7d3cc34] | 538 | } |
---|
| 539 | } |
---|
| 540 | |
---|
[e907683] | 541 | static void cmd_channel( irc_t *irc, char **cmd ) |
---|
[c133d4b8] | 542 | { |
---|
| 543 | irc_channel_t *ic; |
---|
[c7eb771] | 544 | int len; |
---|
| 545 | |
---|
| 546 | len = strlen( cmd[1] ); |
---|
[c133d4b8] | 547 | |
---|
[c7eb771] | 548 | if( len >= 1 && g_strncasecmp( cmd[1], "list", len ) == 0 ) |
---|
[36562b0] | 549 | { |
---|
| 550 | GSList *l; |
---|
| 551 | int i = 0; |
---|
| 552 | |
---|
| 553 | if( strchr( irc->umode, 'b' ) ) |
---|
| 554 | irc_usermsg( irc, "Channel list:" ); |
---|
| 555 | |
---|
| 556 | for( l = irc->channels; l; l = l->next ) |
---|
| 557 | { |
---|
| 558 | irc_channel_t *ic = l->data; |
---|
| 559 | |
---|
| 560 | irc_usermsg( irc, "%2d. %s, %s channel%s", i, ic->name, |
---|
| 561 | set_getstr( &ic->set, "type" ), |
---|
| 562 | ic->flags & IRC_CHANNEL_JOINED ? " (joined)" : "" ); |
---|
| 563 | |
---|
| 564 | i ++; |
---|
| 565 | } |
---|
| 566 | irc_usermsg( irc, "End of channel list" ); |
---|
[e907683] | 567 | |
---|
| 568 | return; |
---|
[36562b0] | 569 | } |
---|
[e907683] | 570 | |
---|
| 571 | if( ( ic = irc_channel_get( irc, cmd[1] ) ) == NULL ) |
---|
[a4d920b] | 572 | { |
---|
[4f22a68c] | 573 | /* If this doesn't match any channel, maybe this is the short |
---|
| 574 | syntax (only works when used inside a channel). */ |
---|
[f7ca587] | 575 | if( ( ic = irc->root->last_channel ) && |
---|
| 576 | ( len = strlen( cmd[1] ) ) && |
---|
| 577 | g_strncasecmp( cmd[1], "set", len ) == 0 ) |
---|
[4f22a68c] | 578 | cmd_set_real( irc, cmd + 1, &ic->set, NULL ); |
---|
| 579 | else |
---|
| 580 | irc_usermsg( irc, "Could not find channel `%s'", cmd[1] ); |
---|
| 581 | |
---|
[e907683] | 582 | return; |
---|
| 583 | } |
---|
| 584 | |
---|
[4f22a68c] | 585 | MIN_ARGS( 2 ); |
---|
| 586 | len = strlen( cmd[2] ); |
---|
| 587 | |
---|
[c7eb771] | 588 | if( len >= 1 && g_strncasecmp( cmd[2], "set", len ) == 0 ) |
---|
[e907683] | 589 | { |
---|
| 590 | cmd_set_real( irc, cmd + 2, &ic->set, NULL ); |
---|
| 591 | } |
---|
[c7eb771] | 592 | else if( len >= 1 && g_strncasecmp( cmd[2], "del", len ) == 0 ) |
---|
[e907683] | 593 | { |
---|
| 594 | if( !( ic->flags & IRC_CHANNEL_JOINED ) && |
---|
[a4d920b] | 595 | ic != ic->irc->default_channel ) |
---|
| 596 | { |
---|
| 597 | irc_usermsg( irc, "Channel %s deleted.", ic->name ); |
---|
| 598 | irc_channel_free( ic ); |
---|
| 599 | } |
---|
| 600 | else |
---|
| 601 | irc_usermsg( irc, "Couldn't remove channel (main channel %s or " |
---|
| 602 | "channels you're still in cannot be deleted).", |
---|
[5266354] | 603 | irc->default_channel->name ); |
---|
[a4d920b] | 604 | } |
---|
[c133d4b8] | 605 | else |
---|
| 606 | { |
---|
[e907683] | 607 | irc_usermsg( irc, "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] ); |
---|
[c133d4b8] | 608 | } |
---|
| 609 | } |
---|
| 610 | |
---|
[f73b969] | 611 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 612 | { |
---|
| 613 | account_t *a; |
---|
[f0cb961] | 614 | int add_on_server = 1; |
---|
[f8de26f] | 615 | |
---|
| 616 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 617 | { |
---|
[77fc000c] | 618 | MIN_ARGS( 3 ); |
---|
[f0cb961] | 619 | add_on_server = 0; |
---|
[7adc657] | 620 | cmd ++; |
---|
[f8de26f] | 621 | } |
---|
[b7d3cc34] | 622 | |
---|
[dbb0ce3] | 623 | if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 624 | { |
---|
| 625 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 626 | return; |
---|
[b7d3cc34] | 627 | } |
---|
[0da65d5] | 628 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 629 | { |
---|
| 630 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 631 | return; |
---|
[b7d3cc34] | 632 | } |
---|
| 633 | |
---|
| 634 | if( cmd[3] ) |
---|
| 635 | { |
---|
| 636 | if( !nick_ok( cmd[3] ) ) |
---|
| 637 | { |
---|
| 638 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 639 | return; |
---|
[b7d3cc34] | 640 | } |
---|
[dbb0ce3] | 641 | else if( irc_user_by_name( irc, cmd[3] ) ) |
---|
[b7d3cc34] | 642 | { |
---|
| 643 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 644 | return; |
---|
[b7d3cc34] | 645 | } |
---|
| 646 | else |
---|
| 647 | { |
---|
[b1f818b] | 648 | nick_set_raw( a, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 649 | } |
---|
| 650 | } |
---|
[f8de26f] | 651 | |
---|
[f0cb961] | 652 | if( add_on_server ) |
---|
[f1d488e] | 653 | { |
---|
| 654 | irc_channel_t *ic; |
---|
| 655 | char *s, *group = NULL;; |
---|
| 656 | |
---|
[f7ca587] | 657 | if( ( ic = irc->root->last_channel ) && |
---|
[f1d488e] | 658 | ( s = set_getstr( &ic->set, "fill_by" ) ) && |
---|
| 659 | strcmp( s, "group" ) == 0 && |
---|
| 660 | ( group = set_getstr( &ic->set, "group" ) ) ) |
---|
| 661 | irc_usermsg( irc, "Adding `%s' to contact list (group %s)", |
---|
| 662 | cmd[2], group ); |
---|
| 663 | else |
---|
| 664 | irc_usermsg( irc, "Adding `%s' to contact list", cmd[2] ); |
---|
| 665 | |
---|
| 666 | a->prpl->add_buddy( a->ic, cmd[2], group ); |
---|
| 667 | } |
---|
[7adc657] | 668 | else |
---|
[f1d488e] | 669 | { |
---|
| 670 | bee_user_t *bu; |
---|
| 671 | irc_user_t *iu; |
---|
| 672 | |
---|
[dbb0ce3] | 673 | /* Only for add -tmp. For regular adds, this callback will |
---|
| 674 | be called once the IM server confirms. */ |
---|
[f1d488e] | 675 | if( ( bu = bee_user_new( irc->b, a->ic, cmd[2], BEE_USER_LOCAL ) ) && |
---|
| 676 | ( iu = bu->ui_data ) ) |
---|
| 677 | irc_usermsg( irc, "Temporarily assigned nickname `%s' " |
---|
| 678 | "to contact `%s'", iu->nick, cmd[2] ); |
---|
| 679 | } |
---|
[f0cb961] | 680 | |
---|
[b7d3cc34] | 681 | } |
---|
| 682 | |
---|
[dbb0ce3] | 683 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
| 684 | { |
---|
| 685 | irc_user_t *iu; |
---|
| 686 | bee_user_t *bu; |
---|
| 687 | char *s; |
---|
| 688 | |
---|
| 689 | if( !( iu = irc_user_by_name( irc, cmd[1] ) ) || !( bu = iu->bu ) ) |
---|
| 690 | { |
---|
| 691 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
| 692 | return; |
---|
| 693 | } |
---|
| 694 | s = g_strdup( bu->handle ); |
---|
| 695 | |
---|
| 696 | bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL ); |
---|
[b1f818b] | 697 | nick_del( bu ); |
---|
[5e98ff0] | 698 | if( g_slist_find( irc->users, iu ) ) |
---|
| 699 | bee_user_free( irc->b, bu ); |
---|
[dbb0ce3] | 700 | |
---|
| 701 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 702 | g_free( s ); |
---|
| 703 | |
---|
| 704 | return; |
---|
| 705 | } |
---|
| 706 | |
---|
[f73b969] | 707 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 708 | { |
---|
[0da65d5] | 709 | struct im_connection *ic; |
---|
[b7d3cc34] | 710 | account_t *a; |
---|
| 711 | |
---|
| 712 | if( !cmd[2] ) |
---|
| 713 | { |
---|
[aa44bdd] | 714 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 715 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 716 | { |
---|
| 717 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 718 | return; |
---|
[b7d3cc34] | 719 | } |
---|
[aa44bdd] | 720 | ic = iu->bu->ic; |
---|
| 721 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 722 | } |
---|
[aa44bdd] | 723 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 724 | { |
---|
| 725 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 726 | return; |
---|
[b7d3cc34] | 727 | } |
---|
[0da65d5] | 728 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 729 | { |
---|
| 730 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 731 | return; |
---|
[b7d3cc34] | 732 | } |
---|
| 733 | |
---|
[0da65d5] | 734 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 735 | { |
---|
| 736 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 737 | } |
---|
[f73b969] | 738 | else |
---|
| 739 | { |
---|
[0da65d5] | 740 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 741 | } |
---|
[b7d3cc34] | 742 | } |
---|
| 743 | |
---|
[f73b969] | 744 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 745 | { |
---|
[9a9b520] | 746 | irc_user_t *iu, *old; |
---|
[b7d3cc34] | 747 | |
---|
[57c96f7] | 748 | iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 749 | |
---|
| 750 | if( iu == NULL ) |
---|
[0baed0d] | 751 | { |
---|
[57c96f7] | 752 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[0baed0d] | 753 | } |
---|
[57c96f7] | 754 | else if( iu == irc->user ) |
---|
[b7d3cc34] | 755 | { |
---|
[6c2404e] | 756 | irc_usermsg( irc, "Use /nick to change your own nickname" ); |
---|
[b7d3cc34] | 757 | } |
---|
[f73b969] | 758 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 759 | { |
---|
| 760 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 761 | } |
---|
[9a9b520] | 762 | else if( ( old = irc_user_by_name( irc, cmd[2] ) ) && old != iu ) |
---|
[b7d3cc34] | 763 | { |
---|
[57c96f7] | 764 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
[b7d3cc34] | 765 | } |
---|
[f73b969] | 766 | else |
---|
[b7d3cc34] | 767 | { |
---|
[57c96f7] | 768 | if( !irc_user_set_nick( iu, cmd[2] ) ) |
---|
| 769 | { |
---|
| 770 | irc_usermsg( irc, "Error while changing nick" ); |
---|
| 771 | return; |
---|
| 772 | } |
---|
| 773 | |
---|
| 774 | if( iu == irc->root ) |
---|
[f73b969] | 775 | { |
---|
[7125cb3] | 776 | /* If we're called internally (user did "set root_nick"), |
---|
| 777 | let's not go O(INF). :-) */ |
---|
[1195cec] | 778 | if( strcmp( cmd[0], "set_rename" ) != 0 ) |
---|
[57c96f7] | 779 | set_setstr( &irc->b->set, "root_nick", cmd[2] ); |
---|
[f73b969] | 780 | } |
---|
[57c96f7] | 781 | else if( iu->bu ) |
---|
[f73b969] | 782 | { |
---|
[b1f818b] | 783 | nick_set( iu->bu, cmd[2] ); |
---|
[f73b969] | 784 | } |
---|
| 785 | |
---|
| 786 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 787 | } |
---|
| 788 | } |
---|
| 789 | |
---|
[1195cec] | 790 | char *set_eval_root_nick( set_t *set, char *new_nick ) |
---|
| 791 | { |
---|
| 792 | irc_t *irc = set->data; |
---|
| 793 | |
---|
[0a6e5d1] | 794 | if( strcmp( irc->root->nick, new_nick ) != 0 ) |
---|
[1195cec] | 795 | { |
---|
[0a6e5d1] | 796 | char *cmd[] = { "set_rename", irc->root->nick, new_nick, NULL }; |
---|
[1195cec] | 797 | |
---|
| 798 | cmd_rename( irc, cmd ); |
---|
| 799 | } |
---|
| 800 | |
---|
[0a6e5d1] | 801 | return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID; |
---|
[1195cec] | 802 | } |
---|
[0baed0d] | 803 | |
---|
[f73b969] | 804 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 805 | { |
---|
[0da65d5] | 806 | struct im_connection *ic; |
---|
[b7d3cc34] | 807 | account_t *a; |
---|
| 808 | |
---|
[2272cb3] | 809 | if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 810 | { |
---|
| 811 | char *format; |
---|
| 812 | GSList *l; |
---|
| 813 | |
---|
| 814 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 815 | format = "%s\t%s"; |
---|
| 816 | else |
---|
[57ef864] | 817 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 818 | |
---|
| 819 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 820 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 821 | { |
---|
[2272cb3] | 822 | bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); |
---|
| 823 | irc_user_t *iu = bu ? bu->ui_data : NULL; |
---|
| 824 | irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); |
---|
[87b6a3e] | 825 | } |
---|
| 826 | irc_usermsg( irc, "End of list." ); |
---|
| 827 | |
---|
| 828 | return; |
---|
| 829 | } |
---|
| 830 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 831 | { |
---|
[2272cb3] | 832 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 833 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 834 | { |
---|
| 835 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 836 | return; |
---|
[b7d3cc34] | 837 | } |
---|
[2272cb3] | 838 | ic = iu->bu->ic; |
---|
| 839 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 840 | } |
---|
[2272cb3] | 841 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 842 | { |
---|
| 843 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 844 | return; |
---|
[b7d3cc34] | 845 | } |
---|
[0da65d5] | 846 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 847 | { |
---|
| 848 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 849 | return; |
---|
[b7d3cc34] | 850 | } |
---|
| 851 | |
---|
[0da65d5] | 852 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 853 | { |
---|
| 854 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 855 | } |
---|
| 856 | else |
---|
| 857 | { |
---|
[84b045d] | 858 | imc_rem_allow( ic, cmd[2] ); |
---|
| 859 | imc_add_block( ic, cmd[2] ); |
---|
[f1d488e] | 860 | irc_usermsg( irc, "Buddy `%s' moved from allow- to block-list", cmd[2] ); |
---|
[b7d3cc34] | 861 | } |
---|
| 862 | } |
---|
| 863 | |
---|
[f73b969] | 864 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 865 | { |
---|
[0da65d5] | 866 | struct im_connection *ic; |
---|
[b7d3cc34] | 867 | account_t *a; |
---|
| 868 | |
---|
[2272cb3] | 869 | if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 870 | { |
---|
| 871 | char *format; |
---|
| 872 | GSList *l; |
---|
| 873 | |
---|
| 874 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 875 | format = "%s\t%s"; |
---|
| 876 | else |
---|
[57ef864] | 877 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 878 | |
---|
| 879 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 880 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 881 | { |
---|
[2272cb3] | 882 | bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); |
---|
| 883 | irc_user_t *iu = bu ? bu->ui_data : NULL; |
---|
| 884 | irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); |
---|
[87b6a3e] | 885 | } |
---|
| 886 | irc_usermsg( irc, "End of list." ); |
---|
| 887 | |
---|
| 888 | return; |
---|
| 889 | } |
---|
| 890 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 891 | { |
---|
[2272cb3] | 892 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 893 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 894 | { |
---|
| 895 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 896 | return; |
---|
[b7d3cc34] | 897 | } |
---|
[2272cb3] | 898 | ic = iu->bu->ic; |
---|
| 899 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 900 | } |
---|
[2272cb3] | 901 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 902 | { |
---|
| 903 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 904 | return; |
---|
[b7d3cc34] | 905 | } |
---|
[0da65d5] | 906 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 907 | { |
---|
| 908 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 909 | return; |
---|
[b7d3cc34] | 910 | } |
---|
| 911 | |
---|
[0da65d5] | 912 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 913 | { |
---|
| 914 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 915 | } |
---|
| 916 | else |
---|
| 917 | { |
---|
[84b045d] | 918 | imc_rem_block( ic, cmd[2] ); |
---|
| 919 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 920 | |
---|
[f1d488e] | 921 | irc_usermsg( irc, "Buddy `%s' moved from block- to allow-list", cmd[2] ); |
---|
[b7d3cc34] | 922 | } |
---|
| 923 | } |
---|
| 924 | |
---|
[f73b969] | 925 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 926 | { |
---|
| 927 | query_t *q = NULL; |
---|
| 928 | int numq = 0; |
---|
| 929 | |
---|
| 930 | if( irc->queries == NULL ) |
---|
| 931 | { |
---|
[65a4a64] | 932 | /* Alright, alright, let's add a tiny easter egg here. */ |
---|
| 933 | static irc_t *last_irc = NULL; |
---|
| 934 | static time_t last_time = 0; |
---|
| 935 | static int times = 0; |
---|
| 936 | static const char *msg[] = { |
---|
| 937 | "Oh yeah, that's right.", |
---|
| 938 | "Alright, alright. Now go back to work.", |
---|
| 939 | "Buuuuuuuuuuuuuuuurp... Excuse me!", |
---|
| 940 | "Yes?", |
---|
| 941 | "No?", |
---|
| 942 | }; |
---|
| 943 | |
---|
| 944 | if( last_irc == irc && time( NULL ) - last_time < 15 ) |
---|
| 945 | { |
---|
| 946 | if( ( ++times >= 3 ) ) |
---|
| 947 | { |
---|
| 948 | irc_usermsg( irc, "%s", msg[rand()%(sizeof(msg)/sizeof(char*))] ); |
---|
| 949 | last_irc = NULL; |
---|
| 950 | times = 0; |
---|
| 951 | return; |
---|
| 952 | } |
---|
| 953 | } |
---|
| 954 | else |
---|
| 955 | { |
---|
| 956 | last_time = time( NULL ); |
---|
| 957 | last_irc = irc; |
---|
| 958 | times = 0; |
---|
| 959 | } |
---|
| 960 | |
---|
[b7d3cc34] | 961 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 962 | return; |
---|
[b7d3cc34] | 963 | } |
---|
| 964 | |
---|
| 965 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 966 | first/last (depending on the query_order setting) one. */ |
---|
| 967 | if( cmd[1] ) |
---|
| 968 | { |
---|
| 969 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 970 | { |
---|
| 971 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 972 | return; |
---|
[b7d3cc34] | 973 | } |
---|
| 974 | |
---|
| 975 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 976 | if( numq == 0 ) |
---|
| 977 | break; |
---|
| 978 | |
---|
| 979 | if( !q ) |
---|
| 980 | { |
---|
| 981 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 982 | return; |
---|
[b7d3cc34] | 983 | } |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 987 | query_answer( irc, q, 1 ); |
---|
| 988 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 989 | query_answer( irc, q, 0 ); |
---|
| 990 | } |
---|
| 991 | |
---|
[f73b969] | 992 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 993 | { |
---|
[e907683] | 994 | cmd_set_real( irc, cmd, &irc->b->set, NULL ); |
---|
[b7d3cc34] | 995 | } |
---|
| 996 | |
---|
[f73b969] | 997 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 998 | { |
---|
| 999 | int online = 0, away = 0, offline = 0; |
---|
[4c3519a] | 1000 | GSList *l; |
---|
[aefa533e] | 1001 | char s[256]; |
---|
| 1002 | char *format; |
---|
[b7d3cc34] | 1003 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 1004 | |
---|
| 1005 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 1006 | online = offline = away = 1; |
---|
| 1007 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 1008 | offline = 1; |
---|
| 1009 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 1010 | away = 1; |
---|
| 1011 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 1012 | online = 1; |
---|
| 1013 | else |
---|
[449a51d] | 1014 | online = away = 1; |
---|
[b7d3cc34] | 1015 | |
---|
[aefa533e] | 1016 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 1017 | format = "%s\t%s\t%s"; |
---|
| 1018 | else |
---|
| 1019 | format = "%-16.16s %-40.40s %s"; |
---|
| 1020 | |
---|
[4c3519a] | 1021 | irc_usermsg( irc, format, "Nick", "Handle/Account", "Status" ); |
---|
[b7d3cc34] | 1022 | |
---|
[acd7959] | 1023 | if( irc->root->last_channel && |
---|
| 1024 | strcmp( set_getstr( &irc->root->last_channel->set, "type" ), "control" ) != 0 ) |
---|
[ac2717b] | 1025 | irc->root->last_channel = NULL; |
---|
| 1026 | |
---|
[4c3519a] | 1027 | for( l = irc->users; l; l = l->next ) |
---|
[b7d3cc34] | 1028 | { |
---|
[4c3519a] | 1029 | irc_user_t *iu = l->data; |
---|
| 1030 | bee_user_t *bu = iu->bu; |
---|
| 1031 | |
---|
[ac2717b] | 1032 | if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) || |
---|
| 1033 | ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE ) |
---|
[4c3519a] | 1034 | continue; |
---|
| 1035 | |
---|
[aefa533e] | 1036 | if( online == 1 ) |
---|
| 1037 | { |
---|
[449a51d] | 1038 | char st[256] = "Online"; |
---|
| 1039 | |
---|
[4c3519a] | 1040 | if( bu->status_msg ) |
---|
| 1041 | g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg ); |
---|
[449a51d] | 1042 | |
---|
[4c3519a] | 1043 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
| 1044 | irc_usermsg( irc, format, iu->nick, s, st ); |
---|
[aefa533e] | 1045 | } |
---|
| 1046 | |
---|
[b7d3cc34] | 1047 | n_online ++; |
---|
| 1048 | } |
---|
| 1049 | |
---|
[4c3519a] | 1050 | for( l = irc->users; l; l = l->next ) |
---|
[b7d3cc34] | 1051 | { |
---|
[4c3519a] | 1052 | irc_user_t *iu = l->data; |
---|
| 1053 | bee_user_t *bu = iu->bu; |
---|
| 1054 | |
---|
[ac2717b] | 1055 | if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) || |
---|
| 1056 | !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) ) |
---|
[4c3519a] | 1057 | continue; |
---|
| 1058 | |
---|
[aefa533e] | 1059 | if( away == 1 ) |
---|
| 1060 | { |
---|
[4c3519a] | 1061 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
| 1062 | irc_usermsg( irc, format, iu->nick, s, irc_user_get_away( iu ) ); |
---|
[aefa533e] | 1063 | } |
---|
[b7d3cc34] | 1064 | n_away ++; |
---|
| 1065 | } |
---|
| 1066 | |
---|
[4c3519a] | 1067 | for( l = irc->users; l; l = l->next ) |
---|
[b7d3cc34] | 1068 | { |
---|
[4c3519a] | 1069 | irc_user_t *iu = l->data; |
---|
| 1070 | bee_user_t *bu = iu->bu; |
---|
| 1071 | |
---|
[ac2717b] | 1072 | if( !bu || ( irc->root->last_channel && !irc_channel_wants_user( irc->root->last_channel, iu ) ) || |
---|
| 1073 | bu->flags & BEE_USER_ONLINE ) |
---|
[4c3519a] | 1074 | continue; |
---|
| 1075 | |
---|
[aefa533e] | 1076 | if( offline == 1 ) |
---|
| 1077 | { |
---|
[4c3519a] | 1078 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
| 1079 | irc_usermsg( irc, format, iu->nick, s, "Offline" ); |
---|
[aefa533e] | 1080 | } |
---|
[b7d3cc34] | 1081 | n_offline ++; |
---|
| 1082 | } |
---|
| 1083 | |
---|
[aa5ac01] | 1084 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 1085 | } |
---|
| 1086 | |
---|
[f73b969] | 1087 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 1088 | { |
---|
| 1089 | query_t *q = irc->queries; |
---|
| 1090 | int num; |
---|
| 1091 | |
---|
| 1092 | if( !q ) |
---|
| 1093 | { |
---|
| 1094 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 1095 | return; |
---|
[b7d3cc34] | 1096 | } |
---|
| 1097 | |
---|
| 1098 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 1099 | |
---|
| 1100 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 1101 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 1102 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 1103 | else |
---|
| 1104 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 1105 | } |
---|
| 1106 | |
---|
[a9a7287] | 1107 | static void cmd_chat( irc_t *irc, char **cmd ) |
---|
| 1108 | { |
---|
| 1109 | account_t *acc; |
---|
| 1110 | |
---|
| 1111 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 1112 | { |
---|
[07054a5] | 1113 | char *channel, *s; |
---|
[7b71feb] | 1114 | struct irc_channel *ic; |
---|
[07054a5] | 1115 | |
---|
| 1116 | MIN_ARGS( 3 ); |
---|
[a9a7287] | 1117 | |
---|
[7b71feb] | 1118 | if( !( acc = account_get( irc->b, cmd[2] ) ) ) |
---|
[a9a7287] | 1119 | { |
---|
| 1120 | irc_usermsg( irc, "Invalid account" ); |
---|
| 1121 | return; |
---|
| 1122 | } |
---|
[5a75d15] | 1123 | else if( !acc->prpl->chat_join ) |
---|
| 1124 | { |
---|
| 1125 | irc_usermsg( irc, "Named chatrooms not supported on that account." ); |
---|
| 1126 | return; |
---|
| 1127 | } |
---|
[a9a7287] | 1128 | |
---|
[07054a5] | 1129 | if( cmd[4] == NULL ) |
---|
| 1130 | { |
---|
| 1131 | channel = g_strdup( cmd[3] ); |
---|
| 1132 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 1133 | *s = 0; |
---|
| 1134 | } |
---|
| 1135 | else |
---|
| 1136 | { |
---|
| 1137 | channel = g_strdup( cmd[4] ); |
---|
| 1138 | } |
---|
| 1139 | |
---|
| 1140 | if( strchr( CTYPES, channel[0] ) == NULL ) |
---|
| 1141 | { |
---|
[7b71feb] | 1142 | s = g_strdup_printf( "#%s", channel ); |
---|
[07054a5] | 1143 | g_free( channel ); |
---|
| 1144 | channel = s; |
---|
[134a02c] | 1145 | |
---|
| 1146 | irc_channel_name_strip( channel ); |
---|
[07054a5] | 1147 | } |
---|
| 1148 | |
---|
[5a75d15] | 1149 | if( ( ic = irc_channel_new( irc, channel ) ) && |
---|
[547ea68] | 1150 | set_setstr( &ic->set, "type", "chat" ) && |
---|
[5a75d15] | 1151 | set_setstr( &ic->set, "chat_type", "room" ) && |
---|
| 1152 | set_setstr( &ic->set, "account", cmd[2] ) && |
---|
| 1153 | set_setstr( &ic->set, "room", cmd[3] ) ) |
---|
| 1154 | { |
---|
| 1155 | irc_usermsg( irc, "Chatroom successfully added." ); |
---|
| 1156 | } |
---|
| 1157 | else |
---|
[a9a7287] | 1158 | { |
---|
[5a75d15] | 1159 | if( ic ) |
---|
| 1160 | irc_channel_free( ic ); |
---|
[a9a7287] | 1161 | |
---|
[5a75d15] | 1162 | irc_usermsg( irc, "Could not add chatroom." ); |
---|
[d995c9b] | 1163 | } |
---|
[d7db346] | 1164 | g_free( channel ); |
---|
[d995c9b] | 1165 | } |
---|
[39f93f0] | 1166 | else if( g_strcasecmp( cmd[1], "with" ) == 0 ) |
---|
| 1167 | { |
---|
[c1a8a16] | 1168 | irc_user_t *iu; |
---|
[3b99524] | 1169 | |
---|
| 1170 | MIN_ARGS( 2 ); |
---|
[39f93f0] | 1171 | |
---|
[c1a8a16] | 1172 | if( ( iu = irc_user_by_name( irc, cmd[2] ) ) && |
---|
| 1173 | iu->bu && iu->bu->ic->acc->prpl->chat_with ) |
---|
[39f93f0] | 1174 | { |
---|
[c1a8a16] | 1175 | if( !iu->bu->ic->acc->prpl->chat_with( iu->bu->ic, iu->bu->handle ) ) |
---|
[39f93f0] | 1176 | { |
---|
| 1177 | irc_usermsg( irc, "(Possible) failure while trying to open " |
---|
[c1a8a16] | 1178 | "a groupchat with %s.", iu->nick ); |
---|
[39f93f0] | 1179 | } |
---|
| 1180 | } |
---|
| 1181 | else |
---|
| 1182 | { |
---|
| 1183 | irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] ); |
---|
| 1184 | } |
---|
| 1185 | } |
---|
[7cd2e8a] | 1186 | else if( g_strcasecmp( cmd[1], "list" ) == 0 || |
---|
| 1187 | g_strcasecmp( cmd[1], "set" ) == 0 || |
---|
| 1188 | g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 1189 | { |
---|
| 1190 | irc_usermsg( irc, "Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command." ); |
---|
| 1191 | cmd_channel( irc, cmd ); |
---|
| 1192 | } |
---|
[a9a7287] | 1193 | else |
---|
| 1194 | { |
---|
| 1195 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); |
---|
| 1196 | } |
---|
[fa29d093] | 1197 | } |
---|
| 1198 | |
---|
[f1d488e] | 1199 | static void cmd_group( irc_t *irc, char **cmd ) |
---|
| 1200 | { |
---|
| 1201 | GSList *l; |
---|
| 1202 | int len; |
---|
| 1203 | |
---|
| 1204 | len = strlen( cmd[1] ); |
---|
| 1205 | if( g_strncasecmp( cmd[1], "list", len ) == 0 ) |
---|
| 1206 | { |
---|
| 1207 | int n = 0; |
---|
| 1208 | |
---|
| 1209 | if( strchr( irc->umode, 'b' ) ) |
---|
| 1210 | irc_usermsg( irc, "Group list:" ); |
---|
| 1211 | |
---|
| 1212 | for( l = irc->b->groups; l; l = l->next ) |
---|
| 1213 | { |
---|
| 1214 | bee_group_t *bg = l->data; |
---|
| 1215 | irc_usermsg( irc, "%d. %s", n ++, bg->name ); |
---|
| 1216 | } |
---|
| 1217 | irc_usermsg( irc, "End of group list" ); |
---|
| 1218 | } |
---|
| 1219 | else |
---|
| 1220 | { |
---|
| 1221 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "group", cmd[1] ); |
---|
| 1222 | } |
---|
| 1223 | } |
---|
| 1224 | |
---|
[b8a491d] | 1225 | static void cmd_transfer( irc_t *irc, char **cmd ) |
---|
[2c2df7d] | 1226 | { |
---|
| 1227 | GSList *files = irc->file_transfers; |
---|
| 1228 | enum { LIST, REJECT, CANCEL }; |
---|
| 1229 | int subcmd = LIST; |
---|
| 1230 | int fid; |
---|
| 1231 | |
---|
| 1232 | if( !files ) |
---|
| 1233 | { |
---|
| 1234 | irc_usermsg( irc, "No pending transfers" ); |
---|
| 1235 | return; |
---|
| 1236 | } |
---|
| 1237 | |
---|
[b8a491d] | 1238 | if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) |
---|
[2c2df7d] | 1239 | { |
---|
| 1240 | subcmd = REJECT; |
---|
| 1241 | } |
---|
[b8a491d] | 1242 | else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && |
---|
| 1243 | cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) |
---|
[2c2df7d] | 1244 | { |
---|
| 1245 | subcmd = CANCEL; |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | for( ; files; files = g_slist_next( files ) ) |
---|
| 1249 | { |
---|
| 1250 | file_transfer_t *file = files->data; |
---|
| 1251 | |
---|
| 1252 | switch( subcmd ) { |
---|
| 1253 | case LIST: |
---|
| 1254 | if ( file->status == FT_STATUS_LISTENING ) |
---|
| 1255 | irc_usermsg( irc, |
---|
| 1256 | "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); |
---|
| 1257 | else |
---|
| 1258 | { |
---|
| 1259 | int kb_per_s = 0; |
---|
[44961cb] | 1260 | time_t diff = time( NULL ) - file->started ? : 1; |
---|
[2c2df7d] | 1261 | if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) |
---|
| 1262 | kb_per_s = file->bytes_transferred / 1024 / diff; |
---|
| 1263 | |
---|
| 1264 | irc_usermsg( irc, |
---|
| 1265 | "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, |
---|
| 1266 | file->bytes_transferred/1024, file->file_size/1024, kb_per_s); |
---|
| 1267 | } |
---|
| 1268 | break; |
---|
| 1269 | case REJECT: |
---|
| 1270 | if( file->status == FT_STATUS_LISTENING ) |
---|
| 1271 | { |
---|
| 1272 | irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); |
---|
[9d4352c] | 1273 | imcb_file_canceled( file->ic, file, "Denied by user" ); |
---|
[2c2df7d] | 1274 | } |
---|
| 1275 | break; |
---|
| 1276 | case CANCEL: |
---|
| 1277 | if( file->local_id == fid ) |
---|
| 1278 | { |
---|
| 1279 | irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); |
---|
[9d4352c] | 1280 | imcb_file_canceled( file->ic, file, "Canceled by user" ); |
---|
[2c2df7d] | 1281 | } |
---|
| 1282 | break; |
---|
| 1283 | } |
---|
| 1284 | } |
---|
| 1285 | } |
---|
| 1286 | |
---|
[180ab31] | 1287 | /* Maybe this should be a stand-alone command as well? */ |
---|
| 1288 | static void bitlbee_whatsnew( irc_t *irc ) |
---|
| 1289 | { |
---|
| 1290 | int last = set_getint( &irc->b->set, "last_version" ); |
---|
| 1291 | GString *msg = g_string_new( "" ); |
---|
| 1292 | char s[16]; |
---|
| 1293 | |
---|
| 1294 | if( last >= BITLBEE_VERSION_CODE ) |
---|
| 1295 | return; |
---|
| 1296 | |
---|
| 1297 | if( last < 0x010206 ) /* 1.2.6 */ |
---|
| 1298 | { |
---|
| 1299 | g_string_append( msg, |
---|
| 1300 | "Twitter support. See \x02help account add twitter\x02.\n" ); |
---|
| 1301 | } |
---|
| 1302 | if( last < 0x010300 ) /* 1.3dev */ |
---|
| 1303 | { |
---|
| 1304 | g_string_append( msg, |
---|
| 1305 | "Support for multiple configurable control channels, " |
---|
| 1306 | "each with a subset of your contact list. See " |
---|
| 1307 | "\x02help channels\x02 for more information.\n" |
---|
| 1308 | "File transfer support for some protocols (more if " |
---|
| 1309 | "you use libpurple). Just /DCC SEND stuff. Incoming " |
---|
| 1310 | "files also become DCC transfers.\n" |
---|
| 1311 | "Many more things, briefly described in " |
---|
| 1312 | "\x02help news1.3\x02.\n" ); |
---|
| 1313 | } |
---|
| 1314 | |
---|
| 1315 | if( msg->len > 0 ) |
---|
| 1316 | irc_usermsg( irc, "%s: This seems to be your first time using this " |
---|
| 1317 | "this version of BitlBee. Here's a list of new " |
---|
| 1318 | "features you may like to know about:\n\n%s\n", |
---|
| 1319 | irc->user->nick, msg->str ); |
---|
| 1320 | |
---|
| 1321 | g_string_free( msg, TRUE ); |
---|
| 1322 | g_snprintf( s, sizeof( s ), "%d", BITLBEE_VERSION_CODE ); |
---|
| 1323 | set_setstr( &irc->b->set, "last_version", s ); |
---|
| 1324 | } |
---|
| 1325 | |
---|
[6c56f42] | 1326 | /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ |
---|
[0298d11] | 1327 | const command_t commands[] = { |
---|
[d860a8d] | 1328 | { "account", 1, cmd_account, 0 }, |
---|
[6c56f42] | 1329 | { "add", 2, cmd_add, 0 }, |
---|
[2272cb3] | 1330 | { "allow", 1, cmd_allow, 0 }, |
---|
[4c3519a] | 1331 | { "blist", 0, cmd_blist, 0 }, |
---|
[2272cb3] | 1332 | { "block", 1, cmd_block, 0 }, |
---|
[c133d4b8] | 1333 | { "channel", 1, cmd_channel, 0 }, |
---|
| 1334 | { "chat", 1, cmd_chat, 0 }, |
---|
[6c56f42] | 1335 | { "drop", 1, cmd_drop, 0 }, |
---|
[9d4352c] | 1336 | { "ft", 0, cmd_transfer, 0 }, |
---|
[f1d488e] | 1337 | { "group", 1, cmd_group, 0 }, |
---|
[6c56f42] | 1338 | { "help", 0, cmd_help, 0 }, |
---|
[0298d11] | 1339 | { "identify", 1, cmd_identify, 0 }, |
---|
[aa44bdd] | 1340 | { "info", 1, cmd_info, 0 }, |
---|
[6c56f42] | 1341 | { "no", 0, cmd_yesno, 0 }, |
---|
[be999a5] | 1342 | { "otr", 1, cmd_otr, 0 }, |
---|
[9d4352c] | 1343 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[0298d11] | 1344 | { "register", 1, cmd_register, 0 }, |
---|
[dbb0ce3] | 1345 | { "remove", 1, cmd_remove, 0 }, |
---|
[0298d11] | 1346 | { "rename", 2, cmd_rename, 0 }, |
---|
[6c56f42] | 1347 | { "save", 0, cmd_save, 0 }, |
---|
[0298d11] | 1348 | { "set", 0, cmd_set, 0 }, |
---|
[9d4352c] | 1349 | { "transfer", 0, cmd_transfer, 0 }, |
---|
[0298d11] | 1350 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 1351 | { NULL } |
---|
| 1352 | }; |
---|