]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-info.c
channel maxusers now unsigned long
[ngircd-alex.git] / src / ngircd / irc-info.c
index e4f65a51f697c083b8afbb8d78e54e293bae3f53..ac9e9d805ae790700f45a85931775804c53b3476 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-info.c,v 1.30 2005/06/17 19:15:43 fw Exp $";
+static char UNUSED id[] = "$Id: irc-info.c,v 1.36 2006/10/06 21:32:58 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -377,7 +377,7 @@ IRC_STATS( CLIENT *Client, REQUEST *Req )
                        con = Conn_First( );
                        while( con != NONE )
                        {
-                               cl = Client_GetFromConn( con );
+                               cl = Conn_GetClient( con );
                                if( cl && (( Client_Type( cl ) == CLIENT_SERVER ) || ( cl == Client )))
                                {
                                        /* Server link or our own connection */
@@ -542,7 +542,8 @@ GLOBAL bool
 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;
@@ -833,6 +834,9 @@ GLOBAL bool
 IRC_Send_LUSERS( CLIENT *Client )
 {
        long cnt;
+#ifndef STRICT_RFC
+       long max;
+#endif
 
        assert( Client != NULL );
 
@@ -861,56 +865,78 @@ IRC_Send_LUSERS( CLIENT *Client )
 
 #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)
+{
+       return IRC_WriteStrClient(Client, RPL_MOTDSTART_MSG,
+               Client_ID( Client ), Client_ID( Client_ThisServer( )));
+}
+
+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)
+{
+       return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
+}
+
+
 GLOBAL bool
 IRC_Show_MOTD( CLIENT *Client )
 {
-       bool ok;
        char line[127];
        FILE *fd;
 
        assert( Client != NULL );
 
-       if( Conf_MotdPhrase[0] )
-       {
-               if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
-               if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), Conf_MotdPhrase )) return DISCONNECTED;
-               return IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ));
+       if (Conf_MotdPhrase[0]) {
+               if (!Show_MOTD_Start(Client))
+                       return DISCONNECTED;
+               if (!Show_MOTD_Sendline(Client, Conf_MotdPhrase))
+                       return DISCONNECTED;
+
+               return Show_MOTD_End(Client);
        }
 
        fd = fopen( Conf_MotdFile, "r" );
-       if( ! fd )
-       {
+       if( ! fd ) {
                Log( LOG_WARNING, "Can't read MOTD file \"%s\": %s", Conf_MotdFile, strerror( errno ));
                return IRC_WriteStrClient( Client, ERR_NOMOTD_MSG, Client_ID( Client ) );
        }
 
-       if( ! IRC_WriteStrClient( Client, RPL_MOTDSTART_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return DISCONNECTED;
-       while( true )
-       {
-               if( ! fgets( line, sizeof( line ), fd )) break;
+       if (!Show_MOTD_Start( Client )) {
+               fclose(fd);
+               return false;
+       }
 
+       while (fgets( line, (int)sizeof line, fd )) {
                ngt_TrimLastChr( line, '\n');
 
-               if( ! IRC_WriteStrClient( Client, RPL_MOTD_MSG, Client_ID( Client ), line ))
-               {
+               if( ! Show_MOTD_Sendline( Client, line)) {
                        fclose( fd );
                        return false;
                }
        }
-       ok = IRC_WriteStrClient( Client, RPL_ENDOFMOTD_MSG, Client_ID( Client ) );
-
-       fclose( fd );
-
-       return ok;
+       fclose(fd);
+       return Show_MOTD_End(Client);
 } /* IRC_Show_MOTD */