[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 | { |
---|
| 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 | { |
---|
| 179 | irc_usermsg( irc, "Could not open a groupchat with %s, maybe you don't have a connection to him/her yet?", u->nick ); |
---|
| 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; |
---|
| 323 | char buff[IRC_MAX_LINE]; |
---|
| 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 | { |
---|
| 333 | if( ( u = user_find( irc, cmd[i] ) ) && u->online ) |
---|
| 334 | { |
---|
| 335 | /* [SH] Make sure we don't use too much buffer space. */ |
---|
| 336 | lenleft -= strlen( u->nick ) + 1; |
---|
| 337 | |
---|
| 338 | if( lenleft < 0 ) |
---|
| 339 | { |
---|
| 340 | break; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | /* [SH] Add the nick to the buffer. Note |
---|
| 344 | * that an extra space is always added. Even |
---|
| 345 | * if it's the last nick in the list. Who |
---|
| 346 | * cares? |
---|
| 347 | */ |
---|
| 348 | |
---|
| 349 | strcat( buff, u->nick ); |
---|
| 350 | strcat( buff, " " ); |
---|
| 351 | } |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | /* [WvG] Well, maybe someone cares, so why not remove it? */ |
---|
| 355 | if( strlen( buff ) > 0 ) |
---|
| 356 | buff[strlen(buff)-1] = '\0'; |
---|
| 357 | |
---|
| 358 | irc_reply( irc, 303, ":%s", buff ); |
---|
| 359 | } |
---|
| 360 | |
---|
[f73b969] | 361 | static void irc_cmd_watch( irc_t *irc, char **cmd ) |
---|
[0298d11] | 362 | { |
---|
| 363 | int i; |
---|
| 364 | |
---|
| 365 | /* Obviously we could also mark a user structure as being |
---|
| 366 | watched, but what if the WATCH command is sent right |
---|
| 367 | after connecting? The user won't exist yet then... */ |
---|
| 368 | for( i = 1; cmd[i]; i ++ ) |
---|
| 369 | { |
---|
| 370 | char *nick; |
---|
| 371 | user_t *u; |
---|
| 372 | |
---|
| 373 | if( !cmd[i][0] || !cmd[i][1] ) |
---|
| 374 | break; |
---|
| 375 | |
---|
| 376 | nick = g_strdup( cmd[i] + 1 ); |
---|
| 377 | nick_lc( nick ); |
---|
| 378 | |
---|
| 379 | u = user_find( irc, nick ); |
---|
| 380 | |
---|
| 381 | if( cmd[i][0] == '+' ) |
---|
| 382 | { |
---|
| 383 | if( !g_hash_table_lookup( irc->watches, nick ) ) |
---|
| 384 | g_hash_table_insert( irc->watches, nick, nick ); |
---|
| 385 | |
---|
| 386 | if( u && u->online ) |
---|
| 387 | irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, time( NULL ), "is online" ); |
---|
| 388 | else |
---|
| 389 | irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", time( NULL ), "is offline" ); |
---|
| 390 | } |
---|
| 391 | else if( cmd[i][0] == '-' ) |
---|
| 392 | { |
---|
| 393 | gpointer okey, ovalue; |
---|
| 394 | |
---|
| 395 | if( g_hash_table_lookup_extended( irc->watches, nick, &okey, &ovalue ) ) |
---|
| 396 | { |
---|
| 397 | g_free( okey ); |
---|
| 398 | g_hash_table_remove( irc->watches, okey ); |
---|
| 399 | |
---|
| 400 | irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" ); |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | |
---|
[f73b969] | 406 | static void irc_cmd_topic( irc_t *irc, char **cmd ) |
---|
[0298d11] | 407 | { |
---|
| 408 | if( cmd[2] ) |
---|
| 409 | irc_reply( irc, 482, "%s :Cannot change topic", cmd[1] ); |
---|
| 410 | else |
---|
| 411 | irc_topic( irc, cmd[1] ); |
---|
| 412 | } |
---|
| 413 | |
---|
[f73b969] | 414 | static void irc_cmd_away( irc_t *irc, char **cmd ) |
---|
[0298d11] | 415 | { |
---|
| 416 | user_t *u = user_find( irc, irc->nick ); |
---|
| 417 | GSList *c = get_connections(); |
---|
| 418 | char *away = cmd[1]; |
---|
| 419 | |
---|
[f73b969] | 420 | if( !u ) return; |
---|
[0298d11] | 421 | |
---|
| 422 | if( away && *away ) |
---|
| 423 | { |
---|
| 424 | int i, j; |
---|
| 425 | |
---|
| 426 | /* Copy away string, but skip control chars. Mainly because |
---|
| 427 | Jabber really doesn't like them. */ |
---|
| 428 | u->away = g_malloc( strlen( away ) + 1 ); |
---|
| 429 | for( i = j = 0; away[i]; i ++ ) |
---|
| 430 | if( ( u->away[j] = away[i] ) >= ' ' ) |
---|
| 431 | j ++; |
---|
| 432 | u->away[j] = 0; |
---|
| 433 | |
---|
| 434 | irc_reply( irc, 306, ":You're now away: %s", u->away ); |
---|
| 435 | /* irc_umode_set( irc, irc->myhost, "+a" ); */ |
---|
| 436 | } |
---|
| 437 | else |
---|
| 438 | { |
---|
| 439 | if( u->away ) g_free( u->away ); |
---|
| 440 | u->away = NULL; |
---|
| 441 | /* irc_umode_set( irc, irc->myhost, "-a" ); */ |
---|
| 442 | irc_reply( irc, 305, ":Welcome back" ); |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | while( c ) |
---|
| 446 | { |
---|
| 447 | if( ((struct gaim_connection *)c->data)->flags & OPT_LOGGED_IN ) |
---|
| 448 | proto_away( c->data, u->away ); |
---|
| 449 | |
---|
| 450 | c = c->next; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | |
---|
[f73b969] | 454 | static void irc_cmd_whois( irc_t *irc, char **cmd ) |
---|
[0298d11] | 455 | { |
---|
| 456 | char *nick = cmd[1]; |
---|
| 457 | user_t *u = user_find( irc, nick ); |
---|
| 458 | |
---|
| 459 | if( u ) |
---|
| 460 | { |
---|
| 461 | irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname ); |
---|
| 462 | |
---|
| 463 | if( u->gc ) |
---|
| 464 | irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->gc->user->username, |
---|
| 465 | *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", u->gc->prpl->name ); |
---|
| 466 | else |
---|
| 467 | irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO ); |
---|
| 468 | |
---|
| 469 | if( !u->online ) |
---|
| 470 | irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" ); |
---|
| 471 | else if( u->away ) |
---|
| 472 | irc_reply( irc, 301, "%s :%s", u->nick, u->away ); |
---|
| 473 | |
---|
| 474 | irc_reply( irc, 318, "%s :End of /WHOIS list", nick ); |
---|
| 475 | } |
---|
| 476 | else |
---|
| 477 | { |
---|
| 478 | irc_reply( irc, 401, "%s :Nick does not exist", nick ); |
---|
| 479 | } |
---|
| 480 | } |
---|
| 481 | |
---|
[f73b969] | 482 | static void irc_cmd_whowas( irc_t *irc, char **cmd ) |
---|
[0298d11] | 483 | { |
---|
| 484 | /* For some reason irssi tries a whowas when whois fails. We can |
---|
| 485 | ignore this, but then the user never gets a "user not found" |
---|
| 486 | message from irssi which is a bit annoying. So just respond |
---|
| 487 | with not-found and irssi users will get better error messages */ |
---|
| 488 | |
---|
| 489 | irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] ); |
---|
| 490 | irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] ); |
---|
| 491 | } |
---|
| 492 | |
---|
[f73b969] | 493 | static void irc_cmd_nickserv( irc_t *irc, char **cmd ) |
---|
[0298d11] | 494 | { |
---|
| 495 | /* [SH] This aliases the NickServ command to PRIVMSG root */ |
---|
| 496 | /* [TV] This aliases the NS command to PRIVMSG root as well */ |
---|
| 497 | root_command( irc, cmd + 1 ); |
---|
| 498 | } |
---|
| 499 | |
---|
[f73b969] | 500 | static void irc_cmd_motd( irc_t *irc, char **cmd ) |
---|
[0298d11] | 501 | { |
---|
| 502 | irc_motd( irc ); |
---|
| 503 | } |
---|
| 504 | |
---|
[f73b969] | 505 | static void irc_cmd_pong( irc_t *irc, char **cmd ) |
---|
[0298d11] | 506 | { |
---|
| 507 | /* We could check the value we get back from the user, but in |
---|
| 508 | fact we don't care, we're just happy he's still alive. */ |
---|
| 509 | irc->last_pong = gettime(); |
---|
| 510 | irc->pinging = 0; |
---|
| 511 | } |
---|
| 512 | |
---|
[f73b969] | 513 | static void irc_cmd_completions( irc_t *irc, char **cmd ) |
---|
[0298d11] | 514 | { |
---|
| 515 | user_t *u = user_find( irc, irc->mynick ); |
---|
| 516 | help_t *h; |
---|
| 517 | set_t *s; |
---|
| 518 | int i; |
---|
| 519 | |
---|
| 520 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" ); |
---|
| 521 | |
---|
| 522 | for( i = 0; commands[i].command; i ++ ) |
---|
| 523 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command ); |
---|
| 524 | |
---|
| 525 | for( h = global.help; h; h = h->next ) |
---|
| 526 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->string ); |
---|
| 527 | |
---|
| 528 | for( s = irc->set; s; s = s->next ) |
---|
| 529 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key ); |
---|
| 530 | |
---|
| 531 | irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" ); |
---|
| 532 | } |
---|
| 533 | |
---|
[f73b969] | 534 | static void irc_cmd_rehash( irc_t *irc, char **cmd ) |
---|
[f4a5940] | 535 | { |
---|
[5424c76] | 536 | if( global.conf->runmode == RUNMODE_INETD ) |
---|
| 537 | ipc_master_cmd_rehash( NULL, NULL ); |
---|
| 538 | else |
---|
| 539 | ipc_to_master( cmd ); |
---|
[f4a5940] | 540 | |
---|
| 541 | irc_reply( irc, 382, "%s :Rehashing", CONF_FILE ); |
---|
| 542 | } |
---|
| 543 | |
---|
[0298d11] | 544 | static const command_t irc_commands[] = { |
---|
| 545 | { "pass", 1, irc_cmd_pass, IRC_CMD_PRE_LOGIN }, |
---|
| 546 | { "user", 4, irc_cmd_user, IRC_CMD_PRE_LOGIN }, |
---|
| 547 | { "nick", 1, irc_cmd_nick, 0 }, |
---|
| 548 | { "quit", 0, irc_cmd_quit, 0 }, |
---|
| 549 | { "ping", 0, irc_cmd_ping, 0 }, |
---|
| 550 | { "oper", 2, irc_cmd_oper, IRC_CMD_LOGGED_IN }, |
---|
| 551 | { "mode", 1, irc_cmd_mode, IRC_CMD_LOGGED_IN }, |
---|
| 552 | { "names", 0, irc_cmd_names, IRC_CMD_LOGGED_IN }, |
---|
| 553 | { "part", 1, irc_cmd_part, IRC_CMD_LOGGED_IN }, |
---|
| 554 | { "join", 1, irc_cmd_join, IRC_CMD_LOGGED_IN }, |
---|
| 555 | { "invite", 2, irc_cmd_invite, IRC_CMD_LOGGED_IN }, |
---|
| 556 | { "privmsg", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
| 557 | { "notice", 1, irc_cmd_privmsg, IRC_CMD_LOGGED_IN }, |
---|
| 558 | { "who", 0, irc_cmd_who, IRC_CMD_LOGGED_IN }, |
---|
| 559 | { "userhost", 1, irc_cmd_userhost, IRC_CMD_LOGGED_IN }, |
---|
| 560 | { "ison", 1, irc_cmd_ison, IRC_CMD_LOGGED_IN }, |
---|
| 561 | { "watch", 1, irc_cmd_watch, IRC_CMD_LOGGED_IN }, |
---|
| 562 | { "topic", 1, irc_cmd_topic, IRC_CMD_LOGGED_IN }, |
---|
| 563 | { "away", 0, irc_cmd_away, IRC_CMD_LOGGED_IN }, |
---|
| 564 | { "whois", 1, irc_cmd_whois, IRC_CMD_LOGGED_IN }, |
---|
| 565 | { "whowas", 1, irc_cmd_whowas, IRC_CMD_LOGGED_IN }, |
---|
| 566 | { "nickserv", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
| 567 | { "ns", 1, irc_cmd_nickserv, IRC_CMD_LOGGED_IN }, |
---|
| 568 | { "motd", 0, irc_cmd_motd, IRC_CMD_LOGGED_IN }, |
---|
| 569 | { "pong", 0, irc_cmd_pong, IRC_CMD_LOGGED_IN }, |
---|
| 570 | { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN }, |
---|
[0431ea1] | 571 | { "die", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[48721c3] | 572 | { "wallops", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
| 573 | { "lilo", 1, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[f4a5940] | 574 | { "rehash", 0, irc_cmd_rehash, IRC_CMD_OPER_ONLY }, |
---|
[54879ab] | 575 | { "restart", 0, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[48721c3] | 576 | { "kill", 2, NULL, IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER }, |
---|
[0298d11] | 577 | { NULL } |
---|
| 578 | }; |
---|
| 579 | |
---|
[f73b969] | 580 | void irc_exec( irc_t *irc, char *cmd[] ) |
---|
[0298d11] | 581 | { |
---|
[f1d38f2] | 582 | int i, n_arg; |
---|
[0298d11] | 583 | |
---|
| 584 | if( !cmd[0] ) |
---|
[f73b969] | 585 | return; |
---|
[0298d11] | 586 | |
---|
| 587 | for( i = 0; irc_commands[i].command; i++ ) |
---|
| 588 | if( g_strcasecmp( irc_commands[i].command, cmd[0] ) == 0 ) |
---|
| 589 | { |
---|
[f1d38f2] | 590 | /* There should be no typo in the next line: */ |
---|
| 591 | for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --; |
---|
| 592 | |
---|
[edf9657] | 593 | if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN ) |
---|
| 594 | { |
---|
| 595 | irc_reply( irc, 462, ":Only allowed before logging in" ); |
---|
| 596 | } |
---|
[f73b969] | 597 | else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN ) |
---|
[edf9657] | 598 | { |
---|
| 599 | irc_reply( irc, 451, ":Register first" ); |
---|
| 600 | } |
---|
[f73b969] | 601 | else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) ) |
---|
[edf9657] | 602 | { |
---|
| 603 | irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" ); |
---|
| 604 | } |
---|
[f1d38f2] | 605 | else if( n_arg < irc_commands[i].required_parameters ) |
---|
[f73b969] | 606 | { |
---|
| 607 | irc_reply( irc, 461, "%s :Need more parameters", cmd[0] ); |
---|
| 608 | } |
---|
| 609 | else if( irc_commands[i].flags & IRC_CMD_TO_MASTER ) |
---|
| 610 | { |
---|
[5424c76] | 611 | /* IPC doesn't make sense in inetd mode, |
---|
| 612 | but the function will catch that. */ |
---|
[0431ea1] | 613 | ipc_to_master( cmd ); |
---|
[f73b969] | 614 | } |
---|
[0431ea1] | 615 | else |
---|
[f73b969] | 616 | { |
---|
| 617 | irc_commands[i].execute( irc, cmd ); |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | break; |
---|
[0298d11] | 621 | } |
---|
| 622 | } |
---|