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