[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 | |
---|
[90bbb0e] | 129 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
| 130 | |
---|
[f73b969] | 131 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 132 | { |
---|
[ab49fdc] | 133 | storage_status_t status = storage_load( irc->nick, cmd[1], irc ); |
---|
[90bbb0e] | 134 | char *account_on[] = { "account", "on", NULL }; |
---|
[b7d3cc34] | 135 | |
---|
[09adf08] | 136 | switch (status) { |
---|
| 137 | case STORAGE_INVALID_PASSWORD: |
---|
[b7d3cc34] | 138 | irc_usermsg( irc, "Incorrect password" ); |
---|
[09adf08] | 139 | break; |
---|
| 140 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 141 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
[09adf08] | 142 | break; |
---|
| 143 | case STORAGE_OK: |
---|
[6ee9d2d] | 144 | irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); |
---|
[238f828] | 145 | irc_umode_set( irc, "+R", 1 ); |
---|
[d5ccd83] | 146 | if( set_getbool( &irc->set, "auto_connect" ) ) |
---|
[90bbb0e] | 147 | cmd_account( irc, account_on ); |
---|
[09adf08] | 148 | break; |
---|
[c121f89] | 149 | case STORAGE_OTHER_ERROR: |
---|
[09adf08] | 150 | default: |
---|
[c121f89] | 151 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
[09adf08] | 152 | break; |
---|
[b7d3cc34] | 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
[f73b969] | 156 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 157 | { |
---|
| 158 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
| 159 | { |
---|
| 160 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
[f73b969] | 161 | return; |
---|
[b7d3cc34] | 162 | } |
---|
[1ee6c18] | 163 | |
---|
[7cad7b4] | 164 | irc_setpass( irc, cmd[1] ); |
---|
[ab49fdc] | 165 | switch( storage_save( irc, FALSE )) { |
---|
[a1f17d4] | 166 | case STORAGE_ALREADY_EXISTS: |
---|
| 167 | irc_usermsg( irc, "Nick is already registered" ); |
---|
| 168 | break; |
---|
| 169 | |
---|
| 170 | case STORAGE_OK: |
---|
[0383943] | 171 | irc_usermsg( irc, "Account successfully created" ); |
---|
[79e826a] | 172 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 173 | irc_umode_set( irc, "+R", 1 ); |
---|
[a1f17d4] | 174 | break; |
---|
| 175 | |
---|
| 176 | default: |
---|
| 177 | irc_usermsg( irc, "Error registering" ); |
---|
| 178 | break; |
---|
[b7d3cc34] | 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
[f73b969] | 182 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 183 | { |
---|
[a1f17d4] | 184 | storage_status_t status; |
---|
| 185 | |
---|
[ab49fdc] | 186 | status = storage_remove (irc->nick, cmd[1]); |
---|
[a1f17d4] | 187 | switch (status) { |
---|
| 188 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 189 | irc_usermsg( irc, "That account does not exist" ); |
---|
[f73b969] | 190 | break; |
---|
[a1f17d4] | 191 | case STORAGE_INVALID_PASSWORD: |
---|
[1ee6c18] | 192 | irc_usermsg( irc, "Password invalid" ); |
---|
[f73b969] | 193 | break; |
---|
[a1f17d4] | 194 | case STORAGE_OK: |
---|
[7cad7b4] | 195 | irc_setpass( irc, NULL ); |
---|
[79e826a] | 196 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[238f828] | 197 | irc_umode_set( irc, "-R", 1 ); |
---|
[a1f17d4] | 198 | irc_usermsg( irc, "Account `%s' removed", irc->nick ); |
---|
[f73b969] | 199 | break; |
---|
[a1f17d4] | 200 | default: |
---|
[30ce1ce] | 201 | irc_usermsg( irc, "Error: `%d'", status ); |
---|
[f73b969] | 202 | break; |
---|
[b7d3cc34] | 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
[f35aee7] | 206 | struct cmd_account_del_data |
---|
[7f421d6] | 207 | { |
---|
[f35aee7] | 208 | account_t *a; |
---|
| 209 | irc_t *irc; |
---|
| 210 | }; |
---|
| 211 | |
---|
| 212 | void cmd_account_del_yes( void *data ) |
---|
| 213 | { |
---|
| 214 | struct cmd_account_del_data *cad = data; |
---|
| 215 | account_t *a; |
---|
[7f421d6] | 216 | |
---|
[f35aee7] | 217 | for( a = cad->irc->accounts; a && a != cad->a; a = a->next ); |
---|
| 218 | |
---|
| 219 | if( a == NULL ) |
---|
| 220 | { |
---|
| 221 | irc_usermsg( cad->irc, "Account already deleted" ); |
---|
| 222 | } |
---|
| 223 | else if( a->ic ) |
---|
[7f421d6] | 224 | { |
---|
[f35aee7] | 225 | irc_usermsg( cad->irc, "Account is still logged in, can't delete" ); |
---|
[7f421d6] | 226 | } |
---|
| 227 | else |
---|
| 228 | { |
---|
[f35aee7] | 229 | account_del( cad->irc, a ); |
---|
| 230 | irc_usermsg( cad->irc, "Account deleted" ); |
---|
[7f421d6] | 231 | } |
---|
[f35aee7] | 232 | g_free( data ); |
---|
[7f421d6] | 233 | } |
---|
| 234 | |
---|
[f35aee7] | 235 | void cmd_account_del_no( void *data ) |
---|
[7f421d6] | 236 | { |
---|
[8dbe021f] | 237 | g_free( data ); |
---|
[7f421d6] | 238 | } |
---|
| 239 | |
---|
[f536a99] | 240 | static void cmd_showset( irc_t *irc, set_t **head, char *key ) |
---|
[f3579fd] | 241 | { |
---|
[f536a99] | 242 | char *val; |
---|
[f3579fd] | 243 | |
---|
[f536a99] | 244 | if( ( val = set_getstr( head, key ) ) ) |
---|
| 245 | irc_usermsg( irc, "%s = `%s'", key, val ); |
---|
[f3579fd] | 246 | else |
---|
[f536a99] | 247 | irc_usermsg( irc, "%s is empty", key ); |
---|
[f3579fd] | 248 | } |
---|
| 249 | |
---|
[e7bc722] | 250 | typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); |
---|
| 251 | |
---|
| 252 | static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead ) |
---|
| 253 | { |
---|
| 254 | char *set_full = NULL, *set_name = NULL, *tmp; |
---|
| 255 | set_t **head; |
---|
| 256 | |
---|
| 257 | if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
| 258 | set_full = cmd[2]; |
---|
| 259 | else |
---|
| 260 | set_full = cmd[1]; |
---|
| 261 | |
---|
| 262 | if( findhead == NULL ) |
---|
| 263 | { |
---|
| 264 | set_name = set_full; |
---|
| 265 | |
---|
| 266 | head = &irc->set; |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | char *id; |
---|
| 271 | |
---|
| 272 | if( !set_full ) |
---|
| 273 | { |
---|
| 274 | /* FIXME: Broken # */ |
---|
| 275 | irc_usermsg( irc, "Not enough parameters given (need %d)", 3 ); |
---|
| 276 | return 0; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | if( ( tmp = strchr( set_full, '/' ) ) ) |
---|
| 280 | { |
---|
| 281 | id = g_strndup( set_full, ( tmp - set_full ) ); |
---|
| 282 | set_name = tmp + 1; |
---|
| 283 | } |
---|
| 284 | else |
---|
| 285 | { |
---|
| 286 | id = g_strdup( set_full ); |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | if( ( head = findhead( irc, id ) ) == NULL ) |
---|
| 290 | { |
---|
| 291 | g_free( id ); |
---|
| 292 | irc_usermsg( irc, "Could not find setting." ); |
---|
| 293 | return 0; |
---|
| 294 | } |
---|
| 295 | g_free( id ); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | if( cmd[1] && cmd[2] && set_name ) |
---|
| 299 | { |
---|
| 300 | set_t *s = set_find( head, set_name ); |
---|
| 301 | int st; |
---|
| 302 | |
---|
| 303 | /* |
---|
[0e639f5] | 304 | FIXME: Make these work again. Probably a gross hack. |
---|
| 305 | |
---|
[e7bc722] | 306 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
| 307 | { |
---|
| 308 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 309 | return 0; |
---|
| 310 | } |
---|
| 311 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
| 312 | { |
---|
| 313 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
| 314 | return 0; |
---|
| 315 | } |
---|
| 316 | */ |
---|
| 317 | |
---|
| 318 | if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
| 319 | st = set_reset( head, set_name ); |
---|
| 320 | else |
---|
| 321 | st = set_setstr( head, set_name, cmd[2] ); |
---|
| 322 | |
---|
| 323 | if( set_getstr( head, set_name ) == NULL ) |
---|
| 324 | { |
---|
| 325 | if( st ) |
---|
| 326 | irc_usermsg( irc, "Setting changed successfully" ); |
---|
| 327 | else |
---|
| 328 | irc_usermsg( irc, "Failed to change setting" ); |
---|
| 329 | } |
---|
| 330 | else |
---|
| 331 | { |
---|
| 332 | cmd_showset( irc, head, set_name ); |
---|
| 333 | } |
---|
| 334 | } |
---|
| 335 | else if( set_name ) |
---|
| 336 | { |
---|
| 337 | cmd_showset( irc, head, set_name ); |
---|
| 338 | } |
---|
| 339 | else |
---|
| 340 | { |
---|
| 341 | set_t *s = *head; |
---|
| 342 | while( s ) |
---|
| 343 | { |
---|
| 344 | cmd_showset( irc, &s, s->key ); |
---|
| 345 | s = s->next; |
---|
| 346 | } |
---|
| 347 | } |
---|
| 348 | |
---|
| 349 | return 1; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | static set_t **cmd_account_set_findhead( irc_t *irc, char *id ) |
---|
| 353 | { |
---|
| 354 | account_t *a; |
---|
| 355 | |
---|
| 356 | if( ( a = account_get( irc, id ) ) ) |
---|
| 357 | return &a->set; |
---|
| 358 | else |
---|
| 359 | return NULL; |
---|
| 360 | } |
---|
| 361 | |
---|
[f73b969] | 362 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 363 | { |
---|
| 364 | account_t *a; |
---|
| 365 | |
---|
[3af70b0] | 366 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 367 | { |
---|
| 368 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 369 | return; |
---|
[b7d3cc34] | 370 | } |
---|
| 371 | |
---|
| 372 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 373 | { |
---|
[7b23afd] | 374 | struct prpl *prpl; |
---|
[b7d3cc34] | 375 | |
---|
| 376 | if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) |
---|
| 377 | { |
---|
| 378 | irc_usermsg( irc, "Not enough parameters" ); |
---|
[f73b969] | 379 | return; |
---|
[b7d3cc34] | 380 | } |
---|
| 381 | |
---|
[a9a7287] | 382 | prpl = find_protocol( cmd[2] ); |
---|
[b7d3cc34] | 383 | |
---|
[7b23afd] | 384 | if( prpl == NULL ) |
---|
[b7d3cc34] | 385 | { |
---|
| 386 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 387 | return; |
---|
[b7d3cc34] | 388 | } |
---|
| 389 | |
---|
[7b23afd] | 390 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 391 | if( cmd[5] ) |
---|
[30ce1ce] | 392 | { |
---|
| 393 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
| 394 | "is now deprecated. Use `account set' instead." ); |
---|
[5100caa] | 395 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[30ce1ce] | 396 | } |
---|
[b7d3cc34] | 397 | |
---|
| 398 | irc_usermsg( irc, "Account successfully added" ); |
---|
| 399 | } |
---|
| 400 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 401 | { |
---|
| 402 | if( !cmd[2] ) |
---|
| 403 | { |
---|
| 404 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 405 | } |
---|
| 406 | else if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
| 407 | { |
---|
| 408 | irc_usermsg( irc, "Invalid account" ); |
---|
| 409 | } |
---|
[0da65d5] | 410 | else if( a->ic ) |
---|
[b7d3cc34] | 411 | { |
---|
| 412 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
| 413 | } |
---|
| 414 | else |
---|
| 415 | { |
---|
[f35aee7] | 416 | struct cmd_account_del_data *cad; |
---|
[7f421d6] | 417 | char *msg; |
---|
| 418 | |
---|
[f35aee7] | 419 | cad = g_malloc( sizeof( struct cmd_account_del_data ) ); |
---|
| 420 | cad->a = a; |
---|
| 421 | cad->irc = irc; |
---|
[8dbe021f] | 422 | |
---|
[7f421d6] | 423 | msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " |
---|
| 424 | "also forget all your saved nicknames. If you want " |
---|
| 425 | "to change your username/password, use the `account " |
---|
| 426 | "set' command. Are you sure you want to delete this " |
---|
| 427 | "account?", a->prpl->name, a->user ); |
---|
[f35aee7] | 428 | query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, cad ); |
---|
[7f421d6] | 429 | g_free( msg ); |
---|
[b7d3cc34] | 430 | } |
---|
| 431 | } |
---|
| 432 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 433 | { |
---|
| 434 | int i = 0; |
---|
| 435 | |
---|
[e6e1f18] | 436 | if( strchr( irc->umode, 'b' ) ) |
---|
| 437 | irc_usermsg( irc, "Account list:" ); |
---|
| 438 | |
---|
[b7d3cc34] | 439 | for( a = irc->accounts; a; a = a->next ) |
---|
| 440 | { |
---|
| 441 | char *con; |
---|
| 442 | |
---|
[0da65d5] | 443 | if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) |
---|
[b7d3cc34] | 444 | con = " (connected)"; |
---|
[0da65d5] | 445 | else if( a->ic ) |
---|
[b7d3cc34] | 446 | con = " (connecting)"; |
---|
| 447 | else if( a->reconnect ) |
---|
| 448 | con = " (awaiting reconnect)"; |
---|
| 449 | else |
---|
| 450 | con = ""; |
---|
| 451 | |
---|
[7b23afd] | 452 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 453 | |
---|
| 454 | i ++; |
---|
| 455 | } |
---|
| 456 | irc_usermsg( irc, "End of account list" ); |
---|
| 457 | } |
---|
| 458 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
| 459 | { |
---|
| 460 | if( cmd[2] ) |
---|
| 461 | { |
---|
| 462 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 463 | { |
---|
[0da65d5] | 464 | if( a->ic ) |
---|
[b7d3cc34] | 465 | { |
---|
| 466 | irc_usermsg( irc, "Account already online" ); |
---|
[f73b969] | 467 | return; |
---|
[b7d3cc34] | 468 | } |
---|
| 469 | else |
---|
| 470 | { |
---|
| 471 | account_on( irc, a ); |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | else |
---|
| 475 | { |
---|
| 476 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 477 | return; |
---|
[b7d3cc34] | 478 | } |
---|
| 479 | } |
---|
| 480 | else |
---|
| 481 | { |
---|
| 482 | if ( irc->accounts ) { |
---|
| 483 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 484 | |
---|
| 485 | for( a = irc->accounts; a; a = a->next ) |
---|
[0da65d5] | 486 | if( !a->ic && a->auto_connect ) |
---|
[b7d3cc34] | 487 | account_on( irc, a ); |
---|
| 488 | } |
---|
| 489 | else |
---|
| 490 | { |
---|
[30ce1ce] | 491 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
[b7d3cc34] | 492 | } |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
| 496 | { |
---|
| 497 | if( !cmd[2] ) |
---|
| 498 | { |
---|
| 499 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 500 | |
---|
| 501 | for( a = irc->accounts; a; a = a->next ) |
---|
| 502 | { |
---|
[0da65d5] | 503 | if( a->ic ) |
---|
[b7d3cc34] | 504 | account_off( irc, a ); |
---|
| 505 | else if( a->reconnect ) |
---|
| 506 | cancel_auto_reconnect( a ); |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 510 | { |
---|
[0da65d5] | 511 | if( a->ic ) |
---|
[b7d3cc34] | 512 | { |
---|
| 513 | account_off( irc, a ); |
---|
| 514 | } |
---|
| 515 | else if( a->reconnect ) |
---|
| 516 | { |
---|
| 517 | cancel_auto_reconnect( a ); |
---|
| 518 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 519 | } |
---|
| 520 | else |
---|
| 521 | { |
---|
| 522 | irc_usermsg( irc, "Account already offline" ); |
---|
[f73b969] | 523 | return; |
---|
[b7d3cc34] | 524 | } |
---|
| 525 | } |
---|
| 526 | else |
---|
| 527 | { |
---|
| 528 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 529 | return; |
---|
[b7d3cc34] | 530 | } |
---|
| 531 | } |
---|
[5100caa] | 532 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 533 | { |
---|
| 534 | if( !cmd[2] ) |
---|
| 535 | { |
---|
| 536 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 537 | return; |
---|
| 538 | } |
---|
| 539 | |
---|
[e7bc722] | 540 | cmd_set_real( irc, cmd + 1, cmd_account_set_findhead ); |
---|
[5100caa] | 541 | } |
---|
[b7d3cc34] | 542 | else |
---|
| 543 | { |
---|
[a9a7287] | 544 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] ); |
---|
[b7d3cc34] | 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
[f73b969] | 548 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 549 | { |
---|
| 550 | account_t *a; |
---|
[f0cb961] | 551 | int add_on_server = 1; |
---|
[f8de26f] | 552 | |
---|
| 553 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 554 | { |
---|
[f0cb961] | 555 | add_on_server = 0; |
---|
[7adc657] | 556 | cmd ++; |
---|
[f8de26f] | 557 | } |
---|
[b7d3cc34] | 558 | |
---|
| 559 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 560 | { |
---|
| 561 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 562 | return; |
---|
[b7d3cc34] | 563 | } |
---|
[0da65d5] | 564 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 565 | { |
---|
| 566 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 567 | return; |
---|
[b7d3cc34] | 568 | } |
---|
| 569 | |
---|
| 570 | if( cmd[3] ) |
---|
| 571 | { |
---|
| 572 | if( !nick_ok( cmd[3] ) ) |
---|
| 573 | { |
---|
| 574 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 575 | return; |
---|
[b7d3cc34] | 576 | } |
---|
| 577 | else if( user_find( irc, cmd[3] ) ) |
---|
| 578 | { |
---|
| 579 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 580 | return; |
---|
[b7d3cc34] | 581 | } |
---|
| 582 | else |
---|
| 583 | { |
---|
[5b52a48] | 584 | nick_set( a, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 585 | } |
---|
| 586 | } |
---|
[f8de26f] | 587 | |
---|
[f0cb961] | 588 | if( add_on_server ) |
---|
[0da65d5] | 589 | a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); |
---|
[7adc657] | 590 | else |
---|
| 591 | /* Yeah, officially this is a call-*back*... So if we just |
---|
| 592 | called add_buddy, we'll wait for the IM server to respond |
---|
| 593 | before we do this. */ |
---|
| 594 | imcb_add_buddy( a->ic, cmd[2], NULL ); |
---|
[f0cb961] | 595 | |
---|
| 596 | irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); |
---|
[b7d3cc34] | 597 | } |
---|
| 598 | |
---|
[f73b969] | 599 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 600 | { |
---|
[0da65d5] | 601 | struct im_connection *ic; |
---|
[b7d3cc34] | 602 | account_t *a; |
---|
| 603 | |
---|
| 604 | if( !cmd[2] ) |
---|
| 605 | { |
---|
| 606 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 607 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 608 | { |
---|
| 609 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 610 | return; |
---|
[b7d3cc34] | 611 | } |
---|
[0da65d5] | 612 | ic = u->ic; |
---|
[b7d3cc34] | 613 | cmd[2] = u->handle; |
---|
| 614 | } |
---|
| 615 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 616 | { |
---|
| 617 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 618 | return; |
---|
[b7d3cc34] | 619 | } |
---|
[0da65d5] | 620 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 621 | { |
---|
| 622 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 623 | return; |
---|
[b7d3cc34] | 624 | } |
---|
| 625 | |
---|
[0da65d5] | 626 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 627 | { |
---|
| 628 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 629 | } |
---|
[f73b969] | 630 | else |
---|
| 631 | { |
---|
[0da65d5] | 632 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 633 | } |
---|
[b7d3cc34] | 634 | } |
---|
| 635 | |
---|
[f73b969] | 636 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 637 | { |
---|
| 638 | user_t *u; |
---|
| 639 | |
---|
| 640 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
| 641 | { |
---|
| 642 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
| 643 | } |
---|
[f73b969] | 644 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
[b7d3cc34] | 645 | { |
---|
| 646 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
| 647 | } |
---|
[f73b969] | 648 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 649 | { |
---|
| 650 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 651 | } |
---|
[f73b969] | 652 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
[b7d3cc34] | 653 | { |
---|
| 654 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
| 655 | } |
---|
[f73b969] | 656 | else |
---|
[b7d3cc34] | 657 | { |
---|
[f73b969] | 658 | user_rename( irc, cmd[1], cmd[2] ); |
---|
| 659 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
| 660 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
| 661 | { |
---|
| 662 | g_free( irc->mynick ); |
---|
| 663 | irc->mynick = g_strdup( cmd[2] ); |
---|
[1195cec] | 664 | |
---|
[7125cb3] | 665 | /* If we're called internally (user did "set root_nick"), |
---|
| 666 | let's not go O(INF). :-) */ |
---|
[1195cec] | 667 | if( strcmp( cmd[0], "set_rename" ) != 0 ) |
---|
| 668 | set_setstr( &irc->set, "root_nick", cmd[2] ); |
---|
[f73b969] | 669 | } |
---|
| 670 | else if( u->send_handler == buddy_send_handler ) |
---|
| 671 | { |
---|
[0da65d5] | 672 | nick_set( u->ic->acc, u->handle, cmd[2] ); |
---|
[f73b969] | 673 | } |
---|
| 674 | |
---|
| 675 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 676 | } |
---|
| 677 | } |
---|
| 678 | |
---|
[1195cec] | 679 | char *set_eval_root_nick( set_t *set, char *new_nick ) |
---|
| 680 | { |
---|
| 681 | irc_t *irc = set->data; |
---|
| 682 | |
---|
| 683 | if( strcmp( irc->mynick, new_nick ) != 0 ) |
---|
| 684 | { |
---|
| 685 | char *cmd[] = { "set_rename", irc->mynick, new_nick, NULL }; |
---|
| 686 | |
---|
| 687 | cmd_rename( irc, cmd ); |
---|
| 688 | } |
---|
| 689 | |
---|
[7125cb3] | 690 | return strcmp( irc->mynick, new_nick ) == 0 ? new_nick : SET_INVALID; |
---|
[1195cec] | 691 | } |
---|
| 692 | |
---|
[f73b969] | 693 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 694 | { |
---|
| 695 | user_t *u; |
---|
| 696 | char *s; |
---|
| 697 | |
---|
[0da65d5] | 698 | if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) |
---|
[b7d3cc34] | 699 | { |
---|
| 700 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
[f73b969] | 701 | return; |
---|
[b7d3cc34] | 702 | } |
---|
| 703 | s = g_strdup( u->handle ); |
---|
| 704 | |
---|
[0da65d5] | 705 | u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); |
---|
| 706 | nick_del( u->ic->acc, u->handle ); |
---|
[b7d3cc34] | 707 | user_del( irc, cmd[1] ); |
---|
| 708 | |
---|
| 709 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 710 | g_free( s ); |
---|
| 711 | |
---|
[f73b969] | 712 | return; |
---|
[b7d3cc34] | 713 | } |
---|
| 714 | |
---|
[f73b969] | 715 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 716 | { |
---|
[0da65d5] | 717 | struct im_connection *ic; |
---|
[b7d3cc34] | 718 | account_t *a; |
---|
| 719 | |
---|
[0da65d5] | 720 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 721 | { |
---|
| 722 | char *format; |
---|
| 723 | GSList *l; |
---|
| 724 | |
---|
| 725 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 726 | format = "%s\t%s"; |
---|
| 727 | else |
---|
[57ef864] | 728 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 729 | |
---|
| 730 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 731 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 732 | { |
---|
[0da65d5] | 733 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 734 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 735 | } |
---|
| 736 | irc_usermsg( irc, "End of list." ); |
---|
| 737 | |
---|
| 738 | return; |
---|
| 739 | } |
---|
| 740 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 741 | { |
---|
| 742 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 743 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 744 | { |
---|
| 745 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 746 | return; |
---|
[b7d3cc34] | 747 | } |
---|
[0da65d5] | 748 | ic = u->ic; |
---|
[b7d3cc34] | 749 | cmd[2] = u->handle; |
---|
| 750 | } |
---|
| 751 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 752 | { |
---|
| 753 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 754 | return; |
---|
[b7d3cc34] | 755 | } |
---|
[0da65d5] | 756 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 757 | { |
---|
| 758 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 759 | return; |
---|
[b7d3cc34] | 760 | } |
---|
| 761 | |
---|
[0da65d5] | 762 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 763 | { |
---|
| 764 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 765 | } |
---|
| 766 | else |
---|
| 767 | { |
---|
[84b045d] | 768 | imc_rem_allow( ic, cmd[2] ); |
---|
| 769 | imc_add_block( ic, cmd[2] ); |
---|
[da3b536] | 770 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
[b7d3cc34] | 771 | } |
---|
| 772 | } |
---|
| 773 | |
---|
[f73b969] | 774 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 775 | { |
---|
[0da65d5] | 776 | struct im_connection *ic; |
---|
[b7d3cc34] | 777 | account_t *a; |
---|
| 778 | |
---|
[0da65d5] | 779 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 780 | { |
---|
| 781 | char *format; |
---|
| 782 | GSList *l; |
---|
| 783 | |
---|
| 784 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 785 | format = "%s\t%s"; |
---|
| 786 | else |
---|
[57ef864] | 787 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 788 | |
---|
| 789 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 790 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 791 | { |
---|
[0da65d5] | 792 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 793 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 794 | } |
---|
| 795 | irc_usermsg( irc, "End of list." ); |
---|
| 796 | |
---|
| 797 | return; |
---|
| 798 | } |
---|
| 799 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 800 | { |
---|
| 801 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 802 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 803 | { |
---|
| 804 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 805 | return; |
---|
[b7d3cc34] | 806 | } |
---|
[0da65d5] | 807 | ic = u->ic; |
---|
[b7d3cc34] | 808 | cmd[2] = u->handle; |
---|
| 809 | } |
---|
| 810 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 811 | { |
---|
| 812 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 813 | return; |
---|
[b7d3cc34] | 814 | } |
---|
[0da65d5] | 815 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 816 | { |
---|
| 817 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 818 | return; |
---|
[b7d3cc34] | 819 | } |
---|
| 820 | |
---|
[0da65d5] | 821 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 822 | { |
---|
| 823 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 824 | } |
---|
| 825 | else |
---|
| 826 | { |
---|
[84b045d] | 827 | imc_rem_block( ic, cmd[2] ); |
---|
| 828 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 829 | |
---|
[da3b536] | 830 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
[b7d3cc34] | 831 | } |
---|
| 832 | } |
---|
| 833 | |
---|
[f73b969] | 834 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 835 | { |
---|
| 836 | query_t *q = NULL; |
---|
| 837 | int numq = 0; |
---|
| 838 | |
---|
| 839 | if( irc->queries == NULL ) |
---|
| 840 | { |
---|
| 841 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 842 | return; |
---|
[b7d3cc34] | 843 | } |
---|
| 844 | |
---|
| 845 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 846 | first/last (depending on the query_order setting) one. */ |
---|
| 847 | if( cmd[1] ) |
---|
| 848 | { |
---|
| 849 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 850 | { |
---|
| 851 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 852 | return; |
---|
[b7d3cc34] | 853 | } |
---|
| 854 | |
---|
| 855 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 856 | if( numq == 0 ) |
---|
| 857 | break; |
---|
| 858 | |
---|
| 859 | if( !q ) |
---|
| 860 | { |
---|
| 861 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 862 | return; |
---|
[b7d3cc34] | 863 | } |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 867 | query_answer( irc, q, 1 ); |
---|
| 868 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 869 | query_answer( irc, q, 0 ); |
---|
| 870 | } |
---|
| 871 | |
---|
[f73b969] | 872 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 873 | { |
---|
[e7bc722] | 874 | cmd_set_real( irc, cmd, NULL ); |
---|
[b7d3cc34] | 875 | } |
---|
| 876 | |
---|
[f73b969] | 877 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 878 | { |
---|
[ab49fdc] | 879 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
[b7d3cc34] | 880 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 881 | else |
---|
| 882 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 883 | } |
---|
| 884 | |
---|
[f73b969] | 885 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 886 | { |
---|
| 887 | int online = 0, away = 0, offline = 0; |
---|
| 888 | user_t *u; |
---|
[aefa533e] | 889 | char s[256]; |
---|
| 890 | char *format; |
---|
[b7d3cc34] | 891 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 892 | |
---|
| 893 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 894 | online = offline = away = 1; |
---|
| 895 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 896 | offline = 1; |
---|
| 897 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 898 | away = 1; |
---|
| 899 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 900 | online = 1; |
---|
| 901 | else |
---|
| 902 | online = away = 1; |
---|
| 903 | |
---|
[aefa533e] | 904 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 905 | format = "%s\t%s\t%s"; |
---|
| 906 | else |
---|
| 907 | format = "%-16.16s %-40.40s %s"; |
---|
| 908 | |
---|
| 909 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 910 | |
---|
[0da65d5] | 911 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 912 | { |
---|
[aefa533e] | 913 | if( online == 1 ) |
---|
| 914 | { |
---|
[e731120] | 915 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 916 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
| 917 | } |
---|
| 918 | |
---|
[b7d3cc34] | 919 | n_online ++; |
---|
| 920 | } |
---|
| 921 | |
---|
[0da65d5] | 922 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
[b7d3cc34] | 923 | { |
---|
[aefa533e] | 924 | if( away == 1 ) |
---|
| 925 | { |
---|
[e731120] | 926 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 927 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 928 | } |
---|
[b7d3cc34] | 929 | n_away ++; |
---|
| 930 | } |
---|
| 931 | |
---|
[0da65d5] | 932 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
[b7d3cc34] | 933 | { |
---|
[aefa533e] | 934 | if( offline == 1 ) |
---|
| 935 | { |
---|
[e731120] | 936 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 937 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 938 | } |
---|
[b7d3cc34] | 939 | n_offline ++; |
---|
| 940 | } |
---|
| 941 | |
---|
[aa5ac01] | 942 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 943 | } |
---|
| 944 | |
---|
[f73b969] | 945 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 946 | { |
---|
| 947 | account_t *a; |
---|
| 948 | |
---|
| 949 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 950 | { |
---|
| 951 | irc_usermsg( irc, "Invalid account"); |
---|
| 952 | } |
---|
[0da65d5] | 953 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 954 | { |
---|
| 955 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 956 | } |
---|
| 957 | else if ( !cmd[2] ) |
---|
| 958 | { |
---|
[0da65d5] | 959 | irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" ); |
---|
[b7d3cc34] | 960 | } |
---|
[0da65d5] | 961 | else if ( !a->prpl->set_my_name ) |
---|
[b7d3cc34] | 962 | { |
---|
| 963 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 964 | } |
---|
| 965 | else |
---|
| 966 | { |
---|
| 967 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
| 968 | |
---|
[0da65d5] | 969 | a->prpl->set_my_name( a->ic, cmd[2] ); |
---|
[b7d3cc34] | 970 | } |
---|
| 971 | } |
---|
| 972 | |
---|
[f73b969] | 973 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 974 | { |
---|
| 975 | query_t *q = irc->queries; |
---|
| 976 | int num; |
---|
| 977 | |
---|
| 978 | if( !q ) |
---|
| 979 | { |
---|
| 980 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 981 | return; |
---|
[b7d3cc34] | 982 | } |
---|
| 983 | |
---|
| 984 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 985 | |
---|
| 986 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 987 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 988 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 989 | else |
---|
| 990 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 991 | } |
---|
| 992 | |
---|
[fa29d093] | 993 | static void cmd_join_chat( irc_t *irc, char **cmd ) |
---|
| 994 | { |
---|
[a9a7287] | 995 | irc_usermsg( irc, "This command is now obsolete. " |
---|
| 996 | "Please try the `chat' command instead." ); |
---|
| 997 | } |
---|
| 998 | |
---|
[e7bc722] | 999 | static set_t **cmd_chat_set_findhead( irc_t *irc, char *id ) |
---|
| 1000 | { |
---|
| 1001 | struct chat *c; |
---|
| 1002 | |
---|
| 1003 | if( ( c = chat_get( irc, id ) ) ) |
---|
| 1004 | return &c->set; |
---|
| 1005 | else |
---|
| 1006 | return NULL; |
---|
| 1007 | } |
---|
| 1008 | |
---|
[a9a7287] | 1009 | static void cmd_chat( irc_t *irc, char **cmd ) |
---|
| 1010 | { |
---|
| 1011 | account_t *acc; |
---|
| 1012 | struct chat *c; |
---|
| 1013 | |
---|
| 1014 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 1015 | { |
---|
| 1016 | if( !( cmd[2] && cmd[3] && cmd[4] ) ) |
---|
| 1017 | { |
---|
| 1018 | irc_usermsg( irc, "Not enough parameters given (need %d)", 4 ); |
---|
| 1019 | return; |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | if( !( acc = account_get( irc, cmd[2] ) ) ) |
---|
| 1023 | { |
---|
| 1024 | irc_usermsg( irc, "Invalid account" ); |
---|
| 1025 | return; |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | if( ( c = chat_add( irc, acc, cmd[3], cmd[4] ) ) ) |
---|
| 1029 | irc_usermsg( irc, "Chatroom added successfully." ); |
---|
| 1030 | else |
---|
| 1031 | irc_usermsg( irc, "Could not add chatroom." ); |
---|
| 1032 | } |
---|
| 1033 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 1034 | { |
---|
| 1035 | int i = 0; |
---|
| 1036 | |
---|
| 1037 | if( strchr( irc->umode, 'b' ) ) |
---|
| 1038 | irc_usermsg( irc, "Chatroom list:" ); |
---|
| 1039 | |
---|
| 1040 | for( c = irc->chatrooms; c; c = c->next ) |
---|
| 1041 | { |
---|
| 1042 | irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name, |
---|
| 1043 | c->acc->user, c->handle, c->channel ); |
---|
| 1044 | |
---|
| 1045 | i ++; |
---|
| 1046 | } |
---|
| 1047 | irc_usermsg( irc, "End of chatroom list" ); |
---|
| 1048 | } |
---|
[e7bc722] | 1049 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 1050 | { |
---|
| 1051 | cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead ); |
---|
| 1052 | } |
---|
[a9a7287] | 1053 | else |
---|
| 1054 | { |
---|
| 1055 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); |
---|
| 1056 | } |
---|
| 1057 | |
---|
| 1058 | |
---|
| 1059 | |
---|
| 1060 | #if 0 |
---|
[fa29d093] | 1061 | account_t *a; |
---|
[0da65d5] | 1062 | struct im_connection *ic; |
---|
[fa29d093] | 1063 | char *chat, *channel, *nick = NULL, *password = NULL; |
---|
[0da65d5] | 1064 | struct groupchat *c; |
---|
[fa29d093] | 1065 | |
---|
| 1066 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 1067 | { |
---|
| 1068 | irc_usermsg( irc, "Invalid account" ); |
---|
| 1069 | return; |
---|
| 1070 | } |
---|
[0da65d5] | 1071 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[fa29d093] | 1072 | { |
---|
| 1073 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 1074 | return; |
---|
| 1075 | } |
---|
| 1076 | else if( a->prpl->chat_join == NULL ) |
---|
| 1077 | { |
---|
| 1078 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 1079 | return; |
---|
| 1080 | } |
---|
[0da65d5] | 1081 | ic = a->ic; |
---|
[fa29d093] | 1082 | |
---|
| 1083 | chat = cmd[2]; |
---|
| 1084 | if( cmd[3] ) |
---|
| 1085 | { |
---|
[9da0bbf] | 1086 | if( cmd[3][0] != '#' && cmd[3][0] != '&' ) |
---|
[7bf4326] | 1087 | channel = g_strdup_printf( "&%s", cmd[3] ); |
---|
| 1088 | else |
---|
| 1089 | channel = g_strdup( cmd[3] ); |
---|
[fa29d093] | 1090 | } |
---|
| 1091 | else |
---|
| 1092 | { |
---|
| 1093 | char *s; |
---|
| 1094 | |
---|
[0e7ab64] | 1095 | channel = g_strdup_printf( "&%s", chat ); |
---|
[fa29d093] | 1096 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 1097 | *s = 0; |
---|
| 1098 | } |
---|
| 1099 | if( cmd[3] && cmd[4] ) |
---|
| 1100 | nick = cmd[4]; |
---|
[e35d1a1] | 1101 | else |
---|
| 1102 | nick = irc->nick; |
---|
[fa29d093] | 1103 | if( cmd[3] && cmd[4] && cmd[5] ) |
---|
| 1104 | password = cmd[5]; |
---|
| 1105 | |
---|
[7bf4326] | 1106 | if( !nick_ok( channel + 1 ) ) |
---|
[0e7ab64] | 1107 | { |
---|
| 1108 | irc_usermsg( irc, "Invalid channel name: %s", channel ); |
---|
| 1109 | g_free( channel ); |
---|
| 1110 | return; |
---|
| 1111 | } |
---|
| 1112 | else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) ) |
---|
| 1113 | { |
---|
| 1114 | irc_usermsg( irc, "Channel already exists: %s", channel ); |
---|
| 1115 | g_free( channel ); |
---|
| 1116 | return; |
---|
| 1117 | } |
---|
[fa29d093] | 1118 | |
---|
[e35d1a1] | 1119 | if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) ) |
---|
| 1120 | { |
---|
| 1121 | g_free( c->channel ); |
---|
| 1122 | c->channel = channel; |
---|
| 1123 | } |
---|
| 1124 | else |
---|
| 1125 | { |
---|
| 1126 | irc_usermsg( irc, "Tried to join chat, not sure if this was successful" ); |
---|
| 1127 | g_free( channel ); |
---|
| 1128 | } |
---|
[a9a7287] | 1129 | #endif |
---|
[fa29d093] | 1130 | } |
---|
| 1131 | |
---|
[0298d11] | 1132 | const command_t commands[] = { |
---|
| 1133 | { "help", 0, cmd_help, 0 }, |
---|
| 1134 | { "identify", 1, cmd_identify, 0 }, |
---|
| 1135 | { "register", 1, cmd_register, 0 }, |
---|
| 1136 | { "drop", 1, cmd_drop, 0 }, |
---|
| 1137 | { "account", 1, cmd_account, 0 }, |
---|
| 1138 | { "add", 2, cmd_add, 0 }, |
---|
| 1139 | { "info", 1, cmd_info, 0 }, |
---|
| 1140 | { "rename", 2, cmd_rename, 0 }, |
---|
| 1141 | { "remove", 1, cmd_remove, 0 }, |
---|
| 1142 | { "block", 1, cmd_block, 0 }, |
---|
| 1143 | { "allow", 1, cmd_allow, 0 }, |
---|
| 1144 | { "save", 0, cmd_save, 0 }, |
---|
| 1145 | { "set", 0, cmd_set, 0 }, |
---|
| 1146 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 1147 | { "no", 0, cmd_yesno, 0 }, |
---|
| 1148 | { "blist", 0, cmd_blist, 0 }, |
---|
| 1149 | { "nick", 1, cmd_nick, 0 }, |
---|
| 1150 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[fa29d093] | 1151 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
[a9a7287] | 1152 | { "chat", 1, cmd_chat, 0 }, |
---|
[0298d11] | 1153 | { NULL } |
---|
| 1154 | }; |
---|