[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 ); |
---|
[d5bd9c0] | 771 | |
---|
| 772 | if( strchr( set_name, '/' ) ) |
---|
| 773 | irc_usermsg( irc, "Warning: / found in setting name, you're probably looking for the `account set' command." ); |
---|
[b7d3cc34] | 774 | } |
---|
| 775 | else |
---|
| 776 | { |
---|
| 777 | set_t *s = irc->set; |
---|
| 778 | while( s ) |
---|
| 779 | { |
---|
| 780 | if( s->value || s->def ) |
---|
[cd428e4] | 781 | irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); |
---|
[5100caa] | 782 | else |
---|
| 783 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
[b7d3cc34] | 784 | s = s->next; |
---|
| 785 | } |
---|
| 786 | } |
---|
| 787 | } |
---|
| 788 | |
---|
[f73b969] | 789 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 790 | { |
---|
[ab49fdc] | 791 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
[b7d3cc34] | 792 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 793 | else |
---|
| 794 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 795 | } |
---|
| 796 | |
---|
[f73b969] | 797 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 798 | { |
---|
| 799 | int online = 0, away = 0, offline = 0; |
---|
| 800 | user_t *u; |
---|
[aefa533e] | 801 | char s[256]; |
---|
| 802 | char *format; |
---|
[b7d3cc34] | 803 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 804 | |
---|
| 805 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 806 | online = offline = away = 1; |
---|
| 807 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 808 | offline = 1; |
---|
| 809 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 810 | away = 1; |
---|
| 811 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 812 | online = 1; |
---|
| 813 | else |
---|
| 814 | online = away = 1; |
---|
| 815 | |
---|
[aefa533e] | 816 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 817 | format = "%s\t%s\t%s"; |
---|
| 818 | else |
---|
| 819 | format = "%-16.16s %-40.40s %s"; |
---|
| 820 | |
---|
| 821 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 822 | |
---|
[0da65d5] | 823 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 824 | { |
---|
[aefa533e] | 825 | if( online == 1 ) |
---|
| 826 | { |
---|
[e731120] | 827 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 828 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
| 829 | } |
---|
| 830 | |
---|
[b7d3cc34] | 831 | n_online ++; |
---|
| 832 | } |
---|
| 833 | |
---|
[0da65d5] | 834 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
[b7d3cc34] | 835 | { |
---|
[aefa533e] | 836 | if( away == 1 ) |
---|
| 837 | { |
---|
[e731120] | 838 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 839 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 840 | } |
---|
[b7d3cc34] | 841 | n_away ++; |
---|
| 842 | } |
---|
| 843 | |
---|
[0da65d5] | 844 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
[b7d3cc34] | 845 | { |
---|
[aefa533e] | 846 | if( offline == 1 ) |
---|
| 847 | { |
---|
[e731120] | 848 | g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user ); |
---|
[aefa533e] | 849 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 850 | } |
---|
[b7d3cc34] | 851 | n_offline ++; |
---|
| 852 | } |
---|
| 853 | |
---|
[aa5ac01] | 854 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 855 | } |
---|
| 856 | |
---|
[f73b969] | 857 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 858 | { |
---|
| 859 | account_t *a; |
---|
| 860 | |
---|
| 861 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 862 | { |
---|
| 863 | irc_usermsg( irc, "Invalid account"); |
---|
| 864 | } |
---|
[0da65d5] | 865 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 866 | { |
---|
| 867 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 868 | } |
---|
| 869 | else if ( !cmd[2] ) |
---|
| 870 | { |
---|
[0da65d5] | 871 | irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" ); |
---|
[b7d3cc34] | 872 | } |
---|
[0da65d5] | 873 | else if ( !a->prpl->set_my_name ) |
---|
[b7d3cc34] | 874 | { |
---|
| 875 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 876 | } |
---|
| 877 | else |
---|
| 878 | { |
---|
| 879 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
| 880 | |
---|
[0da65d5] | 881 | a->prpl->set_my_name( a->ic, cmd[2] ); |
---|
[b7d3cc34] | 882 | } |
---|
| 883 | } |
---|
| 884 | |
---|
[f73b969] | 885 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 886 | { |
---|
| 887 | query_t *q = irc->queries; |
---|
| 888 | int num; |
---|
| 889 | |
---|
| 890 | if( !q ) |
---|
| 891 | { |
---|
| 892 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 893 | return; |
---|
[b7d3cc34] | 894 | } |
---|
| 895 | |
---|
| 896 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 897 | |
---|
| 898 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 899 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 900 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 901 | else |
---|
| 902 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 903 | } |
---|
| 904 | |
---|
[fa29d093] | 905 | static void cmd_join_chat( irc_t *irc, char **cmd ) |
---|
| 906 | { |
---|
| 907 | account_t *a; |
---|
[0da65d5] | 908 | struct im_connection *ic; |
---|
[fa29d093] | 909 | char *chat, *channel, *nick = NULL, *password = NULL; |
---|
[0da65d5] | 910 | struct groupchat *c; |
---|
[fa29d093] | 911 | |
---|
| 912 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 913 | { |
---|
| 914 | irc_usermsg( irc, "Invalid account" ); |
---|
| 915 | return; |
---|
| 916 | } |
---|
[0da65d5] | 917 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[fa29d093] | 918 | { |
---|
| 919 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 920 | return; |
---|
| 921 | } |
---|
| 922 | else if( a->prpl->chat_join == NULL ) |
---|
| 923 | { |
---|
| 924 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 925 | return; |
---|
| 926 | } |
---|
[0da65d5] | 927 | ic = a->ic; |
---|
[fa29d093] | 928 | |
---|
| 929 | chat = cmd[2]; |
---|
| 930 | if( cmd[3] ) |
---|
| 931 | { |
---|
[9da0bbf] | 932 | if( cmd[3][0] != '#' && cmd[3][0] != '&' ) |
---|
[7bf4326] | 933 | channel = g_strdup_printf( "&%s", cmd[3] ); |
---|
| 934 | else |
---|
| 935 | channel = g_strdup( cmd[3] ); |
---|
[fa29d093] | 936 | } |
---|
| 937 | else |
---|
| 938 | { |
---|
| 939 | char *s; |
---|
| 940 | |
---|
[0e7ab64] | 941 | channel = g_strdup_printf( "&%s", chat ); |
---|
[fa29d093] | 942 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 943 | *s = 0; |
---|
| 944 | } |
---|
| 945 | if( cmd[3] && cmd[4] ) |
---|
| 946 | nick = cmd[4]; |
---|
[e35d1a1] | 947 | else |
---|
| 948 | nick = irc->nick; |
---|
[fa29d093] | 949 | if( cmd[3] && cmd[4] && cmd[5] ) |
---|
| 950 | password = cmd[5]; |
---|
| 951 | |
---|
[7bf4326] | 952 | if( !nick_ok( channel + 1 ) ) |
---|
[0e7ab64] | 953 | { |
---|
| 954 | irc_usermsg( irc, "Invalid channel name: %s", channel ); |
---|
| 955 | g_free( channel ); |
---|
| 956 | return; |
---|
| 957 | } |
---|
| 958 | else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) ) |
---|
| 959 | { |
---|
| 960 | irc_usermsg( irc, "Channel already exists: %s", channel ); |
---|
| 961 | g_free( channel ); |
---|
| 962 | return; |
---|
| 963 | } |
---|
[fa29d093] | 964 | |
---|
[e35d1a1] | 965 | if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) ) |
---|
| 966 | { |
---|
| 967 | g_free( c->channel ); |
---|
| 968 | c->channel = channel; |
---|
| 969 | } |
---|
| 970 | else |
---|
| 971 | { |
---|
| 972 | irc_usermsg( irc, "Tried to join chat, not sure if this was successful" ); |
---|
| 973 | g_free( channel ); |
---|
| 974 | } |
---|
[fa29d093] | 975 | } |
---|
| 976 | |
---|
[0298d11] | 977 | const command_t commands[] = { |
---|
| 978 | { "help", 0, cmd_help, 0 }, |
---|
| 979 | { "identify", 1, cmd_identify, 0 }, |
---|
| 980 | { "register", 1, cmd_register, 0 }, |
---|
| 981 | { "drop", 1, cmd_drop, 0 }, |
---|
| 982 | { "account", 1, cmd_account, 0 }, |
---|
| 983 | { "add", 2, cmd_add, 0 }, |
---|
| 984 | { "info", 1, cmd_info, 0 }, |
---|
| 985 | { "rename", 2, cmd_rename, 0 }, |
---|
| 986 | { "remove", 1, cmd_remove, 0 }, |
---|
| 987 | { "block", 1, cmd_block, 0 }, |
---|
| 988 | { "allow", 1, cmd_allow, 0 }, |
---|
| 989 | { "save", 0, cmd_save, 0 }, |
---|
| 990 | { "set", 0, cmd_set, 0 }, |
---|
| 991 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 992 | { "no", 0, cmd_yesno, 0 }, |
---|
| 993 | { "blist", 0, cmd_blist, 0 }, |
---|
| 994 | { "nick", 1, cmd_nick, 0 }, |
---|
| 995 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[fa29d093] | 996 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
[0298d11] | 997 | { NULL } |
---|
| 998 | }; |
---|