]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/client.c
- new Functions: Client_MaxUserCount(), Client_MyMaxUserCount, Adjust_Counters().
[ngircd.git] / src / ngircd / client.c
index cc6641405b4eee17199b27bbb6127f7ddfa0f184..dee2ada5de29ad8834d7309e88c3e7aef1dafc48 100644 (file)
@@ -2,23 +2,13 @@
  * ngIRCd -- The Next Generation IRC Daemon
  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
  *
- * 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
- * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: client.c,v 1.61 2002/10/04 12:39:58 alex Exp $
- *
- * client.c: Management aller Clients
- *
- * Der Begriff "Client" ist in diesem Fall evtl. etwas verwirrend: Clients sind
- * alle Verbindungen, die im gesamten(!) IRC-Netzwerk bekannt sind. Das sind IRC-
- * Clients (User), andere Server und IRC-Services.
- * Ueber welchen IRC-Server die Verbindung nun tatsaechlich in das Netzwerk her-
- * gestellt wurde, muss der jeweiligen Struktur entnommen werden. Ist es dieser
- * Server gewesen, so existiert eine entsprechende CONNECTION-Struktur.
+ * Client management.
  */
 
 
@@ -27,6 +17,8 @@
 
 #include "portab.h"
 
+static char UNUSED id[] = "$Id: client.c,v 1.67 2002/12/22 23:29:09 alex Exp $";
+
 #include "imp.h"
 #include <assert.h>
 #include <unistd.h>
@@ -60,11 +52,15 @@ LOCAL CLIENT *This_Server, *My_Clients;
 LOCAL CHAR GetID_Buffer[GETID_LEN];
 
 
-LOCAL INT Count PARAMS(( CLIENT_TYPE Type ));
-LOCAL INT MyCount PARAMS(( CLIENT_TYPE Type ));
+LOCAL LONG Count PARAMS(( CLIENT_TYPE Type ));
+LOCAL LONG MyCount PARAMS(( CLIENT_TYPE Type ));
 
 LOCAL CLIENT *New_Client_Struct PARAMS(( VOID ));
 LOCAL VOID Generate_MyToken PARAMS(( CLIENT *Client ));
+LOCAL VOID Adjust_Counters PARAMS(( CLIENT *Client ));
+
+
+LONG Max_Users = 0, My_Max_Users = 0;
 
 
 GLOBAL VOID
@@ -105,7 +101,7 @@ Client_Exit( VOID )
        CLIENT *c, *next;
        INT cnt;
 
-       if( NGIRCd_Restart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, FALSE );
+       if( NGIRCd_SignalRestart ) Client_Destroy( This_Server, "Server going down (restarting).", NULL, FALSE );
        else Client_Destroy( This_Server, "Server going down.", NULL, FALSE );
        
        cnt = 0;
@@ -185,6 +181,9 @@ Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, INT Type, CHAR *
        client->next = (POINTER *)My_Clients;
        My_Clients = client;
 
+       /* Adjust counters */
+       Adjust_Counters( client );
+
        return client;
 } /* Client_New */
 
@@ -264,7 +263,7 @@ Client_Destroy( CLIENT *Client, CHAR *LogMsg, CHAR *FwdMsg, BOOLEAN SendQuit )
                                }
 
                                /* andere Server informieren */
-                               if( ! NGIRCd_Quit )
+                               if( ! NGIRCd_SignalQuit )
                                {
                                        if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg );
                                        else IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :", c->id );
@@ -375,7 +374,7 @@ Client_SetFlags( CLIENT *Client, CHAR *Flags )
        assert( Flags != NULL );
 
        strncpy( Client->flags, Flags, CLIENT_FLAGS_LEN - 1 );
-       Client->modes[CLIENT_FLAGS_LEN - 1] = '\0';
+       Client->flags[CLIENT_FLAGS_LEN - 1] = '\0';
 } /* Client_SetFlags */
 
 
@@ -422,6 +421,7 @@ Client_SetType( CLIENT *Client, INT Type )
        assert( Client != NULL );
        Client->type = Type;
        if( Type == CLIENT_SERVER ) Generate_MyToken( Client );
