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