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