+       Adjust_Counters( Client );
 } /* Client_SetType */
 
 
@@ -808,8 +808,9 @@ Client_CheckID( CLIENT *Client, CHAR *ID )
                if( strcasecmp( c->id, ID ) == 0 )
                {
                        /* die Server-ID gibt es bereits */
-                       sprintf( str, "ID \"%s\" already registered!", ID );
-                       Log( LOG_ERR, "%s (on connection %d)", str, Client->conn_id );
+                       sprintf( str, "ID \"%s\" already registered", ID );
+                       if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id );
+                       else Log( LOG_ERR, "%s (via network)!", str );
                        Conn_Close( Client->conn_id, str, str, TRUE );
                        return FALSE;
                }
@@ -840,46 +841,46 @@ Client_Next( CLIENT *c )
 } /* Client_Next */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_UserCount( VOID )
 {
        return Count( CLIENT_USER );
 } /* Client_UserCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_ServiceCount( VOID )
 {
        return Count( CLIENT_SERVICE );;
 } /* Client_ServiceCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_ServerCount( VOID )
 {
        return Count( CLIENT_SERVER );
 } /* Client_ServerCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_MyUserCount( VOID )
 {
        return MyCount( CLIENT_USER );
 } /* Client_MyUserCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_MyServiceCount( VOID )
 {
        return MyCount( CLIENT_SERVICE );
 } /* Client_MyServiceCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_MyServerCount( VOID )
 {
        CLIENT *c;
-       INT cnt;
+       LONG cnt;
 
        cnt = 0;
        c = My_Clients;
@@ -892,11 +893,11 @@ Client_MyServerCount( VOID )
 } /* Client_MyServerCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_OperCount( VOID )
 {
        CLIENT *c;
-       INT cnt;
+       LONG cnt;
 
        cnt = 0;
        c = My_Clients;
@@ -909,11 +910,11 @@ Client_OperCount( VOID )
 } /* Client_OperCount */
 
 
-GLOBAL INT
+GLOBAL LONG
 Client_UnknownCount( VOID )
 {
        CLIENT *c;
-       INT cnt;
+       LONG cnt;
 
        cnt = 0;
        c = My_Clients;
@@ -926,6 +927,20 @@ Client_UnknownCount( VOID )
 } /* Client_UnknownCount */
 
 
+GLOBAL LONG
+Client_MaxUserCount( VOID )
+{
+       return Max_Users;
+} /* Client_MaxUserCount */
+
+
+GLOBAL LONG
+Client_MyMaxUserCount( VOID )
+{
+       return My_Max_Users;
+} /* Client_MyMaxUserCount */
+
+
 GLOBAL BOOLEAN
 Client_IsValidNick( CHAR *Nick )
 {
@@ -953,11 +968,11 @@ Client_IsValidNick( CHAR *Nick )
 } /* Client_IsValidNick */
 
 
-LOCAL INT
+LOCAL LONG
 Count( CLIENT_TYPE Type )
 {
        CLIENT *c;
-       INT cnt;
+       LONG cnt;
 
        cnt = 0;
        c = My_Clients;
@@ -970,11 +985,11 @@ Count( CLIENT_TYPE Type )
 } /* Count */
 
 
-LOCAL INT
+LOCAL LONG
 MyCount( CLIENT_TYPE Type )
 {
        CLIENT *c;
-       INT cnt;
+       LONG cnt;
 
        cnt = 0;
        c = My_Clients;
@@ -1048,4 +1063,24 @@ Generate_MyToken( CLIENT *Client )
 } /* Generate_MyToken */
 
 
+LOCAL VOID
+Adjust_Counters( CLIENT *Client )
+{
+       LONG count;
+
+       assert( Client != NULL );
+
+       if( Client->type != CLIENT_USER ) return;
+       
+       if( Client->conn_id != NONE )
+       {
+               /* Local connection */
+               count = Client_MyUserCount( );
+               if( count > My_Max_Users ) My_Max_Users = count;
+       }
+       count = Client_UserCount( );
+       if( count > Max_Users ) Max_Users = count;
+} /* Adjust_Counters */
+
+
 /* -eof- */