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