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