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