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