[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 | |
---|
[f73b969] | 206 | static void cmd_account( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 207 | { |
---|
| 208 | account_t *a; |
---|
| 209 | |
---|
[3af70b0] | 210 | if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) |
---|
[b7d3cc34] | 211 | { |
---|
| 212 | irc_usermsg( irc, "This server only accepts registered users" ); |
---|
[f73b969] | 213 | return; |
---|
[b7d3cc34] | 214 | } |
---|
| 215 | |
---|
| 216 | if( g_strcasecmp( cmd[1], "add" ) == 0 ) |
---|
| 217 | { |
---|
[7b23afd] | 218 | struct prpl *prpl; |
---|
[b7d3cc34] | 219 | |
---|
| 220 | if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) |
---|
| 221 | { |
---|
| 222 | irc_usermsg( irc, "Not enough parameters" ); |
---|
[f73b969] | 223 | return; |
---|
[b7d3cc34] | 224 | } |
---|
| 225 | |
---|
[7b23afd] | 226 | prpl = find_protocol(cmd[2]); |
---|
[b7d3cc34] | 227 | |
---|
[7b23afd] | 228 | if( prpl == NULL ) |
---|
[b7d3cc34] | 229 | { |
---|
| 230 | irc_usermsg( irc, "Unknown protocol" ); |
---|
[f73b969] | 231 | return; |
---|
[b7d3cc34] | 232 | } |
---|
| 233 | |
---|
[7b23afd] | 234 | a = account_add( irc, prpl, cmd[3], cmd[4] ); |
---|
[b7d3cc34] | 235 | if( cmd[5] ) |
---|
[30ce1ce] | 236 | { |
---|
| 237 | irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " |
---|
| 238 | "is now deprecated. Use `account set' instead." ); |
---|
[5100caa] | 239 | set_setstr( &a->set, "server", cmd[5] ); |
---|
[30ce1ce] | 240 | } |
---|
[b7d3cc34] | 241 | |
---|
| 242 | irc_usermsg( irc, "Account successfully added" ); |
---|
| 243 | } |
---|
| 244 | else if( g_strcasecmp( cmd[1], "del" ) == 0 ) |
---|
| 245 | { |
---|
| 246 | if( !cmd[2] ) |
---|
| 247 | { |
---|
| 248 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 249 | } |
---|
| 250 | else if( !( a = account_get( irc, cmd[2] ) ) ) |
---|
| 251 | { |
---|
| 252 | irc_usermsg( irc, "Invalid account" ); |
---|
| 253 | } |
---|
[0da65d5] | 254 | else if( a->ic ) |
---|
[b7d3cc34] | 255 | { |
---|
| 256 | irc_usermsg( irc, "Account is still logged in, can't delete" ); |
---|
| 257 | } |
---|
| 258 | else |
---|
| 259 | { |
---|
| 260 | account_del( irc, a ); |
---|
| 261 | irc_usermsg( irc, "Account deleted" ); |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | else if( g_strcasecmp( cmd[1], "list" ) == 0 ) |
---|
| 265 | { |
---|
| 266 | int i = 0; |
---|
| 267 | |
---|
[e6e1f18] | 268 | if( strchr( irc->umode, 'b' ) ) |
---|
| 269 | irc_usermsg( irc, "Account list:" ); |
---|
| 270 | |
---|
[b7d3cc34] | 271 | for( a = irc->accounts; a; a = a->next ) |
---|
| 272 | { |
---|
| 273 | char *con; |
---|
| 274 | |
---|
[0da65d5] | 275 | if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) |
---|
[b7d3cc34] | 276 | con = " (connected)"; |
---|
[0da65d5] | 277 | else if( a->ic ) |
---|
[b7d3cc34] | 278 | con = " (connecting)"; |
---|
| 279 | else if( a->reconnect ) |
---|
| 280 | con = " (awaiting reconnect)"; |
---|
| 281 | else |
---|
| 282 | con = ""; |
---|
| 283 | |
---|
[7b23afd] | 284 | irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); |
---|
[b7d3cc34] | 285 | |
---|
| 286 | i ++; |
---|
| 287 | } |
---|
| 288 | irc_usermsg( irc, "End of account list" ); |
---|
| 289 | } |
---|
| 290 | else if( g_strcasecmp( cmd[1], "on" ) == 0 ) |
---|
| 291 | { |
---|
| 292 | if( cmd[2] ) |
---|
| 293 | { |
---|
| 294 | if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 295 | { |
---|
[0da65d5] | 296 | if( a->ic ) |
---|
[b7d3cc34] | 297 | { |
---|
| 298 | irc_usermsg( irc, "Account already online" ); |
---|
[f73b969] | 299 | return; |
---|
[b7d3cc34] | 300 | } |
---|
| 301 | else |
---|
| 302 | { |
---|
| 303 | account_on( irc, a ); |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | else |
---|
| 307 | { |
---|
| 308 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 309 | return; |
---|
[b7d3cc34] | 310 | } |
---|
| 311 | } |
---|
| 312 | else |
---|
| 313 | { |
---|
| 314 | if ( irc->accounts ) { |
---|
| 315 | irc_usermsg( irc, "Trying to get all accounts connected..." ); |
---|
| 316 | |
---|
| 317 | for( a = irc->accounts; a; a = a->next ) |
---|
[0da65d5] | 318 | if( !a->ic && a->auto_connect ) |
---|
[b7d3cc34] | 319 | account_on( irc, a ); |
---|
| 320 | } |
---|
| 321 | else |
---|
| 322 | { |
---|
[30ce1ce] | 323 | irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); |
---|
[b7d3cc34] | 324 | } |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | else if( g_strcasecmp( cmd[1], "off" ) == 0 ) |
---|
| 328 | { |
---|
| 329 | if( !cmd[2] ) |
---|
| 330 | { |
---|
| 331 | irc_usermsg( irc, "Deactivating all active (re)connections..." ); |
---|
| 332 | |
---|
| 333 | for( a = irc->accounts; a; a = a->next ) |
---|
| 334 | { |
---|
[0da65d5] | 335 | if( a->ic ) |
---|
[b7d3cc34] | 336 | account_off( irc, a ); |
---|
| 337 | else if( a->reconnect ) |
---|
| 338 | cancel_auto_reconnect( a ); |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | else if( ( a = account_get( irc, cmd[2] ) ) ) |
---|
| 342 | { |
---|
[0da65d5] | 343 | if( a->ic ) |
---|
[b7d3cc34] | 344 | { |
---|
| 345 | account_off( irc, a ); |
---|
| 346 | } |
---|
| 347 | else if( a->reconnect ) |
---|
| 348 | { |
---|
| 349 | cancel_auto_reconnect( a ); |
---|
| 350 | irc_usermsg( irc, "Reconnect cancelled" ); |
---|
| 351 | } |
---|
| 352 | else |
---|
| 353 | { |
---|
| 354 | irc_usermsg( irc, "Account already offline" ); |
---|
[f73b969] | 355 | return; |
---|
[b7d3cc34] | 356 | } |
---|
| 357 | } |
---|
| 358 | else |
---|
| 359 | { |
---|
| 360 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 361 | return; |
---|
[b7d3cc34] | 362 | } |
---|
| 363 | } |
---|
[5100caa] | 364 | else if( g_strcasecmp( cmd[1], "set" ) == 0 ) |
---|
| 365 | { |
---|
| 366 | char *acc_handle, *set_name = NULL, *tmp; |
---|
| 367 | |
---|
| 368 | if( !cmd[2] ) |
---|
| 369 | { |
---|
| 370 | irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); |
---|
| 371 | return; |
---|
| 372 | } |
---|
| 373 | |
---|
[cd428e4] | 374 | if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) |
---|
| 375 | acc_handle = g_strdup( cmd[3] ); |
---|
| 376 | else |
---|
| 377 | acc_handle = g_strdup( cmd[2] ); |
---|
| 378 | |
---|
[5100caa] | 379 | if( ( tmp = strchr( acc_handle, '/' ) ) ) |
---|
| 380 | { |
---|
| 381 | *tmp = 0; |
---|
| 382 | set_name = tmp + 1; |
---|
| 383 | } |
---|
| 384 | |
---|
[cd428e4] | 385 | if( ( a = account_get( irc, acc_handle ) ) == NULL ) |
---|
[5100caa] | 386 | { |
---|
[75a4b85] | 387 | g_free( acc_handle ); |
---|
[5100caa] | 388 | irc_usermsg( irc, "Invalid account" ); |
---|
| 389 | return; |
---|
| 390 | } |
---|
| 391 | |
---|
[9334cc2] | 392 | if( cmd[3] && set_name ) |
---|
[5100caa] | 393 | { |
---|
| 394 | set_t *s = set_find( &a->set, set_name ); |
---|
| 395 | |
---|
[0da65d5] | 396 | if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY ) |
---|
[5100caa] | 397 | { |
---|
[75a4b85] | 398 | g_free( acc_handle ); |
---|
[911f2eb] | 399 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" ); |
---|
| 400 | return; |
---|
| 401 | } |
---|
[0da65d5] | 402 | else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY ) |
---|
[911f2eb] | 403 | { |
---|
[75a4b85] | 404 | g_free( acc_handle ); |
---|
[911f2eb] | 405 | irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" ); |
---|
[5100caa] | 406 | return; |
---|
| 407 | } |
---|
| 408 | |
---|
[71dc854] | 409 | if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) |
---|
[cd428e4] | 410 | set_reset( &a->set, set_name ); |
---|
| 411 | else |
---|
| 412 | set_setstr( &a->set, set_name, cmd[3] ); |
---|
[5100caa] | 413 | } |
---|
| 414 | if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
| 415 | { |
---|
| 416 | char *s = set_getstr( &a->set, set_name ); |
---|
| 417 | if( s ) |
---|
| 418 | irc_usermsg( irc, "%s = `%s'", set_name, s ); |
---|
| 419 | else |
---|
| 420 | irc_usermsg( irc, "%s is empty", set_name ); |
---|
| 421 | } |
---|
| 422 | else |
---|
| 423 | { |
---|
| 424 | set_t *s = a->set; |
---|
| 425 | while( s ) |
---|
| 426 | { |
---|
| 427 | if( s->value || s->def ) |
---|
[cd428e4] | 428 | irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); |
---|
[5100caa] | 429 | else |
---|
| 430 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
| 431 | s = s->next; |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | g_free( acc_handle ); |
---|
| 436 | } |
---|
[b7d3cc34] | 437 | else |
---|
| 438 | { |
---|
[5c09a59] | 439 | irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] ); |
---|
[b7d3cc34] | 440 | } |
---|
| 441 | } |
---|
| 442 | |
---|
[f73b969] | 443 | static void cmd_add( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 444 | { |
---|
| 445 | account_t *a; |
---|
[f0cb961] | 446 | int add_on_server = 1; |
---|
[f8de26f] | 447 | |
---|
| 448 | if( g_strcasecmp( cmd[1], "-tmp" ) == 0 ) |
---|
| 449 | { |
---|
[f0cb961] | 450 | add_on_server = 0; |
---|
[7adc657] | 451 | cmd ++; |
---|
[f8de26f] | 452 | } |
---|
[b7d3cc34] | 453 | |
---|
| 454 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 455 | { |
---|
| 456 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 457 | return; |
---|
[b7d3cc34] | 458 | } |
---|
[0da65d5] | 459 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 460 | { |
---|
| 461 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 462 | return; |
---|
[b7d3cc34] | 463 | } |
---|
| 464 | |
---|
| 465 | if( cmd[3] ) |
---|
| 466 | { |
---|
| 467 | if( !nick_ok( cmd[3] ) ) |
---|
| 468 | { |
---|
| 469 | irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] ); |
---|
[f73b969] | 470 | return; |
---|
[b7d3cc34] | 471 | } |
---|
| 472 | else if( user_find( irc, cmd[3] ) ) |
---|
| 473 | { |
---|
| 474 | irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] ); |
---|
[f73b969] | 475 | return; |
---|
[b7d3cc34] | 476 | } |
---|
| 477 | else |
---|
| 478 | { |
---|
[5b52a48] | 479 | nick_set( a, cmd[2], cmd[3] ); |
---|
[b7d3cc34] | 480 | } |
---|
| 481 | } |
---|
[f8de26f] | 482 | |
---|
[f0cb961] | 483 | if( add_on_server ) |
---|
[0da65d5] | 484 | a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); |
---|
[7adc657] | 485 | else |
---|
| 486 | /* Yeah, officially this is a call-*back*... So if we just |
---|
| 487 | called add_buddy, we'll wait for the IM server to respond |
---|
| 488 | before we do this. */ |
---|
| 489 | imcb_add_buddy( a->ic, cmd[2], NULL ); |
---|
[f0cb961] | 490 | |
---|
| 491 | irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); |
---|
[b7d3cc34] | 492 | } |
---|
| 493 | |
---|
[f73b969] | 494 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 495 | { |
---|
[0da65d5] | 496 | struct im_connection *ic; |
---|
[b7d3cc34] | 497 | account_t *a; |
---|
| 498 | |
---|
| 499 | if( !cmd[2] ) |
---|
| 500 | { |
---|
| 501 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 502 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 503 | { |
---|
| 504 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 505 | return; |
---|
[b7d3cc34] | 506 | } |
---|
[0da65d5] | 507 | ic = u->ic; |
---|
[b7d3cc34] | 508 | cmd[2] = u->handle; |
---|
| 509 | } |
---|
| 510 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 511 | { |
---|
| 512 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 513 | return; |
---|
[b7d3cc34] | 514 | } |
---|
[0da65d5] | 515 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 516 | { |
---|
| 517 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 518 | return; |
---|
[b7d3cc34] | 519 | } |
---|
| 520 | |
---|
[0da65d5] | 521 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 522 | { |
---|
| 523 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 524 | } |
---|
[f73b969] | 525 | else |
---|
| 526 | { |
---|
[0da65d5] | 527 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 528 | } |
---|
[b7d3cc34] | 529 | } |
---|
| 530 | |
---|
[f73b969] | 531 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 532 | { |
---|
| 533 | user_t *u; |
---|
| 534 | |
---|
| 535 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
| 536 | { |
---|
| 537 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
| 538 | } |
---|
[f73b969] | 539 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
[b7d3cc34] | 540 | { |
---|
| 541 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
| 542 | } |
---|
[f73b969] | 543 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 544 | { |
---|
| 545 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 546 | } |
---|
[f73b969] | 547 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
[b7d3cc34] | 548 | { |
---|
| 549 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
| 550 | } |
---|
[f73b969] | 551 | else |
---|
[b7d3cc34] | 552 | { |
---|
[f73b969] | 553 | user_rename( irc, cmd[1], cmd[2] ); |
---|
| 554 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
| 555 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
| 556 | { |
---|
| 557 | g_free( irc->mynick ); |
---|
| 558 | irc->mynick = g_strdup( cmd[2] ); |
---|
| 559 | } |
---|
| 560 | else if( u->send_handler == buddy_send_handler ) |
---|
| 561 | { |
---|
[0da65d5] | 562 | nick_set( u->ic->acc, u->handle, cmd[2] ); |
---|
[f73b969] | 563 | } |
---|
| 564 | |
---|
| 565 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 566 | } |
---|
| 567 | } |
---|
| 568 | |
---|
[f73b969] | 569 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 570 | { |
---|
| 571 | user_t *u; |
---|
| 572 | char *s; |
---|
| 573 | |
---|
[0da65d5] | 574 | if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) |
---|
[b7d3cc34] | 575 | { |
---|
| 576 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
[f73b969] | 577 | return; |
---|
[b7d3cc34] | 578 | } |
---|
| 579 | s = g_strdup( u->handle ); |
---|
| 580 | |
---|
[0da65d5] | 581 | u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); |
---|
| 582 | nick_del( u->ic->acc, u->handle ); |
---|
[b7d3cc34] | 583 | user_del( irc, cmd[1] ); |
---|
| 584 | |
---|
| 585 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 586 | g_free( s ); |
---|
| 587 | |
---|
[f73b969] | 588 | return; |
---|
[b7d3cc34] | 589 | } |
---|
| 590 | |
---|
[f73b969] | 591 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 592 | { |
---|
[0da65d5] | 593 | struct im_connection *ic; |
---|
[b7d3cc34] | 594 | account_t *a; |
---|
| 595 | |
---|
[0da65d5] | 596 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 597 | { |
---|
| 598 | char *format; |
---|
| 599 | GSList *l; |
---|
| 600 | |
---|
| 601 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 602 | format = "%s\t%s"; |
---|
| 603 | else |
---|
[57ef864] | 604 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 605 | |
---|
| 606 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 607 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 608 | { |
---|
[0da65d5] | 609 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 610 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 611 | } |
---|
| 612 | irc_usermsg( irc, "End of list." ); |
---|
| 613 | |
---|
| 614 | return; |
---|
| 615 | } |
---|
| 616 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 617 | { |
---|
| 618 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 619 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 620 | { |
---|
| 621 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 622 | return; |
---|
[b7d3cc34] | 623 | } |
---|
[0da65d5] | 624 | ic = u->ic; |
---|
[b7d3cc34] | 625 | cmd[2] = u->handle; |
---|
| 626 | } |
---|
| 627 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 628 | { |
---|
| 629 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 630 | return; |
---|
[b7d3cc34] | 631 | } |
---|
[0da65d5] | 632 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 633 | { |
---|
| 634 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 635 | return; |
---|
[b7d3cc34] | 636 | } |
---|
| 637 | |
---|
[0da65d5] | 638 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 639 | { |
---|
| 640 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 641 | } |
---|
| 642 | else |
---|
| 643 | { |
---|
[84b045d] | 644 | imc_rem_allow( ic, cmd[2] ); |
---|
| 645 | imc_add_block( ic, cmd[2] ); |
---|
[da3b536] | 646 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
[b7d3cc34] | 647 | } |
---|
| 648 | } |
---|
| 649 | |
---|
[f73b969] | 650 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 651 | { |
---|
[0da65d5] | 652 | struct im_connection *ic; |
---|
[b7d3cc34] | 653 | account_t *a; |
---|
| 654 | |
---|
[0da65d5] | 655 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 656 | { |
---|
| 657 | char *format; |
---|
| 658 | GSList *l; |
---|
| 659 | |
---|
| 660 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 661 | format = "%s\t%s"; |
---|
| 662 | else |
---|
[57ef864] | 663 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 664 | |
---|
| 665 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 666 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 667 | { |
---|
[0da65d5] | 668 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 669 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 670 | } |
---|
| 671 | irc_usermsg( irc, "End of list." ); |
---|
| 672 | |
---|
| 673 | return; |
---|
| 674 | } |
---|
| 675 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 676 | { |
---|
| 677 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 678 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 679 | { |
---|
| 680 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 681 | return; |
---|
[b7d3cc34] | 682 | } |
---|
[0da65d5] | 683 | ic = u->ic; |
---|
[b7d3cc34] | 684 | cmd[2] = u->handle; |
---|
| 685 | } |
---|
| 686 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 687 | { |
---|
| 688 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 689 | return; |
---|
[b7d3cc34] | 690 | } |
---|
[0da65d5] | 691 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 692 | { |
---|
| 693 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 694 | return; |
---|
[b7d3cc34] | 695 | } |
---|
| 696 | |
---|
[0da65d5] | 697 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 698 | { |
---|
| 699 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 700 | } |
---|
| 701 | else |
---|
| 702 | { |
---|
[84b045d] | 703 | imc_rem_block( ic, cmd[2] ); |
---|
| 704 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 705 | |
---|
[da3b536] | 706 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
[b7d3cc34] | 707 | } |
---|
| 708 | } |
---|
| 709 | |
---|
[f73b969] | 710 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 711 | { |
---|
| 712 | query_t *q = NULL; |
---|
| 713 | int numq = 0; |
---|
| 714 | |
---|
| 715 | if( irc->queries == NULL ) |
---|
| 716 | { |
---|
| 717 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 718 | return; |
---|
[b7d3cc34] | 719 | } |
---|
| 720 | |
---|
| 721 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 722 | first/last (depending on the query_order setting) one. */ |
---|
| 723 | if( cmd[1] ) |
---|
| 724 | { |
---|
| 725 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 726 | { |
---|
| 727 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 728 | return; |
---|
[b7d3cc34] | 729 | } |
---|
| 730 | |
---|
| 731 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 732 | if( numq == 0 ) |
---|
| 733 | break; |
---|
| 734 | |
---|
| 735 | if( !q ) |
---|
| 736 | { |
---|
| 737 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 738 | return; |
---|
[b7d3cc34] | 739 | } |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 743 | query_answer( irc, q, 1 ); |
---|
| 744 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 745 | query_answer( irc, q, 0 ); |
---|
| 746 | } |
---|
| 747 | |
---|
[f73b969] | 748 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 749 | { |
---|
[71dc854] | 750 | char *set_name = cmd[1]; |
---|
[cd428e4] | 751 | |
---|
[b7d3cc34] | 752 | if( cmd[1] && cmd[2] ) |
---|
| 753 | { |
---|
[71dc854] | 754 | if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
[cd428e4] | 755 | { |
---|
| 756 | set_reset( &irc->set, cmd[2] ); |
---|
| 757 | set_name = cmd[2]; |
---|
| 758 | } |
---|
| 759 | else |
---|
| 760 | { |
---|
| 761 | set_setstr( &irc->set, cmd[1], cmd[2] ); |
---|
| 762 | } |
---|
[b7d3cc34] | 763 | } |
---|
[56f260a] | 764 | if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
[b7d3cc34] | 765 | { |
---|
[cd428e4] | 766 | char *s = set_getstr( &irc->set, set_name ); |
---|
| 767 | if( s ) |
---|
| 768 | irc_usermsg( irc, "%s = `%s'", set_name, s ); |
---|
[5100caa] | 769 | else |
---|
[cd428e4] | 770 | irc_usermsg( irc, "%s is empty", set_name ); |
---|
[b7d3cc34] | 771 | } |
---|
| 772 | else |
---|
| 773 | { |
---|
| 774 | set_t *s = irc->set; |
---|
| 775 | while( s ) |
---|
| 776 | { |
---|
| 777 | if( s->value || s->def ) |
---|
[cd428e4] | 778 | irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); |
---|
[5100caa] | 779 | else |
---|
| 780 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
[b7d3cc34] | 781 | s = s->next; |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | } |
---|
| 785 | |
---|
[f73b969] | 786 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 787 | { |
---|
[ab49fdc] | 788 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
[b7d3cc34] | 789 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 790 | else |
---|
| 791 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 792 | } |
---|
| 793 | |
---|
[f73b969] | 794 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 795 | { |
---|
| 796 | int online = 0, away = 0, offline = 0; |
---|
| 797 | user_t *u; |
---|
[aefa533e] | 798 | char s[256]; |
---|
| 799 | char *format; |
---|
[b7d3cc34] | 800 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 801 | |
---|
| 802 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 803 | online = offline = away = 1; |
---|
| 804 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 805 | offline = 1; |
---|
| 806 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 807 | away = 1; |
---|
| 808 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 809 | online = 1; |
---|
| 810 | else |
---|
| 811 | online = away = 1; |
---|
| 812 | |
---|
[aefa533e] | 813 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 814 | format = "%s\t%s\t%s"; |
---|
| 815 | else |
---|
| 816 | format = "%-16.16s %-40.40s %s"; |
---|
| 817 | |
---|
| 818 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 819 | |
---|
[0da65d5] | 820 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 821 | { |
---|
[aefa533e] | 822 | if( online == 1 ) |
---|
| 823 | { |
---|
[e731120] | 824 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 825 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
| 826 | } |
---|
| 827 | |
---|
[b7d3cc34] | 828 | n_online ++; |
---|
| 829 | } |
---|
| 830 | |
---|
[0da65d5] | 831 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
[b7d3cc34] | 832 | { |
---|
[aefa533e] | 833 | if( away == 1 ) |
---|
| 834 | { |
---|
[e731120] | 835 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 836 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 837 | } |
---|
[b7d3cc34] | 838 | n_away ++; |
---|
| 839 | } |
---|
| 840 | |
---|
[0da65d5] | 841 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
[b7d3cc34] | 842 | { |
---|
[aefa533e] | 843 | if( offline == 1 ) |
---|
| 844 | { |
---|
[e731120] | 845 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 846 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 847 | } |
---|
[b7d3cc34] | 848 | n_offline ++; |
---|
| 849 | } |
---|
| 850 | |
---|
[aa5ac01] | 851 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 852 | } |
---|
| 853 | |
---|
[f73b969] | 854 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 855 | { |
---|
| 856 | account_t *a; |
---|
| 857 | |
---|
| 858 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 859 | { |
---|
| 860 | irc_usermsg( irc, "Invalid account"); |
---|
| 861 | } |
---|
[0da65d5] | 862 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 863 | { |
---|
| 864 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 865 | } |
---|
| 866 | else if ( !cmd[2] ) |
---|
| 867 | { |
---|
[0da65d5] | 868 | irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" ); |
---|
[b7d3cc34] | 869 | } |
---|
[0da65d5] | 870 | else if ( !a->prpl->set_my_name ) |
---|
[b7d3cc34] | 871 | { |
---|
| 872 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 873 | } |
---|
| 874 | else |
---|
| 875 | { |
---|
| 876 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
| 877 | |
---|
[0da65d5] | 878 | a->prpl->set_my_name( a->ic, cmd[2] ); |
---|
[b7d3cc34] | 879 | } |
---|
| 880 | } |
---|
| 881 | |
---|
[f73b969] | 882 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 883 | { |
---|
| 884 | query_t *q = irc->queries; |
---|
| 885 | int num; |
---|
| 886 | |
---|
| 887 | if( !q ) |
---|
| 888 | { |
---|
| 889 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 890 | return; |
---|
[b7d3cc34] | 891 | } |
---|
| 892 | |
---|
| 893 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 894 | |
---|
| 895 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 896 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 897 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 898 | else |
---|
| 899 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 900 | } |
---|
| 901 | |
---|
[fa29d093] | 902 | static void cmd_join_chat( irc_t *irc, char **cmd ) |
---|
| 903 | { |
---|
| 904 | account_t *a; |
---|
[0da65d5] | 905 | struct im_connection *ic; |
---|
[fa29d093] | 906 | char *chat, *channel, *nick = NULL, *password = NULL; |
---|
[0da65d5] | 907 | struct groupchat *c; |
---|
[fa29d093] | 908 | |
---|
| 909 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 910 | { |
---|
| 911 | irc_usermsg( irc, "Invalid account" ); |
---|
| 912 | return; |
---|
| 913 | } |
---|
[0da65d5] | 914 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[fa29d093] | 915 | { |
---|
| 916 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 917 | return; |
---|
| 918 | } |
---|
| 919 | else if( a->prpl->chat_join == NULL ) |
---|
| 920 | { |
---|
| 921 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 922 | return; |
---|
| 923 | } |
---|
[0da65d5] | 924 | ic = a->ic; |
---|
[fa29d093] | 925 | |
---|
| 926 | chat = cmd[2]; |
---|
| 927 | if( cmd[3] ) |
---|
| 928 | { |
---|
[9da0bbf] | 929 | if( cmd[3][0] != '#' && cmd[3][0] != '&' ) |
---|
[7bf4326] | 930 | channel = g_strdup_printf( "&%s", cmd[3] ); |
---|
| 931 | else |
---|
| 932 | channel = g_strdup( cmd[3] ); |
---|
[fa29d093] | 933 | } |
---|
| 934 | else |
---|
| 935 | { |
---|
| 936 | char *s; |
---|
| 937 | |
---|
[0e7ab64] | 938 | channel = g_strdup_printf( "&%s", chat ); |
---|
[fa29d093] | 939 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 940 | *s = 0; |
---|
| 941 | } |
---|
| 942 | if( cmd[3] && cmd[4] ) |
---|
| 943 | nick = cmd[4]; |
---|
[e35d1a1] | 944 | else |
---|
| 945 | nick = irc->nick; |
---|
[fa29d093] | 946 | if( cmd[3] && cmd[4] && cmd[5] ) |
---|
| 947 | password = cmd[5]; |
---|
| 948 | |
---|
[7bf4326] | 949 | if( !nick_ok( channel + 1 ) ) |
---|
[0e7ab64] | 950 | { |
---|
| 951 | irc_usermsg( irc, "Invalid channel name: %s", channel ); |
---|
| 952 | g_free( channel ); |
---|
| 953 | return; |
---|
| 954 | } |
---|
| 955 | else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) ) |
---|
| 956 | { |
---|
| 957 | irc_usermsg( irc, "Channel already exists: %s", channel ); |
---|
| 958 | g_free( channel ); |
---|
| 959 | return; |
---|
| 960 | } |
---|
[fa29d093] | 961 | |
---|
[e35d1a1] | 962 | if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) ) |
---|
| 963 | { |
---|
| 964 | g_free( c->channel ); |
---|
| 965 | c->channel = channel; |
---|
| 966 | } |
---|
| 967 | else |
---|
| 968 | { |
---|
| 969 | irc_usermsg( irc, "Tried to join chat, not sure if this was successful" ); |
---|
| 970 | g_free( channel ); |
---|
| 971 | } |
---|
[fa29d093] | 972 | } |
---|
| 973 | |
---|
[0298d11] | 974 | const command_t commands[] = { |
---|
| 975 | { "help", 0, cmd_help, 0 }, |
---|
| 976 | { "identify", 1, cmd_identify, 0 }, |
---|
| 977 | { "register", 1, cmd_register, 0 }, |
---|
| 978 | { "drop", 1, cmd_drop, 0 }, |
---|
| 979 | { "account", 1, cmd_account, 0 }, |
---|
| 980 | { "add", 2, cmd_add, 0 }, |
---|
| 981 | { "info", 1, cmd_info, 0 }, |
---|
| 982 | { "rename", 2, cmd_rename, 0 }, |
---|
| 983 | { "remove", 1, cmd_remove, 0 }, |
---|
| 984 | { "block", 1, cmd_block, 0 }, |
---|
| 985 | { "allow", 1, cmd_allow, 0 }, |
---|
| 986 | { "save", 0, cmd_save, 0 }, |
---|
| 987 | { "set", 0, cmd_set, 0 }, |
---|
| 988 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 989 | { "no", 0, cmd_yesno, 0 }, |
---|
| 990 | { "blist", 0, cmd_blist, 0 }, |
---|
| 991 | { "nick", 1, cmd_nick, 0 }, |
---|
| 992 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[fa29d093] | 993 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
[0298d11] | 994 | { NULL } |
---|
| 995 | }; |
---|