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