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