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