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