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