2001-12-14 09:13:43 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2002-01-02 03:44:36 +01:00
|
|
|
* Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
|
2001-12-14 09:13:43 +01:00
|
|
|
*
|
|
|
|
* Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
|
|
|
|
* der GNU General Public License (GPL), wie von der Free Software Foundation
|
|
|
|
* herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
|
|
|
|
* der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
|
|
|
|
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
2001-12-31 03:18:51 +01:00
|
|
|
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
|
2001-12-14 09:13:43 +01:00
|
|
|
*
|
2002-10-09 15:33:19 +02:00
|
|
|
* $Id: irc.c,v 1.97 2002/10/09 13:33:19 alex Exp $
|
2001-12-14 09:13:43 +01:00
|
|
|
*
|
|
|
|
* irc.c: IRC-Befehle
|
2002-02-28 00:26:36 +01:00
|
|
|
*/
|
2001-12-26 04:21:46 +01:00
|
|
|
|
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "portab.h"
|
2002-02-11 16:15:53 +01:00
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "imp.h"
|
2002-02-28 00:26:36 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2001-12-26 04:21:46 +01:00
|
|
|
|
2002-02-28 00:26:36 +01:00
|
|
|
#include "ngircd.h"
|
2002-05-27 15:09:26 +02:00
|
|
|
#include "conn.h"
|
2002-02-28 00:26:36 +01:00
|
|
|
#include "client.h"
|
2002-05-27 15:09:26 +02:00
|
|
|
#include "channel.h"
|
|
|
|
#include "resolve.h"
|
2002-02-28 00:26:36 +01:00
|
|
|
#include "conf.h"
|
|
|
|
#include "conn.h"
|
|
|
|
#include "irc-write.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "messages.h"
|
2002-05-27 15:09:26 +02:00
|
|
|
#include "parse.h"
|
2002-02-28 00:26:36 +01:00
|
|
|
#include "tool.h"
|
2002-02-11 02:03:20 +01:00
|
|
|
|
2002-03-12 15:37:51 +01:00
|
|
|
#include "exp.h"
|
2002-02-28 00:26:36 +01:00
|
|
|
#include "irc.h"
|
2001-12-26 04:21:46 +01:00
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_MOTD( CLIENT *Client, REQUEST *Req )
|
2001-12-25 20:19:30 +01:00
|
|
|
{
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-04 18:58:44 +01:00
|
|
|
if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2001-12-25 20:19:30 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
2002-01-04 18:58:44 +01:00
|
|
|
if( Req->argc != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2001-12-26 00:13:33 +01:00
|
|
|
|
2002-02-28 00:26:36 +01:00
|
|
|
return IRC_Show_MOTD( Client );
|
2001-12-25 20:19:30 +01:00
|
|
|
} /* IRC_MOTD */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_PRIVMSG( CLIENT *Client, REQUEST *Req )
|
2001-12-27 20:17:26 +01:00
|
|
|
{
|
2002-02-27 18:05:41 +01:00
|
|
|
CLIENT *cl, *from;
|
2002-01-26 19:43:11 +01:00
|
|
|
CHANNEL *chan;
|
2001-12-27 20:17:26 +01:00
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-05 20:15:03 +01:00
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2001-12-27 20:17:26 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
2002-01-04 18:58:44 +01:00
|
|
|
if( Req->argc == 0 ) return IRC_WriteStrClient( Client, ERR_NORECIPIENT_MSG, Client_ID( Client ), Req->command );
|
|
|
|
if( Req->argc == 1 ) return IRC_WriteStrClient( Client, ERR_NOTEXTTOSEND_MSG, Client_ID( Client ));
|
|
|
|
if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2001-12-27 20:17:26 +01:00
|
|
|
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
|
2002-01-05 20:15:03 +01:00
|
|
|
else from = Client;
|
2002-01-12 00:50:55 +01:00
|
|
|
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
2002-02-27 18:05:41 +01:00
|
|
|
cl = Client_Search( Req->argv[0] );
|
|
|
|
if( cl )
|
2001-12-27 20:17:26 +01:00
|
|
|
{
|
2002-06-10 23:08:45 +02:00
|
|
|
/* Okay, Ziel ist ein Client. Aber ist es auch ein User? */
|
|
|
|
if( Client_Type( cl ) != CLIENT_USER ) return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
|
|
|
|
|
2001-12-27 20:17:26 +01:00
|
|
|
/* Okay, Ziel ist ein User */
|
2002-02-27 19:57:21 +01:00
|
|
|
if(( Client_Type( Client ) != CLIENT_SERVER ) && ( strchr( Client_Modes( cl ), 'a' )))
|
|
|
|
{
|
|
|
|
/* Ziel-User ist AWAY: Meldung verschicken */
|
|
|
|
if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( cl ), Client_Away( cl ))) return DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Text senden */
|
2002-01-26 19:43:11 +01:00
|
|
|
if( Client_Conn( from ) > NONE ) Conn_UpdateIdle( Client_Conn( from ));
|
2002-02-27 18:05:41 +01:00
|
|
|
return IRC_WriteStrClientPrefix( cl, from, "PRIVMSG %s :%s", Client_ID( cl ), Req->argv[1] );
|
2001-12-27 20:17:26 +01:00
|
|
|
}
|
2002-01-26 19:43:11 +01:00
|
|
|
|
|
|
|
chan = Channel_Search( Req->argv[0] );
|
2002-03-25 18:04:02 +01:00
|
|
|
if( chan ) return Channel_Write( chan, from, Client, Req->argv[1] );
|
2002-01-26 19:43:11 +01:00
|
|
|
|
|
|
|
return IRC_WriteStrClient( from, ERR_NOSUCHNICK_MSG, Client_ID( from ), Req->argv[0] );
|
2001-12-27 20:17:26 +01:00
|
|
|
} /* IRC_PRIVMSG */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_NOTICE( CLIENT *Client, REQUEST *Req )
|
2001-12-27 20:17:26 +01:00
|
|
|
{
|
2002-01-05 20:15:03 +01:00
|
|
|
CLIENT *to, *from;
|
2001-12-27 20:17:26 +01:00
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-10-09 15:33:19 +02:00
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return;
|
2001-12-27 20:17:26 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if( Req->argc != 2 ) return CONNECTED;
|
|
|
|
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
|
2002-01-05 20:15:03 +01:00
|
|
|
else from = Client;
|
2002-01-12 00:50:55 +01:00
|
|
|
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
2002-01-05 20:15:03 +01:00
|
|
|
|
2001-12-27 20:17:26 +01:00
|
|
|
to = Client_Search( Req->argv[0] );
|
2002-06-11 15:58:43 +02:00
|
|
|
if(( to ) && ( Client_Type( to ) == CLIENT_USER ))
|
2001-12-27 20:17:26 +01:00
|
|
|
{
|
|
|
|
/* Okay, Ziel ist ein User */
|
2002-01-05 20:15:03 +01:00
|
|
|
return IRC_WriteStrClientPrefix( to, from, "NOTICE %s :%s", Client_ID( to ), Req->argv[1] );
|
2001-12-27 20:17:26 +01:00
|
|
|
}
|
2002-01-05 20:15:03 +01:00
|
|
|
else return CONNECTED;
|
2001-12-27 20:17:26 +01:00
|
|
|
} /* IRC_NOTICE */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_NAMES( CLIENT *Client, REQUEST *Req )
|
2001-12-31 16:33:13 +01:00
|
|
|
{
|
2002-02-27 01:50:05 +01:00
|
|
|
CHAR rpl[COMMAND_LEN], *ptr;
|
|
|
|
CLIENT *target, *from, *c;
|
|
|
|
CHANNEL *chan;
|
2001-12-31 16:33:13 +01:00
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-02-27 01:50:05 +01:00
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2001-12-31 16:33:13 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
2002-02-27 01:50:05 +01:00
|
|
|
if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
|
|
|
|
|
|
|
/* From aus Prefix ermitteln */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
|
2002-02-27 01:50:05 +01:00
|
|
|
else from = Client;
|
|
|
|
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
|
|
|
if( Req->argc == 2 )
|
|
|
|
{
|
|
|
|
/* an anderen Server forwarden */
|
2002-03-25 18:04:02 +01:00
|
|
|
target = Client_Search( Req->argv[1] );
|
2002-02-27 01:50:05 +01:00
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
|
|
|
|
|
|
|
|
if( target != Client_ThisServer( ))
|
|
|
|
{
|
|
|
|
/* Ok, anderer Server ist das Ziel: forwarden */
|
|
|
|
return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Req->argc > 0 )
|
|
|
|
{
|
|
|
|
/* bestimmte Channels durchgehen */
|
|
|
|
ptr = strtok( Req->argv[0], "," );
|
|
|
|
while( ptr )
|
|
|
|
{
|
|
|
|
chan = Channel_Search( ptr );
|
|
|
|
if( chan )
|
|
|
|
{
|
|
|
|
/* Namen ausgeben */
|
2002-02-28 00:26:36 +01:00
|
|
|
if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
|
2002-02-27 01:50:05 +01:00
|
|
|
}
|
|
|
|
if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED;
|
|
|
|
|
|
|
|
/* naechsten Namen ermitteln */
|
|
|
|
ptr = strtok( NULL, "," );
|
|
|
|
}
|
|
|
|
return CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* alle Channels durchgehen */
|
|
|
|
chan = Channel_First( );
|
|
|
|
while( chan )
|
|
|
|
{
|
|
|
|
/* Namen ausgeben */
|
2002-02-28 00:26:36 +01:00
|
|
|
if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED;
|
2002-02-27 01:50:05 +01:00
|
|
|
|
|
|
|
/* naechster Channel */
|
|
|
|
chan = Channel_Next( chan );
|
|
|
|
}
|
2001-12-31 16:33:13 +01:00
|
|
|
|
2002-02-27 16:23:27 +01:00
|
|
|
/* Nun noch alle Clients ausgeben, die in keinem Channel sind */
|
2001-12-31 16:33:13 +01:00
|
|
|
c = Client_First( );
|
2002-02-27 01:50:05 +01:00
|
|
|
sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
|
2001-12-31 16:33:13 +01:00
|
|
|
while( c )
|
|
|
|
{
|
2002-02-27 16:23:27 +01:00
|
|
|
if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' )))
|
2001-12-31 16:33:13 +01:00
|
|
|
{
|
2002-02-27 01:50:05 +01:00
|
|
|
/* Okay, das ist ein User: anhaengen */
|
|
|
|
if( rpl[strlen( rpl ) - 1] != ':' ) strcat( rpl, " " );
|
2002-01-04 02:21:47 +01:00
|
|
|
strcat( rpl, Client_ID( c ));
|
2001-12-31 16:33:13 +01:00
|
|
|
|
2002-02-27 01:50:05 +01:00
|
|
|
if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
|
|
|
|
{
|
|
|
|
/* Zeile wird zu lang: senden! */
|
2002-10-04 13:21:46 +02:00
|
|
|
if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
|
2002-02-27 01:50:05 +01:00
|
|
|
sprintf( rpl, RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" );
|
|
|
|
}
|
2001-12-31 16:33:13 +01:00
|
|
|
}
|
2002-02-27 01:50:05 +01:00
|
|
|
|
|
|
|
/* naechster Client */
|
2001-12-31 16:33:13 +01:00
|
|
|
c = Client_Next( c );
|
|
|
|
}
|
2002-02-27 01:50:05 +01:00
|
|
|
if( rpl[strlen( rpl ) - 1] != ':')
|
2001-12-31 16:33:13 +01:00
|
|
|
{
|
|
|
|
/* es wurden User gefunden */
|
2002-10-04 13:21:46 +02:00
|
|
|
if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED;
|
2001-12-31 16:33:13 +01:00
|
|
|
}
|
2002-02-27 01:50:05 +01:00
|
|
|
|
|
|
|
return IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), "*" );
|
2001-12-31 16:33:13 +01:00
|
|
|
} /* IRC_NAMES */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_ISON( CLIENT *Client, REQUEST *Req )
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
|
|
|
CHAR rpl[COMMAND_LEN];
|
|
|
|
CLIENT *c;
|
|
|
|
CHAR *ptr;
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-04 18:58:44 +01:00
|
|
|
if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
2002-01-04 18:58:44 +01:00
|
|
|
if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
strcpy( rpl, RPL_ISON_MSG );
|
|
|
|
for( i = 0; i < Req->argc; i++ )
|
|
|
|
{
|
|
|
|
ptr = strtok( Req->argv[i], " " );
|
|
|
|
while( ptr )
|
|
|
|
{
|
|
|
|
ngt_TrimStr( ptr );
|
2002-03-25 18:04:02 +01:00
|
|
|
c = Client_Search( ptr );
|
2002-01-04 02:21:47 +01:00
|
|
|
if( c && ( Client_Type( c ) == CLIENT_USER ))
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
|
|
|
/* Dieser Nick ist "online" */
|
|
|
|
strcat( rpl, ptr );
|
|
|
|
strcat( rpl, " " );
|
|
|
|
}
|
|
|
|
ptr = strtok( NULL, " " );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
|
|
|
|
|
2002-10-04 13:21:46 +02:00
|
|
|
return IRC_WriteStrClient( Client, "%s", rpl, Client_ID( Client ) );
|
2001-12-31 03:18:51 +01:00
|
|
|
} /* IRC_ISON */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_WHOIS( CLIENT *Client, REQUEST *Req )
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
2002-01-06 00:24:54 +01:00
|
|
|
CLIENT *from, *target, *c;
|
2002-01-29 01:13:45 +01:00
|
|
|
CHAR str[LINE_LEN + 1], *ptr = NULL;
|
|
|
|
CL2CHAN *cl2chan;
|
2002-02-11 02:03:20 +01:00
|
|
|
CHANNEL *chan;
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-05 20:15:03 +01:00
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
2002-01-04 18:58:44 +01:00
|
|
|
if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
/* Client suchen */
|
2002-03-25 18:04:02 +01:00
|
|
|
c = Client_Search( Req->argv[Req->argc - 1] );
|
2002-01-06 00:24:54 +01:00
|
|
|
if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
|
2002-01-05 20:15:03 +01:00
|
|
|
|
|
|
|
/* Empfaenger des WHOIS suchen */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
|
2002-01-06 00:24:54 +01:00
|
|
|
else from = Client;
|
|
|
|
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
|
|
|
/* Forwarden an anderen Server? */
|
|
|
|
if( Req->argc > 1 )
|
|
|
|
{
|
2002-01-06 16:21:29 +01:00
|
|
|
/* angegebenen Ziel-Server suchen */
|
2002-03-25 18:04:02 +01:00
|
|
|
target = Client_Search( Req->argv[1] );
|
2002-01-06 00:24:54 +01:00
|
|
|
if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
|
2002-01-06 16:21:29 +01:00
|
|
|
ptr = Req->argv[1];
|
2002-01-06 00:24:54 +01:00
|
|
|
}
|
2002-02-25 14:21:25 +01:00
|
|
|
else target = Client_ThisServer( );
|
|
|
|
|
|
|
|
assert( target != NULL );
|
2002-01-06 16:21:29 +01:00
|
|
|
|
2002-02-25 14:21:25 +01:00
|
|
|
if(( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], ptr );
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
/* Nick, User und Name */
|
2002-01-06 00:24:54 +01:00
|
|
|
if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
/* Server */
|
2002-01-06 00:24:54 +01:00
|
|
|
if( ! IRC_WriteStrClient( from, RPL_WHOISSERVER_MSG, Client_ID( from ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED;
|
2001-12-31 03:18:51 +01:00
|
|
|
|
2002-01-29 01:13:45 +01:00
|
|
|
/* Channels */
|
|
|
|
sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
|
|
|
|
cl2chan = Channel_FirstChannelOf( c );
|
|
|
|
while( cl2chan )
|
|
|
|
{
|
2002-02-11 02:03:20 +01:00
|
|
|
chan = Channel_GetChannel( cl2chan );
|
|
|
|
assert( chan != NULL );
|
|
|
|
|
2002-01-29 01:13:45 +01:00
|
|
|
/* Channel-Name anhaengen */
|
|
|
|
if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
|
2002-02-11 02:03:20 +01:00
|
|
|
if( strchr( Channel_UserModes( chan, c ), 'o' )) strcat( str, "@" );
|
2002-03-10 19:16:51 +01:00
|
|
|
else if( strchr( Channel_UserModes( chan, c ), 'v' )) strcat( str, "+" );
|
2002-02-11 02:03:20 +01:00
|
|
|
strcat( str, Channel_Name( chan ));
|
2002-01-29 01:13:45 +01:00
|
|
|
|
|
|
|
if( strlen( str ) > ( LINE_LEN - CHANNEL_NAME_LEN - 4 ))
|
|
|
|
{
|
|
|
|
/* Zeile wird zu lang: senden! */
|
2002-10-04 13:21:46 +02:00
|
|
|
if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
|
2002-01-29 01:13:45 +01:00
|
|
|
sprintf( str, RPL_WHOISCHANNELS_MSG, Client_ID( from ), Client_ID( c ));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* naechstes Mitglied suchen */
|
|
|
|
cl2chan = Channel_NextChannelOf( c, cl2chan );
|
|
|
|
}
|
|
|
|
if( str[strlen( str ) - 1] != ':')
|
|
|
|
{
|
|
|
|
/* Es sind noch Daten da, die gesendet werden muessen */
|
2002-10-04 13:21:46 +02:00
|
|
|
if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
|
2002-01-29 01:13:45 +01:00
|
|
|
}
|
|
|
|
|
2001-12-31 03:18:51 +01:00
|
|
|
/* IRC-Operator? */
|
2002-01-04 02:21:47 +01:00
|
|
|
if( Client_HasMode( c, 'o' ))
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
2002-01-06 00:24:54 +01:00
|
|
|
if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
|
2001-12-31 03:18:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Idle (nur lokale Clients) */
|
2002-01-04 02:21:47 +01:00
|
|
|
if( Client_Conn( c ) > NONE )
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
2002-01-06 00:24:54 +01:00
|
|
|
if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
|
2001-12-31 03:18:51 +01:00
|
|
|
}
|
|
|
|
|
2002-02-27 19:23:45 +01:00
|
|
|
/* Away? */
|
|
|
|
if( Client_HasMode( c, 'a' ))
|
|
|
|
{
|
|
|
|
if( ! IRC_WriteStrClient( from, RPL_AWAY_MSG, Client_ID( from ), Client_ID( c ), Client_Away( c ))) return DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
2001-12-31 03:18:51 +01:00
|
|
|
/* End of Whois */
|
2002-01-06 00:24:54 +01:00
|
|
|
return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
|
2001-12-31 03:18:51 +01:00
|
|
|
} /* IRC_WHOIS */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_WHO( CLIENT *Client, REQUEST *Req )
|
2002-03-03 18:15:11 +01:00
|
|
|
{
|
2002-03-03 20:44:30 +01:00
|
|
|
BOOLEAN ok, only_ops;
|
2002-03-04 02:43:20 +01:00
|
|
|
CHAR flags[8], *ptr;
|
2002-03-03 20:44:30 +01:00
|
|
|
CL2CHAN *cl2chan;
|
|
|
|
CHANNEL *chan;
|
|
|
|
CLIENT *c;
|
|
|
|
|
2002-03-03 18:15:11 +01:00
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
|
|
|
if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2002-03-03 20:44:30 +01:00
|
|
|
|
|
|
|
only_ops = FALSE;
|
|
|
|
chan = NULL;
|
|
|
|
|
|
|
|
if( Req->argc == 2 )
|
|
|
|
{
|
|
|
|
/* Nur OPs anzeigen? */
|
|
|
|
if( strcmp( Req->argv[1], "o" ) == 0 ) only_ops = TRUE;
|
|
|
|
#ifdef STRICT_RFC
|
|
|
|
else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
|
|
|
#endif
|
|
|
|
}
|
2002-03-03 18:15:11 +01:00
|
|
|
|
2002-03-03 20:44:30 +01:00
|
|
|
if( Req->argc >= 1 )
|
|
|
|
{
|
|
|
|
/* wurde ein Channel oder Nick-Mask angegeben? */
|
|
|
|
chan = Channel_Search( Req->argv[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( chan )
|
|
|
|
{
|
|
|
|
/* User eines Channels ausgeben */
|
|
|
|
if( ! IRC_Send_WHO( Client, chan, only_ops )) return DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = Client_First( );
|
|
|
|
while( c )
|
|
|
|
{
|
|
|
|
if(( Client_Type( c ) == CLIENT_USER ) && ( ! strchr( Client_Modes( c ), 'i' )))
|
|
|
|
{
|
|
|
|
ok = FALSE;
|
|
|
|
if( Req->argc == 0 ) ok = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( strcasecmp( Req->argv[0], Client_ID( c )) == 0 ) ok = TRUE;
|
|
|
|
else if( strcmp( Req->argv[0], "0" ) == 0 ) ok = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ok && (( ! only_ops ) || ( strchr( Client_Modes( c ), 'o' ))))
|
|
|
|
{
|
|
|
|
/* Flags zusammenbasteln */
|
|
|
|
strcpy( flags, "H" );
|
|
|
|
if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
|
|
|
|
|
|
|
|
/* ausgeben */
|
|
|
|
cl2chan = Channel_FirstChannelOf( c );
|
2002-03-04 02:43:20 +01:00
|
|
|
if( cl2chan ) ptr = Channel_Name( Channel_GetChannel( cl2chan ));
|
|
|
|
else ptr = "*";
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), ptr, Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
|
2002-03-03 20:44:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* naechster Client */
|
|
|
|
c = Client_Next( c );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( chan ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Channel_Name( chan ));
|
|
|
|
else if( Req->argc == 0 ) return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), "*" );
|
|
|
|
else return IRC_WriteStrClient( Client, RPL_ENDOFWHO_MSG, Client_ID( Client ), Req->argv[0] );
|
2002-03-03 18:15:11 +01:00
|
|
|
} /* IRC_WHO */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_USERHOST( CLIENT *Client, REQUEST *Req )
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
|
|
|
CHAR rpl[COMMAND_LEN];
|
|
|
|
CLIENT *c;
|
|
|
|
INT max, i;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-04 18:58:44 +01:00
|
|
|
if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
2002-01-04 18:58:44 +01:00
|
|
|
if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
if( Req->argc > 5 ) max = 5;
|
|
|
|
else max = Req->argc;
|
|
|
|
|
|
|
|
strcpy( rpl, RPL_USERHOST_MSG );
|
|
|
|
for( i = 0; i < max; i++ )
|
|
|
|
{
|
2002-03-25 18:04:02 +01:00
|
|
|
c = Client_Search( Req->argv[i] );
|
2002-01-04 02:21:47 +01:00
|
|
|
if( c && ( Client_Type( c ) == CLIENT_USER ))
|
2001-12-31 03:18:51 +01:00
|
|
|
{
|
|
|
|
/* Dieser Nick ist "online" */
|
2002-01-04 02:21:47 +01:00
|
|
|
strcat( rpl, Client_ID( c ));
|
|
|
|
if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
|
2001-12-31 03:18:51 +01:00
|
|
|
strcat( rpl, "=" );
|
2002-01-04 02:21:47 +01:00
|
|
|
if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
|
2001-12-31 03:18:51 +01:00
|
|
|
else strcat( rpl, "+" );
|
2002-01-04 02:21:47 +01:00
|
|
|
strcat( rpl, Client_User( c ));
|
2001-12-31 03:18:51 +01:00
|
|
|
strcat( rpl, "@" );
|
2002-01-04 02:21:47 +01:00
|
|
|
strcat( rpl, Client_Hostname( c ));
|
2001-12-31 03:18:51 +01:00
|
|
|
strcat( rpl, " " );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
|
|
|
|
|
2002-10-04 13:21:46 +02:00
|
|
|
return IRC_WriteStrClient( Client, "%s", rpl, Client_ID( Client ) );
|
2002-01-02 03:44:36 +01:00
|
|
|
} /* IRC_USERHOST */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_ERROR( CLIENT *Client, REQUEST *Req )
|
2002-01-02 03:44:36 +01:00
|
|
|
{
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-04 02:21:47 +01:00
|
|
|
if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
|
|
|
|
else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
|
2002-01-02 03:44:36 +01:00
|
|
|
|
|
|
|
return CONNECTED;
|
|
|
|
} /* IRC_ERROR */
|
2001-12-31 03:18:51 +01:00
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_LUSERS( CLIENT *Client, REQUEST *Req )
|
2002-01-12 00:50:55 +01:00
|
|
|
{
|
2002-01-16 23:10:18 +01:00
|
|
|
CLIENT *target, *from;
|
|
|
|
|
2002-01-12 00:50:55 +01:00
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
2002-01-16 23:10:18 +01:00
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
2002-01-12 00:50:55 +01:00
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
2002-01-16 23:10:18 +01:00
|
|
|
|
|
|
|
/* Absender ermitteln */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
|
2002-01-16 23:10:18 +01:00
|
|
|
else from = Client;
|
|
|
|
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
|
|
|
/* An anderen Server forwarden? */
|
|
|
|
if( Req->argc == 2 )
|
|
|
|
{
|
2002-03-25 18:04:02 +01:00
|
|
|
target = Client_Search( Req->argv[1] );
|
2002-01-16 23:10:18 +01:00
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
|
|
|
|
else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wer ist der Absender? */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
|
2002-01-16 23:10:18 +01:00
|
|
|
else target = Client;
|
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
2002-01-12 00:50:55 +01:00
|
|
|
|
2002-02-28 00:26:36 +01:00
|
|
|
IRC_Send_LUSERS( target );
|
2002-01-16 23:10:18 +01:00
|
|
|
|
2002-01-12 00:50:55 +01:00
|
|
|
return CONNECTED;
|
|
|
|
} /* IRC_LUSERS */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_LINKS( CLIENT *Client, REQUEST *Req )
|
2002-01-12 00:50:55 +01:00
|
|
|
{
|
|
|
|
CLIENT *target, *from, *c;
|
|
|
|
CHAR *mask;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
|
|
|
|
|
|
|
/* Server-Mask ermitteln */
|
|
|
|
if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
|
|
|
|
else mask = "*";
|
|
|
|
|
|
|
|
/* Absender ermitteln */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
|
2002-01-12 00:50:55 +01:00
|
|
|
else from = Client;
|
|
|
|
if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
|
|
|
/* An anderen Server forwarden? */
|
|
|
|
if( Req->argc == 2 )
|
|
|
|
{
|
2002-03-25 18:04:02 +01:00
|
|
|
target = Client_Search( Req->argv[0] );
|
2002-01-12 00:50:55 +01:00
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
|
|
|
|
else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wer ist der Absender? */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
|
2002-01-12 00:50:55 +01:00
|
|
|
else target = Client;
|
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
|
|
|
c = Client_First( );
|
|
|
|
while( c )
|
|
|
|
{
|
|
|
|
if( Client_Type( c ) == CLIENT_SERVER )
|
|
|
|
{
|
2002-01-29 01:13:45 +01:00
|
|
|
if( ! IRC_WriteStrClient( target, RPL_LINKS_MSG, Client_ID( target ), Client_ID( c ), Client_ID( Client_TopServer( c ) ? Client_TopServer( c ) : Client_ThisServer( )), Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
|
2002-01-12 00:50:55 +01:00
|
|
|
}
|
|
|
|
c = Client_Next( c );
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
|
|
|
|
} /* IRC_LINKS */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_VERSION( CLIENT *Client, REQUEST *Req )
|
2002-02-18 00:38:58 +01:00
|
|
|
{
|
2002-02-26 21:52:40 +01:00
|
|
|
CLIENT *target, *prefix;
|
2002-02-18 00:38:58 +01:00
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
|
|
|
|
|
|
|
/* Ziel suchen */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
|
2002-02-18 00:38:58 +01:00
|
|
|
else target = Client_ThisServer( );
|
|
|
|
|
2002-02-26 21:52:40 +01:00
|
|
|
/* Prefix ermitteln */
|
2002-03-25 18:04:02 +01:00
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
|
2002-02-26 21:52:40 +01:00
|
|
|
else prefix = Client;
|
|
|
|
if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
2002-02-18 00:38:58 +01:00
|
|
|
/* An anderen Server weiterleiten? */
|
|
|
|
if( target != Client_ThisServer( ))
|
|
|
|
{
|
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
|
2002-02-26 21:52:40 +01:00
|
|
|
|
|
|
|
/* forwarden */
|
2002-02-27 01:50:05 +01:00
|
|
|
IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
|
2002-02-18 00:38:58 +01:00
|
|
|
return CONNECTED;
|
|
|
|
}
|
2002-02-19 03:21:17 +01:00
|
|
|
|
2002-02-26 21:52:40 +01:00
|
|
|
/* mit Versionsinfo antworten */
|
2002-05-30 18:52:20 +02:00
|
|
|
return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), PACKAGE, VERSION, NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
|
2002-02-18 00:38:58 +01:00
|
|
|
} /* IRC_VERSION */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_KILL( CLIENT *Client, REQUEST *Req )
|
2002-02-23 22:39:48 +01:00
|
|
|
{
|
|
|
|
CLIENT *prefix, *c;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
|
|
|
if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
|
|
|
|
2002-03-25 18:04:02 +01:00
|
|
|
prefix = Client_Search( Req->prefix );
|
2002-02-23 22:39:48 +01:00
|
|
|
if( ! prefix )
|
|
|
|
{
|
|
|
|
Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
|
|
|
|
prefix = Client_ThisServer( );
|
|
|
|
}
|
|
|
|
|
|
|
|
Log( LOG_NOTICE, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
|
|
|
|
|
|
|
|
/* andere Server benachrichtigen */
|
|
|
|
IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], Req->argv[1] );
|
|
|
|
|
|
|
|
/* haben wir selber einen solchen Client? */
|
2002-03-25 18:04:02 +01:00
|
|
|
c = Client_Search( Req->argv[0] );
|
2002-07-25 13:37:01 +02:00
|
|
|
if( c )
|
|
|
|
{
|
|
|
|
/* Ja, wir haben einen solchen Client */
|
|
|
|
if( Client_Conn( c ) != NONE ) Conn_Close( Client_Conn( c ), NULL, Req->argv[1], TRUE );
|
|
|
|
else Client_Destroy( c, NULL, Req->argv[1], TRUE );
|
|
|
|
}
|
|
|
|
else Log( LOG_NOTICE, "Client with nick \"%s\" is unknown here.", Req->argv[0] );
|
|
|
|
|
2002-02-23 22:39:48 +01:00
|
|
|
return CONNECTED;
|
|
|
|
} /* IRC_KILL */
|
|
|
|
|
|
|
|
|
2002-09-16 11:14:45 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_ADMIN(CLIENT *Client, REQUEST *Req )
|
|
|
|
{
|
|
|
|
CLIENT *target, *prefix;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Req != NULL );
|
|
|
|
|
|
|
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
|
|
|
|
|
|
|
/* Falsche Anzahl Parameter? */
|
|
|
|
if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
|
|
|
|
|
|
|
/* Ziel suchen */
|
|
|
|
if( Req->argc == 1 ) target = Client_Search( Req->argv[0] );
|
|
|
|
else target = Client_ThisServer( );
|
|
|
|
|
|
|
|
/* Prefix ermitteln */
|
|
|
|
if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix );
|
|
|
|
else prefix = Client;
|
|
|
|
if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
|
|
|
|
|
|
|
|
/* An anderen Server weiterleiten? */
|
|
|
|
if( target != Client_ThisServer( ))
|
|
|
|
{
|
|
|
|
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
|
|
|
|
|
|
|
|
/* forwarden */
|
|
|
|
IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] );
|
|
|
|
return CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mit Versionsinfo antworten */
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_ADMINME_MSG, Client_ID( prefix ), Conf_ServerName )) return DISCONNECTED;
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC1_MSG, Client_ID( prefix ), Conf_ServerAdmin1 )) return DISCONNECTED;
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_ADMINLOC2_MSG, Client_ID( prefix ), Conf_ServerAdmin2 )) return DISCONNECTED;
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_ADMINEMAIL_MSG, Client_ID( prefix ), Conf_ServerAdminMail )) return DISCONNECTED;
|
|
|
|
|
|
|
|
return CONNECTED;
|
|
|
|
} /* IRC_ADMIN */
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_Show_MOTD( CLIENT *Client )
|
2001-12-24 02:34:06 +01:00
|
|
|
{
|
2001-12-26 23:48:53 +01:00
|
|
|
BOOLEAN ok;
|
|
|
|
CHAR line[127];
|
|
|
|
FILE *fd;
|
|
|
|
|
2001-12-26 04:21:46 +01:00
|
|
|
assert( Client != NULL );
|
2001-12-26 23:48:53 +01:00
|
|
|
|
|
|
|
fd = fopen( Conf_MotdFile, "r" );
|
|
|
|
if( ! fd )
|
|
|
|
{
|
|
|
|
Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
|
2002-01-04 18:58:44 +01:00
|
|
|
return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
|
2001-12-26 23:48:53 +01:00
|
|
|
}
|
2001-12-26 04:21:46 +01:00
|
|
|
|
2002-01-04 18:58:44 +01:00
|
|
|
IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )));
|
2001-12-26 23:48:53 +01:00
|
|
|
while( TRUE )
|
|
|
|
{
|
|
|
|
if( ! fgets( line, 126, fd )) break;
|
|
|
|
if( line[strlen( line ) - 1] == '\n' ) line[strlen( line ) - 1] = '\0';
|
2002-01-05 20:15:03 +01:00
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
|
|
|
|
{
|
|
|
|
fclose( fd );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-26 23:48:53 +01:00
|
|
|
}
|
2002-01-04 18:58:44 +01:00
|
|
|
ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
|
2001-12-26 23:48:53 +01:00
|
|
|
|
|
|
|
fclose( fd );
|
|
|
|
|
|
|
|
return ok;
|
2002-02-28 00:26:36 +01:00
|
|
|
} /* IRC_Show_MOTD */
|
2002-02-23 22:39:48 +01:00
|
|
|
|
2002-01-04 02:21:47 +01:00
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_Send_NAMES( CLIENT *Client, CHANNEL *Chan )
|
2002-01-28 14:05:48 +01:00
|
|
|
{
|
2002-02-27 16:23:27 +01:00
|
|
|
BOOLEAN is_visible, is_member;
|
2002-01-28 14:05:48 +01:00
|
|
|
CHAR str[LINE_LEN + 1];
|
|
|
|
CL2CHAN *cl2chan;
|
2002-02-11 02:03:20 +01:00
|
|
|
CLIENT *cl;
|
2002-01-28 14:05:48 +01:00
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Chan != NULL );
|
|
|
|
|
2002-02-27 16:23:27 +01:00
|
|
|
if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
|
|
|
|
else is_member = FALSE;
|
|
|
|
|
2002-01-28 14:05:48 +01:00
|
|
|
/* Alle Mitglieder suchen */
|
|
|
|
sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
|
|
|
|
cl2chan = Channel_FirstMember( Chan );
|
|
|
|
while( cl2chan )
|
|
|
|
{
|
2002-02-11 02:03:20 +01:00
|
|
|
cl = Channel_GetClient( cl2chan );
|
|
|
|
|
2002-02-27 16:23:27 +01:00
|
|
|
if( strchr( Client_Modes( cl ), 'i' )) is_visible = FALSE;
|
|
|
|
else is_visible = TRUE;
|
2002-01-28 14:05:48 +01:00
|
|
|
|
2002-02-27 16:23:27 +01:00
|
|
|
if( is_member || is_visible )
|
2002-01-28 14:05:48 +01:00
|
|
|
{
|
2002-02-27 16:23:27 +01:00
|
|
|
/* Nick anhaengen */
|
|
|
|
if( str[strlen( str ) - 1] != ':' ) strcat( str, " " );
|
|
|
|
if( strchr( Channel_UserModes( Chan, cl ), 'o' )) strcat( str, "@" );
|
2002-03-10 19:16:51 +01:00
|
|
|
else if( strchr( Channel_UserModes( Chan, cl ), 'v' )) strcat( str, "+" );
|
2002-02-27 16:23:27 +01:00
|
|
|
strcat( str, Client_ID( cl ));
|
|
|
|
|
|
|
|
if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 ))
|
|
|
|
{
|
|
|
|
/* Zeile wird zu lang: senden! */
|
2002-10-04 13:21:46 +02:00
|
|
|
if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
|
2002-02-27 16:23:27 +01:00
|
|
|
sprintf( str, RPL_NAMREPLY_MSG, Client_ID( Client ), "=", Channel_Name( Chan ));
|
|
|
|
}
|
2002-01-28 14:05:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* naechstes Mitglied suchen */
|
|
|
|
cl2chan = Channel_NextMember( Chan, cl2chan );
|
|
|
|
}
|
|
|
|
if( str[strlen( str ) - 1] != ':')
|
|
|
|
{
|
|
|
|
/* Es sind noch Daten da, die gesendet werden muessen */
|
2002-10-04 13:21:46 +02:00
|
|
|
if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
|
2002-01-28 14:05:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return CONNECTED;
|
2002-02-28 00:26:36 +01:00
|
|
|
} /* IRC_Send_NAMES */
|
2002-01-28 14:05:48 +01:00
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_Send_WHO( CLIENT *Client, CHANNEL *Chan, BOOLEAN OnlyOps )
|
2002-03-03 20:44:30 +01:00
|
|
|
{
|
|
|
|
BOOLEAN is_visible, is_member;
|
|
|
|
CL2CHAN *cl2chan;
|
|
|
|
CHAR flags[8];
|
|
|
|
CLIENT *c;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
assert( Chan != NULL );
|
|
|
|
|
|
|
|
if( Channel_IsMemberOf( Chan, Client )) is_member = TRUE;
|
|
|
|
else is_member = FALSE;
|
|
|
|
|
|
|
|
/* Alle Mitglieder suchen */
|
|
|
|
cl2chan = Channel_FirstMember( Chan );
|
|
|
|
while( cl2chan )
|
|
|
|
{
|
|
|
|
c = Channel_GetClient( cl2chan );
|
|
|
|
|
|
|
|
if( strchr( Client_Modes( c ), 'i' )) is_visible = FALSE;
|
|
|
|
else is_visible = TRUE;
|
|
|
|
|
|
|
|
if( is_member || is_visible )
|
|
|
|
{
|
|
|
|
/* Flags zusammenbasteln */
|
|
|
|
strcpy( flags, "H" );
|
|
|
|
if( strchr( Client_Modes( c ), 'o' )) strcat( flags, "*" );
|
|
|
|
if( strchr( Channel_UserModes( Chan, c ), 'o' )) strcat( flags, "@" );
|
2002-03-10 19:16:51 +01:00
|
|
|
else if( strchr( Channel_UserModes( Chan, c ), 'v' )) strcat( flags, "+" );
|
2002-03-03 20:44:30 +01:00
|
|
|
|
|
|
|
/* ausgeben */
|
|
|
|
if(( ! OnlyOps ) || ( strchr( Client_Modes( c ), 'o' )))
|
|
|
|
{
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_WHOREPLY_MSG, Client_ID( Client ), Channel_Name( Chan ), Client_User( c ), Client_Hostname( c ), Client_ID( Client_Introducer( c )), Client_ID( c ), flags, Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* naechstes Mitglied suchen */
|
|
|
|
cl2chan = Channel_NextMember( Chan, cl2chan );
|
|
|
|
}
|
|
|
|
return CONNECTED;
|
|
|
|
} /* IRC_Send_WHO */
|
|
|
|
|
|
|
|
|
2002-05-27 15:09:26 +02:00
|
|
|
GLOBAL BOOLEAN
|
|
|
|
IRC_Send_LUSERS( CLIENT *Client )
|
2002-02-14 00:05:29 +01:00
|
|
|
{
|
|
|
|
INT cnt;
|
|
|
|
|
|
|
|
assert( Client != NULL );
|
|
|
|
|
|
|
|
/* Users, Services und Serevr im Netz */
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_LUSERCLIENT_MSG, Client_ID( Client ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
|
|
|
|
|
|
|
|
/* IRC-Operatoren im Netz */
|
|
|
|
cnt = Client_OperCount( );
|
|
|
|
if( cnt > 0 )
|
|
|
|
{
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_LUSEROP_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unbekannt Verbindungen */
|
|
|
|
cnt = Client_UnknownCount( );
|
|
|
|
if( cnt > 0 )
|
|
|
|
{
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_LUSERUNKNOWN_MSG, Client_ID( Client ), cnt )) return DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Channels im Netz */
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_LUSERCHANNELS_MSG, Client_ID( Client ), Channel_Count( ))) return DISCONNECTED;
|
|
|
|
|
|
|
|
/* Channels im Netz */
|
|
|
|
if( ! IRC_WriteStrClient( Client, RPL_LUSERME_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
|
|
|
|
|
|
|
|
return CONNECTED;
|
2002-02-28 00:26:36 +01:00
|
|
|
} /* IRC_Send_LUSERS */
|
2002-02-25 18:46:27 +01:00
|
|
|
|
|
|
|
|
2001-12-14 09:13:43 +01:00
|
|
|
/* -eof- */
|