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