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