]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
Removed unnecessary #define of "LOCAL", now use plain C "static" instead.
[ngircd-alex.git] / src / ngircd / client.c
index faf95a6112a0d25ac8cbe8c152aa7514f97bfcad..84715813ffc7a2fd7ff85848cab7f3c7d8db6265 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: client.c,v 1.82 2005/06/04 12:32:09 fw Exp $";
+static char UNUSED id[] = "$Id: client.c,v 1.85 2005/07/31 20:13:08 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -50,19 +50,19 @@ static char UNUSED id[] = "$Id: client.c,v 1.82 2005/06/04 12:32:09 fw Exp $";
 #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
 
 
-LOCAL CLIENT *This_Server, *My_Clients;
-LOCAL char GetID_Buffer[GETID_LEN];
+static CLIENT *This_Server, *My_Clients;
+static char GetID_Buffer[GETID_LEN];
 
-LOCAL WHOWAS My_Whowas[MAX_WHOWAS];
-LOCAL int Last_Whowas = -1;
+static WHOWAS My_Whowas[MAX_WHOWAS];
+static int Last_Whowas = -1;
 
 
-LOCAL long Count PARAMS(( CLIENT_TYPE Type ));
-LOCAL long MyCount PARAMS(( CLIENT_TYPE Type ));
+static long Count PARAMS(( CLIENT_TYPE Type ));
+static 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 ));
+static CLIENT *New_Client_Struct PARAMS(( void ));
+static void Generate_MyToken PARAMS(( CLIENT *Client ));
+static void Adjust_Counters PARAMS(( CLIENT *Client ));
 
 #ifndef Client_DestroyNow
 GLOBAL void Client_DestroyNow PARAMS((CLIENT *Client ));
@@ -172,6 +172,7 @@ Client_New( CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, int Type, char *
        if( ! client ) return NULL;
 
        /* Initialisieren */
+       client->starttime = time(NULL);
        client->conn_id = Idx;
        client->introducer = Introducer;
        client->topserver = TopServer;
@@ -1021,7 +1022,20 @@ Client_GetLastWhowasIndex( void )
 } /* Client_GetLastWhowasIndex */
 
 
-LOCAL long
+/**
+ * Get the start time of this client.
+ * The result is the start time in seconds since 1970-01-01, as reported
+ * by the C function time(NULL).
+ */
+GLOBAL time_t
+Client_StartTime(CLIENT *Client)
+{
+       assert( Client != NULL );
+       return Client->starttime;
+} /* Client_Uptime */
+
+
+static long
 Count( CLIENT_TYPE Type )
 {
        CLIENT *c;
@@ -1038,7 +1052,7 @@ Count( CLIENT_TYPE Type )
 } /* Count */
 
 
-LOCAL long
+static long
 MyCount( CLIENT_TYPE Type )
 {
        CLIENT *c;
@@ -1055,7 +1069,7 @@ MyCount( CLIENT_TYPE Type )
 } /* MyCount */
 
 
-LOCAL CLIENT *
+static CLIENT *
 New_Client_Struct( void )
 {
        /* Neue CLIENT-Struktur pre-initialisieren */
@@ -1082,7 +1096,7 @@ New_Client_Struct( void )
 } /* New_Client */
 
 
-LOCAL void
+static void
 Generate_MyToken( CLIENT *Client )
 {
        CLIENT *c;
@@ -1106,7 +1120,7 @@ Generate_MyToken( CLIENT *Client )
 } /* Generate_MyToken */
 
 
-LOCAL void
+static void
 Adjust_Counters( CLIENT *Client )
 {
        long count;
@@ -1128,6 +1142,9 @@ Adjust_Counters( CLIENT *Client )
 
 /**
  * Register client in My_Whowas structure for further recall by WHOWAS.
+ * Note: Only clients that have been connected at least 30 seconds will be
+ * registered to prevent automated IRC bots to "destroy" a nice server
+ * history database.
  */
 GLOBAL void
 Client_RegisterWhowas( CLIENT *Client )
@@ -1136,6 +1153,10 @@ Client_RegisterWhowas( CLIENT *Client )
        
        assert( Client != NULL );
 
+       /* Don't register clients that were connected less than 30 seconds. */
+       if( time(NULL) - Client->starttime < 30 )
+               return;
+
        slot = Last_Whowas + 1;
        if( slot >= MAX_WHOWAS || slot < 0 ) slot = 0;