#include "portab.h"
-static char UNUSED id[] = "$Id: irc-info.c,v 1.34 2006/09/16 12:22:09 fw Exp $";
+static char UNUSED id[] = "$Id: irc-info.c,v 1.41 2007/12/11 11:29:44 fw Exp $";
#include "imp.h"
#include <assert.h>
} /* IRC_NAMES */
+static unsigned int
+t_diff(time_t *t, const time_t div)
+{
+ time_t diff, remain;
+
+ diff = *t / div;
+
+ remain = diff * div;
+ *t -= remain;
+
+ return diff;
+}
+
+
+static unsigned int
+uptime_days(time_t *now)
+{
+ return t_diff(now, 60 * 60 * 24);
+}
+
+
+static unsigned int
+uptime_hrs(time_t *now)
+{
+ return t_diff(now, 60 * 60);
+}
+
+
+static unsigned int
+uptime_mins(time_t *now)
+{
+ return t_diff(now, 60);
+}
+
+
GLOBAL bool
IRC_STATS( CLIENT *Client, REQUEST *Req )
{
CONN_ID con;
char query;
COMMAND *cmd;
+ time_t time_now;
+ unsigned int days, hrs, mins;
assert( Client != NULL );
assert( Req != NULL );
/* Falsche Anzahl Parameter? */
- if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+ if (Req->argc > 2)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
/* From aus Prefix ermitteln */
- if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
- else from = Client;
- if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+ if (Client_Type(Client) == CLIENT_SERVER)
+ from = Client_Search(Req->prefix);
+ else
+ from = Client;
- if( Req->argc == 2 )
- {
+ if (! from)
+ return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix);
+
+ if (Req->argc == 2) {
/* an anderen Server forwarden */
target = Client_Search( Req->argv[1] );
- if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
+ if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
+ return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
- if( target != Client_ThisServer( ))
- {
+ if( target != Client_ThisServer()) {
/* Ok, anderer Server ist das Ziel: forwarden */
return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] );
}
}
- if( Req->argc > 0 ) query = Req->argv[0][0] ? Req->argv[0][0] : '*';
- else query = '*';
+ if (Req->argc > 0)
+ query = Req->argv[0][0] ? Req->argv[0][0] : '*';
+ else
+ query = '*';
- switch ( query )
- {
+ switch (query) {
case 'l': /* Links */
case 'L':
- con = Conn_First( );
- while( con != NONE )
- {
- cl = Conn_GetClient( con );
- if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
- {
+ time_now = time(NULL);
+ for (con = Conn_First(); con != NONE ;con = Conn_Next(con)) {
+ cl = Conn_GetClient(con);
+ if (!cl)
+ continue;
+ if ((Client_Type(cl) == CLIENT_SERVER) || (cl == Client)) {
/* Server link or our own connection */
#ifdef ZLIB
- if( Conn_Options( con ) & CONN_ZIP )
- {
- if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFOZIP_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Zip_SendBytes( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Zip_RecvBytes( con ), Conn_RecvBytes( con ), (long)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
+ if (Conn_Options(con) & CONN_ZIP) {
+ if (!IRC_WriteStrClient(from, RPL_STATSLINKINFOZIP_MSG,
+ Client_ID(from), Client_Mask(cl), Conn_SendQ(con),
+ Conn_SendMsg(con), Zip_SendBytes(con), Conn_SendBytes(con),
+ Conn_RecvMsg(con), Zip_RecvBytes(con), Conn_RecvBytes(con), (long)(time_now - Conn_StartTime(con))))
+ return DISCONNECTED;
+ continue;
}
- else
#endif
- {
- if( ! IRC_WriteStrClient( from, RPL_STATSLINKINFO_MSG, Client_ID( from ), Client_Mask( cl ), Conn_SendQ( con ), Conn_SendMsg( con ), Conn_SendBytes( con ), Conn_RecvMsg( con ), Conn_RecvBytes( con ), (long)( time( NULL ) - Conn_StartTime( con )))) return DISCONNECTED;
- }
+ if (!IRC_WriteStrClient(from, RPL_STATSLINKINFO_MSG, Client_ID(from),
+ Client_Mask(cl), Conn_SendQ(con), Conn_SendMsg(con), Conn_SendBytes(con),
+ Conn_RecvMsg(con), Conn_RecvBytes(con), (long)(time_now - Conn_StartTime(con))))
+ return DISCONNECTED;
}
- con = Conn_Next( con );
}
break;
- case 'm': /* IRC-Befehle */
+ case 'm': /* IRC-Commands */
case 'M':
cmd = Parse_GetCommandStruct( );
- while( cmd->name )
- {
- if( cmd->lcount > 0 || cmd->rcount > 0 )
- {
- if( ! IRC_WriteStrClient( from, RPL_STATSCOMMANDS_MSG, Client_ID( from ), cmd->name, cmd->lcount, cmd->bytes, cmd->rcount )) return DISCONNECTED;
- }
- cmd++;
+ for (; cmd->name ; cmd++) {
+ if (cmd->lcount == 0 && cmd->rcount == 0)
+ continue;
+ if (!IRC_WriteStrClient(from, RPL_STATSCOMMANDS_MSG, Client_ID(from),
+ cmd->name, cmd->lcount, cmd->bytes, cmd->rcount))
+ return DISCONNECTED;
}
break;
+ case 'u': /* server uptime */
+ case 'U':
+ time_now = time(NULL) - NGIRCd_Start;
+ days = uptime_days(&time_now);
+ hrs = uptime_hrs(&time_now);
+ mins = uptime_mins(&time_now);
+ if (!IRC_WriteStrClient(from, RPL_STATSUPTIME, Client_ID(from),
+ days, hrs, mins, (unsigned int) time_now))
+ return DISCONNECTED;
+ break;
}
- IRC_SetPenalty( from, 2 );
- return IRC_WriteStrClient( from, RPL_ENDOFSTATS_MSG, Client_ID( from ), query );
+ IRC_SetPenalty(from, 2);
+ return IRC_WriteStrClient(from, RPL_ENDOFSTATS_MSG, Client_ID(from), query);
} /* IRC_STATS */
IRC_WHO( CLIENT *Client, REQUEST *Req )
{
bool ok, only_ops;
- char flags[8], *ptr;
+ char flags[8];
+ const char *ptr;
CL2CHAN *cl2chan;
CHANNEL *chan, *cn;
CLIENT *c;
if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
}
- /* Idle (only local clients) */
- if( Client_Conn( c ) > NONE )
- {
- if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
+ /* Idle and signon time (local clients only!) */
+ if (Client_Conn(c) > NONE ) {
+ if (! IRC_WriteStrClient(from, RPL_WHOISIDLE_MSG,
+ Client_ID(from), Client_ID(c),
+ (unsigned long)Conn_GetIdle(Client_Conn(c)),
+ (unsigned long)Conn_GetSignon(Client_Conn(c))))
+ return DISCONNECTED;
}
/* Away? */
GLOBAL bool
IRC_Send_LUSERS( CLIENT *Client )
{
- long cnt;
+ unsigned long cnt;
+#ifndef STRICT_RFC
+ unsigned long max;
+#endif
assert( Client != NULL );
#ifndef STRICT_RFC
/* Maximum number of local users */
- if( ! IRC_WriteStrClient( Client, RPL_LOCALUSERS_MSG, Client_ID( Client ), Client_MyUserCount( ), Client_MyMaxUserCount( ))) return DISCONNECTED;
+ cnt = Client_MyUserCount();
+ max = Client_MyMaxUserCount();
+ if (! IRC_WriteStrClient(Client, RPL_LOCALUSERS_MSG, Client_ID(Client),
+ cnt, max, cnt, max))
+ return DISCONNECTED;
/* Maximum number of users in the network */
- if( ! IRC_WriteStrClient( Client, RPL_NETUSERS_MSG, Client_ID( Client ), Client_UserCount( ), Client_MaxUserCount( ))) return DISCONNECTED;
+ cnt = Client_UserCount();
+ max = Client_MaxUserCount();
+ if(! IRC_WriteStrClient(Client, RPL_NETUSERS_MSG, Client_ID(Client),
+ cnt, max, cnt, max))
+ return DISCONNECTED;
#endif
return CONNECTED;
} /* IRC_Send_LUSERS */
-static bool Show_MOTD_Start(CLIENT *Client)
+static bool
+Show_MOTD_Start(CLIENT *Client)
{
return IRC_WriteStrClient(Client, RPL_MOTDSTART_MSG,
Client_ID( Client ), Client_ID( Client_ThisServer( )));
}
-static bool Show_MOTD_Sendline(CLIENT *Client, const char *msg)
+static bool
+Show_MOTD_Sendline(CLIENT *Client, const char *msg)
{
return IRC_WriteStrClient(Client, RPL_MOTD_MSG, Client_ID( Client ), msg);
}
-static bool Show_MOTD_End(CLIENT *Client)
+static bool
+Show_MOTD_End(CLIENT *Client)
{
return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
}
} /* IRC_Send_WHO */
+/**
+ * Send the ISUPPORT numeric (005).
+ * This numeric indicates the features that are supported by this server.
+ * See <http://www.irc.org/tech_docs/005.html> for details.
+ */
+GLOBAL bool
+IRC_Send_ISUPPORT PARAMS((CLIENT * Client))
+{
+ if (!IRC_WriteStrClient(Client, RPL_ISUPPORT1_MSG, Client_ID(Client),
+ Conf_MaxJoins))
+ return DISCONNECTED;
+ return IRC_WriteStrClient(Client, RPL_ISUPPORT2_MSG, Client_ID(Client),
+ CHANNEL_NAME_LEN - 1, Conf_MaxNickLength - 1,
+ COMMAND_LEN - 23, CLIENT_AWAY_LEN - 1,
+ COMMAND_LEN - 113);
+} /* IRC_Send_ISUPPORT */
+
+
/* -eof- */