[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; |
---|
[f8de26f] | 451 | cmd ++; /* So evil... :-D */ |
---|
| 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 | |
---|
| 483 | /* By making this optional, you can talk to people without having to |
---|
| 484 | add them to your *real* (server-side) contact list. */ |
---|
[f0cb961] | 485 | if( add_on_server ) |
---|
[0da65d5] | 486 | a->ic->acc->prpl->add_buddy( a->ic, cmd[2], NULL ); |
---|
[b7d3cc34] | 487 | |
---|
[f0cb961] | 488 | /* add_buddy( a->ic, NULL, cmd[2], cmd[2] ); */ |
---|
| 489 | |
---|
| 490 | irc_usermsg( irc, "Adding `%s' to your contact list", cmd[2] ); |
---|
[b7d3cc34] | 491 | } |
---|
| 492 | |
---|
[f73b969] | 493 | static void cmd_info( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 494 | { |
---|
[0da65d5] | 495 | struct im_connection *ic; |
---|
[b7d3cc34] | 496 | account_t *a; |
---|
| 497 | |
---|
| 498 | if( !cmd[2] ) |
---|
| 499 | { |
---|
| 500 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 501 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 502 | { |
---|
| 503 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 504 | return; |
---|
[b7d3cc34] | 505 | } |
---|
[0da65d5] | 506 | ic = u->ic; |
---|
[b7d3cc34] | 507 | cmd[2] = u->handle; |
---|
| 508 | } |
---|
| 509 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 510 | { |
---|
| 511 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 512 | return; |
---|
[b7d3cc34] | 513 | } |
---|
[0da65d5] | 514 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 515 | { |
---|
| 516 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 517 | return; |
---|
[b7d3cc34] | 518 | } |
---|
| 519 | |
---|
[0da65d5] | 520 | if( !ic->acc->prpl->get_info ) |
---|
[b7d3cc34] | 521 | { |
---|
| 522 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 523 | } |
---|
[f73b969] | 524 | else |
---|
| 525 | { |
---|
[0da65d5] | 526 | ic->acc->prpl->get_info( ic, cmd[2] ); |
---|
[f73b969] | 527 | } |
---|
[b7d3cc34] | 528 | } |
---|
| 529 | |
---|
[f73b969] | 530 | static void cmd_rename( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 531 | { |
---|
| 532 | user_t *u; |
---|
| 533 | |
---|
| 534 | if( g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
| 535 | { |
---|
| 536 | irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] ); |
---|
| 537 | } |
---|
[f73b969] | 538 | else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) ) |
---|
[b7d3cc34] | 539 | { |
---|
| 540 | irc_usermsg( irc, "Nick `%s' already exists", cmd[2] ); |
---|
| 541 | } |
---|
[f73b969] | 542 | else if( !nick_ok( cmd[2] ) ) |
---|
[b7d3cc34] | 543 | { |
---|
| 544 | irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] ); |
---|
| 545 | } |
---|
[f73b969] | 546 | else if( !( u = user_find( irc, cmd[1] ) ) ) |
---|
[b7d3cc34] | 547 | { |
---|
| 548 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
| 549 | } |
---|
[f73b969] | 550 | else |
---|
[b7d3cc34] | 551 | { |
---|
[f73b969] | 552 | user_rename( irc, cmd[1], cmd[2] ); |
---|
| 553 | irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] ); |
---|
| 554 | if( g_strcasecmp( cmd[1], irc->mynick ) == 0 ) |
---|
| 555 | { |
---|
| 556 | g_free( irc->mynick ); |
---|
| 557 | irc->mynick = g_strdup( cmd[2] ); |
---|
| 558 | } |
---|
| 559 | else if( u->send_handler == buddy_send_handler ) |
---|
| 560 | { |
---|
[0da65d5] | 561 | nick_set( u->ic->acc, u->handle, cmd[2] ); |
---|
[f73b969] | 562 | } |
---|
| 563 | |
---|
| 564 | irc_usermsg( irc, "Nick successfully changed" ); |
---|
[b7d3cc34] | 565 | } |
---|
| 566 | } |
---|
| 567 | |
---|
[f73b969] | 568 | static void cmd_remove( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 569 | { |
---|
| 570 | user_t *u; |
---|
| 571 | char *s; |
---|
| 572 | |
---|
[0da65d5] | 573 | if( !( u = user_find( irc, cmd[1] ) ) || !u->ic ) |
---|
[b7d3cc34] | 574 | { |
---|
| 575 | irc_usermsg( irc, "Buddy `%s' not found", cmd[1] ); |
---|
[f73b969] | 576 | return; |
---|
[b7d3cc34] | 577 | } |
---|
| 578 | s = g_strdup( u->handle ); |
---|
| 579 | |
---|
[0da65d5] | 580 | u->ic->acc->prpl->remove_buddy( u->ic, u->handle, NULL ); |
---|
| 581 | nick_del( u->ic->acc, u->handle ); |
---|
[b7d3cc34] | 582 | user_del( irc, cmd[1] ); |
---|
| 583 | |
---|
| 584 | irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] ); |
---|
| 585 | g_free( s ); |
---|
| 586 | |
---|
[f73b969] | 587 | return; |
---|
[b7d3cc34] | 588 | } |
---|
| 589 | |
---|
[f73b969] | 590 | static void cmd_block( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 591 | { |
---|
[0da65d5] | 592 | struct im_connection *ic; |
---|
[b7d3cc34] | 593 | account_t *a; |
---|
| 594 | |
---|
[0da65d5] | 595 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 596 | { |
---|
| 597 | char *format; |
---|
| 598 | GSList *l; |
---|
| 599 | |
---|
| 600 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 601 | format = "%s\t%s"; |
---|
| 602 | else |
---|
[57ef864] | 603 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 604 | |
---|
| 605 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 606 | for( l = a->ic->deny; l; l = l->next ) |
---|
[87b6a3e] | 607 | { |
---|
[0da65d5] | 608 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 609 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 610 | } |
---|
| 611 | irc_usermsg( irc, "End of list." ); |
---|
| 612 | |
---|
| 613 | return; |
---|
| 614 | } |
---|
| 615 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 616 | { |
---|
| 617 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 618 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 619 | { |
---|
| 620 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 621 | return; |
---|
[b7d3cc34] | 622 | } |
---|
[0da65d5] | 623 | ic = u->ic; |
---|
[b7d3cc34] | 624 | cmd[2] = u->handle; |
---|
| 625 | } |
---|
| 626 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 627 | { |
---|
| 628 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 629 | return; |
---|
[b7d3cc34] | 630 | } |
---|
[0da65d5] | 631 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 632 | { |
---|
| 633 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 634 | return; |
---|
[b7d3cc34] | 635 | } |
---|
| 636 | |
---|
[0da65d5] | 637 | if( !ic->acc->prpl->add_deny || !ic->acc->prpl->rem_permit ) |
---|
[b7d3cc34] | 638 | { |
---|
| 639 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 640 | } |
---|
| 641 | else |
---|
| 642 | { |
---|
[84b045d] | 643 | imc_rem_allow( ic, cmd[2] ); |
---|
| 644 | imc_add_block( ic, cmd[2] ); |
---|
[da3b536] | 645 | irc_usermsg( irc, "Buddy `%s' moved from your allow- to your block-list", cmd[2] ); |
---|
[b7d3cc34] | 646 | } |
---|
| 647 | } |
---|
| 648 | |
---|
[f73b969] | 649 | static void cmd_allow( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 650 | { |
---|
[0da65d5] | 651 | struct im_connection *ic; |
---|
[b7d3cc34] | 652 | account_t *a; |
---|
| 653 | |
---|
[0da65d5] | 654 | if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->ic ) |
---|
[87b6a3e] | 655 | { |
---|
| 656 | char *format; |
---|
| 657 | GSList *l; |
---|
| 658 | |
---|
| 659 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 660 | format = "%s\t%s"; |
---|
| 661 | else |
---|
[57ef864] | 662 | format = "%-32.32s %-16.16s"; |
---|
[87b6a3e] | 663 | |
---|
| 664 | irc_usermsg( irc, format, "Handle", "Nickname" ); |
---|
[0da65d5] | 665 | for( l = a->ic->permit; l; l = l->next ) |
---|
[87b6a3e] | 666 | { |
---|
[0da65d5] | 667 | user_t *u = user_findhandle( a->ic, l->data ); |
---|
[87b6a3e] | 668 | irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" ); |
---|
| 669 | } |
---|
| 670 | irc_usermsg( irc, "End of list." ); |
---|
| 671 | |
---|
| 672 | return; |
---|
| 673 | } |
---|
| 674 | else if( !cmd[2] ) |
---|
[b7d3cc34] | 675 | { |
---|
| 676 | user_t *u = user_find( irc, cmd[1] ); |
---|
[0da65d5] | 677 | if( !u || !u->ic ) |
---|
[b7d3cc34] | 678 | { |
---|
| 679 | irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] ); |
---|
[f73b969] | 680 | return; |
---|
[b7d3cc34] | 681 | } |
---|
[0da65d5] | 682 | ic = u->ic; |
---|
[b7d3cc34] | 683 | cmd[2] = u->handle; |
---|
| 684 | } |
---|
| 685 | else if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 686 | { |
---|
| 687 | irc_usermsg( irc, "Invalid account" ); |
---|
[f73b969] | 688 | return; |
---|
[b7d3cc34] | 689 | } |
---|
[0da65d5] | 690 | else if( !( ( ic = a->ic ) && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 691 | { |
---|
| 692 | irc_usermsg( irc, "That account is not on-line" ); |
---|
[f73b969] | 693 | return; |
---|
[b7d3cc34] | 694 | } |
---|
| 695 | |
---|
[0da65d5] | 696 | if( !ic->acc->prpl->rem_deny || !ic->acc->prpl->add_permit ) |
---|
[b7d3cc34] | 697 | { |
---|
| 698 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 699 | } |
---|
| 700 | else |
---|
| 701 | { |
---|
[84b045d] | 702 | imc_rem_block( ic, cmd[2] ); |
---|
| 703 | imc_add_allow( ic, cmd[2] ); |
---|
[b7d3cc34] | 704 | |
---|
[da3b536] | 705 | irc_usermsg( irc, "Buddy `%s' moved from your block- to your allow-list", cmd[2] ); |
---|
[b7d3cc34] | 706 | } |
---|
| 707 | } |
---|
| 708 | |
---|
[f73b969] | 709 | static void cmd_yesno( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 710 | { |
---|
| 711 | query_t *q = NULL; |
---|
| 712 | int numq = 0; |
---|
| 713 | |
---|
| 714 | if( irc->queries == NULL ) |
---|
| 715 | { |
---|
| 716 | irc_usermsg( irc, "Did I ask you something?" ); |
---|
[f73b969] | 717 | return; |
---|
[b7d3cc34] | 718 | } |
---|
| 719 | |
---|
| 720 | /* If there's an argument, the user seems to want to answer another question than the |
---|
| 721 | first/last (depending on the query_order setting) one. */ |
---|
| 722 | if( cmd[1] ) |
---|
| 723 | { |
---|
| 724 | if( sscanf( cmd[1], "%d", &numq ) != 1 ) |
---|
| 725 | { |
---|
| 726 | irc_usermsg( irc, "Invalid query number" ); |
---|
[f73b969] | 727 | return; |
---|
[b7d3cc34] | 728 | } |
---|
| 729 | |
---|
| 730 | for( q = irc->queries; q; q = q->next, numq -- ) |
---|
| 731 | if( numq == 0 ) |
---|
| 732 | break; |
---|
| 733 | |
---|
| 734 | if( !q ) |
---|
| 735 | { |
---|
| 736 | irc_usermsg( irc, "Uhm, I never asked you something like that..." ); |
---|
[f73b969] | 737 | return; |
---|
[b7d3cc34] | 738 | } |
---|
| 739 | } |
---|
| 740 | |
---|
| 741 | if( g_strcasecmp( cmd[0], "yes" ) == 0 ) |
---|
| 742 | query_answer( irc, q, 1 ); |
---|
| 743 | else if( g_strcasecmp( cmd[0], "no" ) == 0 ) |
---|
| 744 | query_answer( irc, q, 0 ); |
---|
| 745 | } |
---|
| 746 | |
---|
[f73b969] | 747 | static void cmd_set( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 748 | { |
---|
[71dc854] | 749 | char *set_name = cmd[1]; |
---|
[cd428e4] | 750 | |
---|
[b7d3cc34] | 751 | if( cmd[1] && cmd[2] ) |
---|
| 752 | { |
---|
[71dc854] | 753 | if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 ) |
---|
[cd428e4] | 754 | { |
---|
| 755 | set_reset( &irc->set, cmd[2] ); |
---|
| 756 | set_name = cmd[2]; |
---|
| 757 | } |
---|
| 758 | else |
---|
| 759 | { |
---|
| 760 | set_setstr( &irc->set, cmd[1], cmd[2] ); |
---|
| 761 | } |
---|
[b7d3cc34] | 762 | } |
---|
[56f260a] | 763 | if( set_name ) /* else 'forgotten' on purpose.. Must show new value after changing */ |
---|
[b7d3cc34] | 764 | { |
---|
[cd428e4] | 765 | char *s = set_getstr( &irc->set, set_name ); |
---|
| 766 | if( s ) |
---|
| 767 | irc_usermsg( irc, "%s = `%s'", set_name, s ); |
---|
[5100caa] | 768 | else |
---|
[cd428e4] | 769 | irc_usermsg( irc, "%s is empty", set_name ); |
---|
[b7d3cc34] | 770 | } |
---|
| 771 | else |
---|
| 772 | { |
---|
| 773 | set_t *s = irc->set; |
---|
| 774 | while( s ) |
---|
| 775 | { |
---|
| 776 | if( s->value || s->def ) |
---|
[cd428e4] | 777 | irc_usermsg( irc, "%s = `%s'", s->key, s->value ? s->value : s->def ); |
---|
[5100caa] | 778 | else |
---|
| 779 | irc_usermsg( irc, "%s is empty", s->key ); |
---|
[b7d3cc34] | 780 | s = s->next; |
---|
| 781 | } |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | |
---|
[f73b969] | 785 | static void cmd_save( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 786 | { |
---|
[ab49fdc] | 787 | if( storage_save( irc, TRUE ) == STORAGE_OK ) |
---|
[b7d3cc34] | 788 | irc_usermsg( irc, "Configuration saved" ); |
---|
| 789 | else |
---|
| 790 | irc_usermsg( irc, "Configuration could not be saved!" ); |
---|
| 791 | } |
---|
| 792 | |
---|
[f73b969] | 793 | static void cmd_blist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 794 | { |
---|
| 795 | int online = 0, away = 0, offline = 0; |
---|
| 796 | user_t *u; |
---|
[aefa533e] | 797 | char s[256]; |
---|
| 798 | char *format; |
---|
[b7d3cc34] | 799 | int n_online = 0, n_away = 0, n_offline = 0; |
---|
| 800 | |
---|
| 801 | if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 ) |
---|
| 802 | online = offline = away = 1; |
---|
| 803 | else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 ) |
---|
| 804 | offline = 1; |
---|
| 805 | else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 ) |
---|
| 806 | away = 1; |
---|
| 807 | else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 ) |
---|
| 808 | online = 1; |
---|
| 809 | else |
---|
| 810 | online = away = 1; |
---|
| 811 | |
---|
[aefa533e] | 812 | if( strchr( irc->umode, 'b' ) != NULL ) |
---|
| 813 | format = "%s\t%s\t%s"; |
---|
| 814 | else |
---|
| 815 | format = "%-16.16s %-40.40s %s"; |
---|
| 816 | |
---|
| 817 | irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" ); |
---|
[b7d3cc34] | 818 | |
---|
[0da65d5] | 819 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && !u->away ) |
---|
[b7d3cc34] | 820 | { |
---|
[aefa533e] | 821 | if( online == 1 ) |
---|
| 822 | { |
---|
[0da65d5] | 823 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->ic->acc->prpl->name ); |
---|
[aefa533e] | 824 | irc_usermsg( irc, format, u->nick, s, "Online" ); |
---|
| 825 | } |
---|
| 826 | |
---|
[b7d3cc34] | 827 | n_online ++; |
---|
| 828 | } |
---|
| 829 | |
---|
[0da65d5] | 830 | for( u = irc->users; u; u = u->next ) if( u->ic && u->online && u->away ) |
---|
[b7d3cc34] | 831 | { |
---|
[aefa533e] | 832 | if( away == 1 ) |
---|
| 833 | { |
---|
[0da65d5] | 834 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->ic->acc->prpl->name ); |
---|
[aefa533e] | 835 | irc_usermsg( irc, format, u->nick, s, u->away ); |
---|
| 836 | } |
---|
[b7d3cc34] | 837 | n_away ++; |
---|
| 838 | } |
---|
| 839 | |
---|
[0da65d5] | 840 | for( u = irc->users; u; u = u->next ) if( u->ic && !u->online ) |
---|
[b7d3cc34] | 841 | { |
---|
[aefa533e] | 842 | if( offline == 1 ) |
---|
| 843 | { |
---|
[0da65d5] | 844 | g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->ic->acc->prpl->name ); |
---|
[aefa533e] | 845 | irc_usermsg( irc, format, u->nick, s, "Offline" ); |
---|
| 846 | } |
---|
[b7d3cc34] | 847 | n_offline ++; |
---|
| 848 | } |
---|
| 849 | |
---|
[aa5ac01] | 850 | irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline ); |
---|
[b7d3cc34] | 851 | } |
---|
| 852 | |
---|
[f73b969] | 853 | static void cmd_nick( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 854 | { |
---|
| 855 | account_t *a; |
---|
| 856 | |
---|
| 857 | if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 858 | { |
---|
| 859 | irc_usermsg( irc, "Invalid account"); |
---|
| 860 | } |
---|
[0da65d5] | 861 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[b7d3cc34] | 862 | { |
---|
| 863 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 864 | } |
---|
| 865 | else if ( !cmd[2] ) |
---|
| 866 | { |
---|
[0da65d5] | 867 | irc_usermsg( irc, "Your name is `%s'" , a->ic->displayname ? a->ic->displayname : "NULL" ); |
---|
[b7d3cc34] | 868 | } |
---|
[0da65d5] | 869 | else if ( !a->prpl->set_my_name ) |
---|
[b7d3cc34] | 870 | { |
---|
| 871 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 872 | } |
---|
| 873 | else |
---|
| 874 | { |
---|
| 875 | irc_usermsg( irc, "Setting your name to `%s'", cmd[2] ); |
---|
| 876 | |
---|
[0da65d5] | 877 | a->prpl->set_my_name( a->ic, cmd[2] ); |
---|
[b7d3cc34] | 878 | } |
---|
| 879 | } |
---|
| 880 | |
---|
[f73b969] | 881 | static void cmd_qlist( irc_t *irc, char **cmd ) |
---|
[b7d3cc34] | 882 | { |
---|
| 883 | query_t *q = irc->queries; |
---|
| 884 | int num; |
---|
| 885 | |
---|
| 886 | if( !q ) |
---|
| 887 | { |
---|
| 888 | irc_usermsg( irc, "There are no pending questions." ); |
---|
[f73b969] | 889 | return; |
---|
[b7d3cc34] | 890 | } |
---|
| 891 | |
---|
| 892 | irc_usermsg( irc, "Pending queries:" ); |
---|
| 893 | |
---|
| 894 | for( num = 0; q; q = q->next, num ++ ) |
---|
[0da65d5] | 895 | if( q->ic ) /* Not necessary yet, but it might come later */ |
---|
[c2fb3809] | 896 | irc_usermsg( irc, "%d, %s(%s): %s", num, q->ic->acc->prpl->name, q->ic->acc->user, q->question ); |
---|
[5c09a59] | 897 | else |
---|
| 898 | irc_usermsg( irc, "%d, BitlBee: %s", num, q->question ); |
---|
[b7d3cc34] | 899 | } |
---|
| 900 | |
---|
[fa29d093] | 901 | static void cmd_join_chat( irc_t *irc, char **cmd ) |
---|
| 902 | { |
---|
| 903 | account_t *a; |
---|
[0da65d5] | 904 | struct im_connection *ic; |
---|
[fa29d093] | 905 | char *chat, *channel, *nick = NULL, *password = NULL; |
---|
[0da65d5] | 906 | struct groupchat *c; |
---|
[fa29d093] | 907 | |
---|
| 908 | if( !( a = account_get( irc, cmd[1] ) ) ) |
---|
| 909 | { |
---|
| 910 | irc_usermsg( irc, "Invalid account" ); |
---|
| 911 | return; |
---|
| 912 | } |
---|
[0da65d5] | 913 | else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) ) |
---|
[fa29d093] | 914 | { |
---|
| 915 | irc_usermsg( irc, "That account is not on-line" ); |
---|
| 916 | return; |
---|
| 917 | } |
---|
| 918 | else if( a->prpl->chat_join == NULL ) |
---|
| 919 | { |
---|
| 920 | irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] ); |
---|
| 921 | return; |
---|
| 922 | } |
---|
[0da65d5] | 923 | ic = a->ic; |
---|
[fa29d093] | 924 | |
---|
| 925 | chat = cmd[2]; |
---|
| 926 | if( cmd[3] ) |
---|
| 927 | { |
---|
[9da0bbf] | 928 | if( cmd[3][0] != '#' && cmd[3][0] != '&' ) |
---|
[7bf4326] | 929 | channel = g_strdup_printf( "&%s", cmd[3] ); |
---|
| 930 | else |
---|
| 931 | channel = g_strdup( cmd[3] ); |
---|
[fa29d093] | 932 | } |
---|
| 933 | else |
---|
| 934 | { |
---|
| 935 | char *s; |
---|
| 936 | |
---|
[0e7ab64] | 937 | channel = g_strdup_printf( "&%s", chat ); |
---|
[fa29d093] | 938 | if( ( s = strchr( channel, '@' ) ) ) |
---|
| 939 | *s = 0; |
---|
| 940 | } |
---|
| 941 | if( cmd[3] && cmd[4] ) |
---|
| 942 | nick = cmd[4]; |
---|
[e35d1a1] | 943 | else |
---|
| 944 | nick = irc->nick; |
---|
[fa29d093] | 945 | if( cmd[3] && cmd[4] && cmd[5] ) |
---|
| 946 | password = cmd[5]; |
---|
| 947 | |
---|
[7bf4326] | 948 | if( !nick_ok( channel + 1 ) ) |
---|
[0e7ab64] | 949 | { |
---|
| 950 | irc_usermsg( irc, "Invalid channel name: %s", channel ); |
---|
| 951 | g_free( channel ); |
---|
| 952 | return; |
---|
| 953 | } |
---|
| 954 | else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) ) |
---|
| 955 | { |
---|
| 956 | irc_usermsg( irc, "Channel already exists: %s", channel ); |
---|
| 957 | g_free( channel ); |
---|
| 958 | return; |
---|
| 959 | } |
---|
[fa29d093] | 960 | |
---|
[e35d1a1] | 961 | if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) ) |
---|
| 962 | { |
---|
| 963 | g_free( c->channel ); |
---|
| 964 | c->channel = channel; |
---|
| 965 | } |
---|
| 966 | else |
---|
| 967 | { |
---|
| 968 | irc_usermsg( irc, "Tried to join chat, not sure if this was successful" ); |
---|
| 969 | g_free( channel ); |
---|
| 970 | } |
---|
[fa29d093] | 971 | } |
---|
| 972 | |
---|
[0298d11] | 973 | const command_t commands[] = { |
---|
| 974 | { "help", 0, cmd_help, 0 }, |
---|
| 975 | { "identify", 1, cmd_identify, 0 }, |
---|
| 976 | { "register", 1, cmd_register, 0 }, |
---|
| 977 | { "drop", 1, cmd_drop, 0 }, |
---|
| 978 | { "account", 1, cmd_account, 0 }, |
---|
| 979 | { "add", 2, cmd_add, 0 }, |
---|
| 980 | { "info", 1, cmd_info, 0 }, |
---|
| 981 | { "rename", 2, cmd_rename, 0 }, |
---|
| 982 | { "remove", 1, cmd_remove, 0 }, |
---|
| 983 | { "block", 1, cmd_block, 0 }, |
---|
| 984 | { "allow", 1, cmd_allow, 0 }, |
---|
| 985 | { "save", 0, cmd_save, 0 }, |
---|
| 986 | { "set", 0, cmd_set, 0 }, |
---|
| 987 | { "yes", 0, cmd_yesno, 0 }, |
---|
| 988 | { "no", 0, cmd_yesno, 0 }, |
---|
| 989 | { "blist", 0, cmd_blist, 0 }, |
---|
| 990 | { "nick", 1, cmd_nick, 0 }, |
---|
| 991 | { "qlist", 0, cmd_qlist, 0 }, |
---|
[fa29d093] | 992 | { "join_chat", 2, cmd_join_chat, 0 }, |
---|
[0298d11] | 993 | { NULL } |
---|
| 994 | }; |
---|