[b7d3cc34] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
| 4 | * Copyright 2002-2004 Wilmer van der Gaast and others * |
---|
| 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* User manager (root) commands */ |
---|
| 8 | |
---|
| 9 | /* |
---|
| 10 | This program is free software; you can redistribute it and/or modify |
---|
| 11 | it under the terms of the GNU General Public License as published by |
---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | (at your option) any later version. |
---|
| 14 | |
---|
| 15 | This program is distributed in the hope that it will be useful, |
---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | GNU General Public License for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GNU General Public License with |
---|
| 21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
| 22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
| 23 | Suite 330, Boston, MA 02111-1307 USA |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #define BITLBEE_CORE |
---|
| 27 | #include "commands.h" |
---|
| 28 | #include "crypting.h" |
---|
| 29 | #include "bitlbee.h" |
---|
| 30 | #include "help.h" |
---|
| 31 | |
---|
| 32 | #include <string.h> |
---|
| 33 | |
---|
[f73b969] | 34 | void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) |
---|
[7e563ed] | 35 | { |
---|
| 36 | char *cmd[IRC_MAX_ARGS]; |
---|
| 37 | char *s; |
---|
| 38 | int k; |
---|
| 39 | char q = 0; |
---|
| 40 | |
---|
| 41 | memset( cmd, 0, sizeof( cmd ) ); |
---|
| 42 | cmd[0] = command; |
---|
| 43 | k = 1; |
---|
| 44 | for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) |
---|
| 45 | if( *s == ' ' && !q ) |
---|
| 46 | { |
---|
| 47 | *s = 0; |
---|
| 48 | while( *++s == ' ' ); |
---|
| 49 | if( *s == '"' || *s == '\'' ) |
---|
| 50 | { |
---|
| 51 | q = *s; |
---|
| 52 | s ++; |
---|
| 53 | } |
---|
| 54 | if( *s ) |
---|
| 55 | { |
---|
| 56 | cmd[k++] = s; |
---|
| 57 | s --; |
---|
| 58 | } |
---|
[619a681] | 59 | else |
---|
| 60 | { |
---|
| 61 | break; |
---|
| 62 | } |
---|
[7e563ed] | 63 | } |
---|
[79c6f9f] | 64 | else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) |
---|
| 65 | { |
---|
| 66 | char *cpy; |
---|
| 67 | |
---|
| 68 | for( cpy = s; *cpy; cpy ++ ) |
---|
| 69 | cpy[0] = cpy[1]; |
---|
| 70 | } |
---|
[7e563ed] | 71 | else if( *s == q ) |
---|
| 72 | { |
---|
| 73 | q = *s = 0; |
---|
| 74 | } |
---|
| 75 | cmd[k] = NULL; |
---|
| 76 | |
---|
[f73b969] | 77 | root_command( irc, cmd ); |
---|
[7e563ed] | 78 | } |
---|
| 79 | |
---|
[f73b969] | 80 | void root_command( irc_t *irc, char *cmd[] ) |
---|
[7e563ed] | 81 | { |
---|
| 82 | int i; |
---|
| 83 | |
---|
| 84 | if( !cmd[0] ) |
---|
[f73b969] | 85 | return; |
---|
[7e563ed] | 86 | |
---|
| 87 | for( i = 0; commands[i].command; i++ ) |
---|
| 88 | if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) |
---|
| 89 | { |
---|
| 90 | if( !cmd[commands[i].required_parameters] ) |
---|
| 91 | { |
---|
| 92 | irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); |
---|
[f73b969] | 93 | return; |
---|
[7e563ed] | 94 | } |
---|
| 95 | commands[i].execute( irc, cmd ); |
---|
[f73b969] | 96 | return; |
---|
[7e563ed] | 97 | } |
---|
| 98 | |
---|
| 99 | irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); |
---|
| 100 | } |
---|
| 101 | |
---|
[f73b969] | 102 | static void cmd_help( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 103 | { |
---|
| 104 | char param[80]; |
---|
| 105 | int i; |
---|
| 106 | char *s; |
---|
| 107 | |
---|
| 108 | memset( param, 0, sizeof(param) ); |
---|
| 109 | for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { |
---|
| 110 | if ( i != 1 ) // prepend space except for the first parameter |
---|
| 111 | strcat(param, " "); |
---|
| 112 | strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | s = help_get( &(global.help), param ); |
---|
| 116 | if( !s ) s = help_get( &(global.help), "" ); |
---|
| 117 | |
---|
| 118 | if( s ) |
---|
| 119 | { |
---|
| 120 | irc_usermsg( irc, "%s", s ); |
---|
| 121 | g_free( s ); |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
| 125 | irc_usermsg( irc, "Error opening helpfile." ); |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
[90bbb0e] | 129 | static void cmd_account( irc_t *irc, char **cmd ); |
---|
| 130 | |
---|
[f73b969] | 131 | static void cmd_identify( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 132 | { |
---|
[ab49fdc] | 133 | storage_status_t status = storage_load( irc->nick, cmd[1], irc ); |
---|
[90bbb0e] | 134 | char *account_on[] = { "account", "on", NULL }; |
---|
[b7d3cc34] | 135 | |
---|
[09adf08] | 136 | switch (status) { |
---|
| 137 | case STORAGE_INVALID_PASSWORD: |
---|
[b7d3cc34] | 138 | irc_usermsg( irc, "Incorrect password" ); |
---|
[09adf08] | 139 | break; |
---|
| 140 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 141 | irc_usermsg( irc, "The nick is (probably) not registered" ); |
---|
[09adf08] | 142 | break; |
---|
| 143 | case STORAGE_OK: |
---|
[6ee9d2d] | 144 | irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); |
---|
[238f828] | 145 | irc_umode_set( irc, "+R", 1 ); |
---|
[d5ccd83] | 146 | if( set_getbool( &irc->set, "auto_connect" ) ) |
---|
[90bbb0e] | 147 | cmd_account( irc, account_on ); |
---|
[09adf08] | 148 | break; |
---|
[c121f89] | 149 | case STORAGE_OTHER_ERROR: |
---|
[09adf08] | 150 | default: |
---|
[c121f89] | 151 | irc_usermsg( irc, "Unknown error while loading configuration" ); |
---|
[09adf08] | 152 | break; |
---|
[b7d3cc34] | 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
[f73b969] | 156 | static void cmd_register( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 157 | { |
---|
| 158 | if( global.conf->authmode == AUTHMODE_REGISTERED ) |
---|
| 159 | { |
---|
| 160 | irc_usermsg( irc, "This server does not allow registering new accounts" ); |
---|
[f73b969] | 161 | return; |
---|
[b7d3cc34] | 162 | } |
---|
[1ee6c18] | 163 | |
---|
[7cad7b4] | 164 | irc_setpass( irc, cmd[1] ); |
---|
[ab49fdc] | 165 | switch( storage_save( irc, FALSE )) { |
---|
[a1f17d4] | 166 | case STORAGE_ALREADY_EXISTS: |
---|
| 167 | irc_usermsg( irc, "Nick is already registered" ); |
---|
| 168 | break; |
---|
| 169 | |
---|
| 170 | case STORAGE_OK: |
---|
[0383943] | 171 | irc_usermsg( irc, "Account successfully created" ); |
---|
[79e826a] | 172 | irc->status |= USTATUS_IDENTIFIED; |
---|
[238f828] | 173 | irc_umode_set( irc, "+R", 1 ); |
---|
[a1f17d4] | 174 | break; |
---|
| 175 | |
---|
| 176 | default: |
---|
| 177 | irc_usermsg( irc, "Error registering" ); |
---|
| 178 | break; |
---|
[b7d3cc34] | 179 | } |
---|
| 180 | } |
---|
| 181 | |
---|
[f73b969] | 182 | static void cmd_drop( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 183 | { |
---|
[a1f17d4] | 184 | storage_status_t status; |
---|
| 185 | |
---|
[ab49fdc] | 186 | status = storage_remove (irc->nick, cmd[1]); |
---|
[a1f17d4] | 187 | switch (status) { |
---|
| 188 | case STORAGE_NO_SUCH_USER: |
---|
[b7d3cc34] | 189 | irc_usermsg( irc, "That account does not exist" ); |
---|
[f73b969] | 190 | break; |
---|
[a1f17d4] | 191 | case STORAGE_INVALID_PASSWORD: |
---|
[1ee6c18] | 192 | irc_usermsg( irc, "Password invalid" ); |
---|
[f73b969] | 193 | break; |
---|
[a1f17d4] | 194 | case STORAGE_OK: |
---|
[7cad7b4] | 195 | irc_setpass( irc, NULL ); |
---|
[79e826a] | 196 | irc->status &= ~USTATUS_IDENTIFIED; |
---|
[238f828] | 197 | irc_umode_set( irc, "-R", 1 ); |
---|
[a1f17d4] | 198 | irc_usermsg( irc, "Account `%s' removed", irc->nick ); |
---|
[f73b969] | 199 | break; |
---|
[a1f17d4] | 200 | default: |
---|
[30ce1ce] | 201 | irc_usermsg( irc, "Error: `%d'", status ); |
---|
[f73b969] | 202 | break; |
---|
[b7d3cc34] | 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
[7f421d6] | 206 | void cmd_account_del_yes( gpointer w, void *data ) |
---|
| 207 | { |
---|
| 208 | account_t *a = data; |
---|
| 209 | irc_t *irc = a->irc; |
---|
| 210 | |
---|
| 211 | if( a->ic ) |
---|
| 212 | { |
---|
| 213 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
| 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
| 217 | account_del( irc, a ); |
---|
| 218 | irc_usermsg( irc, "Account deleted" ); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | void cmd_account_del_no( gpointer w, void *data ) |
---|
| 223 | { |
---|
| 224 | } |
---|
| 225 | |
---|
[f73b969] | 226 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 227 | { |
---|
| 228 | account_t *a; |
---|
| 229 | |
---|
[3af70b0] | 230 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 231 | { |
---|
| 232 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 233 | return; |
---|
[b7d3cc34] | 234 | } |
---|
| 235 | |
---|
| 236 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 237 | { |
---|
[7b23afd] | 238 | struct prpl *prpl; |
---|
[b7d3cc34] | 239 | |
---|
| 240 | if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) |
---|
| 241 | { |
---|
| 242 | irc_usermsg( irc, "Not enough parameters" ); |
---|
[f73b969] | 243 | return; |
---|
[b7d3cc34] | 244 | } |
---|
| 245 | |
---|
[7b23afd] | 246 | prpl = find_protocol(cmd[2]); |
---|
[b7d3cc34] | 247 | |
---|
[7b23afd] | 248 | if( prpl == NULL ) |
---|
[b7d3cc34] | 249 | { |
---|
| 250 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 251 | return; |
---|
[b7d3cc34] | 252 | } |
---|
| 253 | |
---|
[7b23afd] | 254 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 255 | if( cmd[5] ) |
---|
[30ce1ce] | 256 | { |
---|
| 257 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
| 258 | "is now deprecated. Use `account set' instead." ); |
---|
[5100caa] | 259 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[30ce1ce] | 260 | } |
---|
[b7d3cc34] | 261 | |
---|
| 262 | irc_usermsg( irc, "Account successfully added" ); |
---|
| 263 | } |
---|
| 264 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 265 | { |
---|
| 266 | if( !cmd[2] ) |
---|
| 267 | { |
---|
| 268 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 269 | } |
---|
| 270 | else if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
| 271 | { |
---|
| 272 | irc_usermsg( irc, "Invalid account" ); |
---|
| 273 | } |
---|
[0da65d5] | 274 | else if( a->ic ) |
---|
[b7d3cc34] | 275 | { |
---|
| 276 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
| 277 | } |
---|
| 278 | else |
---|
| 279 | { |
---|
[7f421d6] | 280 | char *msg; |
---|
| 281 | |
---|
| 282 | msg = g_strdup_printf( "If you remove this account (%s(%s)), BitlBee will " |
---|
| 283 | "also forget all your saved nicknames. If you want " |
---|
| 284 | "to change your username/password, use the `account " |
---|
| 285 | "set' command. Are you sure you want to delete this " |
---|
| 286 | "account?", a->prpl->name, a->user ); |
---|
| 287 | query_add( irc, NULL, msg, cmd_account_del_yes, cmd_account_del_no, a ); |
---|
| 288 | g_free( msg ); |
---|
[b7d3cc34] | 289 | } |
---|
| 290 | } |
---|
| 291 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 292 | { |
---|
| 293 | int i = 0; |
---|
| 294 | |
---|
[e6e1f18] | 295 | if( strchr( irc->umode, 'b' ) ) |
---|
| 296 | irc_usermsg( irc, "Account list:" ); |
---|
| 297 | |
---|
[b7d3cc34] | 298 | for( a = irc->accounts; a; a = a->next ) |
---|
| 299 | { |
---|
| 300 | char *con; |
---|
| 301 | |
---|
[0da65d5] | 302 | if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) |
---|
[b7d3cc34] | 303 | con = " (connected)"; |
---|
[0da65d5] | 304 | else if( a->ic ) |
---|
[b7d3cc34] | 305 | con = " (connecting)"; |
---|
| 306 | else if( a->reconnect ) |
---|
| 307 | con = " (awaiting reconnect)"; |
---|
| 308 | else |
---|
| 309 | con = ""; |
---|
| 310 | |
---|
[7b23afd] | 311 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 312 | |
---|
| 313 | i ++; |
---|
| 314 | } |
---|
| 315 | irc_usermsg( irc, "End of account list" ); |
---|
| 316 | } |
---|
| 317 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
| 318 | { |
---|
| 319 | if( cmd[2] ) |
---|
| 320 | { |
---|
| 321 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 322 | { |
---|
[0da65d5] | 323 | if( a->ic ) |
---|
[b7d3cc34] | 324 | { |
---|
| 325 | irc_usermsg( irc, "Account already online" ); |
---|
[f73b969] | 326 | return; |
---|
[b7d3cc34] | 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
| 330 | account_on( irc, a ); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | else |
---|
| 334 | { |
---|
| 335 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 336 | return; |
---|
[b7d3cc34] | 337 | } |
---|
| 338 | } |
---|
| 339 | else |
---|
| 340 | { |
---|
| 341 | if ( irc->accounts ) { |
---|
| 342 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 343 | |
---|
| 344 | for( a = irc->accounts; a; a = a->next ) |
---|
[0da65d5] | 345 | if( !a->ic && a->auto_connect ) |
---|
[b7d3cc34] | 346 | account_on( irc, a ); |
---|
| 347 | } |
---|
| 348 | else |
---|
| 349 | { |
---|
[30ce1ce] | 350 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
[b7d3cc34] | 351 | } |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
| 355 | { |
---|
| 356 | if( !cmd[2] ) |
---|
| 357 | { |
---|
| 358 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 359 | |
---|
| 360 | for( a = irc->accounts; a; a = a->next ) |
---|
| 361 | { |
---|
[0da65d5] | 362 | if( a->ic ) |
---|
[b7d3cc34] | 363 | account_off( irc, a ); |
---|
| 364 | else if( a->reconnect ) |
---|
| 365 | cancel_auto_reconnect( a ); |
---|
| 366 | } |
---|
| 367 | } |
---|
| 368 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 369 | { |
---|
[0da65d5] | 370 | if( a->ic ) |
---|
[b7d3cc34] | 371 | { |
---|
| 372 | account_off( irc, a ); |
---|
| 373 | } |
---|
| 374 | else if( a->reconnect ) |
---|
| 375 | { |
---|
| 376 | cancel_auto_reconnect( a ); |
---|
| 377 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 378 | } |
---|
| 379 | else |
---|
| 380 | { |
---|
| 381 | irc_usermsg( irc, "Account already offline" ); |
---|
[f73b969] | 382 | return; |
---|
[b7d3cc34] | 383 | } |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 388 | return; |
---|
[b7d3cc34] | 389 | } |
---|
| 390 | } |
---|
[5100caa] | 391 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 392 | { |
---|
| 393 | char *acc_handle, *set_name = NULL, *tmp; |
---|
| 394 | |
---|
| 395 | if( !cmd[2] ) |
---|
| 396 | { |
---|
| 397 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 398 | return; |
---|
| 399 | } |
---|
| 400 | |
---|
[cd428e4] | 401 | if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) |
---|
| 402 | acc_handle = g_strdup( cmd[3] ); |
---|
| 403 | else |
---|
| 404 | acc_handle = g_strdup( cmd[2] ); |
---|
| 405 | |
---|
[5100caa] | 406 | if( ( tmp = strchr( acc_handle, '/' ) ) ) |
---|
| 407 | { |
---|
| 408 | *tmp = 0; |
---|
| 409 | set_name = tmp + 1; |
---|
| 410 | } |
---|
| 411 | |
---|
[cd428e4] | 412 | if( ( a = account_get( irc, acc_handle ) ) == NULL ) |
---|
[5100caa] | 413 | { |
---|
[75a4b85] | 414 | g_free( acc_handle ); |
---|
[5100caa] | 415 | irc_usermsg( irc, "Invalid account" ); |
---|
| 416 | return; |
---|
| 417 | } |
---|
| 418 | |
---|
[9334cc2] | 419 | if( cmd[3] && set_name ) |
---|
[5100caa] | 420 | { |
---|
| 421 | set_t *s = set_find( &a->set, set_name ); |
---|
| 422 | |
---|
[0da65d5] | 423 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
[5100caa] | 424 | { |
---|
[75a4b85] | 425 | g_free( acc_handle ); |
---|
[911f2eb] | 426 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 427 | return; |
---|
| 428 | } |
---|
[0da65d5] | 429 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
[911f2eb] | 430 | { |
---|
[75a4b85] | 431 | g_free( acc_handle ); |
---|
[911f2eb] | 432 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
[5100caa] | 433 | return; |
---|
| 434 | } |
---|
| 435 | |
---|
[71dc854] | 436 | if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) |
---|
[cd428e4] | 437 | set_reset( &a->set, set_name ); |
---|
| 438 | else |
---|
| 439 | set_setstr( &a->set, set_name, cmd[3] ); |
---|
[5100caa] | 440 | } |
---|
| 441 | if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
| 442 | { |
---|
| 443 | char *s = set_getstr( &a->set, set_name ); |
---|
| 444 | if( s ) |
---|
| 445 | irc_usermsg( irc, "%s = `%s'", set_name, s ); |
---|
| 446 | else |
---|
| 447 | irc_usermsg( irc, "%s is empty", set_name ); |
---|
| 448 | } |
---|
| 449 | else |
---|
| 450 | { |
---|
| 451 | set_t *s = a->set; |
---|
| 452 | while( s ) |
---|
| 453 | { |
---|
| 454 | if( s->value || s->def ) |
---|
[cd428e4] | 455 | irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); |
---|
[5100caa] | 456 | else |
---|
| 457 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
| 458 | s = s->next; |
---|
| 459 | } |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | g_free( acc_handle ); |
---|
| 463 | } |
---|
[b7d3cc34] | 464 | else |
---|
| 465 | { |
---|
[5c09a59] | 466 | irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] ); |
---|
[b7d3cc34] | 467 | } |
---|
| 468 | } |
---|
| 469 | |
---|
[f73b969] | 470 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 471 | { |
---|
| 472 | account_t *a; |
---|
[f0cb961] | 473 | int add_on_server = 1; |
---|
[f8de26f] | 474 | |
---|
| 475 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 476 | { |
---|
[f0cb961] | 477 | add_on_server = 0; |
---|
[7adc657] | 478 | cmd ++; |
---|
[f8de26f] | 479 | } |
---|
[b7d3cc34] | 480 | |
---|
| 481 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 482 | { |
---|
| 483 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 484 | return; |
---|
[b7d3cc34] | 485 | } |
---|
[0da65d5] | 486 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 487 | { |
---|
| 488 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 489 | return; |
---|
[b7d3cc34] | 490 | } |
---|
| 491 | |
---|
| 492 | if( cmd[3] ) |
---|
| 493 | { |
---|
| 494 | if( !nick_ok( cmd[3] ) ) |
---|
| 495 | { |
---|
| 496 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 497 | return; |
---|
[b7d3cc34] | 498 | } |
---|
| 499 | else if( user_find( irc, cmd[3] ) ) |
---|
| 500 | { |
---|
| 501 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 502 | return; |
---|
[b7d3cc34] | 503 | } |
---|
| 504 | else |
---|
| 505 | { |
---|
[5b52a48] | 506 | nick_set( a, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 507 | } |
---|
| 508 | } |
---|
[f8de26f] | 509 | |
---|
[f0cb961] | 510 | if( add_on_server ) |
---|
[0da65d5] | 511 | a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); |
---|
[7adc657] | 512 | else |
---|
| 513 | /* Yeah, officially this is a call-*back*... So if we just |
---|
| 514 | called add_buddy, we'll wait for the IM server to respond |
---|
| 515 | before we do this. */ |
---|
| 516 | imcb_add_buddy( a->ic, cmd[2], NULL ); |
---|
[f0cb961] | 517 | |
---|
| 518 | irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); |
---|
[b7d3cc34] | 519 | } |
---|
| 520 | |
---|
[f73b969] | 521 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 522 | { |
---|
[0da65d5] | 523 | struct im_connection *ic; |
---|
[b7d3cc34] | 524 | account_t *a; |
---|
| 525 | |
---|
| 526 | if( !cmd[2] ) |
---|
| 527 | { |
---|
| 528 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 529 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 530 | { |
---|
| 531 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 532 | return; |
---|
[b7d3cc34] | 533 | } |
---|
[0da65d5] | 534 | ic = u->ic; |
---|
[b7d3cc34] | 535 | cmd[2] = u->handle; |
---|
| 536 | } |
---|
| 537 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 538 | { |
---|
| 539 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 540 | return; |
---|
[b7d3cc34] | 541 | } |
---|
[0da65d5] | 542 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 543 | { |
---|
| 544 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 545 | return; |
---|
[b7d3cc34] | 546 | } |
---|
| 547 | |
---|
[0da65d5] | 548 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 549 | { |
---|
| 550 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 551 | } |
---|
[f73b969] | 552 | else |
---|
| 553 | { |
---|
[0da65d5] | 554 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 555 | } |
---|
[b7d3cc34] | 556 | } |
---|
| 557 | |
---|
[f73b969] | 558 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 559 | { |
---|
| 560 | user_t *u; |
---|
| 561 | |
---|
| 562 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
| 563 | { |
---|
| 564 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
| 565 | } |
---|
[f73b969] | 566 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
[b7d3cc34] | 567 | { |
---|
| 568 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
| 569 | } |
---|
[f73b969] | 570 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 571 | { |
---|
| 572 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 573 | } |
---|
[f73b969] | 574 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
[b7d3cc34] | 575 | { |
---|
| 576 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
| 577 | } |
---|
[f73b969] | 578 | else |
---|
[b7d3cc34] | 579 | { |
---|
[f73b969] | 580 | user_rename( irc, cmd[1], cmd[2] ); |
---|
| 581 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
| 582 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
| 583 | { |
---|
| 584 | g_free( irc->mynick ); |
---|
| 585 | irc->mynick = g_strdup( cmd[2] ); |
---|
| 586 | } |
---|
| 587 | else if( u->send_handler == buddy_send_handler ) |
---|
| 588 | { |
---|
[0da65d5] | 589 | nick_set( u->ic->acc, u->handle, cmd[2] ); |
---|
[f73b969] | 590 | } |
---|
| 591 | |
---|
| 592 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 593 | } |
---|
| 594 | } |
---|
| 595 | |
---|
[f73b969] | 596 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 597 | { |
---|
| 598 | user_t *u; |
---|
| 599 | char *s; |
---|
| 600 | |
---|
[0da65d5] | 601 | if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) |
---|
[b7d3cc34] | 602 | { |
---|
| 603 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
[f73b969] | 604 | return; |
---|
[b7d3cc34] | 605 | } |
---|
| 606 | s = g_strdup( u->handle ); |
---|
| 607 | |
---|
[0da65d5] | 608 | u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); |
---|
| 609 | nick_del( u->ic->acc, u->handle ); |
---|
[b7d3cc34] | 610 | user_del( irc, cmd[1] ); |
---|
| 611 | |
---|
| 612 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 613 | g_free( s ); |
---|
| 614 | |
---|
[f73b969] | 615 | return; |
---|
[b7d3cc34] | 616 | } |
---|
| 617 | |
---|
[f73b969] | 618 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 619 | { |
---|
[0da65d5] | 620 | struct im_connection *ic; |
---|
[b7d3cc34] | 621 | account_t *a; |
---|
| 622 | |
---|
[0da65d5] | 623 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 624 | { |
---|
| 625 | char *format; |
---|
| 626 | GSList *l; |
---|
| 627 | |
---|
| 628 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 629 | format = "%s\t%s"; |
---|
| 630 | else |
---|
[57ef864] | 631 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 632 | |
---|
| 633 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 634 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 635 | { |
---|
[0da65d5] | 636 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 637 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 638 | } |
---|
| 639 | irc_usermsg( irc, "End of list." ); |
---|
| 640 | |
---|
| 641 | return; |
---|
| 642 | } |
---|
| 643 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 644 | { |
---|
| 645 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 646 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 647 | { |
---|
| 648 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 649 | return; |
---|
[b7d3cc34] | 650 | } |
---|
[0da65d5] | 651 | ic = u->ic; |
---|
[b7d3cc34] | 652 | cmd[2] = u->handle; |
---|
| 653 | } |
---|
| 654 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 655 | { |
---|
| 656 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 657 | return; |
---|
[b7d3cc34] | 658 | } |
---|
[0da65d5] | 659 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 660 | { |
---|
| 661 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 662 | return; |
---|
[b7d3cc34] | 663 | } |
---|
| 664 | |
---|
[0da65d5] | 665 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 666 | { |
---|
| 667 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 668 | } |
---|
| 669 | else |
---|
| 670 | { |
---|
[84b045d] | 671 | imc_rem_allow( ic, cmd[2] ); |
---|
| 672 | imc_add_block( ic, cmd[2] ); |
---|
[da3b536] | 673 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
[b7d3cc34] | 674 | } |
---|
| 675 | } |
---|
| 676 | |
---|
[f73b969] | 677 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 678 | { |
---|
[0da65d5] | 679 | struct im_connection *ic; |
---|
[b7d3cc34] | 680 | account_t *a; |
---|
| 681 | |
---|
[0da65d5] | 682 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 683 | { |
---|
| 684 | char *format; |
---|
| 685 | GSList *l; |
---|
| 686 | |
---|
| 687 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 688 | format = "%s\t%s"; |
---|
| 689 | else |
---|
[57ef864] | 690 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 691 | |
---|
| 692 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 693 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 694 | { |
---|
[0da65d5] | 695 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 696 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 697 | } |
---|
| 698 | irc_usermsg( irc, "End of list." ); |
---|
| 699 | |
---|
| 700 | return; |
---|
| 701 | } |
---|
| 702 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 703 | { |
---|
| 704 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 705 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 706 | { |
---|
| 707 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 708 | return; |
---|
[b7d3cc34] | 709 | } |
---|
[0da65d5] | 710 | ic = u->ic; |
---|
[b7d3cc34] | 711 | cmd[2] = u->handle; |
---|
| 712 | } |
---|
| 713 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 714 | { |
---|
| 715 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 716 | return; |
---|
[b7d3cc34] | 717 | } |
---|
[0da65d5] | 718 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 719 | { |
---|
| 720 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 721 | return; |
---|
[b7d3cc34] | 722 | } |
---|
| 723 | |
---|
[0da65d5] | 724 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 725 | { |
---|
| 726 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 727 | } |
---|
| 728 | else |
---|
| 729 | { |
---|
[84b045d] | 730 | imc_rem_block( ic, cmd[2] ); |
---|
| 731 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 732 | |
---|
[da3b536] | 733 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
[b7d3cc34] | 734 | } |
---|
| 735 | } |
---|
| 736 | |
---|
[f73b969] | 737 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 738 | { |
---|
| 739 | query_t *q = NULL; |
---|
| 740 | int numq = 0; |
---|
| 741 | |
---|
| 742 | if( irc->queries == NULL ) |
---|
| 743 | { |
---|
| 744 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 745 | return; |
---|
[b7d3cc34] | 746 | } |
---|
| 747 | |
---|
| 748 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 749 | first/last (depending on the query_order setting) one. */ |
---|
| 750 | if( cmd[1] ) |
---|
| 751 | { |
---|
| 752 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 753 | { |
---|
| 754 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 755 | return; |
---|
[b7d3cc34] | 756 | } |
---|
| 757 | |
---|
| 758 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 759 | if( numq == 0 ) |
---|
| 760 | break; |
---|
| 761 | |
---|
| 762 | if( !q ) |
---|
| 763 | { |
---|
| 764 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 765 | return; |
---|
[b7d3cc34] | 766 | } |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 770 | query_answer( irc, q, 1 ); |
---|
| 771 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 772 | query_answer( irc, q, 0 ); |
---|
| 773 | } |
---|
| 774 | |
---|
[f73b969] | 775 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 776 | { |
---|
[71dc854] | 777 | char *set_name = cmd[1]; |
---|
[cd428e4] | 778 | |
---|
[b7d3cc34] | 779 | if( cmd[1] && cmd[2] ) |
---|
| 780 | { |
---|
[71dc854] | 781 | if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
[cd428e4] | 782 | { |
---|
| 783 | set_reset( &irc->set, cmd[2] ); |
---|
| 784 | set_name = cmd[2]; |
---|
| 785 | } |
---|
| 786 | else |
---|
| 787 | { |
---|
| 788 | set_setstr( &irc->set, cmd[1], cmd[2] ); |
---|
| 789 | } |
---|
[b7d3cc34] | 790 | } |
---|
[56f260a] | 791 | if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
[b7d3cc34] | 792 | { |
---|
[cd428e4] | 793 | char *s = set_getstr( &irc->set, set_name ); |
---|
| 794 | if( s ) |
---|
| 795 | irc_usermsg( irc, "%s = `%s'", set_name, s ); |
---|
[5100caa] | 796 | else |
---|
[cd428e4] | 797 | irc_usermsg( irc, "%s is empty", set_name ); |
---|
[d5bd9c0] | 798 | |
---|
| 799 | if( strchr( set_name, '/' ) ) |
---|
| 800 | irc_usermsg( irc, "Warning: / found in setting name, you're probably looking for the `account set' command." ); |
---|
[b7d3cc34] | 801 | } |
---|
| 802 | else |
---|
| 803 | { |
---|
| 804 | set_t *s = irc->set; |
---|
| 805 | while( s ) |
---|
| 806 | { |
---|
| 807 | if( s->value || s->def ) |
---|
[cd428e4] | 808 | irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); |
---|
[5100caa] | 809 | else |
---|
| 810 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
[b7d3cc34] | 811 | s = s->next; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | } |
---|
| 815 | |
---|
[f73b969] | 816 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 817 | { |
---|
[ab49fdc] | 818 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
[b7d3cc34] | 819 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 820 | else |
---|
| 821 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 822 | } |
---|
| 823 | |
---|
[f73b969] | 824 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 825 | { |
---|
| 826 | int online = 0, away = 0, offline = 0; |
---|
| 827 | user_t *u; |
---|
[aefa533e] | 828 | char s[256]; |
---|
| 829 | char *format; |
---|
[b7d3cc34] | 830 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 831 | |
---|
| 832 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 833 | online = offline = away = 1; |
---|
| 834 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 835 | offline = 1; |
---|
| 836 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 837 | away = 1; |
---|
| 838 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 839 | online = 1; |
---|
| 840 | else |
---|
| 841 | online = away = 1; |
---|
| 842 | |
---|
[aefa533e] | 843 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 844 | format = "%s\t%s\t%s"; |
---|
| 845 | else |
---|
| 846 | format = "%-16.16s %-40.40s %s"; |
---|
| 847 | |
---|
| 848 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 849 | |
---|
[0da65d5] | 850 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 851 | { |
---|
[aefa533e] | 852 | if( online == 1 ) |
---|
| 853 | { |
---|
[e731120] | 854 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 855 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
| 856 | } |
---|
| 857 | |
---|
[b7d3cc34] | 858 | n_online ++; |
---|
| 859 | } |
---|
| 860 | |
---|
[0da65d5] | 861 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
[b7d3cc34] | 862 | { |
---|
[aefa533e] | 863 | if( away == 1 ) |
---|
| 864 | { |
---|
[e731120] | 865 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 866 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 867 | } |
---|
[b7d3cc34] | 868 | n_away ++; |
---|
| 869 | } |
---|
| 870 | |
---|
[0da65d5] | 871 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
[b7d3cc34] | 872 | { |
---|
[aefa533e] | 873 | if( offline == 1 ) |
---|
| 874 | { |
---|
[e731120] | 875 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 876 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 877 | } |
---|
[b7d3cc34] | 878 | n_offline ++; |
---|
| 879 | } |
---|
| 880 | |
---|
[aa5ac01] | 881 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 882 | } |
---|
| 883 | |
---|
[f73b969] | 884 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 885 | { |
---|
| 886 | account_t *a; |
---|
| 887 | |
---|
| 888 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 889 | { |
---|
| 890 | irc_usermsg( irc, "Invalid account"); |
---|
| 891 | } |
---|
[0da65d5] | 892 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 893 | { |
---|
| 894 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 895 | } |
---|
| 896 | else if ( !cmd[2] ) |
---|
| 897 | { |
---|
[0da65d5] | 898 | irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" ); |
---|
[b7d3cc34] | 899 | } |
---|
[0da65d5] | 900 | else if ( !a->prpl->set_my_name ) |
---|
[b7d3cc34] | 901 | { |
---|
| 902 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 903 | } |
---|
| 904 | else |
---|
| 905 | { |
---|
| 906 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
| 907 | |
---|
[0da65d5] | 908 | a->prpl->set_my_name( a->ic, cmd[2] ); |
---|
[b7d3cc34] | 909 | } |
---|
| 910 | } |
---|
| 911 | |
---|
[f73b969] | 912 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 913 | { |
---|
| 914 | query_t *q = irc->queries; |
---|
| 915 | int num; |
---|
| 916 | |
---|
| 917 | if( !q ) |
---|
| 918 | { |
---|
| 919 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 920 | return; |
---|
[b7d3cc34] | 921 | } |
---|
| 922 | |
---|
| 923 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 924 | |
---|
| 925 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 926 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 927 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 928 | else |
---|
| 929 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 930 | } |
---|
| 931 | |
---|
[fa29d093] | 932 | static void cmd_join_chat( irc_t *irc, char **cmd ) |
---|
| 933 | { |
---|
| 934 | account_t *a; |
---|
[0da65d5] | 935 | struct im_connection *ic; |
---|
[fa29d093] | 936 | char *chat, *channel, *nick = NULL, *password = NULL; |
---|
[0da65d5] | 937 | struct groupchat *c; |
---|
[fa29d093] | 938 | |
---|
| 939 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 940 | { |
---|
| 941 | irc_usermsg( irc, "Invalid account" ); |
---|
| 942 | return; |
---|
| 943 | } |
---|
[0da65d5] | 944 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[fa29d093] | 945 | { |
---|
| 946 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 947 | return; |
---|
| 948 | } |
---|
| 949 | else if( a->prpl->chat_join == NULL ) |
---|
| 950 | { |
---|
| 951 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 952 | return; |
---|
| 953 | } |
---|
[0da65d5] | 954 | ic = a->ic; |
---|
[fa29d093] | 955 | |
---|
| 956 | chat = cmd[2]; |
---|
| 957 | if( cmd[3] ) |
---|
| 958 | { |
---|
[9da0bbf] | 959 | if( cmd[3][0] != '#' && cmd[3][0] != '&' ) |
---|
[7bf4326] | 960 | channel = g_strdup_printf( "&%s", cmd[3] ); |
---|
| 961 | else |
---|
| 962 | channel = g_strdup( cmd[3] ); |
---|
[fa29d093] | 963 | } |
---|
| 964 | else |
---|
| 965 | { |
---|
| 966 | char *s; |
---|
| 967 | |
---|
[0e7ab64] | 968 | channel = g_strdup_printf( "&%s", chat ); |
---|
[fa29d093] | 969 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 970 | *s = 0; |
---|
| 971 | } |
---|
| 972 | if( cmd[3] && cmd[4] ) |
---|
| 973 | nick = cmd[4]; |
---|
[e35d1a1] | 974 | else |
---|
| 975 | nick = irc->nick; |
---|
[fa29d093] | 976 | if( cmd[3] && cmd[4] && cmd[5] ) |
---|
| 977 | password = cmd[5]; |
---|
| 978 | |
---|
[7bf4326] | 979 | if( !nick_ok( channel + 1 ) ) |
---|
[0e7ab64] | 980 | { |
---|
| 981 | irc_usermsg( irc, "Invalid channel name: %s", channel ); |
---|
| 982 | g_free( channel ); |
---|
| 983 | return; |
---|
| 984 | } |
---|
| 985 | else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) ) |
---|
| 986 | { |
---|
| 987 | irc_usermsg( irc, "Channel already exists: %s", channel ); |
---|
| 988 | g_free( channel ); |
---|
| 989 | return; |
---|
| 990 | } |
---|
[fa29d093] | 991 | |
---|
[e35d1a1] | 992 | if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) ) |
---|
| 993 | { |
---|
| 994 | g_free( c->channel ); |
---|
| 995 | c->channel = channel; |
---|
| 996 | } |
---|
| 997 | else |
---|
| 998 | { |
---|
| 999 | irc_usermsg( irc, "Tried to join chat, not sure if this was successful" ); |
---|
| 1000 | g_free( channel ); |
---|
| 1001 | } |
---|
[fa29d093] | 1002 | } |
---|
| 1003 | |
---|
[0298d11] | 1004 | const command_t commands[] = { |
---|
| 1005 | { "help", 0, cmd_help, 0 }, |
---|
| 1006 | { "identify", 1, cmd_identify, 0 }, |
---|
| 1007 | { "register", 1, cmd_register, 0 }, |
---|
| 1008 | { "drop", 1, cmd_drop, 0 }, |
---|
| 1009 | { "account", 1, cmd_account, 0 }, |
---|
| 1010 | { "add", 2, cmd_add, 0 }, |
---|
| 1011 | { "info", 1, cmd_info, 0 }, |
---|
| 1012 | { "rename", 2, cmd_rename, 0 }, |
---|
| 1013 | { "remove", 1, cmd_remove, 0 }, |
---|
| 1014 | { "block", 1, cmd_block, 0 }, |
---|
| 1015 | { "allow", 1, cmd_allow, 0 }, |
---|
| 1016 | { "save", 0, cmd_save, 0 }, |
---|
| 1017 | { "set", 0, cmd_set, 0 }, |
---|
| 1018 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 1019 | { "no", 0, cmd_yesno, 0 }, |
---|
| 1020 | { "blist", 0, cmd_blist, 0 }, |
---|
| 1021 | { "nick", 1, cmd_nick, 0 }, |
---|
| 1022 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[fa29d093] | 1023 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
[0298d11] | 1024 | { NULL } |
---|
| 1025 | }; |
---|