[0298d11] | 1 | /********************************************************************\ |
---|
| 2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
| 3 | * * |
---|
[3ddb7477] | 4 | * Copyright 2002-2010 Wilmer van der Gaast and others * |
---|
[0298d11] | 5 | \********************************************************************/ |
---|
| 6 | |
---|
| 7 | /* IRC 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 "bitlbee.h" |
---|
[0431ea1] | 28 | #include "ipc.h" |
---|
[b75acf6] | 29 | #include "chat.h" |
---|
[0298d11] | 30 | |
---|
[f73b969] | 31 | static void irc_cmd_pass( irc_t *irc, char **cmd ) |
---|
[0298d11] | 32 | { |
---|
[a199d33] | 33 | if( irc->status & USTATUS_LOGGED_IN ) |
---|
| 34 | { |
---|
| 35 | char *send_cmd[] = { "identify", cmd[1], NULL }; |
---|
| 36 | |
---|
| 37 | /* We're already logged in, this client seems to send the PASS |
---|
| 38 | command last. (Possibly it won't send it at all if it turns |
---|
| 39 | out we don't require it, which will break this feature.) |
---|
| 40 | Try to identify using the given password. */ |
---|
[fb117aee] | 41 | return root_command( irc, send_cmd ); |
---|
[a199d33] | 42 | } |
---|
| 43 | /* Handling in pre-logged-in state, first see if this server is |
---|
| 44 | password-protected: */ |
---|
| 45 | else if( global.conf->auth_pass && |
---|
[c029350] | 46 | ( strncmp( global.conf->auth_pass, "md5:", 4 ) == 0 ? |
---|
| 47 | md5_verify_password( cmd[1], global.conf->auth_pass + 4 ) == 0 : |
---|
| 48 | strcmp( cmd[1], global.conf->auth_pass ) == 0 ) ) |
---|
[0298d11] | 49 | { |
---|
[79e826a] | 50 | irc->status |= USTATUS_AUTHORIZED; |
---|
[de3e100] | 51 | irc_check_login( irc ); |
---|
[0298d11] | 52 | } |
---|
[a199d33] | 53 | else if( global.conf->auth_pass ) |
---|
[0298d11] | 54 | { |
---|
[3ddb7477] | 55 | irc_send_num( irc, 464, ":Incorrect password" ); |
---|
[0298d11] | 56 | } |
---|
[a199d33] | 57 | else |
---|
| 58 | { |
---|
| 59 | /* Remember the password and try to identify after USER/NICK. */ |
---|
[3ddb7477] | 60 | /*irc_setpass( irc, cmd[1] ); */ |
---|
[a199d33] | 61 | irc_check_login( irc ); |
---|
| 62 | } |
---|
[0298d11] | 63 | } |
---|
| 64 | |
---|
[f73b969] | 65 | static void irc_cmd_user( irc_t *irc, char **cmd ) |
---|
[0298d11] | 66 | { |
---|
[3ddb7477] | 67 | irc->user->user = g_strdup( cmd[1] ); |
---|
| 68 | irc->user->fullname = g_strdup( cmd[4] ); |
---|
[edf9657] | 69 | |
---|
| 70 | irc_check_login( irc ); |
---|
[0298d11] | 71 | } |
---|
| 72 | |
---|
[f73b969] | 73 | static void irc_cmd_nick( irc_t *irc, char **cmd ) |
---|
[0298d11] | 74 | { |
---|
[3ddb7477] | 75 | if( irc->user->nick ) |
---|
[0298d11] | 76 | { |
---|
[3ddb7477] | 77 | irc_send_num( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" ); |
---|
[0298d11] | 78 | } |
---|
[280c56a] | 79 | else if( irc_user_by_name( irc, cmd[1] ) ) |
---|
[0298d11] | 80 | { |
---|
[3ddb7477] | 81 | irc_send_num( irc, 433, ":This nick is already in use" ); |
---|
[0298d11] | 82 | } |
---|
| 83 | else if( !nick_ok( cmd[1] ) ) |
---|
| 84 | { |
---|
| 85 | /* [SH] Invalid characters. */ |
---|
[3ddb7477] | 86 | irc_send_num( irc, 432, ":This nick contains invalid characters" ); |
---|
[0298d11] | 87 | } |
---|
| 88 | else |
---|
| 89 | { |
---|
[3ddb7477] | 90 | irc->user->nick = g_strdup( cmd[1] ); |
---|
[edf9657] | 91 | |
---|
| 92 | irc_check_login( irc ); |
---|
[0298d11] | 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
[f73b969] | 96 | static void irc_cmd_quit( irc_t *irc, char **cmd ) |
---|
[0298d11] | 97 | { |
---|
[f73b969] | 98 | if( cmd[1] && *cmd[1] ) |
---|
| 99 | irc_abort( irc, 0, "Quit: %s", cmd[1] ); |
---|
| 100 | else |
---|
| 101 | irc_abort( irc, 0, "Leaving..." ); |
---|
[0298d11] | 102 | } |
---|
| 103 | |
---|
[f73b969] | 104 | static void irc_cmd_ping( irc_t *irc, char **cmd ) |
---|
[0298d11] | 105 | { |
---|
[ebaebfe] | 106 | irc_write( irc, ":%s PONG %s :%s", irc->root->host, |
---|
| 107 | irc->root->host, cmd[1]?cmd[1]:irc->root->host ); |
---|
[0298d11] | 108 | } |
---|
| 109 | |
---|
[3923003] | 110 | static void irc_cmd_pong( irc_t *irc, char **cmd ) |
---|
| 111 | { |
---|
| 112 | /* We could check the value we get back from the user, but in |
---|
| 113 | fact we don't care, we're just happy s/he's still alive. */ |
---|
| 114 | irc->last_pong = gettime(); |
---|
| 115 | irc->pinging = 0; |
---|
| 116 | } |
---|
| 117 | |
---|
[b9e020a] | 118 | static void irc_cmd_join( irc_t *irc, char **cmd ) |
---|
| 119 | { |
---|
| 120 | irc_channel_t *ic; |
---|
| 121 | |
---|
| 122 | if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) |
---|
| 123 | ic = irc_channel_new( irc, cmd[1] ); |
---|
| 124 | |
---|
| 125 | if( ic == NULL ) |
---|
| 126 | irc_send_num( irc, 479, "%s :Invalid channel name", cmd[1] ); |
---|
| 127 | |
---|
| 128 | if( ic->flags & IRC_CHANNEL_JOINED ) |
---|
| 129 | return; /* Dude, you're already there... |
---|
| 130 | RFC doesn't have any reply for that though? */ |
---|
| 131 | |
---|
| 132 | irc_channel_add_user( ic, irc->user ); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | static void irc_cmd_names( irc_t *irc, char **cmd ) |
---|
| 136 | { |
---|
| 137 | irc_channel_t *ic; |
---|
| 138 | |
---|
| 139 | if( cmd[1] && ( ic = irc_channel_by_name( irc, cmd[1] ) ) ) |
---|
| 140 | irc_send_names( ic ); |
---|
| 141 | /* With no args, we should show /names of all chans. Make the code |
---|
| 142 | below work well if necessary. |
---|
| 143 | else |
---|
| 144 | { |
---|
| 145 | GSList *l; |
---|
| 146 | |
---|
| 147 | for( l = irc->channels; l; l = l->next ) |
---|
| 148 | irc_send_names( l->data ); |
---|
| 149 | } |
---|
| 150 | */ |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | static void irc_cmd_part( irc_t *irc, char **cmd ) |
---|
| 154 | { |
---|
| 155 | irc_channel_t *ic; |
---|
| 156 | |
---|
| 157 | if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) |
---|
| 158 | { |
---|
| 159 | irc_send_num( irc, 403, "%s :No such channel", cmd[1] ); |
---|
| 160 | } |
---|
| 161 | else if( !irc_channel_del_user( ic, irc->user ) ) |
---|
| 162 | { |
---|
| 163 | irc_send_num( irc, 442, "%s :You're not on that channel", cmd[1] ); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
[b95932e] | 167 | static void irc_cmd_whois( irc_t *irc, char **cmd ) |
---|
| 168 | { |
---|
| 169 | char *nick = cmd[1]; |
---|
[280c56a] | 170 | irc_user_t *iu = irc_user_by_name( irc, nick ); |
---|
[b95932e] | 171 | |
---|
| 172 | if( iu ) |
---|
| 173 | irc_send_whois( iu ); |
---|
| 174 | else |
---|
| 175 | irc_send_num( irc, 401, "%s :Nick does not exist", nick ); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | static void irc_cmd_whowas( irc_t *irc, char **cmd ) |
---|
| 179 | { |
---|
| 180 | /* For some reason irssi tries a whowas when whois fails. We can |
---|
| 181 | ignore this, but then the user never gets a "user not found" |
---|
| 182 | message from irssi which is a bit annoying. So just respond |
---|
| 183 | with not-found and irssi users will get better error messages */ |
---|
| 184 | |
---|
| 185 | irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] ); |
---|
| 186 | irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] ); |
---|
| 187 | } |
---|
| 188 | |
---|
[9b69eb7] | 189 | static void irc_cmd_motd( irc_t *irc, char **cmd ) |
---|
| 190 | { |
---|
| 191 | irc_send_motd( irc ); |
---|
| 192 | } |
---|
| 193 | |
---|
[f73b969] | 194 | static void irc_cmd_mode( irc_t *irc, char **cmd ) |
---|
[0298d11] | 195 | { |
---|
[b919363] | 196 | if( irc_channel_name_ok( cmd[1] ) ) |
---|
[0298d11] | 197 | { |
---|
[b919363] | 198 | irc_channel_t *ic; |
---|
| 199 | |
---|
| 200 | if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) |
---|
| 201 | irc_send_num( irc, 403, "%s :No such channel", cmd[1] ); |
---|
| 202 | else if( cmd[2] ) |
---|
[0298d11] | 203 | { |
---|
| 204 | if( *cmd[2] == '+' || *cmd[2] == '-' ) |
---|
[3ddb7477] | 205 | irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] ); |
---|
[0298d11] | 206 | else if( *cmd[2] == 'b' ) |
---|
[3ddb7477] | 207 | irc_send_num( irc, 368, "%s :No bans possible", cmd[1] ); |
---|
[0298d11] | 208 | } |
---|
| 209 | else |
---|
[b919363] | 210 | irc_send_num( irc, 324, "%s +%s", cmd[1], ic->mode ); |
---|
[0298d11] | 211 | } |
---|
| 212 | else |
---|
| 213 | { |
---|
[b919363] | 214 | if( nick_cmp( cmd[1], irc->user->nick ) == 0 ) |
---|
[0298d11] | 215 | { |
---|
| 216 | if( cmd[2] ) |
---|
| 217 | irc_umode_set( irc, cmd[2], 0 ); |
---|
[2f13222] | 218 | else |
---|
[3ddb7477] | 219 | irc_send_num( irc, 221, "+%s", irc->umode ); |
---|
[0298d11] | 220 | } |
---|
| 221 | else |
---|
[3ddb7477] | 222 | irc_send_num( irc, 502, ":Don't touch their modes" ); |
---|
[0298d11] | 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
[2f53ada] | 226 | static void irc_cmd_who( irc_t *irc, char **cmd ) |
---|
| 227 | { |
---|
| 228 | char *channel = cmd[1]; |
---|
| 229 | irc_channel_t *ic; |
---|
| 230 | |
---|
| 231 | if( !channel || *channel == '0' || *channel == '*' || !*channel ) |
---|
| 232 | irc_send_who( irc, irc->users, "**" ); |
---|
| 233 | else if( ( ic = irc_channel_by_name( irc, channel ) ) ) |
---|
| 234 | irc_send_who( irc, ic->users, channel ); |
---|
| 235 | else |
---|
| 236 | irc_send_num( irc, 403, "%s :No such channel", channel ); |
---|
| 237 | } |
---|
| 238 | |
---|
[280c56a] | 239 | static void irc_cmd_privmsg( irc_t *irc, char **cmd ) |
---|
[b919363] | 240 | { |
---|
[280c56a] | 241 | irc_channel_t *ic; |
---|
| 242 | irc_user_t *iu; |
---|
| 243 | |
---|
| 244 | if( !cmd[2] ) |
---|
[b919363] | 245 | { |
---|
[280c56a] | 246 | irc_send_num( irc, 412, ":No text to send" ); |
---|
| 247 | } |
---|
| 248 | else if( irc_channel_name_ok( cmd[1] ) && |
---|
| 249 | ( ic = irc_channel_by_name( irc, cmd[1] ) ) ) |
---|
| 250 | { |
---|
| 251 | if( ic->f->privmsg ) |
---|
| 252 | ic->f->privmsg( ic, cmd[2] ); |
---|
| 253 | } |
---|
| 254 | else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) ) |
---|
| 255 | { |
---|
| 256 | if( iu->f->privmsg ) |
---|
| 257 | iu->f->privmsg( iu, cmd[2] ); |
---|
[b919363] | 258 | } |
---|
| 259 | else |
---|
| 260 | { |
---|
[280c56a] | 261 | irc_send_num( irc, 401, "%s :No such nick/channel", cmd[1] ); |
---|
[b919363] | 262 | } |
---|
| 263 | |
---|
[0298d11] | 264 | |
---|
[280c56a] | 265 | #if 0 |
---|
[9b69eb7] | 266 | else if( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
[0298d11] | 267 | { |
---|
| 268 | } |
---|
| 269 | else |
---|
| 270 | { |
---|
| 271 | if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) |
---|
| 272 | { |
---|
| 273 | unsigned int i; |
---|
[5c9512f] | 274 | char *t = set_getstr( &irc->set, "default_target" ); |
---|
[0298d11] | 275 | |
---|
| 276 | if( g_strcasecmp( t, "last" ) == 0 && irc->last_target ) |
---|
| 277 | cmd[1] = irc->last_target; |
---|
| 278 | else if( g_strcasecmp( t, "root" ) == 0 ) |
---|
| 279 | cmd[1] = irc->mynick; |
---|
| 280 | |
---|
| 281 | for( i = 0; i < strlen( cmd[2] ); i ++ ) |
---|
| 282 | { |
---|
| 283 | if( cmd[2][i] == ' ' ) break; |
---|
| 284 | if( cmd[2][i] == ':' || cmd[2][i] == ',' ) |
---|
| 285 | { |
---|
| 286 | cmd[1] = cmd[2]; |
---|
| 287 | cmd[2] += i; |
---|
| 288 | *cmd[2] = 0; |
---|
| 289 | while( *(++cmd[2]) == ' ' ); |
---|
| 290 | break; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | irc->is_private = 0; |
---|
| 295 | |
---|
| 296 | if( cmd[1] != irc->last_target ) |
---|
| 297 | { |
---|
[f9756bd] | 298 | g_free( irc->last_target ); |
---|
[0298d11] | 299 | irc->last_target = g_strdup( cmd[1] ); |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | else |
---|
| 303 | { |
---|
| 304 | irc->is_private = 1; |
---|
| 305 | } |
---|
[6bbb939] | 306 | irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 ); |
---|
[0298d11] | 307 | } |
---|
[280c56a] | 308 | #endif |
---|
| 309 | } |
---|
| 310 | |
---|
[d860a8d] | 311 | static void irc_cmd_nickserv( irc_t *irc, char **cmd ) |
---|
| 312 | { |
---|
| 313 | /* [SH] This aliases the NickServ command to PRIVMSG root */ |
---|
| 314 | /* [TV] This aliases the NS command to PRIVMSG root as well */ |
---|
| 315 | root_command( irc, cmd + 1 ); |
---|
| 316 | } |
---|
| 317 | |
---|
[280c56a] | 318 | |
---|
| 319 | |
---|
| 320 | #if 0 |
---|
| 321 | //#if 0 |
---|
| 322 | static void irc_cmd_oper( irc_t *irc, char **cmd ) |
---|
| 323 | { |
---|
| 324 | if( global.conf->oper_pass && |
---|
| 325 | ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ? |
---|
| 326 | md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 : |
---|
| 327 | strcmp( cmd[2], global.conf->oper_pass ) == 0 ) ) |
---|
| 328 | { |
---|
| 329 | irc_umode_set( irc, "+o", 1 ); |
---|
| 330 | irc_send_num( irc, 381, ":Password accepted" ); |
---|
| 331 | } |
---|
| 332 | else |
---|
| 333 | { |
---|
| 334 | irc_send_num( irc, 432, ":Incorrect password" ); |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | static void irc_cmd_invite( irc_t *irc, char **cmd ) |
---|
| 339 | { |
---|
| 340 | char *nick = cmd[1], *channel = cmd[2]; |
---|
| 341 | struct groupchat *c = irc_chat_by_channel( irc, channel ); |
---|
| 342 | user_t *u = user_find( irc, nick ); |
---|
| 343 | |
---|
| 344 | if( u && c && ( u->ic == c->ic ) ) |
---|
| 345 | if( c->ic && c->ic->acc->prpl->chat_invite ) |
---|
| 346 | { |
---|
| 347 | c->ic->acc->prpl->chat_invite( c, u->handle, NULL ); |
---|
| 348 | irc_send_num( irc, 341, "%s %s", nick, channel ); |
---|
| 349 | return; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | irc_send_num( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel ); |
---|
[0298d11] | 353 | } |
---|
| 354 | |
---|
[f73b969] | 355 | static void irc_cmd_userhost( irc_t *irc, char **cmd ) |
---|
[0298d11] | 356 | { |
---|
| 357 | user_t *u; |
---|
| 358 | int i; |
---|
| 359 | |
---|
| 360 | /* [TV] Usable USERHOST-implementation according to |
---|
| 361 | RFC1459. Without this, mIRC shows an error |
---|
| 362 | while connecting, and the used way of rejecting |
---|
| 363 | breaks standards. |
---|
| 364 | */ |
---|
| 365 | |
---|
| 366 | for( i = 1; cmd[i]; i ++ ) |
---|
| 367 | if( ( u = user_find( irc, cmd[i] ) ) ) |
---|
| 368 | { |
---|
| 369 | if( u->online && u->away ) |
---|
[3ddb7477] | 370 | irc_send_num( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host ); |
---|
[0298d11] | 371 | else |
---|
[3ddb7477] | 372 | irc_send_num( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host ); |
---|
[0298d11] | 373 | } |
---|
| 374 | } |
---|
| 375 | |
---|
[f73b969] | 376 | static void irc_cmd_ison( irc_t *irc, char **cmd ) |
---|
[0298d11] | 377 | { |
---|
| 378 | user_t *u; |
---|
[b4e4b95] | 379 | char buff[IRC_MAX_LINE]; |
---|
[0298d11] | 380 | int lenleft, i; |
---|
| 381 | |
---|
| 382 | buff[0] = '\0'; |
---|
| 383 | |
---|
| 384 | /* [SH] Leave room for : and \0 */ |
---|
| 385 | lenleft = IRC_MAX_LINE - 2; |
---|
| 386 | |
---|
| 387 | for( i = 1; cmd[i]; i ++ ) |
---|
| 388 | { |
---|
[42616d1] | 389 | char *this, *next; |
---|
| 390 | |
---|
| 391 | this = cmd[i]; |
---|
| 392 | while( *this ) |
---|
[0298d11] | 393 | { |
---|
[42616d1] | 394 | if( ( next = strchr( this, ' ' ) ) ) |
---|
| 395 | *next = 0; |
---|
[0298d11] | 396 | |
---|
[42616d1] | 397 | if( ( u = user_find( irc, this ) ) && u->online ) |
---|
[0298d11] | 398 | { |
---|
[42616d1] | 399 | lenleft -= strlen( u->nick ) + 1; |
---|
| 400 | |
---|
| 401 | if( lenleft < 0 ) |
---|
| 402 | break; |
---|
| 403 | |
---|
| 404 | strcat( buff, u->nick ); |
---|
| 405 | strcat( buff, " " ); |
---|
[0298d11] | 406 | } |
---|
| 407 | |
---|
[42616d1] | 408 | if( next ) |
---|
| 409 | { |
---|
| 410 | *next = ' '; |
---|
| 411 | this = next + 1; |
---|
| 412 | } |
---|
| 413 | else |
---|
| 414 | { |
---|
| 415 | break; |
---|
| 416 | } |
---|
[0298d11] | 417 | } |
---|
[42616d1] | 418 | |
---|
| 419 | /* *sigh* */ |
---|
| 420 | if( lenleft < 0 ) |
---|
| 421 | break; |
---|
[0298d11] | 422 | } |
---|
| 423 | |
---|
| 424 | if( strlen( buff ) > 0 ) |
---|
| 425 | buff[strlen(buff)-1] = '\0'; |
---|
| 426 | |
---|
[3ddb7477] | 427 | irc_send_num( irc, 303, ":%s", buff ); |
---|
[0298d11] | 428 | } |
---|
| 429 | |
---|
[f73b969] | 430 | static void irc_cmd_watch( irc_t *irc, char **cmd ) |
---|
[0298d11] | 431 | { |
---|
| 432 | int i; |
---|
| 433 | |
---|
| 434 | /* Obviously we could also mark a user structure as being |
---|
| 435 | watched, but what if the WATCH command is sent right |
---|
| 436 | after connecting? The user won't exist yet then... */ |
---|
| 437 | for( i = 1; cmd[i]; i ++ ) |
---|
| 438 | { |
---|
| 439 | char *nick; |
---|
| 440 | user_t *u; |
---|
| 441 | |
---|
| 442 | if( !cmd[i][0] || !cmd[i][1] ) |
---|
| 443 | break; |
---|
| 444 | |
---|
| 445 | nick = g_strdup( cmd[i] + 1 ); |
---|
| 446 | nick_lc( nick ); |
---|
| 447 | |
---|
| 448 | u = user_find( irc, nick ); |
---|
| 449 | |
---|
| 450 | if( cmd[i][0] == '+' ) |
---|
| 451 | { |
---|
| 452 | if( !g_hash_table_lookup( irc->watches, nick ) ) |
---|
| 453 | g_hash_table_insert( irc->watches, nick, nick ); |
---|
| 454 | |
---|
| 455 | if( u && u->online ) |
---|
[3ddb7477] | 456 | irc_send_num( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" ); |
---|
[0298d11] | 457 | else |
---|
[3ddb7477] | 458 | irc_send_num( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" ); |
---|
[0298d11] | 459 | } |
---|
| 460 | else if( cmd[i][0] == '-' ) |
---|
| 461 | { |
---|
| 462 | gpointer okey, ovalue; |
---|
| 463 | |
---|
| 464 | if( g_hash_table_lookup_extended( irc->watches, nick, &okey, &ovalue ) ) |
---|
| 465 | { |
---|
| 466 | g_hash_table_remove( irc->watches, okey ); |
---|
[e59b4f6] | 467 | g_free( okey ); |
---|
[0298d11] | 468 | |
---|
[3ddb7477] | 469 | irc_send_num( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" ); |
---|
[0298d11] | 470 | } |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | |
---|
[f73b969] | 475 | static void irc_cmd_topic( irc_t *irc, char **cmd ) |
---|
[0298d11] | 476 | { |
---|
[50e1776] | 477 | char *channel = cmd[1]; |
---|
| 478 | char *topic = cmd[2]; |
---|
| 479 | |
---|
| 480 | if( topic ) |
---|
| 481 | { |
---|
| 482 | /* Send the topic */ |
---|
| 483 | struct groupchat *c = irc_chat_by_channel( irc, channel ); |
---|
| 484 | if( c && c->ic && c->ic->acc->prpl->chat_topic ) |
---|
| 485 | c->ic->acc->prpl->chat_topic( c, topic ); |
---|
| 486 | } |
---|
[0298d11] | 487 | else |
---|
[50e1776] | 488 | { |
---|
| 489 | /* Get the topic */ |
---|
| 490 | irc_topic( irc, channel ); |
---|
| 491 | } |
---|
[0298d11] | 492 | } |
---|
| 493 | |
---|
[f73b969] | 494 | static void irc_cmd_away( irc_t *irc, char **cmd ) |
---|
[0298d11] | 495 | { |
---|
| 496 | user_t *u = user_find( irc, irc->nick ); |
---|
| 497 | char *away = cmd[1]; |
---|
| 498 | |
---|
[f73b969] | 499 | if( !u ) return; |
---|
[0298d11] | 500 | |
---|
| 501 | if( away && *away ) |
---|
| 502 | { |
---|
| 503 | int i, j; |
---|
| 504 | |
---|
| 505 | /* Copy away string, but skip control chars. Mainly because |
---|
| 506 | Jabber really doesn't like them. */ |
---|
| 507 | u->away = g_malloc( strlen( away ) + 1 ); |
---|
| 508 | for( i = j = 0; away[i]; i ++ ) |
---|
| 509 | if( ( u->away[j] = away[i] ) >= ' ' ) |
---|
| 510 | j ++; |
---|
| 511 | u->away[j] = 0; |
---|
| 512 | |
---|
[3ddb7477] | 513 | irc_send_num( irc, 306, ":You're now away: %s", u->away ); |
---|
[0298d11] | 514 | /* irc_umode_set( irc, irc->myhost, "+a" ); */ |
---|
| 515 | } |
---|
| 516 | else |
---|
| 517 | { |
---|
| 518 | if( u->away ) g_free( u->away ); |
---|
| 519 | u->away = NULL; |
---|
| 520 | /* irc_umode_set( irc, irc->myhost, "-a" ); */ |
---|
[3ddb7477] | 521 | irc_send_num( irc, 305, ":Welcome back" ); |
---|
[0298d11] | 522 | } |
---|
| 523 | |
---|
[58adb7e] | 524 | set_setstr( &irc->set, "away", u->away ); |
---|
[0298d11] | 525 | } |
---|
| 526 | |
---|
[82898af] | 527 | static void irc_cmd_version( irc_t *irc, char **cmd ) |
---|
| 528 | { |
---|
[3ddb7477] | 529 | irc_send_num( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU ); |
---|
[82898af] | 530 | } |
---|
| 531 | |
---|
[f73b969] | 532 | static void irc_cmd_completions( irc_t *irc, char **cmd ) |
---|
[0298d11] | 533 | { |
---|
| 534 | user_t *u = user_find( irc, irc->mynick ); |
---|
| 535 | help_t *h; |
---|
| 536 | set_t *s; |
---|
| 537 | int i; |
---|
| 538 | |
---|
| 539 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" ); |
---|
| 540 | |
---|
| 541 | for( i = 0; commands[i].command; i ++ ) |
---|
| 542 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command ); |
---|
| 543 | |
---|
| 544 | for( h = global.help; h; h = h->next ) |
---|
[0fbda193] | 545 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title ); |
---|
[0298d11] | 546 | |
---|
| 547 | for( s = irc->set; s; s = s->next ) |
---|
| 548 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key ); |
---|
| 549 | |
---|
| 550 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" ); |
---|
| 551 | } |
---|
| 552 | |
---|
[f73b969] | 553 | static void irc_cmd_rehash( irc_t *irc, char **cmd ) |
---|
[f4a5940] | 554 | { |
---|
[5424c76] | 555 | if( global.conf->runmode == RUNMODE_INETD ) |
---|
| 556 | ipc_master_cmd_rehash( NULL, NULL ); |
---|
| 557 | else |
---|
| 558 | ipc_to_master( cmd ); |
---|
[f4a5940] | 559 | |
---|
[3ddb7477] | 560 | irc_send_num( irc, 382, "%s :Rehashing", global.conf_file ); |
---|
[f4a5940] | 561 | } |
---|
[3ddb7477] | 562 | #endif |
---|
[f4a5940] | 563 | |
---|
[0298d11] | 564 | static const command_t irc_commands[] = { |
---|
[a199d33] | 565 | { "pass", 1, irc_cmd_pass, 0 }, |
---|
[0298d11] | 566 | { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, |
---|
| 567 | { "nick", 1, irc_cmd_nick, 0 }, |
---|
| 568 | { "quit", 0, irc_cmd_quit, 0 }, |
---|
| 569 | { "ping", 0, irc_cmd_ping, 0 }, |
---|
[3923003] | 570 | { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN }, |
---|
[b9e020a] | 571 | { "join", 1, irc_cmd_join, IRC_CMD_LOGGED_IN }, |
---|
| 572 | { "names", 1, irc_cmd_names, IRC_CMD_LOGGED_IN }, |
---|
| 573 | { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN }, |
---|
[b95932e] | 574 | { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN }, |
---|
| 575 | { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN }, |
---|
[9b69eb7] | 576 | { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN }, |
---|
[b919363] | 577 | { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, |
---|
[2f53ada] | 578 | { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN }, |
---|
[280c56a] | 579 | { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
[d860a8d] | 580 | { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
| 581 | { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
[ebaebfe] | 582 | #if 0 |
---|
[0298d11] | 583 | { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, |
---|
| 584 | { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, |
---|
| 585 | { "notice", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
| 586 | { "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN }, |
---|
| 587 | { "ison", 1, irc_cmd_ison, IRC_CMD_LOGGED_IN }, |
---|
| 588 | { "watch", 1, irc_cmd_watch, IRC_CMD_LOGGED_IN }, |
---|
| 589 | { "topic", 1, irc_cmd_topic, IRC_CMD_LOGGED_IN }, |
---|
| 590 | { "away", 0, irc_cmd_away, IRC_CMD_LOGGED_IN }, |
---|
[82898af] | 591 | { "version", 0, irc_cmd_version, IRC_CMD_LOGGED_IN }, |
---|
[0298d11] | 592 | { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN }, |
---|
[0431ea1] | 593 | { "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[565a1ea] | 594 | { "deaf", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[48721c3] | 595 | { "wallops", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[dfc8a46] | 596 | { "wall", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[f4a5940] | 597 | { "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY }, |
---|
[54879ab] | 598 | { "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[48721c3] | 599 | { "kill", 2, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[3ddb7477] | 600 | #endif |
---|
[0298d11] | 601 | { NULL } |
---|
| 602 | }; |
---|
| 603 | |
---|
[f73b969] | 604 | void irc_exec( irc_t *irc, char *cmd[] ) |
---|
[0298d11] | 605 | { |
---|
[f1d38f2] | 606 | int i, n_arg; |
---|
[0298d11] | 607 | |
---|
| 608 | if( !cmd[0] ) |
---|
[f73b969] | 609 | return; |
---|
[0298d11] | 610 | |
---|
| 611 | for( i = 0; irc_commands[i].command; i++ ) |
---|
| 612 | if( g_strcasecmp( irc_commands[i].command, cmd[0] ) == 0 ) |
---|
| 613 | { |
---|
[f1d38f2] | 614 | /* There should be no typo in the next line: */ |
---|
| 615 | for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --; |
---|
| 616 | |
---|
[79e826a] | 617 | if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN ) |
---|
[edf9657] | 618 | { |
---|
[3ddb7477] | 619 | irc_send_num( irc, 462, ":Only allowed before logging in" ); |
---|
[edf9657] | 620 | } |
---|
[3af70b0] | 621 | else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) ) |
---|
[edf9657] | 622 | { |
---|
[3ddb7477] | 623 | irc_send_num( irc, 451, ":Register first" ); |
---|
[edf9657] | 624 | } |
---|
[f73b969] | 625 | else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) ) |
---|
[edf9657] | 626 | { |
---|
[3ddb7477] | 627 | irc_send_num( irc, 481, ":Permission denied - You're not an IRC operator" ); |
---|
[edf9657] | 628 | } |
---|
[f1d38f2] | 629 | else if( n_arg < irc_commands[i].required_parameters ) |
---|
[f73b969] | 630 | { |
---|
[3ddb7477] | 631 | irc_send_num( irc, 461, "%s :Need more parameters", cmd[0] ); |
---|
[f73b969] | 632 | } |
---|
| 633 | else if( irc_commands[i].flags & IRC_CMD_TO_MASTER ) |
---|
| 634 | { |
---|
[5424c76] | 635 | /* IPC doesn't make sense in inetd mode, |
---|
| 636 | but the function will catch that. */ |
---|
[0431ea1] | 637 | ipc_to_master( cmd ); |
---|
[f73b969] | 638 | } |
---|
[0431ea1] | 639 | else |
---|
[f73b969] | 640 | { |
---|
| 641 | irc_commands[i].execute( irc, cmd ); |
---|
| 642 | } |
---|
| 643 | |
---|
[2f13222] | 644 | return; |
---|
[0298d11] | 645 | } |
---|
[2f13222] | 646 | |
---|
| 647 | if( irc->status >= USTATUS_LOGGED_IN ) |
---|
[3ddb7477] | 648 | irc_send_num( irc, 421, "%s :Unknown command", cmd[0] ); |
---|
[0298d11] | 649 | } |
---|