[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" |
---|
| 31 | |
---|
| 32 | #include <string.h> |
---|
| 33 | |
---|
[f73b969] | 34 | void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) |
---|
[7e563ed] | 35 | { |
---|
| 36 | char *cmd[IRC_MAX_ARGS]; |
---|
| 37 | char *s; |
---|
| 38 | int k; |
---|
| 39 | char q = 0; |
---|
| 40 | |
---|
| 41 | memset( cmd, 0, sizeof( cmd ) ); |
---|
| 42 | cmd[0] = command; |
---|
| 43 | k = 1; |
---|
| 44 | for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) |
---|
| 45 | if( *s == ' ' && !q ) |
---|
| 46 | { |
---|
| 47 | *s = 0; |
---|
| 48 | while( *++s == ' ' ); |
---|
| 49 | if( *s == '"' || *s == '\'' ) |
---|
| 50 | { |
---|
| 51 | q = *s; |
---|
| 52 | s ++; |
---|
| 53 | } |
---|
| 54 | if( *s ) |
---|
| 55 | { |
---|
| 56 | cmd[k++] = s; |
---|
| 57 | s --; |
---|
| 58 | } |
---|
[619a681] | 59 | else |
---|
| 60 | { |
---|
| 61 | break; |
---|
| 62 | } |
---|
[7e563ed] | 63 | } |
---|
[79c6f9f] | 64 | else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) |
---|
| 65 | { |
---|
| 66 | char *cpy; |
---|
| 67 | |
---|
| 68 | for( cpy = s; *cpy; cpy ++ ) |
---|
| 69 | cpy[0] = cpy[1]; |
---|
| 70 | } |
---|
[7e563ed] | 71 | else if( *s == q ) |
---|
| 72 | { |
---|
| 73 | q = *s = 0; |
---|
| 74 | } |
---|
| 75 | cmd[k] = NULL; |
---|
| 76 | |
---|
[f73b969] | 77 | root_command( irc, cmd ); |
---|
[7e563ed] | 78 | } |
---|
| 79 | |
---|
[f73b969] | 80 | void root_command( irc_t *irc, char *cmd[] ) |
---|
[7e563ed] | 81 | { |
---|
| 82 | int i; |
---|
| 83 | |
---|
| 84 | if( !cmd[0] ) |
---|
[f73b969] | 85 | return; |
---|
[7e563ed] | 86 | |
---|
| 87 | for( i = 0; commands[i].command; i++ ) |
---|
| 88 | if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) |
---|
| 89 | { |
---|
| 90 | if( !cmd[commands[i].required_parameters] ) |
---|
| 91 | { |
---|
| 92 | irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); |
---|
[f73b969] | 93 | return; |
---|
[7e563ed] | 94 | } |
---|
| 95 | commands[i].execute( irc, cmd ); |
---|
[f73b969] | 96 | return; |
---|
[7e563ed] | 97 | } |
---|
| 98 | |
---|
| 99 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
| 100 | } |
---|
| 101 | |
---|
[f73b969] | 102 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 103 | { |
---|
| 104 | char param[80]; |
---|
| 105 | int i; |
---|
| 106 | char *s; |
---|
| 107 | |
---|
| 108 | memset( param, 0, sizeof(param) ); |
---|
| 109 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
| 110 | if ( i != 1 ) // prepend space except for the first parameter |
---|
| 111 | strcat(param, " "); |
---|
| 112 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | s = help_get( &(global.help), param ); |
---|
| 116 | if( !s ) s = help_get( &(global.help), "" ); |
---|
| 117 | |
---|
| 118 | if( s ) |
---|
| 119 | { |
---|
| 120 | irc_usermsg( irc, "%s", s ); |
---|
| 121 | g_free( s ); |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
| 125 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
[90bbb0e] | 129 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
| 130 | |
---|
[f73b969] | 131 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 132 | { |
---|
[ab49fdc] | 133 | storage_status_t status = storage_load( irc->nick, cmd[1], irc ); |
---|
[90bbb0e] | 134 | char *account_on[] = { "account", "on", NULL }; |
---|
[b7d3cc34] | 135 | |
---|
[09adf08] | 136 | switch (status) { |
---|
| 137 | case STORAGE_INVALID_PASSWORD: |
---|
[b7d3cc34] | 138 | irc_usermsg( irc, "Incorrect password" ); |
---|
[09adf08] | 139 | break; |
---|
| 140 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 141 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
[09adf08] | 142 | break; |
---|
| 143 | case STORAGE_OK: |
---|
[6ee9d2d] | 144 | irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); |
---|
[238f828] | 145 | irc_umode_set( irc, "+R", 1 ); |
---|
[5c9512f] | 146 | if( set_getint( &irc->set, "auto_connect" ) ) |
---|
[90bbb0e] | 147 | cmd_account( irc, account_on ); |
---|
[09adf08] | 148 | break; |
---|
[c121f89] | 149 | case STORAGE_OTHER_ERROR: |
---|
[09adf08] | 150 | default: |
---|
[c121f89] | 151 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
[09adf08] | 152 | break; |
---|
[b7d3cc34] | 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
[f73b969] | 156 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 157 | { |
---|
| 158 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
| 159 | { |
---|
| 160 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
[f73b969] | 161 | return; |
---|
[b7d3cc34] | 162 | } |
---|
[1ee6c18] | 163 | |
---|
[7cad7b4] | 164 | irc_setpass( irc, cmd[1] ); |
---|
[ab49fdc] | 165 | switch( storage_save( irc, FALSE )) { |
---|
[a1f17d4] | 166 | case STORAGE_ALREADY_EXISTS: |
---|
| 167 | irc_usermsg( irc, "Nick is already registered" ); |
---|
| 168 | break; |
---|
| 169 | |
---|
| 170 | case STORAGE_OK: |
---|
[79e826a] | 171 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 172 | irc_umode_set( irc, "+R", 1 ); |
---|
[a1f17d4] | 173 | break; |
---|
| 174 | |
---|
| 175 | default: |
---|
| 176 | irc_usermsg( irc, "Error registering" ); |
---|
| 177 | break; |
---|
[b7d3cc34] | 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
[f73b969] | 181 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 182 | { |
---|
[a1f17d4] | 183 | storage_status_t status; |
---|
| 184 | |
---|
[ab49fdc] | 185 | status = storage_remove (irc->nick, cmd[1]); |
---|
[a1f17d4] | 186 | switch (status) { |
---|
| 187 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 188 | irc_usermsg( irc, "That account does not exist" ); |
---|
[f73b969] | 189 | break; |
---|
[a1f17d4] | 190 | case STORAGE_INVALID_PASSWORD: |
---|
[1ee6c18] | 191 | irc_usermsg( irc, "Password invalid" ); |
---|
[f73b969] | 192 | break; |
---|
[a1f17d4] | 193 | case STORAGE_OK: |
---|
[7cad7b4] | 194 | irc_setpass( irc, NULL ); |
---|
[79e826a] | 195 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[238f828] | 196 | irc_umode_set( irc, "-R", 1 ); |
---|
[a1f17d4] | 197 | irc_usermsg( irc, "Account `%s' removed", irc->nick ); |
---|
[f73b969] | 198 | break; |
---|
[a1f17d4] | 199 | default: |
---|
| 200 | irc_usermsg( irc, "Error: '%d'", status ); |
---|
[f73b969] | 201 | break; |
---|
[b7d3cc34] | 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
[f73b969] | 205 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 206 | { |
---|
| 207 | account_t *a; |
---|
| 208 | |
---|
[3af70b0] | 209 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 210 | { |
---|
| 211 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 212 | return; |
---|
[b7d3cc34] | 213 | } |
---|
| 214 | |
---|
| 215 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 216 | { |
---|
[7b23afd] | 217 | struct prpl *prpl; |
---|
[b7d3cc34] | 218 | |
---|
| 219 | if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) |
---|
| 220 | { |
---|
| 221 | irc_usermsg( irc, "Not enough parameters" ); |
---|
[f73b969] | 222 | return; |
---|
[b7d3cc34] | 223 | } |
---|
| 224 | |
---|
[7b23afd] | 225 | prpl = find_protocol(cmd[2]); |
---|
[b7d3cc34] | 226 | |
---|
[7b23afd] | 227 | if( prpl == NULL ) |
---|
[b7d3cc34] | 228 | { |
---|
| 229 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 230 | return; |
---|
[b7d3cc34] | 231 | } |
---|
| 232 | |
---|
[7b23afd] | 233 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 234 | if( cmd[5] ) |
---|
[5100caa] | 235 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[b7d3cc34] | 236 | |
---|
| 237 | irc_usermsg( irc, "Account successfully added" ); |
---|
| 238 | } |
---|
| 239 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 240 | { |
---|
| 241 | if( !cmd[2] ) |
---|
| 242 | { |
---|
| 243 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 244 | } |
---|
| 245 | else if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
| 246 | { |
---|
| 247 | irc_usermsg( irc, "Invalid account" ); |
---|
| 248 | } |
---|
| 249 | else if( a->gc ) |
---|
| 250 | { |
---|
| 251 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
| 252 | } |
---|
| 253 | else |
---|
| 254 | { |
---|
| 255 | account_del( irc, a ); |
---|
| 256 | irc_usermsg( irc, "Account deleted" ); |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 260 | { |
---|
| 261 | int i = 0; |
---|
| 262 | |
---|
[e6e1f18] | 263 | if( strchr( irc->umode, 'b' ) ) |
---|
| 264 | irc_usermsg( irc, "Account list:" ); |
---|
| 265 | |
---|
[b7d3cc34] | 266 | for( a = irc->accounts; a; a = a->next ) |
---|
| 267 | { |
---|
| 268 | char *con; |
---|
| 269 | |
---|
| 270 | if( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) |
---|
| 271 | con = " (connected)"; |
---|
| 272 | else if( a->gc ) |
---|
| 273 | con = " (connecting)"; |
---|
| 274 | else if( a->reconnect ) |
---|
| 275 | con = " (awaiting reconnect)"; |
---|
| 276 | else |
---|
| 277 | con = ""; |
---|
| 278 | |
---|
[7b23afd] | 279 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 280 | |
---|
| 281 | i ++; |
---|
| 282 | } |
---|
| 283 | irc_usermsg( irc, "End of account list" ); |
---|
| 284 | } |
---|
| 285 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
| 286 | { |
---|
| 287 | if( cmd[2] ) |
---|
| 288 | { |
---|
| 289 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 290 | { |
---|
| 291 | if( a->gc ) |
---|
| 292 | { |
---|
| 293 | irc_usermsg( irc, "Account already online" ); |
---|
[f73b969] | 294 | return; |
---|
[b7d3cc34] | 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | account_on( irc, a ); |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | else |
---|
| 302 | { |
---|
| 303 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 304 | return; |
---|
[b7d3cc34] | 305 | } |
---|
| 306 | } |
---|
| 307 | else |
---|
| 308 | { |
---|
| 309 | if ( irc->accounts ) { |
---|
| 310 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 311 | |
---|
| 312 | for( a = irc->accounts; a; a = a->next ) |
---|
[2b14eef] | 313 | if( !a->gc && a->auto_connect ) |
---|
[b7d3cc34] | 314 | account_on( irc, a ); |
---|
| 315 | } |
---|
| 316 | else |
---|
| 317 | { |
---|
| 318 | irc_usermsg( irc, "No accounts known. Use 'account add' to add one." ); |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
| 323 | { |
---|
| 324 | if( !cmd[2] ) |
---|
| 325 | { |
---|
| 326 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 327 | |
---|
| 328 | for( a = irc->accounts; a; a = a->next ) |
---|
| 329 | { |
---|
| 330 | if( a->gc ) |
---|
| 331 | account_off( irc, a ); |
---|
| 332 | else if( a->reconnect ) |
---|
| 333 | cancel_auto_reconnect( a ); |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 337 | { |
---|
| 338 | if( a->gc ) |
---|
| 339 | { |
---|
| 340 | account_off( irc, a ); |
---|
| 341 | } |
---|
| 342 | else if( a->reconnect ) |
---|
| 343 | { |
---|
| 344 | cancel_auto_reconnect( a ); |
---|
| 345 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 346 | } |
---|
| 347 | else |
---|
| 348 | { |
---|
| 349 | irc_usermsg( irc, "Account already offline" ); |
---|
[f73b969] | 350 | return; |
---|
[b7d3cc34] | 351 | } |
---|
| 352 | } |
---|
| 353 | else |
---|
| 354 | { |
---|
| 355 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 356 | return; |
---|
[b7d3cc34] | 357 | } |
---|
| 358 | } |
---|
[5100caa] | 359 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 360 | { |
---|
| 361 | char *acc_handle, *set_name = NULL, *tmp; |
---|
| 362 | |
---|
| 363 | if( !cmd[2] ) |
---|
| 364 | { |
---|
| 365 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 366 | return; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | acc_handle = g_strdup( cmd[2] ); |
---|
| 370 | if( ( tmp = strchr( acc_handle, '/' ) ) ) |
---|
| 371 | { |
---|
| 372 | *tmp = 0; |
---|
| 373 | set_name = tmp + 1; |
---|
| 374 | } |
---|
| 375 | a = account_get( irc, acc_handle ); |
---|
| 376 | |
---|
| 377 | if( a == NULL ) |
---|
| 378 | { |
---|
| 379 | irc_usermsg( irc, "Invalid account" ); |
---|
| 380 | return; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | if( cmd[3] ) |
---|
| 384 | { |
---|
| 385 | set_t *s = set_find( &a->set, set_name ); |
---|
| 386 | |
---|
| 387 | if( a->gc && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
| 388 | { |
---|
[911f2eb] | 389 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 390 | return; |
---|
| 391 | } |
---|
| 392 | else if( !a->gc && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
| 393 | { |
---|
| 394 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
[5100caa] | 395 | return; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | set_setstr( &a->set, set_name, cmd[3] ); |
---|
| 399 | |
---|
| 400 | if( ( strcmp( cmd[3], "=" ) ) == 0 && cmd[4] ) |
---|
| 401 | irc_usermsg( irc, "Warning: Correct syntax: \002account set <variable> <value>\002 (without =)" ); |
---|
| 402 | } |
---|
| 403 | if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
| 404 | { |
---|
| 405 | char *s = set_getstr( &a->set, set_name ); |
---|
| 406 | if( s ) |
---|
| 407 | irc_usermsg( irc, "%s = `%s'", set_name, s ); |
---|
| 408 | else |
---|
| 409 | irc_usermsg( irc, "%s is empty", set_name ); |
---|
| 410 | } |
---|
| 411 | else |
---|
| 412 | { |
---|
| 413 | set_t *s = a->set; |
---|
| 414 | while( s ) |
---|
| 415 | { |
---|
| 416 | if( s->value || s->def ) |
---|
| 417 | irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def ); |
---|
| 418 | else |
---|
| 419 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
| 420 | s = s->next; |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | g_free( acc_handle ); |
---|
| 425 | } |
---|
[b7d3cc34] | 426 | else |
---|
| 427 | { |
---|
[5c09a59] | 428 | irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] ); |
---|
[b7d3cc34] | 429 | } |
---|
| 430 | } |
---|
| 431 | |
---|
[f73b969] | 432 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 433 | { |
---|
| 434 | account_t *a; |
---|
[f8de26f] | 435 | int add_for_real = 1; |
---|
| 436 | |
---|
| 437 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 438 | { |
---|
| 439 | add_for_real = 0; |
---|
| 440 | cmd ++; /* So evil... :-D */ |
---|
| 441 | } |
---|
[b7d3cc34] | 442 | |
---|
| 443 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 444 | { |
---|
| 445 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 446 | return; |
---|
[b7d3cc34] | 447 | } |
---|
| 448 | else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
| 449 | { |
---|
| 450 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 451 | return; |
---|
[b7d3cc34] | 452 | } |
---|
| 453 | |
---|
| 454 | if( cmd[3] ) |
---|
| 455 | { |
---|
| 456 | if( !nick_ok( cmd[3] ) ) |
---|
| 457 | { |
---|
| 458 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 459 | return; |
---|
[b7d3cc34] | 460 | } |
---|
| 461 | else if( user_find( irc, cmd[3] ) ) |
---|
| 462 | { |
---|
| 463 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 464 | return; |
---|
[b7d3cc34] | 465 | } |
---|
| 466 | else |
---|
| 467 | { |
---|
[0a3c243] | 468 | nick_set( irc, cmd[2], a->gc->acc->prpl, cmd[3] ); |
---|
[b7d3cc34] | 469 | } |
---|
| 470 | } |
---|
[f8de26f] | 471 | |
---|
| 472 | /* By making this optional, you can talk to people without having to |
---|
| 473 | add them to your *real* (server-side) contact list. */ |
---|
| 474 | if( add_for_real ) |
---|
[0a3c243] | 475 | a->gc->acc->prpl->add_buddy( a->gc, cmd[2] ); |
---|
[f8de26f] | 476 | |
---|
[b7d3cc34] | 477 | add_buddy( a->gc, NULL, cmd[2], cmd[2] ); |
---|
| 478 | |
---|
| 479 | irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick ); |
---|
| 480 | } |
---|
| 481 | |
---|
[f73b969] | 482 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 483 | { |
---|
| 484 | struct gaim_connection *gc; |
---|
| 485 | account_t *a; |
---|
| 486 | |
---|
| 487 | if( !cmd[2] ) |
---|
| 488 | { |
---|
| 489 | user_t *u = user_find( irc, cmd[1] ); |
---|
| 490 | if( !u || !u->gc ) |
---|
| 491 | { |
---|
| 492 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 493 | return; |
---|
[b7d3cc34] | 494 | } |
---|
| 495 | gc = u->gc; |
---|
| 496 | cmd[2] = u->handle; |
---|
| 497 | } |
---|
| 498 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 499 | { |
---|
| 500 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 501 | return; |
---|
[b7d3cc34] | 502 | } |
---|
| 503 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
| 504 | { |
---|
| 505 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 506 | return; |
---|
[b7d3cc34] | 507 | } |
---|
| 508 | |
---|
[0a3c243] | 509 | if( !gc->acc->prpl->get_info ) |
---|
[b7d3cc34] | 510 | { |
---|
| 511 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 512 | } |
---|
[f73b969] | 513 | else |
---|
| 514 | { |
---|
[0a3c243] | 515 | gc->acc->prpl->get_info( gc, cmd[2] ); |
---|
[f73b969] | 516 | } |
---|
[b7d3cc34] | 517 | } |
---|
| 518 | |
---|
[f73b969] | 519 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 520 | { |
---|
| 521 | user_t *u; |
---|
| 522 | |
---|
| 523 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
| 524 | { |
---|
| 525 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
| 526 | } |
---|
[f73b969] | 527 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
[b7d3cc34] | 528 | { |
---|
| 529 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
| 530 | } |
---|
[f73b969] | 531 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 532 | { |
---|
| 533 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 534 | } |
---|
[f73b969] | 535 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
[b7d3cc34] | 536 | { |
---|
| 537 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
| 538 | } |
---|
[f73b969] | 539 | else |
---|
[b7d3cc34] | 540 | { |
---|
[f73b969] | 541 | user_rename( irc, cmd[1], cmd[2] ); |
---|
| 542 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
| 543 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
| 544 | { |
---|
| 545 | g_free( irc->mynick ); |
---|
| 546 | irc->mynick = g_strdup( cmd[2] ); |
---|
| 547 | } |
---|
| 548 | else if( u->send_handler == buddy_send_handler ) |
---|
| 549 | { |
---|
[0a3c243] | 550 | nick_set( irc, u->handle, u->gc->acc->prpl, cmd[2] ); |
---|
[f73b969] | 551 | } |
---|
| 552 | |
---|
| 553 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 554 | } |
---|
| 555 | } |
---|
| 556 | |
---|
[f73b969] | 557 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 558 | { |
---|
| 559 | user_t *u; |
---|
| 560 | char *s; |
---|
| 561 | |
---|
| 562 | if( !( u = user_find( irc, cmd[1] ) ) || !u->gc ) |
---|
| 563 | { |
---|
| 564 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
[f73b969] | 565 | return; |
---|
[b7d3cc34] | 566 | } |
---|
| 567 | s = g_strdup( u->handle ); |
---|
| 568 | |
---|
[0a3c243] | 569 | u->gc->acc->prpl->remove_buddy( u->gc, u->handle, NULL ); |
---|
[b7d3cc34] | 570 | user_del( irc, cmd[1] ); |
---|
| 571 | nick_del( irc, cmd[1] ); |
---|
| 572 | |
---|
| 573 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 574 | g_free( s ); |
---|
| 575 | |
---|
[f73b969] | 576 | return; |
---|
[b7d3cc34] | 577 | } |
---|
| 578 | |
---|
[f73b969] | 579 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 580 | { |
---|
| 581 | struct gaim_connection *gc; |
---|
| 582 | account_t *a; |
---|
| 583 | |
---|
[87b6a3e] | 584 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc ) |
---|
| 585 | { |
---|
| 586 | char *format; |
---|
| 587 | GSList *l; |
---|
| 588 | |
---|
| 589 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 590 | format = "%s\t%s"; |
---|
| 591 | else |
---|
[57ef864] | 592 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 593 | |
---|
| 594 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
| 595 | for( l = a->gc->deny; l; l = l->next ) |
---|
| 596 | { |
---|
| 597 | user_t *u = user_findhandle( a->gc, l->data ); |
---|
| 598 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 599 | } |
---|
| 600 | irc_usermsg( irc, "End of list." ); |
---|
| 601 | |
---|
| 602 | return; |
---|
| 603 | } |
---|
| 604 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 605 | { |
---|
| 606 | user_t *u = user_find( irc, cmd[1] ); |
---|
| 607 | if( !u || !u->gc ) |
---|
| 608 | { |
---|
| 609 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 610 | return; |
---|
[b7d3cc34] | 611 | } |
---|
| 612 | gc = u->gc; |
---|
| 613 | cmd[2] = u->handle; |
---|
| 614 | } |
---|
| 615 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 616 | { |
---|
| 617 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 618 | return; |
---|
[b7d3cc34] | 619 | } |
---|
| 620 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
| 621 | { |
---|
| 622 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 623 | return; |
---|
[b7d3cc34] | 624 | } |
---|
| 625 | |
---|
[0a3c243] | 626 | if( !gc->acc->prpl->add_deny || !gc->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 627 | { |
---|
| 628 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 629 | } |
---|
| 630 | else |
---|
| 631 | { |
---|
[da3b536] | 632 | bim_rem_allow( gc, cmd[2] ); |
---|
| 633 | bim_add_block( gc, cmd[2] ); |
---|
| 634 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
[b7d3cc34] | 635 | } |
---|
| 636 | } |
---|
| 637 | |
---|
[f73b969] | 638 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 639 | { |
---|
| 640 | struct gaim_connection *gc; |
---|
| 641 | account_t *a; |
---|
| 642 | |
---|
[87b6a3e] | 643 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc ) |
---|
| 644 | { |
---|
| 645 | char *format; |
---|
| 646 | GSList *l; |
---|
| 647 | |
---|
| 648 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 649 | format = "%s\t%s"; |
---|
| 650 | else |
---|
[57ef864] | 651 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 652 | |
---|
| 653 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
| 654 | for( l = a->gc->deny; l; l = l->next ) |
---|
| 655 | { |
---|
| 656 | user_t *u = user_findhandle( a->gc, l->data ); |
---|
| 657 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 658 | } |
---|
| 659 | irc_usermsg( irc, "End of list." ); |
---|
| 660 | |
---|
| 661 | return; |
---|
| 662 | } |
---|
| 663 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 664 | { |
---|
| 665 | user_t *u = user_find( irc, cmd[1] ); |
---|
| 666 | if( !u || !u->gc ) |
---|
| 667 | { |
---|
| 668 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 669 | return; |
---|
[b7d3cc34] | 670 | } |
---|
| 671 | gc = u->gc; |
---|
| 672 | cmd[2] = u->handle; |
---|
| 673 | } |
---|
| 674 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 675 | { |
---|
| 676 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 677 | return; |
---|
[b7d3cc34] | 678 | } |
---|
| 679 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
| 680 | { |
---|
| 681 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 682 | return; |
---|
[b7d3cc34] | 683 | } |
---|
| 684 | |
---|
[0a3c243] | 685 | if( !gc->acc->prpl->rem_deny || !gc->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 686 | { |
---|
| 687 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 688 | } |
---|
| 689 | else |
---|
| 690 | { |
---|
[da3b536] | 691 | bim_rem_block( gc, cmd[2] ); |
---|
| 692 | bim_add_allow( gc, cmd[2] ); |
---|
[b7d3cc34] | 693 | |
---|
[da3b536] | 694 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
[b7d3cc34] | 695 | } |
---|
| 696 | } |
---|
| 697 | |
---|
[f73b969] | 698 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 699 | { |
---|
| 700 | query_t *q = NULL; |
---|
| 701 | int numq = 0; |
---|
| 702 | |
---|
| 703 | if( irc->queries == NULL ) |
---|
| 704 | { |
---|
| 705 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 706 | return; |
---|
[b7d3cc34] | 707 | } |
---|
| 708 | |
---|
| 709 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 710 | first/last (depending on the query_order setting) one. */ |
---|
| 711 | if( cmd[1] ) |
---|
| 712 | { |
---|
| 713 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 714 | { |
---|
| 715 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 716 | return; |
---|
[b7d3cc34] | 717 | } |
---|
| 718 | |
---|
| 719 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 720 | if( numq == 0 ) |
---|
| 721 | break; |
---|
| 722 | |
---|
| 723 | if( !q ) |
---|
| 724 | { |
---|
| 725 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 726 | return; |
---|
[b7d3cc34] | 727 | } |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 731 | query_answer( irc, q, 1 ); |
---|
| 732 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 733 | query_answer( irc, q, 0 ); |
---|
| 734 | } |
---|
| 735 | |
---|
[f73b969] | 736 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 737 | { |
---|
| 738 | if( cmd[1] && cmd[2] ) |
---|
| 739 | { |
---|
[5c9512f] | 740 | set_setstr( &irc->set, cmd[1], cmd[2] ); |
---|
[8365610] | 741 | |
---|
| 742 | if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] ) |
---|
| 743 | irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" ); |
---|
[b7d3cc34] | 744 | } |
---|
| 745 | if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
| 746 | { |
---|
[5c9512f] | 747 | char *s = set_getstr( &irc->set, cmd[1] ); |
---|
[b7d3cc34] | 748 | if( s ) |
---|
| 749 | irc_usermsg( irc, "%s = `%s'", cmd[1], s ); |
---|
[5100caa] | 750 | else |
---|
| 751 | irc_usermsg( irc, "%s is empty", cmd[1] ); |
---|
[b7d3cc34] | 752 | } |
---|
| 753 | else |
---|
| 754 | { |
---|
| 755 | set_t *s = irc->set; |
---|
| 756 | while( s ) |
---|
| 757 | { |
---|
| 758 | if( s->value || s->def ) |
---|
| 759 | irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def ); |
---|
[5100caa] | 760 | else |
---|
| 761 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
[b7d3cc34] | 762 | s = s->next; |
---|
| 763 | } |
---|
| 764 | } |
---|
| 765 | } |
---|
| 766 | |
---|
[f73b969] | 767 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 768 | { |
---|
[ab49fdc] | 769 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
[b7d3cc34] | 770 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 771 | else |
---|
| 772 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 773 | } |
---|
| 774 | |
---|
[f73b969] | 775 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 776 | { |
---|
| 777 | int online = 0, away = 0, offline = 0; |
---|
| 778 | user_t *u; |
---|
[aefa533e] | 779 | char s[256]; |
---|
| 780 | char *format; |
---|
[b7d3cc34] | 781 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 782 | |
---|
| 783 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 784 | online = offline = away = 1; |
---|
| 785 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 786 | offline = 1; |
---|
| 787 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 788 | away = 1; |
---|
| 789 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 790 | online = 1; |
---|
| 791 | else |
---|
| 792 | online = away = 1; |
---|
| 793 | |
---|
[aefa533e] | 794 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 795 | format = "%s\t%s\t%s"; |
---|
| 796 | else |
---|
| 797 | format = "%-16.16s %-40.40s %s"; |
---|
| 798 | |
---|
| 799 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 800 | |
---|
[aefa533e] | 801 | for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away ) |
---|
[b7d3cc34] | 802 | { |
---|
[aefa533e] | 803 | if( online == 1 ) |
---|
| 804 | { |
---|
[0a3c243] | 805 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->acc->prpl->name ); |
---|
[aefa533e] | 806 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
| 807 | } |
---|
| 808 | |
---|
[b7d3cc34] | 809 | n_online ++; |
---|
| 810 | } |
---|
| 811 | |
---|
[aefa533e] | 812 | for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away ) |
---|
[b7d3cc34] | 813 | { |
---|
[aefa533e] | 814 | if( away == 1 ) |
---|
| 815 | { |
---|
[0a3c243] | 816 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->acc->prpl->name ); |
---|
[aefa533e] | 817 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 818 | } |
---|
[b7d3cc34] | 819 | n_away ++; |
---|
| 820 | } |
---|
| 821 | |
---|
[aefa533e] | 822 | for( u = irc->users; u; u = u->next ) if( u->gc && !u->online ) |
---|
[b7d3cc34] | 823 | { |
---|
[aefa533e] | 824 | if( offline == 1 ) |
---|
| 825 | { |
---|
[0a3c243] | 826 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->acc->prpl->name ); |
---|
[aefa533e] | 827 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 828 | } |
---|
[b7d3cc34] | 829 | n_offline ++; |
---|
| 830 | } |
---|
| 831 | |
---|
[aa5ac01] | 832 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 833 | } |
---|
| 834 | |
---|
[f73b969] | 835 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 836 | { |
---|
| 837 | account_t *a; |
---|
| 838 | |
---|
| 839 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 840 | { |
---|
| 841 | irc_usermsg( irc, "Invalid account"); |
---|
| 842 | } |
---|
| 843 | else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
| 844 | { |
---|
| 845 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 846 | } |
---|
| 847 | else if ( !cmd[2] ) |
---|
| 848 | { |
---|
| 849 | irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" ); |
---|
| 850 | } |
---|
[0a3c243] | 851 | else if ( !a->prpl->set_info ) |
---|
[b7d3cc34] | 852 | { |
---|
| 853 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 854 | } |
---|
| 855 | else |
---|
| 856 | { |
---|
| 857 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
| 858 | |
---|
[0a3c243] | 859 | a->prpl->set_info( a->gc, cmd[2] ); |
---|
[b7d3cc34] | 860 | } |
---|
| 861 | } |
---|
| 862 | |
---|
[f73b969] | 863 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 864 | { |
---|
| 865 | query_t *q = irc->queries; |
---|
| 866 | int num; |
---|
| 867 | |
---|
| 868 | if( !q ) |
---|
| 869 | { |
---|
| 870 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 871 | return; |
---|
[b7d3cc34] | 872 | } |
---|
| 873 | |
---|
| 874 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 875 | |
---|
| 876 | for( num = 0; q; q = q->next, num ++ ) |
---|
[5c09a59] | 877 | if( q->gc ) /* Not necessary yet, but it might come later */ |
---|
[0a3c243] | 878 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->gc->acc->prpl->name, q->gc->username, q->question ); |
---|
[5c09a59] | 879 | else |
---|
| 880 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 881 | } |
---|
| 882 | |
---|
[f73b969] | 883 | static void cmd_import_buddies( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 884 | { |
---|
| 885 | struct gaim_connection *gc; |
---|
| 886 | account_t *a; |
---|
| 887 | nick_t *n; |
---|
| 888 | |
---|
| 889 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 890 | { |
---|
| 891 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 892 | return; |
---|
[b7d3cc34] | 893 | } |
---|
| 894 | else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) ) |
---|
| 895 | { |
---|
| 896 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 897 | return; |
---|
[b7d3cc34] | 898 | } |
---|
| 899 | |
---|
| 900 | if( cmd[2] ) |
---|
| 901 | { |
---|
| 902 | if( g_strcasecmp( cmd[2], "clear" ) == 0 ) |
---|
| 903 | { |
---|
| 904 | user_t *u; |
---|
| 905 | |
---|
[0a3c243] | 906 | /* FIXME: Hmmm, this is actually pretty dangerous code... REMOVEME? :-) */ |
---|
[b7d3cc34] | 907 | for( u = irc->users; u; u = u->next ) |
---|
| 908 | if( u->gc == gc ) |
---|
| 909 | { |
---|
[0a3c243] | 910 | u->gc->acc->prpl->remove_buddy( u->gc, u->handle, NULL ); |
---|
[b7d3cc34] | 911 | user_del( irc, u->nick ); |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | irc_usermsg( irc, "Old buddy list cleared." ); |
---|
| 915 | } |
---|
| 916 | else |
---|
| 917 | { |
---|
| 918 | irc_usermsg( irc, "Invalid argument: %s", cmd[2] ); |
---|
[f73b969] | 919 | return; |
---|
[b7d3cc34] | 920 | } |
---|
| 921 | } |
---|
| 922 | |
---|
| 923 | for( n = gc->irc->nicks; n; n = n->next ) |
---|
| 924 | { |
---|
[0a3c243] | 925 | if( n->proto == gc->acc->prpl && !user_findhandle( gc, n->handle ) ) |
---|
[b7d3cc34] | 926 | { |
---|
[0a3c243] | 927 | gc->acc->prpl->add_buddy( gc, n->handle ); |
---|
[b7d3cc34] | 928 | add_buddy( gc, NULL, n->handle, NULL ); |
---|
| 929 | } |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." ); |
---|
| 933 | } |
---|
[0298d11] | 934 | |
---|
| 935 | const command_t commands[] = { |
---|
| 936 | { "help", 0, cmd_help, 0 }, |
---|
| 937 | { "identify", 1, cmd_identify, 0 }, |
---|
| 938 | { "register", 1, cmd_register, 0 }, |
---|
| 939 | { "drop", 1, cmd_drop, 0 }, |
---|
| 940 | { "account", 1, cmd_account, 0 }, |
---|
| 941 | { "add", 2, cmd_add, 0 }, |
---|
| 942 | { "info", 1, cmd_info, 0 }, |
---|
| 943 | { "rename", 2, cmd_rename, 0 }, |
---|
| 944 | { "remove", 1, cmd_remove, 0 }, |
---|
| 945 | { "block", 1, cmd_block, 0 }, |
---|
| 946 | { "allow", 1, cmd_allow, 0 }, |
---|
| 947 | { "save", 0, cmd_save, 0 }, |
---|
| 948 | { "set", 0, cmd_set, 0 }, |
---|
| 949 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 950 | { "no", 0, cmd_yesno, 0 }, |
---|
| 951 | { "blist", 0, cmd_blist, 0 }, |
---|
| 952 | { "nick", 1, cmd_nick, 0 }, |
---|
| 953 | { "import_buddies", 1, cmd_import_buddies, 0 }, |
---|
| 954 | { "qlist", 0, cmd_qlist, 0 }, |
---|
| 955 | { NULL } |
---|
| 956 | }; |
---|