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