[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[0baed0d] | 4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
[b7d3cc34] | 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 "bitlbee.h" |
---|
| 29 | #include "help.h" |
---|
[f1c2b21] | 30 | #include "ipc.h" |
---|
[b7d3cc34] | 31 | |
---|
[280c56a] | 32 | void root_command_string( irc_t *irc, char *command ) |
---|
[7e563ed] | 33 | { |
---|
[24b8bbb] | 34 | root_command( irc, split_command_parts( command ) ); |
---|
[7e563ed] | 35 | } |
---|
| 36 | |
---|
[3b99524] | 37 | #define MIN_ARGS( x, y... ) \ |
---|
| 38 | do \ |
---|
| 39 | { \ |
---|
[07054a5] | 40 | int blaat; \ |
---|
| 41 | for( blaat = 0; blaat <= x; blaat ++ ) \ |
---|
| 42 | if( cmd[blaat] == NULL ) \ |
---|
[3b99524] | 43 | { \ |
---|
| 44 | irc_usermsg( irc, "Not enough parameters given (need %d).", x ); \ |
---|
| 45 | return y; \ |
---|
| 46 | } \ |
---|
| 47 | } while( 0 ) |
---|
| 48 | |
---|
[f73b969] | 49 | void root_command( irc_t *irc, char *cmd[] ) |
---|
[7e563ed] | 50 | { |
---|
[6c56f42] | 51 | int i, len; |
---|
[7e563ed] | 52 | |
---|
| 53 | if( !cmd[0] ) |
---|
[f73b969] | 54 | return; |
---|
[7e563ed] | 55 | |
---|
[6c56f42] | 56 | len = strlen( cmd[0] ); |
---|
[7e563ed] | 57 | for( i = 0; commands[i].command; i++ ) |
---|
[6c56f42] | 58 | if( g_strncasecmp( commands[i].command, cmd[0], len ) == 0 ) |
---|
[7e563ed] | 59 | { |
---|
[6c56f42] | 60 | if( commands[i+1].command && |
---|
| 61 | g_strncasecmp( commands[i+1].command, cmd[0], len ) == 0 ) |
---|
| 62 | /* Only match on the first letters if the match is unique. */ |
---|
| 63 | break; |
---|
| 64 | |
---|
[3b99524] | 65 | MIN_ARGS( commands[i].required_parameters ); |
---|
| 66 | |
---|
[7e563ed] | 67 | commands[i].execute( irc, cmd ); |
---|
[f73b969] | 68 | return; |
---|
[7e563ed] | 69 | } |
---|
| 70 | |
---|
| 71 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
| 72 | } |
---|
| 73 | |
---|
[f73b969] | 74 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 75 | { |
---|
| 76 | char param[80]; |
---|
| 77 | int i; |
---|
| 78 | char *s; |
---|
| 79 | |
---|
| 80 | memset( param, 0, sizeof(param) ); |
---|
| 81 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
| 82 | if ( i != 1 ) // prepend space except for the first parameter |
---|
| 83 | strcat(param, " "); |
---|
| 84 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | s = help_get( &(global.help), param ); |
---|
| 88 | if( !s ) s = help_get( &(global.help), "" ); |
---|
| 89 | |
---|
| 90 | if( s ) |
---|
| 91 | { |
---|
| 92 | irc_usermsg( irc, "%s", s ); |
---|
| 93 | g_free( s ); |
---|
| 94 | } |
---|
| 95 | else |
---|
| 96 | { |
---|
| 97 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
[90bbb0e] | 101 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
| 102 | |
---|
[f73b969] | 103 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 104 | { |
---|
[92cb8c4] | 105 | storage_status_t status; |
---|
| 106 | gboolean load = TRUE; |
---|
| 107 | char *password = cmd[1]; |
---|
[b7d3cc34] | 108 | |
---|
[92cb8c4] | 109 | if( irc->status & USTATUS_IDENTIFIED ) |
---|
[e9cf291] | 110 | { |
---|
| 111 | irc_usermsg( irc, "You're already logged in." ); |
---|
| 112 | return; |
---|
| 113 | } |
---|
| 114 | |
---|
[92cb8c4] | 115 | if( strncmp( cmd[1], "-no", 3 ) == 0 ) |
---|
| 116 | { |
---|
| 117 | load = FALSE; |
---|
| 118 | password = cmd[2]; |
---|
| 119 | } |
---|
| 120 | else if( strncmp( cmd[1], "-force", 6 ) == 0 ) |
---|
| 121 | { |
---|
| 122 | password = cmd[2]; |
---|
| 123 | } |
---|
| 124 | else if( irc->b->accounts != NULL ) |
---|
| 125 | { |
---|
| 126 | irc_usermsg( irc, |
---|
| 127 | "You're trying to identify yourself, but already have " |
---|
| 128 | "at least one IM account set up. " |
---|
| 129 | "Use \x02identify -noload\x02 or \x02identify -force\x02 " |
---|
| 130 | "instead (see \x02help identify\x02)." ); |
---|
| 131 | return; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | if( password == NULL ) |
---|
| 135 | { |
---|
| 136 | MIN_ARGS( 2 ); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | if( load ) |
---|
| 140 | status = storage_load( irc, password ); |
---|
| 141 | else |
---|
| 142 | status = storage_check_pass( irc->user->nick, password ); |
---|
| 143 | |
---|
[09adf08] | 144 | switch (status) { |
---|
| 145 | case STORAGE_INVALID_PASSWORD: |
---|
[b7d3cc34] | 146 | irc_usermsg( irc, "Incorrect password" ); |
---|
[09adf08] | 147 | break; |
---|
| 148 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 149 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
[09adf08] | 150 | break; |
---|
| 151 | case STORAGE_OK: |
---|
[92cb8c4] | 152 | irc_usermsg( irc, "Password accepted%s", |
---|
| 153 | load ? ", settings and accounts loaded" : "" ); |
---|
| 154 | irc_setpass( irc, password ); |
---|
[3183c21] | 155 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 156 | irc_umode_set( irc, "+R", 1 ); |
---|
[6c2404e] | 157 | |
---|
[e92c4f4] | 158 | /* The following code is a bit hairy now. With takeover |
---|
| 159 | support, we shouldn't immediately auto_connect in case |
---|
| 160 | we're going to offer taking over an existing session. |
---|
| 161 | Do it in 200ms since that should give the parent process |
---|
| 162 | enough time to come back to us. */ |
---|
| 163 | if( load ) |
---|
[6c2404e] | 164 | { |
---|
[e92c4f4] | 165 | irc_channel_auto_joins( irc, NULL ); |
---|
[fe4f28f] | 166 | if( !set_getbool( &irc->default_channel->set, "auto_join" ) ) |
---|
| 167 | irc_channel_del_user( irc->default_channel, irc->user, |
---|
| 168 | IRC_CDU_PART, "auto_join disabled " |
---|
| 169 | "for this channel." ); |
---|
[e92c4f4] | 170 | if( set_getbool( &irc->b->set, "auto_connect" ) ) |
---|
[6c2404e] | 171 | irc->login_source_id = b_timeout_add( 200, |
---|
| 172 | cmd_identify_finish, irc ); |
---|
| 173 | } |
---|
[e92c4f4] | 174 | |
---|
| 175 | /* If ipc_child_identify() returns FALSE, it means we're |
---|
| 176 | already sure that there's no takeover target (only |
---|
| 177 | possible in 1-process daemon mode). Start auto_connect |
---|
| 178 | immediately. */ |
---|
| 179 | if( !ipc_child_identify( irc ) && load && |
---|
| 180 | set_getbool( &irc->b->set, "auto_connect" ) ) |
---|
[6c2404e] | 181 | cmd_identify_finish( irc, 0, 0 ); |
---|
| 182 | |
---|
[09adf08] | 183 | break; |
---|
[c121f89] | 184 | case STORAGE_OTHER_ERROR: |
---|
[09adf08] | 185 | default: |
---|
[c121f89] | 186 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
[09adf08] | 187 | break; |
---|
[b7d3cc34] | 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
[6c2404e] | 191 | gboolean cmd_identify_finish( gpointer data, gint fd, b_input_condition cond ) |
---|
| 192 | { |
---|
| 193 | char *account_on[] = { "account", "on", NULL }; |
---|
| 194 | irc_t *irc = data; |
---|
| 195 | |
---|
| 196 | cmd_account( irc, account_on ); |
---|
| 197 | |
---|
[af9f2ca] | 198 | b_event_remove( irc->login_source_id ); |
---|
[f545372] | 199 | irc->login_source_id = -1; |
---|
[6c2404e] | 200 | return FALSE; |
---|
| 201 | } |
---|
| 202 | |
---|
[f73b969] | 203 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 204 | { |
---|
| 205 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
| 206 | { |
---|
| 207 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
[f73b969] | 208 | return; |
---|
[b7d3cc34] | 209 | } |
---|
[1ee6c18] | 210 | |
---|
[3183c21] | 211 | switch( storage_save( irc, cmd[1], FALSE ) ) { |
---|
[a1f17d4] | 212 | case STORAGE_ALREADY_EXISTS: |
---|
| 213 | irc_usermsg( irc, "Nick is already registered" ); |
---|
| 214 | break; |
---|
| 215 | |
---|
| 216 | case STORAGE_OK: |
---|
[0383943] | 217 | irc_usermsg( irc, "Account successfully created" ); |
---|
[3183c21] | 218 | irc_setpass( irc, cmd[1] ); |
---|
[79e826a] | 219 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 220 | irc_umode_set( irc, "+R", 1 ); |
---|
[a1f17d4] | 221 | break; |
---|
| 222 | |
---|
| 223 | default: |
---|
| 224 | irc_usermsg( irc, "Error registering" ); |
---|
| 225 | break; |
---|
[b7d3cc34] | 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
[f73b969] | 229 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 230 | { |
---|
[a1f17d4] | 231 | storage_status_t status; |
---|
| 232 | |
---|
[1f92a58] | 233 | status = storage_remove (irc->user->nick, cmd[1]); |
---|
[a1f17d4] | 234 | switch (status) { |
---|
| 235 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 236 | irc_usermsg( irc, "That account does not exist" ); |
---|
[f73b969] | 237 | break; |
---|
[a1f17d4] | 238 | case STORAGE_INVALID_PASSWORD: |
---|
[1ee6c18] | 239 | irc_usermsg( irc, "Password invalid" ); |
---|
[f73b969] | 240 | break; |
---|
[a1f17d4] | 241 | case STORAGE_OK: |
---|
[7cad7b4] | 242 | irc_setpass( irc, NULL ); |
---|
[79e826a] | 243 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[238f828] | 244 | irc_umode_set( irc, "-R", 1 ); |
---|
[1f92a58] | 245 | irc_usermsg( irc, "Account `%s' removed", irc->user->nick ); |
---|
[f73b969] | 246 | break; |
---|
[a1f17d4] | 247 | default: |
---|
[30ce1ce] | 248 | irc_usermsg( irc, "Error: `%d'", status ); |
---|
[f73b969] | 249 | break; |
---|
[b7d3cc34] | 250 | } |
---|
| 251 | } |
---|
[1f92a58] | 252 | |
---|
| 253 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
| 254 | { |
---|
| 255 | if( ( irc->status & USTATUS_IDENTIFIED ) == 0 ) |
---|
| 256 | irc_usermsg( irc, "Please create an account first" ); |
---|
| 257 | else if( storage_save( irc, NULL, TRUE ) == STORAGE_OK ) |
---|
| 258 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 259 | else |
---|
| 260 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 261 | } |
---|
[b7d3cc34] | 262 | |
---|
[f536a99] | 263 | static void cmd_showset( irc_t *irc, set_t **head, char *key ) |
---|
[f3579fd] | 264 | { |
---|
[f536a99] | 265 | char *val; |
---|
[f3579fd] | 266 | |
---|
[f536a99] | 267 | if( ( val = set_getstr( head, key ) ) ) |
---|
| 268 | irc_usermsg( irc, "%s = `%s'", key, val ); |
---|
[f3579fd] | 269 | else |
---|
[f536a99] | 270 | irc_usermsg( irc, "%s is empty", key ); |
---|
[f3579fd] | 271 | } |
---|
| 272 | |
---|
[e7bc722] | 273 | typedef set_t** (*cmd_set_findhead)( irc_t*, char* ); |
---|
[c05eb5b] | 274 | typedef int (*cmd_set_checkflags)( irc_t*, set_t *set ); |
---|
[e7bc722] | 275 | |
---|
[e907683] | 276 | static int cmd_set_real( irc_t *irc, char **cmd, set_t **head, cmd_set_checkflags checkflags ) |
---|
[e7bc722] | 277 | { |
---|
[e907683] | 278 | char *set_name = NULL, *value = NULL; |
---|
| 279 | gboolean del = FALSE; |
---|
[e7bc722] | 280 | |
---|
| 281 | if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
[d4810df] | 282 | { |
---|
| 283 | MIN_ARGS( 2, 0 ); |
---|
[e907683] | 284 | set_name = cmd[2]; |
---|
| 285 | del = TRUE; |
---|
[d4810df] | 286 | } |
---|
[e7bc722] | 287 | else |
---|
| 288 | { |
---|
[e907683] | 289 | set_name = cmd[1]; |
---|
| 290 | value = cmd[2]; |
---|
[e7bc722] | 291 | } |
---|
| 292 | |
---|
[e907683] | 293 | if( set_name && ( value || del ) ) |
---|
[e7bc722] | 294 | { |
---|
| 295 | set_t *s = set_find( head, set_name ); |
---|
| 296 | int st; |
---|
| 297 | |
---|
[8a08d92] | 298 | if( s && checkflags && checkflags( irc, s ) == 0 ) |
---|
[e7bc722] | 299 | return 0; |
---|
| 300 | |
---|
[e907683] | 301 | if( del ) |
---|
[e7bc722] | 302 | st = set_reset( head, set_name ); |
---|
| 303 | else |
---|
[e907683] | 304 | st = set_setstr( head, set_name, value ); |
---|
[e7bc722] | 305 | |
---|
| 306 | if( set_getstr( head, set_name ) == NULL ) |
---|
| 307 | { |
---|
[e907683] | 308 | /* This happens when changing the passwd, for example. |
---|
| 309 | Showing these msgs instead gives slightly clearer |
---|
| 310 | feedback. */ |
---|
[e7bc722] | 311 | if( st ) |
---|
| 312 | irc_usermsg( irc, "Setting changed successfully" ); |
---|
| 313 | else |
---|
| 314 | irc_usermsg( irc, "Failed to change setting" ); |
---|
| 315 | } |
---|
| 316 | else |
---|
| 317 | { |
---|
| 318 | cmd_showset( irc, head, set_name ); |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | else if( set_name ) |
---|
| 322 | { |
---|
| 323 | cmd_showset( irc, head, set_name ); |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | { |
---|
| 327 | set_t *s = *head; |
---|
| 328 | while( s ) |
---|
| 329 | { |
---|
| 330 | cmd_showset( irc, &s, s->key ); |
---|
| 331 | s = s->next; |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | return 1; |
---|
| 336 | } |
---|
| 337 | |
---|
[c05eb5b] | 338 | static int cmd_account_set_checkflags( irc_t *irc, set_t *s ) |
---|
| 339 | { |
---|
| 340 | account_t *a = s->data; |
---|
| 341 | |
---|
| 342 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
| 343 | { |
---|
| 344 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 345 | return 0; |
---|
| 346 | } |
---|
| 347 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
| 348 | { |
---|
| 349 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
| 350 | return 0; |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | return 1; |
---|
| 354 | } |
---|
| 355 | |
---|
[f73b969] | 356 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 357 | { |
---|
| 358 | account_t *a; |
---|
[c7eb771] | 359 | int len; |
---|
[b7d3cc34] | 360 | |
---|
[3af70b0] | 361 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 362 | { |
---|
| 363 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 364 | return; |
---|
[b7d3cc34] | 365 | } |
---|
| 366 | |
---|
[c7eb771] | 367 | len = strlen( cmd[1] ); |
---|
| 368 | |
---|
| 369 | if( len >= 1 && g_strncasecmp( cmd[1], "add", len ) == 0 ) |
---|
[b7d3cc34] | 370 | { |
---|
[7b23afd] | 371 | struct prpl *prpl; |
---|
[b7d3cc34] | 372 | |
---|
[3b99524] | 373 | MIN_ARGS( 4 ); |
---|
[b7d3cc34] | 374 | |
---|
[a9a7287] | 375 | prpl = find_protocol( cmd[2] ); |
---|
[b7d3cc34] | 376 | |
---|
[7b23afd] | 377 | if( prpl == NULL ) |
---|
[b7d3cc34] | 378 | { |
---|
| 379 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 380 | return; |
---|
[b7d3cc34] | 381 | } |
---|
| 382 | |
---|
[d860a8d] | 383 | a = account_add( irc->b, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 384 | if( cmd[5] ) |
---|
[30ce1ce] | 385 | { |
---|
| 386 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
| 387 | "is now deprecated. Use `account set' instead." ); |
---|
[5100caa] | 388 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[30ce1ce] | 389 | } |
---|
[b7d3cc34] | 390 | |
---|
| 391 | irc_usermsg( irc, "Account successfully added" ); |
---|
[e907683] | 392 | |
---|
| 393 | return; |
---|
[b7d3cc34] | 394 | } |
---|
[c7eb771] | 395 | else if( len >= 1 && g_strncasecmp( cmd[1], "list", len ) == 0 ) |
---|
[b7d3cc34] | 396 | { |
---|
| 397 | int i = 0; |
---|
| 398 | |
---|
[e6e1f18] | 399 | if( strchr( irc->umode, 'b' ) ) |
---|
| 400 | irc_usermsg( irc, "Account list:" ); |
---|
| 401 | |
---|
[d860a8d] | 402 | for( a = irc->b->accounts; a; a = a->next ) |
---|
[b7d3cc34] | 403 | { |
---|
| 404 | char *con; |
---|
| 405 | |
---|
[0da65d5] | 406 | if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) |
---|
[b7d3cc34] | 407 | con = " (connected)"; |
---|
[0da65d5] | 408 | else if( a->ic ) |
---|
[b7d3cc34] | 409 | con = " (connecting)"; |
---|
| 410 | else if( a->reconnect ) |
---|
| 411 | con = " (awaiting reconnect)"; |
---|
| 412 | else |
---|
| 413 | con = ""; |
---|
| 414 | |
---|
[7b23afd] | 415 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 416 | |
---|
| 417 | i ++; |
---|
| 418 | } |
---|
| 419 | irc_usermsg( irc, "End of account list" ); |
---|
[e907683] | 420 | |
---|
| 421 | return; |
---|
| 422 | } |
---|
| 423 | else if( cmd[2] ) |
---|
| 424 | { |
---|
| 425 | /* Try the following two only if cmd[2] == NULL */ |
---|
[b7d3cc34] | 426 | } |
---|
[c7eb771] | 427 | else if( len >= 2 && g_strncasecmp( cmd[1], "on", len ) == 0 ) |
---|
[b7d3cc34] | 428 | { |
---|
[e907683] | 429 | if ( irc->b->accounts ) |
---|
[b7d3cc34] | 430 | { |
---|
[e907683] | 431 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 432 | |
---|
| 433 | for( a = irc->b->accounts; a; a = a->next ) |
---|
| 434 | if( !a->ic && a->auto_connect ) |
---|
[d860a8d] | 435 | account_on( irc->b, a ); |
---|
[e907683] | 436 | } |
---|
[b7d3cc34] | 437 | else |
---|
| 438 | { |
---|
[e907683] | 439 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
[b7d3cc34] | 440 | } |
---|
[e907683] | 441 | |
---|
| 442 | return; |
---|
[b7d3cc34] | 443 | } |
---|
[c7eb771] | 444 | else if( len >= 2 && g_strncasecmp( cmd[1], "off", len ) == 0 ) |
---|
[b7d3cc34] | 445 | { |
---|
[e907683] | 446 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 447 | |
---|
| 448 | for( a = irc->b->accounts; a; a = a->next ) |
---|
[b7d3cc34] | 449 | { |
---|
[0da65d5] | 450 | if( a->ic ) |
---|
[d860a8d] | 451 | account_off( irc->b, a ); |
---|
[b7d3cc34] | 452 | else if( a->reconnect ) |
---|
| 453 | cancel_auto_reconnect( a ); |
---|
[e907683] | 454 | } |
---|
| 455 | |
---|
| 456 | return; |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | MIN_ARGS( 2 ); |
---|
[c7eb771] | 460 | len = strlen( cmd[2] ); |
---|
[e907683] | 461 | |
---|
| 462 | /* At least right now, don't accept on/off/set/del as account IDs even |
---|
| 463 | if they're a proper match, since people not familiar with the new |
---|
| 464 | syntax yet may get a confusing/nasty surprise. */ |
---|
| 465 | if( g_strcasecmp( cmd[1], "on" ) == 0 || |
---|
| 466 | g_strcasecmp( cmd[1], "off" ) == 0 || |
---|
| 467 | g_strcasecmp( cmd[1], "set" ) == 0 || |
---|
| 468 | g_strcasecmp( cmd[1], "del" ) == 0 || |
---|
| 469 | ( a = account_get( irc->b, cmd[1] ) ) == NULL ) |
---|
| 470 | { |
---|
| 471 | irc_usermsg( irc, "Could not find account `%s'. Note that the syntax " |
---|
| 472 | "of the account command changed, see \x02help account\x02.", cmd[1] ); |
---|
| 473 | |
---|
| 474 | return; |
---|
| 475 | } |
---|
| 476 | |
---|
[c7eb771] | 477 | if( len >= 1 && g_strncasecmp( cmd[2], "del", len ) == 0 ) |
---|
[e907683] | 478 | { |
---|
| 479 | if( a->ic ) |
---|
| 480 | { |
---|
| 481 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
[b7d3cc34] | 482 | } |
---|
| 483 | else |
---|
| 484 | { |
---|
[e907683] | 485 | account_del( irc->b, a ); |
---|
| 486 | irc_usermsg( irc, "Account deleted" ); |
---|
[b7d3cc34] | 487 | } |
---|
| 488 | } |
---|
[c7eb771] | 489 | else if( len >= 2 && g_strncasecmp( cmd[2], "on", len ) == 0 ) |
---|
[5100caa] | 490 | { |
---|
[e907683] | 491 | if( a->ic ) |
---|
| 492 | irc_usermsg( irc, "Account already online" ); |
---|
| 493 | else |
---|
| 494 | account_on( irc->b, a ); |
---|
| 495 | } |
---|
[c7eb771] | 496 | else if( len >= 2 && g_strncasecmp( cmd[2], "off", len ) == 0 ) |
---|
[e907683] | 497 | { |
---|
| 498 | if( a->ic ) |
---|
| 499 | { |
---|
| 500 | account_off( irc->b, a ); |
---|
| 501 | } |
---|
| 502 | else if( a->reconnect ) |
---|
| 503 | { |
---|
| 504 | cancel_auto_reconnect( a ); |
---|
| 505 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 506 | } |
---|
| 507 | else |
---|
| 508 | { |
---|
| 509 | irc_usermsg( irc, "Account already offline" ); |
---|
| 510 | } |
---|
| 511 | } |
---|
[c7eb771] | 512 | else if( len >= 1 && g_strncasecmp( cmd[2], "set", len ) == 0 ) |
---|
[e907683] | 513 | { |
---|
| 514 | cmd_set_real( irc, cmd + 2, &a->set, cmd_account_set_checkflags ); |
---|
[5100caa] | 515 | } |
---|
[b7d3cc34] | 516 | else |
---|
| 517 | { |
---|
[e907683] | 518 | irc_usermsg( irc, "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[2] ); |
---|
[b7d3cc34] | 519 | } |
---|
| 520 | } |
---|
| 521 | |
---|
[e907683] | 522 | static void cmd_channel( irc_t *irc, char **cmd ) |
---|
[c133d4b8] | 523 | { |
---|
| 524 | irc_channel_t *ic; |
---|
[c7eb771] | 525 | int len; |
---|
| 526 | |
---|
| 527 | len = strlen( cmd[1] ); |
---|
[c133d4b8] | 528 | |
---|
[c7eb771] | 529 | if( len >= 1 && g_strncasecmp( cmd[1], "list", len ) == 0 ) |
---|
[36562b0] | 530 | { |
---|
| 531 | GSList *l; |
---|
| 532 | int i = 0; |
---|
| 533 | |
---|
| 534 | if( strchr( irc->umode, 'b' ) ) |
---|
| 535 | irc_usermsg( irc, "Channel list:" ); |
---|
| 536 | |
---|
| 537 | for( l = irc->channels; l; l = l->next ) |
---|
| 538 | { |
---|
| 539 | irc_channel_t *ic = l->data; |
---|
| 540 | |
---|
| 541 | irc_usermsg( irc, "%2d. %s, %s channel%s", i, ic->name, |
---|
| 542 | set_getstr( &ic->set, "type" ), |
---|
| 543 | ic->flags & IRC_CHANNEL_JOINED ? " (joined)" : "" ); |
---|
| 544 | |
---|
| 545 | i ++; |
---|
| 546 | } |
---|
| 547 | irc_usermsg( irc, "End of channel list" ); |
---|
[e907683] | 548 | |
---|
| 549 | return; |
---|
[36562b0] | 550 | } |
---|
[e907683] | 551 | |
---|
| 552 | if( ( ic = irc_channel_get( irc, cmd[1] ) ) == NULL ) |
---|
[a4d920b] | 553 | { |
---|
[4f22a68c] | 554 | /* If this doesn't match any channel, maybe this is the short |
---|
| 555 | syntax (only works when used inside a channel). */ |
---|
| 556 | if( ( len = strlen( cmd[1] ) ) && |
---|
| 557 | g_strncasecmp( cmd[1], "set", len ) == 0 && |
---|
| 558 | ( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) ) |
---|
| 559 | cmd_set_real( irc, cmd + 1, &ic->set, NULL ); |
---|
| 560 | else |
---|
| 561 | irc_usermsg( irc, "Could not find channel `%s'", cmd[1] ); |
---|
| 562 | |
---|
[e907683] | 563 | return; |
---|
| 564 | } |
---|
| 565 | |
---|
[4f22a68c] | 566 | MIN_ARGS( 2 ); |
---|
| 567 | len = strlen( cmd[2] ); |
---|
| 568 | |
---|
[c7eb771] | 569 | if( len >= 1 && g_strncasecmp( cmd[2], "set", len ) == 0 ) |
---|
[e907683] | 570 | { |
---|
| 571 | cmd_set_real( irc, cmd + 2, &ic->set, NULL ); |
---|
| 572 | } |
---|
[c7eb771] | 573 | else if( len >= 1 && g_strncasecmp( cmd[2], "del", len ) == 0 ) |
---|
[e907683] | 574 | { |
---|
| 575 | if( !( ic->flags & IRC_CHANNEL_JOINED ) && |
---|
[a4d920b] | 576 | ic != ic->irc->default_channel ) |
---|
| 577 | { |
---|
| 578 | irc_usermsg( irc, "Channel %s deleted.", ic->name ); |
---|
| 579 | irc_channel_free( ic ); |
---|
| 580 | } |
---|
| 581 | else |
---|
| 582 | irc_usermsg( irc, "Couldn't remove channel (main channel %s or " |
---|
| 583 | "channels you're still in cannot be deleted).", |
---|
[5266354] | 584 | irc->default_channel->name ); |
---|
[a4d920b] | 585 | } |
---|
[c133d4b8] | 586 | else |
---|
| 587 | { |
---|
[e907683] | 588 | irc_usermsg( irc, "Unknown command: %s [...] %s. Please use \x02help commands\x02 to get a list of available commands.", "channel", cmd[1] ); |
---|
[c133d4b8] | 589 | } |
---|
| 590 | } |
---|
| 591 | |
---|
[f73b969] | 592 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 593 | { |
---|
| 594 | account_t *a; |
---|
[f0cb961] | 595 | int add_on_server = 1; |
---|
[f8de26f] | 596 | |
---|
| 597 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 598 | { |
---|
[77fc000c] | 599 | MIN_ARGS( 3 ); |
---|
[f0cb961] | 600 | add_on_server = 0; |
---|
[7adc657] | 601 | cmd ++; |
---|
[f8de26f] | 602 | } |
---|
[b7d3cc34] | 603 | |
---|
[dbb0ce3] | 604 | if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 605 | { |
---|
| 606 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 607 | return; |
---|
[b7d3cc34] | 608 | } |
---|
[0da65d5] | 609 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 610 | { |
---|
| 611 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 612 | return; |
---|
[b7d3cc34] | 613 | } |
---|
| 614 | |
---|
| 615 | if( cmd[3] ) |
---|
| 616 | { |
---|
| 617 | if( !nick_ok( cmd[3] ) ) |
---|
| 618 | { |
---|
| 619 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 620 | return; |
---|
[b7d3cc34] | 621 | } |
---|
[dbb0ce3] | 622 | else if( irc_user_by_name( irc, cmd[3] ) ) |
---|
[b7d3cc34] | 623 | { |
---|
| 624 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 625 | return; |
---|
[b7d3cc34] | 626 | } |
---|
| 627 | else |
---|
| 628 | { |
---|
[b1f818b] | 629 | nick_set_raw( a, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 630 | } |
---|
| 631 | } |
---|
[f8de26f] | 632 | |
---|
[f0cb961] | 633 | if( add_on_server ) |
---|
[f1d488e] | 634 | { |
---|
| 635 | irc_channel_t *ic; |
---|
| 636 | char *s, *group = NULL;; |
---|
| 637 | |
---|
| 638 | if( ( ic = irc_channel_by_name( irc, irc->last_root_cmd ) ) && |
---|
| 639 | ( s = set_getstr( &ic->set, "fill_by" ) ) && |
---|
| 640 | strcmp( s, "group" ) == 0 && |
---|
| 641 | ( group = set_getstr( &ic->set, "group" ) ) ) |
---|
| 642 | irc_usermsg( irc, "Adding `%s' to contact list (group %s)", |
---|
| 643 | cmd[2], group ); |
---|
| 644 | else |
---|
| 645 | irc_usermsg( irc, "Adding `%s' to contact list", cmd[2] ); |
---|
| 646 | |
---|
| 647 | a->prpl->add_buddy( a->ic, cmd[2], group ); |
---|
| 648 | } |
---|
[7adc657] | 649 | else |
---|
[f1d488e] | 650 | { |
---|
| 651 | bee_user_t *bu; |
---|
| 652 | irc_user_t *iu; |
---|
| 653 | |
---|
[dbb0ce3] | 654 | /* Only for add -tmp. For regular adds, this callback will |
---|
| 655 | be called once the IM server confirms. */ |
---|
[f1d488e] | 656 | if( ( bu = bee_user_new( irc->b, a->ic, cmd[2], BEE_USER_LOCAL ) ) && |
---|
| 657 | ( iu = bu->ui_data ) ) |
---|
| 658 | irc_usermsg( irc, "Temporarily assigned nickname `%s' " |
---|
| 659 | "to contact `%s'", iu->nick, cmd[2] ); |
---|
| 660 | } |
---|
[f0cb961] | 661 | |
---|
[b7d3cc34] | 662 | } |
---|
| 663 | |
---|
[dbb0ce3] | 664 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
| 665 | { |
---|
| 666 | irc_user_t *iu; |
---|
| 667 | bee_user_t *bu; |
---|
| 668 | char *s; |
---|
| 669 | |
---|
| 670 | if( !( iu = irc_user_by_name( irc, cmd[1] ) ) || !( bu = iu->bu ) ) |
---|
| 671 | { |
---|
| 672 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
| 673 | return; |
---|
| 674 | } |
---|
| 675 | s = g_strdup( bu->handle ); |
---|
| 676 | |
---|
| 677 | bu->ic->acc->prpl->remove_buddy( bu->ic, bu->handle, NULL ); |
---|
[b1f818b] | 678 | nick_del( bu ); |
---|
[5e98ff0] | 679 | if( g_slist_find( irc->users, iu ) ) |
---|
| 680 | bee_user_free( irc->b, bu ); |
---|
[dbb0ce3] | 681 | |
---|
| 682 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 683 | g_free( s ); |
---|
| 684 | |
---|
| 685 | return; |
---|
| 686 | } |
---|
| 687 | |
---|
[f73b969] | 688 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 689 | { |
---|
[0da65d5] | 690 | struct im_connection *ic; |
---|
[b7d3cc34] | 691 | account_t *a; |
---|
| 692 | |
---|
| 693 | if( !cmd[2] ) |
---|
| 694 | { |
---|
[aa44bdd] | 695 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 696 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 697 | { |
---|
| 698 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 699 | return; |
---|
[b7d3cc34] | 700 | } |
---|
[aa44bdd] | 701 | ic = iu->bu->ic; |
---|
| 702 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 703 | } |
---|
[aa44bdd] | 704 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 705 | { |
---|
| 706 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 707 | return; |
---|
[b7d3cc34] | 708 | } |
---|
[0da65d5] | 709 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 710 | { |
---|
| 711 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 712 | return; |
---|
[b7d3cc34] | 713 | } |
---|
| 714 | |
---|
[0da65d5] | 715 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 716 | { |
---|
| 717 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 718 | } |
---|
[f73b969] | 719 | else |
---|
| 720 | { |
---|
[0da65d5] | 721 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 722 | } |
---|
[b7d3cc34] | 723 | } |
---|
| 724 | |
---|
[f73b969] | 725 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 726 | { |
---|
[9a9b520] | 727 | irc_user_t *iu, *old; |
---|
[b7d3cc34] | 728 | |
---|
[57c96f7] | 729 | iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 730 | |
---|
| 731 | if( iu == NULL ) |
---|
[0baed0d] | 732 | { |
---|
[57c96f7] | 733 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[0baed0d] | 734 | } |
---|
[57c96f7] | 735 | else if( iu == irc->user ) |
---|
[b7d3cc34] | 736 | { |
---|
[6c2404e] | 737 | irc_usermsg( irc, "Use /nick to change your own nickname" ); |
---|
[b7d3cc34] | 738 | } |
---|
[f73b969] | 739 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 740 | { |
---|
| 741 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 742 | } |
---|
[9a9b520] | 743 | else if( ( old = irc_user_by_name( irc, cmd[2] ) ) && old != iu ) |
---|
[b7d3cc34] | 744 | { |
---|
[57c96f7] | 745 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
[b7d3cc34] | 746 | } |
---|
[f73b969] | 747 | else |
---|
[b7d3cc34] | 748 | { |
---|
[57c96f7] | 749 | if( !irc_user_set_nick( iu, cmd[2] ) ) |
---|
| 750 | { |
---|
| 751 | irc_usermsg( irc, "Error while changing nick" ); |
---|
| 752 | return; |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | if( iu == irc->root ) |
---|
[f73b969] | 756 | { |
---|
[7125cb3] | 757 | /* If we're called internally (user did "set root_nick"), |
---|
| 758 | let's not go O(INF). :-) */ |
---|
[1195cec] | 759 | if( strcmp( cmd[0], "set_rename" ) != 0 ) |
---|
[57c96f7] | 760 | set_setstr( &irc->b->set, "root_nick", cmd[2] ); |
---|
[f73b969] | 761 | } |
---|
[57c96f7] | 762 | else if( iu->bu ) |
---|
[f73b969] | 763 | { |
---|
[b1f818b] | 764 | nick_set( iu->bu, cmd[2] ); |
---|
[f73b969] | 765 | } |
---|
| 766 | |
---|
| 767 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 768 | } |
---|
| 769 | } |
---|
| 770 | |
---|
[1195cec] | 771 | char *set_eval_root_nick( set_t *set, char *new_nick ) |
---|
| 772 | { |
---|
| 773 | irc_t *irc = set->data; |
---|
| 774 | |
---|
[0a6e5d1] | 775 | if( strcmp( irc->root->nick, new_nick ) != 0 ) |
---|
[1195cec] | 776 | { |
---|
[0a6e5d1] | 777 | char *cmd[] = { "set_rename", irc->root->nick, new_nick, NULL }; |
---|
[1195cec] | 778 | |
---|
| 779 | cmd_rename( irc, cmd ); |
---|
| 780 | } |
---|
| 781 | |
---|
[0a6e5d1] | 782 | return strcmp( irc->root->nick, new_nick ) == 0 ? new_nick : SET_INVALID; |
---|
[1195cec] | 783 | } |
---|
[0baed0d] | 784 | |
---|
[f73b969] | 785 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 786 | { |
---|
[0da65d5] | 787 | struct im_connection *ic; |
---|
[b7d3cc34] | 788 | account_t *a; |
---|
| 789 | |
---|
[2272cb3] | 790 | if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 791 | { |
---|
| 792 | char *format; |
---|
| 793 | GSList *l; |
---|
| 794 | |
---|
| 795 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 796 | format = "%s\t%s"; |
---|
| 797 | else |
---|
[57ef864] | 798 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 799 | |
---|
| 800 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 801 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 802 | { |
---|
[2272cb3] | 803 | bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); |
---|
| 804 | irc_user_t *iu = bu ? bu->ui_data : NULL; |
---|
| 805 | irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); |
---|
[87b6a3e] | 806 | } |
---|
| 807 | irc_usermsg( irc, "End of list." ); |
---|
| 808 | |
---|
| 809 | return; |
---|
| 810 | } |
---|
| 811 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 812 | { |
---|
[2272cb3] | 813 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 814 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 815 | { |
---|
| 816 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 817 | return; |
---|
[b7d3cc34] | 818 | } |
---|
[2272cb3] | 819 | ic = iu->bu->ic; |
---|
| 820 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 821 | } |
---|
[2272cb3] | 822 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 823 | { |
---|
| 824 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 825 | return; |
---|
[b7d3cc34] | 826 | } |
---|
[0da65d5] | 827 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 828 | { |
---|
| 829 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 830 | return; |
---|
[b7d3cc34] | 831 | } |
---|
| 832 | |
---|
[0da65d5] | 833 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 834 | { |
---|
| 835 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 836 | } |
---|
| 837 | else |
---|
| 838 | { |
---|
[84b045d] | 839 | imc_rem_allow( ic, cmd[2] ); |
---|
| 840 | imc_add_block( ic, cmd[2] ); |
---|
[f1d488e] | 841 | irc_usermsg( irc, "Buddy `%s' moved from allow- to block-list", cmd[2] ); |
---|
[b7d3cc34] | 842 | } |
---|
| 843 | } |
---|
| 844 | |
---|
[f73b969] | 845 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 846 | { |
---|
[0da65d5] | 847 | struct im_connection *ic; |
---|
[b7d3cc34] | 848 | account_t *a; |
---|
| 849 | |
---|
[2272cb3] | 850 | if( !cmd[2] && ( a = account_get( irc->b, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 851 | { |
---|
| 852 | char *format; |
---|
| 853 | GSList *l; |
---|
| 854 | |
---|
| 855 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 856 | format = "%s\t%s"; |
---|
| 857 | else |
---|
[57ef864] | 858 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 859 | |
---|
| 860 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 861 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 862 | { |
---|
[2272cb3] | 863 | bee_user_t *bu = bee_user_by_handle( irc->b, a->ic, l->data ); |
---|
| 864 | irc_user_t *iu = bu ? bu->ui_data : NULL; |
---|
| 865 | irc_usermsg( irc, format, l->data, iu ? iu->nick : "(none)" ); |
---|
[87b6a3e] | 866 | } |
---|
| 867 | irc_usermsg( irc, "End of list." ); |
---|
| 868 | |
---|
| 869 | return; |
---|
| 870 | } |
---|
| 871 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 872 | { |
---|
[2272cb3] | 873 | irc_user_t *iu = irc_user_by_name( irc, cmd[1] ); |
---|
| 874 | if( !iu || !iu->bu ) |
---|
[b7d3cc34] | 875 | { |
---|
| 876 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 877 | return; |
---|
[b7d3cc34] | 878 | } |
---|
[2272cb3] | 879 | ic = iu->bu->ic; |
---|
| 880 | cmd[2] = iu->bu->handle; |
---|
[b7d3cc34] | 881 | } |
---|
[2272cb3] | 882 | else if( !( a = account_get( irc->b, cmd[1] ) ) ) |
---|
[b7d3cc34] | 883 | { |
---|
| 884 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 885 | return; |
---|
[b7d3cc34] | 886 | } |
---|
[0da65d5] | 887 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 888 | { |
---|
| 889 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 890 | return; |
---|
[b7d3cc34] | 891 | } |
---|
| 892 | |
---|
[0da65d5] | 893 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 894 | { |
---|
| 895 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 896 | } |
---|
| 897 | else |
---|
| 898 | { |
---|
[84b045d] | 899 | imc_rem_block( ic, cmd[2] ); |
---|
| 900 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 901 | |
---|
[f1d488e] | 902 | irc_usermsg( irc, "Buddy `%s' moved from block- to allow-list", cmd[2] ); |
---|
[b7d3cc34] | 903 | } |
---|
| 904 | } |
---|
| 905 | |
---|
[f73b969] | 906 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 907 | { |
---|
| 908 | query_t *q = NULL; |
---|
| 909 | int numq = 0; |
---|
| 910 | |
---|
| 911 | if( irc->queries == NULL ) |
---|
| 912 | { |
---|
| 913 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 914 | return; |
---|
[b7d3cc34] | 915 | } |
---|
| 916 | |
---|
| 917 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 918 | first/last (depending on the query_order setting) one. */ |
---|
| 919 | if( cmd[1] ) |
---|
| 920 | { |
---|
| 921 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 922 | { |
---|
| 923 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 924 | return; |
---|
[b7d3cc34] | 925 | } |
---|
| 926 | |
---|
| 927 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 928 | if( numq == 0 ) |
---|
| 929 | break; |
---|
| 930 | |
---|
| 931 | if( !q ) |
---|
| 932 | { |
---|
| 933 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 934 | return; |
---|
[b7d3cc34] | 935 | } |
---|
| 936 | } |
---|
| 937 | |
---|
| 938 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 939 | query_answer( irc, q, 1 ); |
---|
| 940 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 941 | query_answer( irc, q, 0 ); |
---|
| 942 | } |
---|
| 943 | |
---|
[f73b969] | 944 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 945 | { |
---|
[e907683] | 946 | cmd_set_real( irc, cmd, &irc->b->set, NULL ); |
---|
[b7d3cc34] | 947 | } |
---|
| 948 | |
---|
[f73b969] | 949 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 950 | { |
---|
| 951 | int online = 0, away = 0, offline = 0; |
---|
[4c3519a] | 952 | GSList *l; |
---|
[aefa533e] | 953 | char s[256]; |
---|
| 954 | char *format; |
---|
[b7d3cc34] | 955 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 956 | |
---|
| 957 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 958 | online = offline = away = 1; |
---|
| 959 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 960 | offline = 1; |
---|
| 961 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 962 | away = 1; |
---|
| 963 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 964 | online = 1; |
---|
| 965 | else |
---|
[449a51d] | 966 | online = away = 1; |
---|
[b7d3cc34] | 967 | |
---|
[aefa533e] | 968 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 969 | format = "%s\t%s\t%s"; |
---|
| 970 | else |
---|
| 971 | format = "%-16.16s %-40.40s %s"; |
---|
| 972 | |
---|
[4c3519a] | 973 | irc_usermsg( irc, format, "Nick", "Handle/Account", "Status" ); |
---|
[b7d3cc34] | 974 | |
---|
[4c3519a] | 975 | for( l = irc->users; l; l = l->next ) |
---|
[b7d3cc34] | 976 | { |
---|
[4c3519a] | 977 | irc_user_t *iu = l->data; |
---|
| 978 | bee_user_t *bu = iu->bu; |
---|
| 979 | |
---|
| 980 | if( !bu || ( bu->flags & ( BEE_USER_ONLINE | BEE_USER_AWAY ) ) != BEE_USER_ONLINE ) |
---|
| 981 | continue; |
---|
| 982 | |
---|
[aefa533e] | 983 | if( online == 1 ) |
---|
| 984 | { |
---|
[449a51d] | 985 | char st[256] = "Online"; |
---|
| 986 | |
---|
[4c3519a] | 987 | if( bu->status_msg ) |
---|
| 988 | g_snprintf( st, sizeof( st ) - 1, "Online (%s)", bu->status_msg ); |
---|
[449a51d] | 989 | |
---|
[4c3519a] | 990 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
| 991 | irc_usermsg( irc, format, iu->nick, s, st ); |
---|
[aefa533e] | 992 | } |
---|
| 993 | |
---|
[b7d3cc34] | 994 | n_online ++; |
---|
| 995 | } |
---|
| 996 | |
---|
[4c3519a] | 997 | for( l = irc->users; l; l = l->next ) |
---|
[b7d3cc34] | 998 | { |
---|
[4c3519a] | 999 | irc_user_t *iu = l->data; |
---|
| 1000 | bee_user_t *bu = iu->bu; |
---|
| 1001 | |
---|
| 1002 | if( !bu || !( bu->flags & BEE_USER_ONLINE ) || !( bu->flags & BEE_USER_AWAY ) ) |
---|
| 1003 | continue; |
---|
| 1004 | |
---|
[aefa533e] | 1005 | if( away == 1 ) |
---|
| 1006 | { |
---|
[4c3519a] | 1007 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
| 1008 | irc_usermsg( irc, format, iu->nick, s, irc_user_get_away( iu ) ); |
---|
[aefa533e] | 1009 | } |
---|
[b7d3cc34] | 1010 | n_away ++; |
---|
| 1011 | } |
---|
| 1012 | |
---|
[4c3519a] | 1013 | for( l = irc->users; l; l = l->next ) |
---|
[b7d3cc34] | 1014 | { |
---|
[4c3519a] | 1015 | irc_user_t *iu = l->data; |
---|
| 1016 | bee_user_t *bu = iu->bu; |
---|
| 1017 | |
---|
| 1018 | if( !bu || bu->flags & BEE_USER_ONLINE ) |
---|
| 1019 | continue; |
---|
| 1020 | |
---|
[aefa533e] | 1021 | if( offline == 1 ) |
---|
| 1022 | { |
---|
[4c3519a] | 1023 | g_snprintf( s, sizeof( s ) - 1, "%s %s(%s)", bu->handle, bu->ic->acc->prpl->name, bu->ic->acc->user ); |
---|
| 1024 | irc_usermsg( irc, format, iu->nick, s, "Offline" ); |
---|
[aefa533e] | 1025 | } |
---|
[b7d3cc34] | 1026 | n_offline ++; |
---|
| 1027 | } |
---|
| 1028 | |
---|
[aa5ac01] | 1029 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 1030 | } |
---|
| 1031 | |
---|
[f73b969] | 1032 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 1033 | { |
---|
| 1034 | query_t *q = irc->queries; |
---|
| 1035 | int num; |
---|
| 1036 | |
---|
| 1037 | if( !q ) |
---|
| 1038 | { |
---|
| 1039 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 1040 | return; |
---|
[b7d3cc34] | 1041 | } |
---|
| 1042 | |
---|
| 1043 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 1044 | |
---|
| 1045 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 1046 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 1047 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 1048 | else |
---|
| 1049 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 1050 | } |
---|
| 1051 | |
---|
[a9a7287] | 1052 | static void cmd_chat( irc_t *irc, char **cmd ) |
---|
| 1053 | { |
---|
| 1054 | account_t *acc; |
---|
| 1055 | |
---|
| 1056 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 1057 | { |
---|
[07054a5] | 1058 | char *channel, *s; |
---|
[7b71feb] | 1059 | struct irc_channel *ic; |
---|
[07054a5] | 1060 | |
---|
| 1061 | MIN_ARGS( 3 ); |
---|
[a9a7287] | 1062 | |
---|
[7b71feb] | 1063 | if( !( acc = account_get( irc->b, cmd[2] ) ) ) |
---|
[a9a7287] | 1064 | { |
---|
| 1065 | irc_usermsg( irc, "Invalid account" ); |
---|
| 1066 | return; |
---|
| 1067 | } |
---|
[5a75d15] | 1068 | else if( !acc->prpl->chat_join ) |
---|
| 1069 | { |
---|
| 1070 | irc_usermsg( irc, "Named chatrooms not supported on that account." ); |
---|
| 1071 | return; |
---|
| 1072 | } |
---|
[a9a7287] | 1073 | |
---|
[07054a5] | 1074 | if( cmd[4] == NULL ) |
---|
| 1075 | { |
---|
| 1076 | channel = g_strdup( cmd[3] ); |
---|
| 1077 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 1078 | *s = 0; |
---|
| 1079 | } |
---|
| 1080 | else |
---|
| 1081 | { |
---|
| 1082 | channel = g_strdup( cmd[4] ); |
---|
| 1083 | } |
---|
| 1084 | |
---|
| 1085 | if( strchr( CTYPES, channel[0] ) == NULL ) |
---|
| 1086 | { |
---|
[7b71feb] | 1087 | s = g_strdup_printf( "#%s", channel ); |
---|
[07054a5] | 1088 | g_free( channel ); |
---|
| 1089 | channel = s; |
---|
[134a02c] | 1090 | |
---|
| 1091 | irc_channel_name_strip( channel ); |
---|
[07054a5] | 1092 | } |
---|
| 1093 | |
---|
[5a75d15] | 1094 | if( ( ic = irc_channel_new( irc, channel ) ) && |
---|
[547ea68] | 1095 | set_setstr( &ic->set, "type", "chat" ) && |
---|
[5a75d15] | 1096 | set_setstr( &ic->set, "chat_type", "room" ) && |
---|
| 1097 | set_setstr( &ic->set, "account", cmd[2] ) && |
---|
| 1098 | set_setstr( &ic->set, "room", cmd[3] ) ) |
---|
| 1099 | { |
---|
| 1100 | irc_usermsg( irc, "Chatroom successfully added." ); |
---|
| 1101 | } |
---|
| 1102 | else |
---|
[a9a7287] | 1103 | { |
---|
[5a75d15] | 1104 | if( ic ) |
---|
| 1105 | irc_channel_free( ic ); |
---|
[a9a7287] | 1106 | |
---|
[5a75d15] | 1107 | irc_usermsg( irc, "Could not add chatroom." ); |
---|
[d995c9b] | 1108 | } |
---|
[d7db346] | 1109 | g_free( channel ); |
---|
[d995c9b] | 1110 | } |
---|
[39f93f0] | 1111 | else if( g_strcasecmp( cmd[1], "with" ) == 0 ) |
---|
| 1112 | { |
---|
[c1a8a16] | 1113 | irc_user_t *iu; |
---|
[3b99524] | 1114 | |
---|
| 1115 | MIN_ARGS( 2 ); |
---|
[39f93f0] | 1116 | |
---|
[c1a8a16] | 1117 | if( ( iu = irc_user_by_name( irc, cmd[2] ) ) && |
---|
| 1118 | iu->bu && iu->bu->ic->acc->prpl->chat_with ) |
---|
[39f93f0] | 1119 | { |
---|
[c1a8a16] | 1120 | if( !iu->bu->ic->acc->prpl->chat_with( iu->bu->ic, iu->bu->handle ) ) |
---|
[39f93f0] | 1121 | { |
---|
| 1122 | irc_usermsg( irc, "(Possible) failure while trying to open " |
---|
[c1a8a16] | 1123 | "a groupchat with %s.", iu->nick ); |
---|
[39f93f0] | 1124 | } |
---|
| 1125 | } |
---|
| 1126 | else |
---|
| 1127 | { |
---|
| 1128 | irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] ); |
---|
| 1129 | } |
---|
| 1130 | } |
---|
[7cd2e8a] | 1131 | else if( g_strcasecmp( cmd[1], "list" ) == 0 || |
---|
| 1132 | g_strcasecmp( cmd[1], "set" ) == 0 || |
---|
| 1133 | g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 1134 | { |
---|
| 1135 | irc_usermsg( irc, "Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command." ); |
---|
| 1136 | cmd_channel( irc, cmd ); |
---|
| 1137 | } |
---|
[a9a7287] | 1138 | else |
---|
| 1139 | { |
---|
| 1140 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] ); |
---|
| 1141 | } |
---|
[fa29d093] | 1142 | } |
---|
| 1143 | |
---|
[f1d488e] | 1144 | static void cmd_group( irc_t *irc, char **cmd ) |
---|
| 1145 | { |
---|
| 1146 | GSList *l; |
---|
| 1147 | int len; |
---|
| 1148 | |
---|
| 1149 | len = strlen( cmd[1] ); |
---|
| 1150 | if( g_strncasecmp( cmd[1], "list", len ) == 0 ) |
---|
| 1151 | { |
---|
| 1152 | int n = 0; |
---|
| 1153 | |
---|
| 1154 | if( strchr( irc->umode, 'b' ) ) |
---|
| 1155 | irc_usermsg( irc, "Group list:" ); |
---|
| 1156 | |
---|
| 1157 | for( l = irc->b->groups; l; l = l->next ) |
---|
| 1158 | { |
---|
| 1159 | bee_group_t *bg = l->data; |
---|
| 1160 | irc_usermsg( irc, "%d. %s", n ++, bg->name ); |
---|
| 1161 | } |
---|
| 1162 | irc_usermsg( irc, "End of group list" ); |
---|
| 1163 | } |
---|
| 1164 | else |
---|
| 1165 | { |
---|
| 1166 | irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "group", cmd[1] ); |
---|
| 1167 | } |
---|
| 1168 | } |
---|
| 1169 | |
---|
[b8a491d] | 1170 | static void cmd_transfer( irc_t *irc, char **cmd ) |
---|
[2c2df7d] | 1171 | { |
---|
| 1172 | GSList *files = irc->file_transfers; |
---|
| 1173 | enum { LIST, REJECT, CANCEL }; |
---|
| 1174 | int subcmd = LIST; |
---|
| 1175 | int fid; |
---|
| 1176 | |
---|
| 1177 | if( !files ) |
---|
| 1178 | { |
---|
| 1179 | irc_usermsg( irc, "No pending transfers" ); |
---|
| 1180 | return; |
---|
| 1181 | } |
---|
| 1182 | |
---|
[b8a491d] | 1183 | if( cmd[1] && ( strcmp( cmd[1], "reject" ) == 0 ) ) |
---|
[2c2df7d] | 1184 | { |
---|
| 1185 | subcmd = REJECT; |
---|
| 1186 | } |
---|
[b8a491d] | 1187 | else if( cmd[1] && ( strcmp( cmd[1], "cancel" ) == 0 ) && |
---|
| 1188 | cmd[2] && ( sscanf( cmd[2], "%d", &fid ) == 1 ) ) |
---|
[2c2df7d] | 1189 | { |
---|
| 1190 | subcmd = CANCEL; |
---|
| 1191 | } |
---|
| 1192 | |
---|
| 1193 | for( ; files; files = g_slist_next( files ) ) |
---|
| 1194 | { |
---|
| 1195 | file_transfer_t *file = files->data; |
---|
| 1196 | |
---|
| 1197 | switch( subcmd ) { |
---|
| 1198 | case LIST: |
---|
| 1199 | if ( file->status == FT_STATUS_LISTENING ) |
---|
| 1200 | irc_usermsg( irc, |
---|
| 1201 | "Pending file(id %d): %s (Listening...)", file->local_id, file->file_name); |
---|
| 1202 | else |
---|
| 1203 | { |
---|
| 1204 | int kb_per_s = 0; |
---|
[44961cb] | 1205 | time_t diff = time( NULL ) - file->started ? : 1; |
---|
[2c2df7d] | 1206 | if ( ( file->started > 0 ) && ( file->bytes_transferred > 0 ) ) |
---|
| 1207 | kb_per_s = file->bytes_transferred / 1024 / diff; |
---|
| 1208 | |
---|
| 1209 | irc_usermsg( irc, |
---|
| 1210 | "Pending file(id %d): %s (%10zd/%zd kb, %d kb/s)", file->local_id, file->file_name, |
---|
| 1211 | file->bytes_transferred/1024, file->file_size/1024, kb_per_s); |
---|
| 1212 | } |
---|
| 1213 | break; |
---|
| 1214 | case REJECT: |
---|
| 1215 | if( file->status == FT_STATUS_LISTENING ) |
---|
| 1216 | { |
---|
| 1217 | irc_usermsg( irc, "Rejecting file transfer for %s", file->file_name ); |
---|
[9d4352c] | 1218 | imcb_file_canceled( file->ic, file, "Denied by user" ); |
---|
[2c2df7d] | 1219 | } |
---|
| 1220 | break; |
---|
| 1221 | case CANCEL: |
---|
| 1222 | if( file->local_id == fid ) |
---|
| 1223 | { |
---|
| 1224 | irc_usermsg( irc, "Canceling file transfer for %s", file->file_name ); |
---|
[9d4352c] | 1225 | imcb_file_canceled( file->ic, file, "Canceled by user" ); |
---|
[2c2df7d] | 1226 | } |
---|
| 1227 | break; |
---|
| 1228 | } |
---|
| 1229 | } |
---|
| 1230 | } |
---|
| 1231 | |
---|
[6c56f42] | 1232 | /* IMPORTANT: Keep this list sorted! The short command logic needs that. */ |
---|
[0298d11] | 1233 | const command_t commands[] = { |
---|
[d860a8d] | 1234 | { "account", 1, cmd_account, 0 }, |
---|
[6c56f42] | 1235 | { "add", 2, cmd_add, 0 }, |
---|
[2272cb3] | 1236 | { "allow", 1, cmd_allow, 0 }, |
---|
[4c3519a] | 1237 | { "blist", 0, cmd_blist, 0 }, |
---|
[2272cb3] | 1238 | { "block", 1, cmd_block, 0 }, |
---|
[c133d4b8] | 1239 | { "channel", 1, cmd_channel, 0 }, |
---|
| 1240 | { "chat", 1, cmd_chat, 0 }, |
---|
[6c56f42] | 1241 | { "drop", 1, cmd_drop, 0 }, |
---|
[9d4352c] | 1242 | { "ft", 0, cmd_transfer, 0 }, |
---|
[f1d488e] | 1243 | { "group", 1, cmd_group, 0 }, |
---|
[6c56f42] | 1244 | { "help", 0, cmd_help, 0 }, |
---|
[0298d11] | 1245 | { "identify", 1, cmd_identify, 0 }, |
---|
[aa44bdd] | 1246 | { "info", 1, cmd_info, 0 }, |
---|
[6c56f42] | 1247 | { "no", 0, cmd_yesno, 0 }, |
---|
[9d4352c] | 1248 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[0298d11] | 1249 | { "register", 1, cmd_register, 0 }, |
---|
[dbb0ce3] | 1250 | { "remove", 1, cmd_remove, 0 }, |
---|
[0298d11] | 1251 | { "rename", 2, cmd_rename, 0 }, |
---|
[6c56f42] | 1252 | { "save", 0, cmd_save, 0 }, |
---|
[0298d11] | 1253 | { "set", 0, cmd_set, 0 }, |
---|
[9d4352c] | 1254 | { "transfer", 0, cmd_transfer, 0 }, |
---|
[0298d11] | 1255 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 1256 | { NULL } |
---|
| 1257 | }; |
---|