[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" |
---|
[b75acf6] | 30 | #include "chat.h" |
---|
[b7d3cc34] | 31 | |
---|
| 32 | #include <string.h> |
---|
| 33 | |
---|
[280c56a] | 34 | void root_command_string( irc_t *irc, char *command ) |
---|
[7e563ed] | 35 | { |
---|
[24b8bbb] | 36 | root_command( irc, split_command_parts( command ) ); |
---|
[7e563ed] | 37 | } |
---|
| 38 | |
---|
[3b99524] | 39 | #define MIN_ARGS( x, y... ) \ |
---|
| 40 | do \ |
---|
| 41 | { \ |
---|
[07054a5] | 42 | int blaat; \ |
---|
| 43 | for( blaat = 0; blaat <= x; blaat ++ ) \ |
---|
| 44 | if( cmd[blaat] == NULL ) \ |
---|
[3b99524] | 45 | { \ |
---|
| 46 | irc_usermsg( irc, "Not enough parameters given (need %d).", x ); \ |
---|
| 47 | return y; \ |
---|
| 48 | } \ |
---|
| 49 | } while( 0 ) |
---|
| 50 | |
---|
[f73b969] | 51 | void root_command( irc_t *irc, char *cmd[] ) |
---|
[7e563ed] | 52 | { |
---|
[6c56f42] | 53 | int i, len; |
---|
[7e563ed] | 54 | |
---|
| 55 | if( !cmd[0] ) |
---|
[f73b969] | 56 | return; |
---|
[7e563ed] | 57 | |
---|
[6c56f42] | 58 | len = strlen( cmd[0] ); |
---|
[7e563ed] | 59 | for( i = 0; commands[i].command; i++ ) |
---|
[6c56f42] | 60 | if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 ) |
---|
[7e563ed] | 61 | { |
---|
[6c56f42] | 62 | if( commands[i+1].command && |
---|
| 63 | g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 ) |
---|
| 64 | /* Only match on the first letters if the match is unique. */ |
---|
| 65 | break; |
---|
| 66 | |
---|
[3b99524] | 67 | MIN_ARGS( commands[i].required_parameters ); |
---|
| 68 | |
---|
[7e563ed] | 69 | commands[i].execute( irc, cmd ); |
---|
[f73b969] | 70 | return; |
---|
[7e563ed] | 71 | } |
---|
| 72 | |
---|
| 73 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
| 74 | } |
---|
| 75 | |
---|
[f73b969] | 76 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 77 | { |
---|
| 78 | char param[80]; |
---|
| 79 | int i; |
---|
| 80 | char *s; |
---|
| 81 | |
---|
| 82 | memset( param, 0, sizeof(param) ); |
---|
| 83 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
| 84 | if ( i != 1 ) // prepend space except for the first parameter |
---|
| 85 | strcat(param, " "); |
---|
| 86 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | s = help_get( &(global.help), param ); |
---|
| 90 | if( !s ) s = help_get( &(global.help), "" ); |
---|
| 91 | |
---|
| 92 | if( s ) |
---|
| 93 | { |
---|
| 94 | irc_usermsg( irc, "%s", s ); |
---|
| 95 | g_free( s ); |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[90bbb0e] | 103 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
| 104 | |
---|
[f73b969] | 105 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 106 | { |
---|
[3183c21] | 107 | storage_status_t status = storage_load( irc, cmd[1] ); |
---|
[90bbb0e] | 108 | char *account_on[] = { "account", "on", NULL }; |
---|
[b7d3cc34] | 109 | |
---|
[e9cf291] | 110 | if( strchr( irc->umode, 'R' ) != NULL ) |
---|
| 111 | { |
---|
| 112 | irc_usermsg( irc, "You're already logged in." ); |
---|
| 113 | return; |
---|
| 114 | } |
---|
| 115 | |
---|
[09adf08] | 116 | switch (status) { |
---|
| 117 | case STORAGE_INVALID_PASSWORD: |
---|
[b7d3cc34] | 118 | irc_usermsg( irc, "Incorrect password" ); |
---|
[09adf08] | 119 | break; |
---|
| 120 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 121 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
[09adf08] | 122 | break; |
---|
| 123 | case STORAGE_OK: |
---|
[6ee9d2d] | 124 | irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); |
---|
[3183c21] | 125 | irc_setpass( irc, cmd[1] ); |
---|
| 126 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 127 | irc_umode_set( irc, "+R", 1 ); |
---|
[1f92a58] | 128 | if( set_getbool( &irc->b->set, "auto_connect" ) ) |
---|
[90bbb0e] | 129 | cmd_account( irc, account_on ); |
---|
[09adf08] | 130 | break; |
---|
[c121f89] | 131 | case STORAGE_OTHER_ERROR: |
---|
[09adf08] | 132 | default: |
---|
[c121f89] | 133 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
[09adf08] | 134 | break; |
---|
[b7d3cc34] | 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
[f73b969] | 138 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 139 | { |
---|
| 140 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
| 141 | { |
---|
| 142 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
[f73b969] | 143 | return; |
---|
[b7d3cc34] | 144 | } |
---|
[1ee6c18] | 145 | |
---|
[3183c21] | 146 | switch( storage_save( irc, cmd[1], FALSE ) ) { |
---|
[a1f17d4] | 147 | case STORAGE_ALREADY_EXISTS: |
---|
| 148 | irc_usermsg( irc, "Nick is already registered" ); |
---|
| 149 | break; |
---|
| 150 | |
---|
| 151 | case STORAGE_OK: |
---|
[0383943] | 152 | irc_usermsg( irc, "Account successfully created" ); |
---|
[3183c21] | 153 | irc_setpass( irc, cmd[1] ); |
---|
[79e826a] | 154 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 155 | irc_umode_set( irc, "+R", 1 ); |
---|
[a1f17d4] | 156 | break; |
---|
| 157 | |
---|
| 158 | default: |
---|
| 159 | irc_usermsg( irc, "Error registering" ); |
---|
| 160 | break; |
---|
[b7d3cc34] | 161 | } |
---|
| 162 | } |
---|
| 163 | |
---|
[f73b969] | 164 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 165 | { |
---|
[a1f17d4] | 166 | storage_status_t status; |
---|
| 167 | |
---|
[1f92a58] | 168 | status = storage_remove (irc->user->nick, cmd[1]); |
---|
[a1f17d4] | 169 | switch (status) { |
---|
| 170 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 171 | irc_usermsg( irc, "That account does not exist" ); |
---|
[f73b969] | 172 | break; |
---|
[a1f17d4] | 173 | case STORAGE_INVALID_PASSWORD: |
---|
[1ee6c18] | 174 | irc_usermsg( irc, "Password invalid" ); |
---|
[f73b969] | 175 | break; |
---|
[a1f17d4] | 176 | case STORAGE_OK: |
---|
[7cad7b4] | 177 | irc_setpass( irc, NULL ); |
---|
[79e826a] | 178 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[238f828] | 179 | irc_umode_set( irc, "-R", 1 ); |
---|
[1f92a58] | 180 | irc_usermsg( irc, "Account `%s' removed", irc->user->nick ); |
---|
[f73b969] | 181 | break; |
---|
[a1f17d4] | 182 | default: |
---|
[30ce1ce] | 183 | irc_usermsg( irc, "Error: `%d'", status ); |
---|
[f73b969] | 184 | break; |
---|
[b7d3cc34] | 185 | } |
---|
| 186 | } |
---|
[1f92a58] | 187 | |
---|
| 188 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
| 189 | { |
---|
| 190 | if( ( irc->status & USTATUS_IDENTIFIED ) == 0 ) |
---|
| 191 | irc_usermsg( irc, "Please create an account first" ); |
---|
| 192 | else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK ) |
---|
| 193 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 194 | else |
---|
| 195 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 196 | } |
---|
[b7d3cc34] | 197 | |
---|
[f35aee7] | 198 | struct cmd_account_del_data |
---|
[7f421d6] | 199 | { |
---|
[f35aee7] | 200 | account_t *a; |
---|
| 201 | irc_t *irc; |
---|
| 202 | }; |
---|
| 203 | |
---|
| 204 | void cmd_account_del_yes( void *data ) |
---|
| 205 | { |
---|
| 206 | struct cmd_account_del_data *cad = data; |
---|
| 207 | account_t *a; |
---|
[7f421d6] | 208 | |
---|
[d860a8d] | 209 | for( a = cad->irc->b->accounts; a && a != cad->a; a = a->next ); |
---|
[f35aee7] | 210 | |
---|
| 211 | if( a == NULL ) |
---|
| 212 | { |
---|
| 213 | irc_usermsg( cad->irc, "Account already deleted" ); |
---|
| 214 | } |
---|
| 215 | else if( a->ic ) |
---|
[7f421d6] | 216 | { |
---|
[f35aee7] | 217 | irc_usermsg( cad->irc, "Account is still logged in, can't delete" ); |
---|
[7f421d6] | 218 | } |
---|
| 219 | else |
---|
| 220 | { |
---|
[d860a8d] | 221 | account_del( cad->irc->b, a ); |
---|
[f35aee7] | 222 | irc_usermsg( cad->irc, "Account deleted" ); |
---|
[7f421d6] | 223 | } |
---|
[f35aee7] | 224 | g_free( data ); |
---|
[7f421d6] | 225 | } |
---|
| 226 | |
---|
[f35aee7] | 227 | void cmd_account_del_no( void *data ) |
---|
[7f421d6] | 228 | { |
---|
[8dbe021f] | 229 | g_free( data ); |
---|
[7f421d6] | 230 | } |
---|
| 231 | |
---|
[f536a99] | 232 | static void cmd_showset( irc_t *irc, set_t **head, char *key ) |
---|
[f3579fd] | 233 | { |
---|
[f536a99] | 234 | char *val; |
---|
[f3579fd] | 235 | |
---|
[f536a99] | 236 | if( ( val = set_getstr( head, key ) ) ) |
---|
| 237 | irc_usermsg( irc, "%s = `%s'", key, val ); |
---|
[f3579fd] | 238 | else |
---|
[f536a99] | 239 | irc_usermsg( irc, "%s is empty", key ); |
---|
[f3579fd] | 240 | } |
---|
| 241 | |
---|
[e7bc722] | 242 | typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); |
---|
[c05eb5b] | 243 | typedef int (*cmd_set_checkflags)( irc_t*, set_t *set ); |
---|
[e7bc722] | 244 | |
---|
[c05eb5b] | 245 | static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead, cmd_set_checkflags checkflags ) |
---|
[e7bc722] | 246 | { |
---|
| 247 | char *set_full = NULL, *set_name = NULL, *tmp; |
---|
| 248 | set_t **head; |
---|
| 249 | |
---|
| 250 | if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
[d4810df] | 251 | { |
---|
| 252 | MIN_ARGS( 2, 0 ); |
---|
[e7bc722] | 253 | set_full = cmd[2]; |
---|
[d4810df] | 254 | } |
---|
[e7bc722] | 255 | else |
---|
| 256 | set_full = cmd[1]; |
---|
| 257 | |
---|
| 258 | if( findhead == NULL ) |
---|
| 259 | { |
---|
| 260 | set_name = set_full; |
---|
| 261 | |
---|
[d860a8d] | 262 | head = &irc->b->set; |
---|
[e7bc722] | 263 | } |
---|
| 264 | else |
---|
| 265 | { |
---|
| 266 | char *id; |
---|
| 267 | |
---|
| 268 | if( ( tmp = strchr( set_full, '/' ) ) ) |
---|
| 269 | { |
---|
| 270 | id = g_strndup( set_full, ( tmp - set_full ) ); |
---|
| 271 | set_name = tmp + 1; |
---|
| 272 | } |
---|
| 273 | else |
---|
| 274 | { |
---|
| 275 | id = g_strdup( set_full ); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | if( ( head = findhead( irc, id ) ) == NULL ) |
---|
| 279 | { |
---|
| 280 | g_free( id ); |
---|
| 281 | irc_usermsg( irc, "Could not find setting." ); |
---|
| 282 | return 0; |
---|
| 283 | } |
---|
| 284 | g_free( id ); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | if( cmd[1] && cmd[2] && set_name ) |
---|
| 288 | { |
---|
| 289 | set_t *s = set_find( head, set_name ); |
---|
| 290 | int st; |
---|
| 291 | |
---|
[8a08d92] | 292 | if( s && checkflags && checkflags( irc, s ) == 0 ) |
---|
[e7bc722] | 293 | return 0; |
---|
| 294 | |
---|
| 295 | if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
| 296 | st = set_reset( head, set_name ); |
---|
| 297 | else |
---|
| 298 | st = set_setstr( head, set_name, cmd[2] ); |
---|
| 299 | |
---|
| 300 | if( set_getstr( head, set_name ) == NULL ) |
---|
| 301 | { |
---|
| 302 | if( st ) |
---|
| 303 | irc_usermsg( irc, "Setting changed successfully" ); |
---|
| 304 | else |
---|
| 305 | irc_usermsg( irc, "Failed to change setting" ); |
---|
| 306 | } |
---|
| 307 | else |
---|
| 308 | { |
---|
| 309 | cmd_showset( irc, head, set_name ); |
---|
| 310 | } |
---|
| 311 | } |
---|
| 312 | else if( set_name ) |
---|
| 313 | { |
---|
| 314 | cmd_showset( irc, head, set_name ); |
---|
| 315 | } |
---|
| 316 | else |
---|
| 317 | { |
---|
| 318 | set_t *s = *head; |
---|
| 319 | while( s ) |
---|
| 320 | { |
---|
| 321 | cmd_showset( irc, &s, s->key ); |
---|
| 322 | s = s->next; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | return 1; |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | static set_t **cmd_account_set_findhead( irc_t *irc, char *id ) |
---|
| 330 | { |
---|
| 331 | account_t *a; |
---|
| 332 | |
---|
[d860a8d] | 333 | if( ( a = account_get( irc->b, id ) ) ) |
---|
[e7bc722] | 334 | return &a->set; |
---|
| 335 | else |
---|
| 336 | return NULL; |
---|
| 337 | } |
---|
| 338 | |
---|
[c05eb5b] | 339 | static int cmd_account_set_checkflags( irc_t *irc, set_t *s ) |
---|
| 340 | { |
---|
| 341 | account_t *a = s->data; |
---|
| 342 | |
---|
| 343 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
| 344 | { |
---|
| 345 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 346 | return 0; |
---|
| 347 | } |
---|
| 348 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
| 349 | { |
---|
| 350 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
| 351 | return 0; |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | return 1; |
---|
| 355 | } |
---|
| 356 | |
---|
[f73b969] | 357 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 358 | { |
---|
| 359 | account_t *a; |
---|
| 360 | |
---|
[3af70b0] | 361 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 362 | { |
---|
| 363 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 364 | return; |
---|
[b7d3cc34] | 365 | } |
---|
| 366 | |
---|
| 367 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 368 | { |
---|
[7b23afd] | 369 | struct prpl *prpl; |
---|
[b7d3cc34] | 370 | |
---|
[3b99524] | 371 | MIN_ARGS( 4 ); |
---|
[b7d3cc34] | 372 | |
---|
[a9a7287] | 373 | prpl = find_protocol( cmd[2] ); |
---|
[b7d3cc34] | 374 | |
---|
[7b23afd] | 375 | if( prpl == NULL ) |
---|
[b7d3cc34] | 376 | { |
---|
| 377 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 378 | return; |
---|
[b7d3cc34] | 379 | } |
---|
| 380 | |
---|
[d860a8d] | 381 | a = account_add( irc->b, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 382 | if( cmd[5] ) |
---|
[30ce1ce] | 383 | { |
---|
| 384 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
| 385 | "is now deprecated. Use `account set' instead." ); |
---|
[5100caa] | 386 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[30ce1ce] | 387 | } |
---|
[b7d3cc34] | 388 | |
---|
| 389 | irc_usermsg( irc, "Account successfully added" ); |
---|
| 390 | } |
---|
| 391 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 392 | { |
---|
[3b99524] | 393 | MIN_ARGS( 2 ); |
---|
| 394 | |
---|
[d860a8d] | 395 | if( !( a = account_get( irc->b, cmd[2] ) ) ) |
---|
[b7d3cc34] | 396 | { |
---|
| 397 | irc_usermsg( irc, "Invalid account" ); |
---|
| 398 | } |
---|
[0da65d5] | 399 | else if( a->ic ) |
---|
[b7d3cc34] | 400 | { |
---|
| 401 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
| 402 | } |
---|
| 403 | else |
---|
| 404 | { |
---|
[f35aee7] | 405 | struct cmd_account_del_data *cad; |
---|
[7f421d6] | 406 | char *msg; |
---|
| 407 | |
---|
[f35aee7] | 408 | cad = g_malloc( sizeof( struct cmd_account_del_data ) ); |
---|
| 409 | cad->a = a; |
---|
| 410 | cad->irc = irc; |
---|
[8dbe021f] | 411 | |
---|
[7f421d6] | 412 | msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " |
---|
| 413 | "also forget all your saved nicknames. If you want " |
---|
| 414 | "to change your username/password, use the `account " |
---|
| 415 | "set' command. Are you sure you want to delete this " |
---|
| 416 | "account?", a->prpl->name, a->user ); |
---|
[d860a8d] | 417 | //query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); |
---|
[7f421d6] | 418 | g_free( msg ); |
---|
[b7d3cc34] | 419 | } |
---|
| 420 | } |
---|
| 421 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 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 | |
---|
[7b23afd] | 441 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 442 | |
---|
| 443 | i ++; |
---|
| 444 | } |
---|
| 445 | irc_usermsg( irc, "End of account list" ); |
---|
| 446 | } |
---|
| 447 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
| 448 | { |
---|
| 449 | if( cmd[2] ) |
---|
| 450 | { |
---|
[d860a8d] | 451 | if( ( a = account_get( irc->b, cmd[2] ) ) ) |
---|
[b7d3cc34] | 452 | { |
---|
[0da65d5] | 453 | if( a->ic ) |
---|
[b7d3cc34] | 454 | { |
---|
| 455 | irc_usermsg( irc, "Account already online" ); |
---|
[f73b969] | 456 | return; |
---|
[b7d3cc34] | 457 | } |
---|
| 458 | else |
---|
| 459 | { |
---|
[d860a8d] | 460 | account_on( irc->b, a ); |
---|
[b7d3cc34] | 461 | } |
---|
| 462 | } |
---|
| 463 | else |
---|
| 464 | { |
---|
| 465 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 466 | return; |
---|
[b7d3cc34] | 467 | } |
---|
| 468 | } |
---|
| 469 | else |
---|
| 470 | { |
---|
[d860a8d] | 471 | if ( irc->b->accounts ) |
---|
| 472 | { |
---|
[b7d3cc34] | 473 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 474 | |
---|
[d860a8d] | 475 | for( a = irc->b->accounts; a; a = a->next ) |
---|
[0da65d5] | 476 | if( !a->ic && a->auto_connect ) |
---|
[d860a8d] | 477 | account_on( irc->b, a ); |
---|
[b7d3cc34] | 478 | } |
---|
| 479 | else |
---|
| 480 | { |
---|
[30ce1ce] | 481 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
[b7d3cc34] | 482 | } |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
| 486 | { |
---|
| 487 | if( !cmd[2] ) |
---|
| 488 | { |
---|
| 489 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 490 | |
---|
[d860a8d] | 491 | for( a = irc->b->accounts; a; a = a->next ) |
---|
[b7d3cc34] | 492 | { |
---|
[0da65d5] | 493 | if( a->ic ) |
---|
[d860a8d] | 494 | account_off( irc->b, a ); |
---|
[b7d3cc34] | 495 | else if( a->reconnect ) |
---|
| 496 | cancel_auto_reconnect( a ); |
---|
| 497 | } |
---|
| 498 | } |
---|
[d860a8d] | 499 | else if( ( a = account_get( irc->b, cmd[2] ) ) ) |
---|
[b7d3cc34] | 500 | { |
---|
[0da65d5] | 501 | if( a->ic ) |
---|
[b7d3cc34] | 502 | { |
---|
[d860a8d] | 503 | account_off( irc->b, a ); |
---|
[b7d3cc34] | 504 | } |
---|
| 505 | else if( a->reconnect ) |
---|
| 506 | { |
---|
| 507 | cancel_auto_reconnect( a ); |
---|
| 508 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 509 | } |
---|
| 510 | else |
---|
| 511 | { |
---|
| 512 | irc_usermsg( irc, "Account already offline" ); |
---|
[f73b969] | 513 | return; |
---|
[b7d3cc34] | 514 | } |
---|
| 515 | } |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 519 | return; |
---|
[b7d3cc34] | 520 | } |
---|
| 521 | } |
---|
[5100caa] | 522 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 523 | { |
---|
[3b99524] | 524 | MIN_ARGS( 2 ); |
---|
[5100caa] | 525 | |
---|
[c05eb5b] | 526 | cmd_set_real( irc, cmd + 1, cmd_account_set_findhead, cmd_account_set_checkflags ); |
---|
[5100caa] | 527 | } |
---|
[b7d3cc34] | 528 | else |
---|
| 529 | { |
---|
[a9a7287] | 530 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] ); |
---|
[b7d3cc34] | 531 | } |
---|
| 532 | } |
---|
| 533 | |
---|
[f73b969] | 534 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 535 | { |
---|
| 536 | account_t *a; |
---|
[f0cb961] | 537 | int add_on_server = 1; |
---|
[f8de26f] | 538 | |
---|
| 539 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 540 | { |
---|
[77fc000c] | 541 | MIN_ARGS( 3 ); |
---|
[f0cb961] | 542 | add_on_server = 0; |
---|
[7adc657] | 543 | cmd ++; |
---|
[f8de26f] | 544 | } |
---|
[b7d3cc34] | 545 | |
---|
[dbb0ce3] | 546 | if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 547 | { |
---|
| 548 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 549 | return; |
---|
[b7d3cc34] | 550 | } |
---|
[0da65d5] | 551 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 552 | { |
---|
| 553 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 554 | return; |
---|
[b7d3cc34] | 555 | } |
---|
| 556 | |
---|
| 557 | if( cmd[3] ) |
---|
| 558 | { |
---|
| 559 | if( !nick_ok( cmd[3] ) ) |
---|
| 560 | { |
---|
| 561 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 562 | return; |
---|
[b7d3cc34] | 563 | } |
---|
[dbb0ce3] | 564 | else if( irc_user_by_name( irc, cmd[3] ) ) |
---|
[b7d3cc34] | 565 | { |
---|
| 566 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 567 | return; |
---|
[b7d3cc34] | 568 | } |
---|
| 569 | else |
---|
| 570 | { |
---|
[5b52a48] | 571 | nick_set( a, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 572 | } |
---|
| 573 | } |
---|
[f8de26f] | 574 | |
---|
[f0cb961] | 575 | if( add_on_server ) |
---|
[0da65d5] | 576 | a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); |
---|
[7adc657] | 577 | else |
---|
[dbb0ce3] | 578 | /* Only for add -tmp. For regular adds, this callback will |
---|
| 579 | be called once the IM server confirms. */ |
---|
| 580 | bee_user_new( irc->b, a->ic, cmd[2] ); |
---|
[f0cb961] | 581 | |
---|
| 582 | irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); |
---|
[b7d3cc34] | 583 | } |
---|
| 584 | |
---|
[dbb0ce3] | 585 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
| 586 | { |
---|
| 587 | irc_user_t *iu; |
---|
| 588 | bee_user_t *bu; |
---|
| 589 | char *s; |
---|
| 590 | |
---|
| 591 | if( !( iu = irc_user_by_name( irc, cmd[1] ) ) || !( bu = iu->bu ) ) |
---|
| 592 | { |
---|
| 593 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
| 594 | return; |
---|
| 595 | } |
---|
| 596 | s = g_strdup( bu->handle ); |
---|
| 597 | |
---|
| 598 | bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL ); |
---|
| 599 | nick_del( bu->ic->acc, bu->handle ); |
---|
[eabc9d2] | 600 | //TODO(wilmer): bee_user_free() and/or let the IM mod do it? irc_user_free( irc, cmd[1] ); |
---|
[dbb0ce3] | 601 | |
---|
| 602 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 603 | g_free( s ); |
---|
| 604 | |
---|
| 605 | return; |
---|
| 606 | } |
---|
| 607 | |
---|
[f73b969] | 608 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 609 | { |
---|
[0da65d5] | 610 | struct im_connection *ic; |
---|
[b7d3cc34] | 611 | account_t *a; |
---|
| 612 | |
---|
| 613 | if( !cmd[2] ) |
---|
| 614 | { |
---|
[aa44bdd] | 615 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 616 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 617 | { |
---|
| 618 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 619 | return; |
---|
[b7d3cc34] | 620 | } |
---|
[aa44bdd] | 621 | ic = iu->bu->ic; |
---|
| 622 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 623 | } |
---|
[aa44bdd] | 624 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 625 | { |
---|
| 626 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 627 | return; |
---|
[b7d3cc34] | 628 | } |
---|
[0da65d5] | 629 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 630 | { |
---|
| 631 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 632 | return; |
---|
[b7d3cc34] | 633 | } |
---|
| 634 | |
---|
[0da65d5] | 635 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 636 | { |
---|
| 637 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 638 | } |
---|
[f73b969] | 639 | else |
---|
| 640 | { |
---|
[0da65d5] | 641 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 642 | } |
---|
[b7d3cc34] | 643 | } |
---|
| 644 | |
---|
[f73b969] | 645 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 646 | { |
---|
[57c96f7] | 647 | irc_user_t *iu; |
---|
[b7d3cc34] | 648 | |
---|
[57c96f7] | 649 | iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 650 | |
---|
| 651 | if( iu == NULL ) |
---|
[0baed0d] | 652 | { |
---|
[57c96f7] | 653 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[0baed0d] | 654 | } |
---|
[57c96f7] | 655 | else if( iu == irc->user ) |
---|
[b7d3cc34] | 656 | { |
---|
[57c96f7] | 657 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
[b7d3cc34] | 658 | } |
---|
[f73b969] | 659 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 660 | { |
---|
| 661 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 662 | } |
---|
[57c96f7] | 663 | else if( irc_user_by_name( irc, cmd[2] ) ) |
---|
[b7d3cc34] | 664 | { |
---|
[57c96f7] | 665 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
[b7d3cc34] | 666 | } |
---|
[f73b969] | 667 | else |
---|
[b7d3cc34] | 668 | { |
---|
[57c96f7] | 669 | if( !irc_user_set_nick( iu, cmd[2] ) ) |
---|
| 670 | { |
---|
| 671 | irc_usermsg( irc, "Error while changing nick" ); |
---|
| 672 | return; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | if( iu == irc->root ) |
---|
[f73b969] | 676 | { |
---|
[7125cb3] | 677 | /* If we're called internally (user did "set root_nick"), |
---|
| 678 | let's not go O(INF). :-) */ |
---|
[1195cec] | 679 | if( strcmp( cmd[0], "set_rename" ) != 0 ) |
---|
[57c96f7] | 680 | set_setstr( &irc->b->set, "root_nick", cmd[2] ); |
---|
[f73b969] | 681 | } |
---|
[57c96f7] | 682 | else if( iu->bu ) |
---|
[f73b969] | 683 | { |
---|
[57c96f7] | 684 | nick_set( iu->bu->ic->acc, iu->bu->handle, cmd[2] ); |
---|
[f73b969] | 685 | } |
---|
| 686 | |
---|
| 687 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 688 | } |
---|
| 689 | } |
---|
| 690 | |
---|
[57c96f7] | 691 | #if 0 |
---|
[1195cec] | 692 | char *set_eval_root_nick( set_t *set, char *new_nick ) |
---|
| 693 | { |
---|
| 694 | irc_t *irc = set->data; |
---|
| 695 | |
---|
| 696 | if( strcmp( irc->mynick, new_nick ) != 0 ) |
---|
| 697 | { |
---|
| 698 | char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL }; |
---|
| 699 | |
---|
| 700 | cmd_rename( irc, cmd ); |
---|
| 701 | } |
---|
| 702 | |
---|
[7125cb3] | 703 | return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID; |
---|
[1195cec] | 704 | } |
---|
| 705 | |
---|
[0baed0d] | 706 | char *set_eval_control_channel( set_t *set, char *new_name ) |
---|
| 707 | { |
---|
| 708 | irc_t *irc = set->data; |
---|
| 709 | |
---|
| 710 | if( strcmp( irc->channel, new_name ) != 0 ) |
---|
| 711 | { |
---|
| 712 | char *cmd[] = { "set_rename", irc->channel, new_name, NULL }; |
---|
| 713 | |
---|
| 714 | cmd_rename( irc, cmd ); |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | return strcmp( irc->channel, new_name ) == 0 ? new_name : SET_INVALID; |
---|
| 718 | } |
---|
| 719 | |
---|
[f73b969] | 720 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 721 | { |
---|
[0da65d5] | 722 | struct im_connection *ic; |
---|
[b7d3cc34] | 723 | account_t *a; |
---|
| 724 | |
---|
[0da65d5] | 725 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 726 | { |
---|
| 727 | char *format; |
---|
| 728 | GSList *l; |
---|
| 729 | |
---|
| 730 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 731 | format = "%s\t%s"; |
---|
| 732 | else |
---|
[57ef864] | 733 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 734 | |
---|
| 735 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 736 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 737 | { |
---|
[0da65d5] | 738 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 739 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 740 | } |
---|
| 741 | irc_usermsg( irc, "End of list." ); |
---|
| 742 | |
---|
| 743 | return; |
---|
| 744 | } |
---|
| 745 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 746 | { |
---|
| 747 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 748 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 749 | { |
---|
| 750 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 751 | return; |
---|
[b7d3cc34] | 752 | } |
---|
[0da65d5] | 753 | ic = u->ic; |
---|
[b7d3cc34] | 754 | cmd[2] = u->handle; |
---|
| 755 | } |
---|
| 756 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 757 | { |
---|
| 758 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 759 | return; |
---|
[b7d3cc34] | 760 | } |
---|
[0da65d5] | 761 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 762 | { |
---|
| 763 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 764 | return; |
---|
[b7d3cc34] | 765 | } |
---|
| 766 | |
---|
[0da65d5] | 767 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 768 | { |
---|
| 769 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 770 | } |
---|
| 771 | else |
---|
| 772 | { |
---|
[84b045d] | 773 | imc_rem_allow( ic, cmd[2] ); |
---|
| 774 | imc_add_block( ic, cmd[2] ); |
---|
[da3b536] | 775 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
[b7d3cc34] | 776 | } |
---|
| 777 | } |
---|
| 778 | |
---|
[f73b969] | 779 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 780 | { |
---|
[0da65d5] | 781 | struct im_connection *ic; |
---|
[b7d3cc34] | 782 | account_t *a; |
---|
| 783 | |
---|
[0da65d5] | 784 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 785 | { |
---|
| 786 | char *format; |
---|
| 787 | GSList *l; |
---|
| 788 | |
---|
| 789 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 790 | format = "%s\t%s"; |
---|
| 791 | else |
---|
[57ef864] | 792 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 793 | |
---|
| 794 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 795 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 796 | { |
---|
[0da65d5] | 797 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 798 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 799 | } |
---|
| 800 | irc_usermsg( irc, "End of list." ); |
---|
| 801 | |
---|
| 802 | return; |
---|
| 803 | } |
---|
| 804 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 805 | { |
---|
| 806 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 807 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 808 | { |
---|
| 809 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 810 | return; |
---|
[b7d3cc34] | 811 | } |
---|
[0da65d5] | 812 | ic = u->ic; |
---|
[b7d3cc34] | 813 | cmd[2] = u->handle; |
---|
| 814 | } |
---|
| 815 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 816 | { |
---|
| 817 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 818 | return; |
---|
[b7d3cc34] | 819 | } |
---|
[0da65d5] | 820 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 821 | { |
---|
| 822 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 823 | return; |
---|
[b7d3cc34] | 824 | } |
---|
| 825 | |
---|
[0da65d5] | 826 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 827 | { |
---|
| 828 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 829 | } |
---|
| 830 | else |
---|
| 831 | { |
---|
[84b045d] | 832 | imc_rem_block( ic, cmd[2] ); |
---|
| 833 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 834 | |
---|
[da3b536] | 835 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
[b7d3cc34] | 836 | } |
---|
| 837 | } |
---|
[dbb0ce3] | 838 | #endif |
---|
[b7d3cc34] | 839 | |
---|
[f73b969] | 840 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 841 | { |
---|
| 842 | query_t *q = NULL; |
---|
| 843 | int numq = 0; |
---|
| 844 | |
---|
| 845 | if( irc->queries == NULL ) |
---|
| 846 | { |
---|
| 847 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 848 | return; |
---|
[b7d3cc34] | 849 | } |
---|
| 850 | |
---|
| 851 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 852 | first/last (depending on the query_order setting) one. */ |
---|
| 853 | if( cmd[1] ) |
---|
| 854 | { |
---|
| 855 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 856 | { |
---|
| 857 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 858 | return; |
---|
[b7d3cc34] | 859 | } |
---|
| 860 | |
---|
| 861 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 862 | if( numq == 0 ) |
---|
| 863 | break; |
---|
| 864 | |
---|
| 865 | if( !q ) |
---|
| 866 | { |
---|
| 867 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 868 | return; |
---|
[b7d3cc34] | 869 | } |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 873 | query_answer( irc, q, 1 ); |
---|
| 874 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 875 | query_answer( irc, q, 0 ); |
---|
| 876 | } |
---|
| 877 | |
---|
[f73b969] | 878 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 879 | { |
---|
[c05eb5b] | 880 | cmd_set_real( irc, cmd, NULL, NULL ); |
---|
[b7d3cc34] | 881 | } |
---|
| 882 | |
---|
[dbb0ce3] | 883 | #if 0 |
---|
[f73b969] | 884 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 885 | { |
---|
| 886 | int online = 0, away = 0, offline = 0; |
---|
| 887 | user_t *u; |
---|
[aefa533e] | 888 | char s[256]; |
---|
| 889 | char *format; |
---|
[b7d3cc34] | 890 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 891 | |
---|
| 892 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 893 | online = offline = away = 1; |
---|
| 894 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 895 | offline = 1; |
---|
| 896 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 897 | away = 1; |
---|
| 898 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 899 | online = 1; |
---|
| 900 | else |
---|
[449a51d] | 901 | online = away = 1; |
---|
[b7d3cc34] | 902 | |
---|
[aefa533e] | 903 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 904 | format = "%s\t%s\t%s"; |
---|
| 905 | else |
---|
| 906 | format = "%-16.16s %-40.40s %s"; |
---|
| 907 | |
---|
| 908 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 909 | |
---|
[0da65d5] | 910 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 911 | { |
---|
[aefa533e] | 912 | if( online == 1 ) |
---|
| 913 | { |
---|
[449a51d] | 914 | char st[256] = "Online"; |
---|
| 915 | |
---|
| 916 | if( u->status_msg ) |
---|
| 917 | g_snprintf( st, sizeof( st ) - 1, "Online (%s)", u->status_msg ); |
---|
| 918 | |
---|
[e731120] | 919 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[449a51d] | 920 | irc_usermsg( irc, format, u->nick, s, st ); |
---|
[aefa533e] | 921 | } |
---|
| 922 | |
---|
[b7d3cc34] | 923 | n_online ++; |
---|
| 924 | } |
---|
| 925 | |
---|
[0da65d5] | 926 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
[b7d3cc34] | 927 | { |
---|
[aefa533e] | 928 | if( away == 1 ) |
---|
| 929 | { |
---|
[e731120] | 930 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 931 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 932 | } |
---|
[b7d3cc34] | 933 | n_away ++; |
---|
| 934 | } |
---|
| 935 | |
---|
[0da65d5] | 936 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
[b7d3cc34] | 937 | { |
---|
[aefa533e] | 938 | if( offline == 1 ) |
---|
| 939 | { |
---|
[e731120] | 940 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 941 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 942 | } |
---|
[b7d3cc34] | 943 | n_offline ++; |
---|
| 944 | } |
---|
| 945 | |
---|
[aa5ac01] | 946 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 947 | } |
---|
| 948 | |
---|
[f73b969] | 949 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 950 | { |
---|
| 951 | query_t *q = irc->queries; |
---|
| 952 | int num; |
---|
| 953 | |
---|
| 954 | if( !q ) |
---|
| 955 | { |
---|
| 956 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 957 | return; |
---|
[b7d3cc34] | 958 | } |
---|
| 959 | |
---|
| 960 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 961 | |
---|
| 962 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 963 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 964 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 965 | else |
---|
| 966 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 967 | } |
---|
| 968 | |
---|
[e7bc722] | 969 | static set_t **cmd_chat_set_findhead( irc_t *irc, char *id ) |
---|
| 970 | { |
---|
| 971 | struct chat *c; |
---|
| 972 | |
---|
| 973 | if( ( c = chat_get( irc, id ) ) ) |
---|
| 974 | return &c->set; |
---|
| 975 | else |
---|
| 976 | return NULL; |
---|
| 977 | } |
---|
| 978 | |
---|
[a9a7287] | 979 | static void cmd_chat( irc_t *irc, char **cmd ) |
---|
| 980 | { |
---|
| 981 | account_t *acc; |
---|
| 982 | struct chat *c; |
---|
| 983 | |
---|
| 984 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 985 | { |
---|
[07054a5] | 986 | char *channel, *s; |
---|
| 987 | |
---|
| 988 | MIN_ARGS( 3 ); |
---|
[a9a7287] | 989 | |
---|
| 990 | if( !( acc = account_get( irc, cmd[2] ) ) ) |
---|
| 991 | { |
---|
| 992 | irc_usermsg( irc, "Invalid account" ); |
---|
| 993 | return; |
---|
| 994 | } |
---|
| 995 | |
---|
[07054a5] | 996 | if( cmd[4] == NULL ) |
---|
| 997 | { |
---|
| 998 | channel = g_strdup( cmd[3] ); |
---|
| 999 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 1000 | *s = 0; |
---|
| 1001 | } |
---|
| 1002 | else |
---|
| 1003 | { |
---|
| 1004 | channel = g_strdup( cmd[4] ); |
---|
| 1005 | } |
---|
| 1006 | |
---|
| 1007 | if( strchr( CTYPES, channel[0] ) == NULL ) |
---|
| 1008 | { |
---|
| 1009 | s = g_strdup_printf( "%c%s", CTYPES[0], channel ); |
---|
| 1010 | g_free( channel ); |
---|
| 1011 | channel = s; |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | if( ( c = chat_add( irc, acc, cmd[3], channel ) ) ) |
---|
[a9a7287] | 1015 | irc_usermsg( irc, "Chatroom added successfully." ); |
---|
| 1016 | else |
---|
| 1017 | irc_usermsg( irc, "Could not add chatroom." ); |
---|
[07054a5] | 1018 | |
---|
| 1019 | g_free( channel ); |
---|
[a9a7287] | 1020 | } |
---|
| 1021 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 1022 | { |
---|
| 1023 | int i = 0; |
---|
| 1024 | |
---|
| 1025 | if( strchr( irc->umode, 'b' ) ) |
---|
| 1026 | irc_usermsg( irc, "Chatroom list:" ); |
---|
| 1027 | |
---|
| 1028 | for( c = irc->chatrooms; c; c = c->next ) |
---|
| 1029 | { |
---|
| 1030 | irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name, |
---|
| 1031 | c->acc->user, c->handle, c->channel ); |
---|
| 1032 | |
---|
| 1033 | i ++; |
---|
| 1034 | } |
---|
| 1035 | irc_usermsg( irc, "End of chatroom list" ); |
---|
| 1036 | } |
---|
[e7bc722] | 1037 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 1038 | { |
---|
[2ea8736] | 1039 | MIN_ARGS( 2 ); |
---|
| 1040 | |
---|
[c05eb5b] | 1041 | cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead, NULL ); |
---|
[e7bc722] | 1042 | } |
---|
[d995c9b] | 1043 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 1044 | { |
---|
[3b99524] | 1045 | MIN_ARGS( 2 ); |
---|
[d995c9b] | 1046 | |
---|
| 1047 | if( ( c = chat_get( irc, cmd[2] ) ) ) |
---|
| 1048 | { |
---|
| 1049 | chat_del( irc, c ); |
---|
| 1050 | } |
---|
| 1051 | else |
---|
| 1052 | { |
---|
| 1053 | irc_usermsg( irc, "Could not remove chat." ); |
---|
| 1054 | } |
---|
| 1055 | } |
---|
[39f93f0] | 1056 | else if( g_strcasecmp( cmd[1], "with" ) == 0 ) |
---|
| 1057 | { |
---|
| 1058 | user_t *u; |
---|
[3b99524] | 1059 | |
---|
| 1060 | MIN_ARGS( 2 ); |
---|
[39f93f0] | 1061 | |
---|
| 1062 | if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with ) |
---|
| 1063 | { |
---|
| 1064 | if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) ) |
---|
| 1065 | { |
---|
| 1066 | irc_usermsg( irc, "(Possible) failure while trying to open " |
---|
| 1067 | "a groupchat with %s.", u->nick ); |
---|
| 1068 | } |
---|
| 1069 | } |
---|
| 1070 | else |
---|
| 1071 | { |
---|
| 1072 | irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] ); |
---|
| 1073 | } |
---|
| 1074 | } |
---|
[a9a7287] | 1075 | else |
---|
| 1076 | { |
---|
| 1077 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); |
---|
| 1078 | } |
---|
[fa29d093] | 1079 | } |
---|
| 1080 | |
---|
[b8a491d] | 1081 | static void cmd_transfer( irc_t *irc, char **cmd ) |
---|
[2c2df7d] | 1082 | { |
---|
| 1083 | GSList *files = irc->file_transfers; |
---|
| 1084 | enum { LIST, REJECT, CANCEL }; |
---|
| 1085 | int subcmd = LIST; |
---|
| 1086 | int fid; |
---|
| 1087 | |
---|
| 1088 | if( !files ) |
---|
| 1089 | { |
---|
| 1090 | irc_usermsg( irc, "No pending transfers" ); |
---|
| 1091 | return; |
---|
| 1092 | } |
---|
| 1093 | |
---|
[b8a491d] | 1094 | if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) |
---|
[2c2df7d] | 1095 | { |
---|
| 1096 | subcmd = REJECT; |
---|
| 1097 | } |
---|
[b8a491d] | 1098 | else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && |
---|
| 1099 | cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) |
---|
[2c2df7d] | 1100 | { |
---|
| 1101 | subcmd = CANCEL; |
---|
| 1102 | } |
---|
| 1103 | |
---|
| 1104 | for( ; files; files = g_slist_next( files ) ) |
---|
| 1105 | { |
---|
| 1106 | file_transfer_t *file = files->data; |
---|
| 1107 | |
---|
| 1108 | switch( subcmd ) { |
---|
| 1109 | case LIST: |
---|
| 1110 | if ( file->status == FT_STATUS_LISTENING ) |
---|
| 1111 | irc_usermsg( irc, |
---|
| 1112 | "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); |
---|
| 1113 | else |
---|
| 1114 | { |
---|
| 1115 | int kb_per_s = 0; |
---|
[44961cb] | 1116 | time_t diff = time( NULL ) - file->started ? : 1; |
---|
[2c2df7d] | 1117 | if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) |
---|
| 1118 | kb_per_s = file->bytes_transferred / 1024 / diff; |
---|
| 1119 | |
---|
| 1120 | irc_usermsg( irc, |
---|
| 1121 | "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, |
---|
| 1122 | file->bytes_transferred/1024, file->file_size/1024, kb_per_s); |
---|
| 1123 | } |
---|
| 1124 | break; |
---|
| 1125 | case REJECT: |
---|
| 1126 | if( file->status == FT_STATUS_LISTENING ) |
---|
| 1127 | { |
---|
| 1128 | irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); |
---|
| 1129 | imcb_file_canceled( file, "Denied by user" ); |
---|
| 1130 | } |
---|
| 1131 | break; |
---|
| 1132 | case CANCEL: |
---|
| 1133 | if( file->local_id == fid ) |
---|
| 1134 | { |
---|
| 1135 | irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); |
---|
| 1136 | imcb_file_canceled( file, "Canceled by user" ); |
---|
| 1137 | } |
---|
| 1138 | break; |
---|
| 1139 | } |
---|
| 1140 | } |
---|
| 1141 | } |
---|
[280c56a] | 1142 | #endif |
---|
[2c2df7d] | 1143 | |
---|
[6c56f42] | 1144 | /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ |
---|
[0298d11] | 1145 | const command_t commands[] = { |
---|
[d860a8d] | 1146 | { "account", 1, cmd_account, 0 }, |
---|
[6c56f42] | 1147 | { "add", 2, cmd_add, 0 }, |
---|
| 1148 | { "drop", 1, cmd_drop, 0 }, |
---|
| 1149 | { "help", 0, cmd_help, 0 }, |
---|
[0298d11] | 1150 | { "identify", 1, cmd_identify, 0 }, |
---|
[aa44bdd] | 1151 | { "info", 1, cmd_info, 0 }, |
---|
[6c56f42] | 1152 | { "no", 0, cmd_yesno, 0 }, |
---|
[0298d11] | 1153 | { "register", 1, cmd_register, 0 }, |
---|
[dbb0ce3] | 1154 | { "remove", 1, cmd_remove, 0 }, |
---|
[0298d11] | 1155 | { "rename", 2, cmd_rename, 0 }, |
---|
[6c56f42] | 1156 | { "save", 0, cmd_save, 0 }, |
---|
[0298d11] | 1157 | { "set", 0, cmd_set, 0 }, |
---|
| 1158 | { "yes", 0, cmd_yesno, 0 }, |
---|
[dbb0ce3] | 1159 | #if 0 |
---|
[6c56f42] | 1160 | { "allow", 1, cmd_allow, 0 }, |
---|
[0298d11] | 1161 | { "blist", 0, cmd_blist, 0 }, |
---|
[6c56f42] | 1162 | { "block", 1, cmd_block, 0 }, |
---|
| 1163 | { "chat", 1, cmd_chat, 0 }, |
---|
| 1164 | { "ft", 0, cmd_transfer, 0 }, |
---|
| 1165 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
[0298d11] | 1166 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[b8a491d] | 1167 | { "transfer", 0, cmd_transfer, 0 }, |
---|
[280c56a] | 1168 | #endif |
---|
[0298d11] | 1169 | { NULL } |
---|
| 1170 | }; |
---|