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