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