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