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