[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 | /* TODO: Attach this one to NOTICE too! */ |
---|
| 236 | static int irc_cmd_privmsg( irc_t *irc, char **cmd ) |
---|
| 237 | { |
---|
| 238 | if ( !cmd[2] ) |
---|
| 239 | { |
---|
| 240 | irc_reply( irc, 412, ":No text to send" ); |
---|
| 241 | } |
---|
| 242 | else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 ) |
---|
| 243 | { |
---|
| 244 | irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] ); |
---|
| 245 | } |
---|
| 246 | else |
---|
| 247 | { |
---|
| 248 | if( g_strcasecmp( cmd[1], irc->channel ) == 0 ) |
---|
| 249 | { |
---|
| 250 | unsigned int i; |
---|
| 251 | char *t = set_getstr( irc, "default_target" ); |
---|
| 252 | |
---|
| 253 | if( g_strcasecmp( t, "last" ) == 0 && irc->last_target ) |
---|
| 254 | cmd[1] = irc->last_target; |
---|
| 255 | else if( g_strcasecmp( t, "root" ) == 0 ) |
---|
| 256 | cmd[1] = irc->mynick; |
---|
| 257 | |
---|
| 258 | for( i = 0; i < strlen( cmd[2] ); i ++ ) |
---|
| 259 | { |
---|
| 260 | if( cmd[2][i] == ' ' ) break; |
---|
| 261 | if( cmd[2][i] == ':' || cmd[2][i] == ',' ) |
---|
| 262 | { |
---|
| 263 | cmd[1] = cmd[2]; |
---|
| 264 | cmd[2] += i; |
---|
| 265 | *cmd[2] = 0; |
---|
| 266 | while( *(++cmd[2]) == ' ' ); |
---|
| 267 | break; |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | irc->is_private = 0; |
---|
| 272 | |
---|
| 273 | if( cmd[1] != irc->last_target ) |
---|
| 274 | { |
---|
| 275 | if( irc->last_target ) |
---|
| 276 | g_free( irc->last_target ); |
---|
| 277 | irc->last_target = g_strdup( cmd[1] ); |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | else |
---|
| 281 | { |
---|
| 282 | irc->is_private = 1; |
---|
| 283 | } |
---|
| 284 | irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? IM_FLAG_AWAY : 0 ); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | return( 1 ); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | static int irc_cmd_who( irc_t *irc, char **cmd ) |
---|
| 291 | { |
---|
| 292 | char *channel = cmd[1]; |
---|
| 293 | user_t *u = irc->users; |
---|
| 294 | struct conversation *c; |
---|
| 295 | GList *l; |
---|
| 296 | |
---|
| 297 | if( !channel || *channel == '0' || *channel == '*' || !*channel ) |
---|
| 298 | while( u ) |
---|
| 299 | { |
---|
| 300 | 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 ); |
---|
| 301 | u = u->next; |
---|
| 302 | } |
---|
| 303 | else if( g_strcasecmp( channel, irc->channel ) == 0 ) |
---|
| 304 | while( u ) |
---|
| 305 | { |
---|
| 306 | if( u->online ) |
---|
| 307 | 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 ); |
---|
| 308 | u = u->next; |
---|
| 309 | } |
---|
| 310 | else if( ( c = conv_findchannel( channel ) ) ) |
---|
| 311 | for( l = c->in_room; l; l = l->next ) |
---|
| 312 | { |
---|
| 313 | if( ( u = user_findhandle( c->gc, l->data ) ) ) |
---|
| 314 | 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 ); |
---|
| 315 | } |
---|
| 316 | else if( ( u = user_find( irc, channel ) ) ) |
---|
| 317 | 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 ); |
---|
| 318 | |
---|
[b23c5c7] | 319 | irc_reply( irc, 315, "%s :End of /WHO list", channel?channel:"**" ); |
---|
[0298d11] | 320 | |
---|
| 321 | return( 1 ); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | static int irc_cmd_userhost( irc_t *irc, char **cmd ) |
---|
| 325 | { |
---|
| 326 | user_t *u; |
---|
| 327 | int i; |
---|
| 328 | |
---|
| 329 | /* [TV] Usable USERHOST-implementation according to |
---|
| 330 | RFC1459. Without this, mIRC shows an error |
---|
| 331 | while connecting, and the used way of rejecting |
---|
| 332 | breaks standards. |
---|
| 333 | */ |
---|
| 334 | |
---|
| 335 | for( i = 1; cmd[i]; i ++ ) |
---|
| 336 | if( ( u = user_find( irc, cmd[i] ) ) ) |
---|
| 337 | { |
---|
| 338 | if( u->online && u->away ) |
---|
| 339 | irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host ); |
---|
| 340 | else |
---|
| 341 | irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host ); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | return( 1 ); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | static int irc_cmd_ison( irc_t *irc, char **cmd ) |
---|
| 348 | { |
---|
| 349 | user_t *u; |
---|
| 350 | char buff[IRC_MAX_LINE]; |
---|
| 351 | int lenleft, i; |
---|
| 352 | |
---|
| 353 | buff[0] = '\0'; |
---|
| 354 | |
---|
| 355 | /* [SH] Leave room for : and \0 */ |
---|
| 356 | lenleft = IRC_MAX_LINE - 2; |
---|
| 357 | |
---|
| 358 | for( i = 1; cmd[i]; i ++ ) |
---|
| 359 | { |
---|
| 360 | if( ( u = user_find( irc, cmd[i] ) ) && u->online ) |
---|
| 361 | { |
---|
| 362 | /* [SH] Make sure we don't use too much buffer space. */ |
---|
| 363 | lenleft -= strlen( u->nick ) + 1; |
---|
| 364 | |
---|
| 365 | if( lenleft < 0 ) |
---|
| 366 | { |
---|
| 367 | break; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | /* [SH] Add the nick to the buffer. Note |
---|
| 371 | * that an extra space is always added. Even |
---|
| 372 | * if it's the last nick in the list. Who |
---|
| 373 | * cares? |
---|
| 374 | */ |
---|
| 375 | |
---|
| 376 | strcat( buff, u->nick ); |
---|
| 377 | strcat( buff, " " ); |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | /* [WvG] Well, maybe someone cares, so why not remove it? */ |
---|
| 382 | if( strlen( buff ) > 0 ) |
---|
| 383 | buff[strlen(buff)-1] = '\0'; |
---|
| 384 | |
---|
| 385 | irc_reply( irc, 303, ":%s", buff ); |
---|
| 386 | |
---|
| 387 | return( 1 ); |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | static int irc_cmd_watch( irc_t *irc, char **cmd ) |
---|
| 391 | { |
---|
| 392 | int i; |
---|
| 393 | |
---|
| 394 | /* Obviously we could also mark a user structure as being |
---|
| 395 | watched, but what if the WATCH command is sent right |
---|
| 396 | after connecting? The user won't exist yet then... */ |
---|
| 397 | for( i = 1; cmd[i]; i ++ ) |
---|
| 398 | { |
---|
| 399 | char *nick; |
---|
| 400 | user_t *u; |
---|
| 401 | |
---|
| 402 | if( !cmd[i][0] || !cmd[i][1] ) |
---|
| 403 | break; |
---|
| 404 | |
---|
| 405 | nick = g_strdup( cmd[i] + 1 ); |
---|
| 406 | nick_lc( nick ); |
---|
| 407 | |
---|
| 408 | u = user_find( irc, nick ); |
---|
| 409 | |
---|
| 410 | if( cmd[i][0] == '+' ) |
---|
| 411 | { |
---|
| 412 | if( !g_hash_table_lookup( irc->watches, nick ) ) |
---|
| 413 | g_hash_table_insert( irc->watches, nick, nick ); |
---|
| 414 | |
---|
| 415 | if( u && u->online ) |
---|
| 416 | irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, time( NULL ), "is online" ); |
---|
| 417 | else |
---|
| 418 | irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", time( NULL ), "is offline" ); |
---|
| 419 | } |
---|
| 420 | else if( cmd[i][0] == '-' ) |
---|
| 421 | { |
---|
| 422 | gpointer okey, ovalue; |
---|
| 423 | |
---|
| 424 | if( g_hash_table_lookup_extended( irc->watches, nick, &okey, &ovalue ) ) |
---|
| 425 | { |
---|
| 426 | g_free( okey ); |
---|
| 427 | g_hash_table_remove( irc->watches, okey ); |
---|
| 428 | |
---|
| 429 | irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" ); |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | return( 1 ); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | static int irc_cmd_topic( irc_t *irc, char **cmd ) |
---|
| 438 | { |
---|
| 439 | if( cmd[2] ) |
---|
| 440 | irc_reply( irc, 482, "%s :Cannot change topic", cmd[1] ); |
---|
| 441 | else |
---|
| 442 | irc_topic( irc, cmd[1] ); |
---|
| 443 | |
---|
| 444 | return( 1 ); |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | static int irc_cmd_away( irc_t *irc, char **cmd ) |
---|
| 448 | { |
---|
| 449 | user_t *u = user_find( irc, irc->nick ); |
---|
| 450 | GSList *c = get_connections(); |
---|
| 451 | char *away = cmd[1]; |
---|
| 452 | |
---|
| 453 | if( !u ) return( 1 ); |
---|
| 454 | |
---|
| 455 | if( away && *away ) |
---|
| 456 | { |
---|
| 457 | int i, j; |
---|
| 458 | |
---|
| 459 | /* Copy away string, but skip control chars. Mainly because |
---|
| 460 | Jabber really doesn't like them. */ |
---|
| 461 | u->away = g_malloc( strlen( away ) + 1 ); |
---|
| 462 | for( i = j = 0; away[i]; i ++ ) |
---|
| 463 | if( ( u->away[j] = away[i] ) >= ' ' ) |
---|
| 464 | j ++; |
---|
| 465 | u->away[j] = 0; |
---|
| 466 | |
---|
| 467 | irc_reply( irc, 306, ":You're now away: %s", u->away ); |
---|
| 468 | /* irc_umode_set( irc, irc->myhost, "+a" ); */ |
---|
| 469 | } |
---|
| 470 | else |
---|
| 471 | { |
---|
| 472 | if( u->away ) g_free( u->away ); |
---|
| 473 | u->away = NULL; |
---|
| 474 | /* irc_umode_set( irc, irc->myhost, "-a" ); */ |
---|
| 475 | irc_reply( irc, 305, ":Welcome back" ); |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | while( c ) |
---|
| 479 | { |
---|
| 480 | if( ((struct gaim_connection *)c->data)->flags & OPT_LOGGED_IN ) |
---|
| 481 | proto_away( c->data, u->away ); |
---|
| 482 | |
---|
| 483 | c = c->next; |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | return( 1 ); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | static int irc_cmd_whois( irc_t *irc, char **cmd ) |
---|
| 490 | { |
---|
| 491 | char *nick = cmd[1]; |
---|
| 492 | user_t *u = user_find( irc, nick ); |
---|
| 493 | |
---|
| 494 | if( u ) |
---|
| 495 | { |
---|
| 496 | irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname ); |
---|
| 497 | |
---|
| 498 | if( u->gc ) |
---|
| 499 | irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->gc->user->username, |
---|
| 500 | *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", u->gc->prpl->name ); |
---|
| 501 | else |
---|
| 502 | irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO ); |
---|
| 503 | |
---|
| 504 | if( !u->online ) |
---|
| 505 | irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" ); |
---|
| 506 | else if( u->away ) |
---|
| 507 | irc_reply( irc, 301, "%s :%s", u->nick, u->away ); |
---|
| 508 | |
---|
| 509 | irc_reply( irc, 318, "%s :End of /WHOIS list", nick ); |
---|
| 510 | } |
---|
| 511 | else |
---|
| 512 | { |
---|
| 513 | irc_reply( irc, 401, "%s :Nick does not exist", nick ); |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | return( 1 ); |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | static int irc_cmd_whowas( irc_t *irc, char **cmd ) |
---|
| 520 | { |
---|
| 521 | /* For some reason irssi tries a whowas when whois fails. We can |
---|
| 522 | ignore this, but then the user never gets a "user not found" |
---|
| 523 | message from irssi which is a bit annoying. So just respond |
---|
| 524 | with not-found and irssi users will get better error messages */ |
---|
| 525 | |
---|
| 526 | irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] ); |
---|
| 527 | irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] ); |
---|
| 528 | |
---|
| 529 | return( 1 ); |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | /* TODO: Alias to NS */ |
---|
| 533 | static int irc_cmd_nickserv( irc_t *irc, char **cmd ) |
---|
| 534 | { |
---|
| 535 | /* [SH] This aliases the NickServ command to PRIVMSG root */ |
---|
| 536 | /* [TV] This aliases the NS command to PRIVMSG root as well */ |
---|
| 537 | root_command( irc, cmd + 1 ); |
---|
| 538 | |
---|
| 539 | return( 1 ); |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | static int irc_cmd_motd( irc_t *irc, char **cmd ) |
---|
| 543 | { |
---|
| 544 | irc_motd( irc ); |
---|
| 545 | |
---|
| 546 | return( 1 ); |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | static int irc_cmd_pong( irc_t *irc, char **cmd ) |
---|
| 550 | { |
---|
| 551 | /* We could check the value we get back from the user, but in |
---|
| 552 | fact we don't care, we're just happy he's still alive. */ |
---|
| 553 | irc->last_pong = gettime(); |
---|
| 554 | irc->pinging = 0; |
---|
| 555 | |
---|
| 556 | return( 1 ); |
---|
| 557 | } |
---|
| 558 | |
---|
| 559 | static int irc_cmd_completions( irc_t *irc, char **cmd ) |
---|
| 560 | { |
---|
| 561 | user_t *u = user_find( irc, irc->mynick ); |
---|
| 562 | help_t *h; |
---|
| 563 | set_t *s; |
---|
| 564 | int i; |
---|
| 565 | |
---|
| 566 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" ); |
---|
| 567 | |
---|
| 568 | for( i = 0; commands[i].command; i ++ ) |
---|
| 569 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command ); |
---|
| 570 | |
---|
| 571 | for( h = global.help; h; h = h->next ) |
---|
| 572 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->string ); |
---|
| 573 | |
---|
| 574 | for( s = irc->set; s; s = s->next ) |
---|
| 575 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key ); |
---|
| 576 | |
---|
| 577 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" ); |
---|
| 578 | |
---|
| 579 | return( 1 ); |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | static const command_t irc_commands[] = { |
---|
| 583 | { "pass", 1, irc_cmd_pass, IRC_CMD_PRE_LOGIN }, |
---|
| 584 | { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, |
---|
| 585 | { "nick", 1, irc_cmd_nick, 0 }, |
---|
| 586 | { "quit", 0, irc_cmd_quit, 0 }, |
---|
| 587 | { "ping", 0, irc_cmd_ping, 0 }, |
---|
| 588 | { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, |
---|
| 589 | { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, |
---|
| 590 | { "names", 0, irc_cmd_names, IRC_CMD_LOGGED_IN }, |
---|
| 591 | { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN }, |
---|
| 592 | { "join", 1, irc_cmd_join, IRC_CMD_LOGGED_IN }, |
---|
| 593 | { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, |
---|
| 594 | { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
| 595 | { "notice", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
| 596 | { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN }, |
---|
| 597 | { "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN }, |
---|
| 598 | { "ison", 1, irc_cmd_ison, IRC_CMD_LOGGED_IN }, |
---|
| 599 | { "watch", 1, irc_cmd_watch, IRC_CMD_LOGGED_IN }, |
---|
| 600 | { "topic", 1, irc_cmd_topic, IRC_CMD_LOGGED_IN }, |
---|
| 601 | { "away", 0, irc_cmd_away, IRC_CMD_LOGGED_IN }, |
---|
| 602 | { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN }, |
---|
| 603 | { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN }, |
---|
| 604 | { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
| 605 | { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
| 606 | { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN }, |
---|
| 607 | { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN }, |
---|
| 608 | { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN }, |
---|
[0431ea1] | 609 | { "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
| 610 | { "wallop", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[0298d11] | 611 | { NULL } |
---|
| 612 | }; |
---|
| 613 | |
---|
| 614 | int irc_exec( irc_t *irc, char *cmd[] ) |
---|
| 615 | { |
---|
| 616 | int i, j; |
---|
| 617 | |
---|
| 618 | if( !cmd[0] ) |
---|
| 619 | return( 1 ); |
---|
| 620 | |
---|
| 621 | for( i = 0; irc_commands[i].command; i++ ) |
---|
| 622 | if( g_strcasecmp( irc_commands[i].command, cmd[0] ) == 0 ) |
---|
| 623 | { |
---|
[edf9657] | 624 | if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN ) |
---|
| 625 | { |
---|
| 626 | irc_reply( irc, 462, ":Only allowed before logging in" ); |
---|
| 627 | return( 1 ); |
---|
| 628 | } |
---|
[0298d11] | 629 | if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN ) |
---|
[edf9657] | 630 | { |
---|
| 631 | irc_reply( irc, 451, ":Register first" ); |
---|
| 632 | return( 1 ); |
---|
| 633 | } |
---|
[0298d11] | 634 | if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) ) |
---|
[edf9657] | 635 | { |
---|
| 636 | irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" ); |
---|
| 637 | return( 1 ); |
---|
| 638 | } |
---|
[0298d11] | 639 | |
---|
| 640 | for( j = 1; j <= irc_commands[i].required_parameters; j ++ ) |
---|
| 641 | if( !cmd[j] ) |
---|
| 642 | { |
---|
| 643 | irc_reply( irc, 461, "%s :Need more parameters", cmd[0] ); |
---|
| 644 | return( 1 ); |
---|
| 645 | } |
---|
| 646 | |
---|
[0431ea1] | 647 | if( irc_commands[i].flags & IRC_CMD_TO_MASTER ) |
---|
| 648 | ipc_to_master( cmd ); |
---|
| 649 | else |
---|
| 650 | return irc_commands[i].execute( irc, cmd ); |
---|
[0298d11] | 651 | } |
---|
| 652 | |
---|
| 653 | return( 1 ); |
---|
| 654 | } |
---|