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