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