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