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