From 77e4a80f977edd5be25df1197b52cf6926a805a6 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Wed, 15 Jan 2003 20:38:29 +0000
Subject: [PATCH] The incrementing of the stats.nusers field (new users today
 statistic) is now handled by newuserdat() instead of sbbs_t::logoffstats(),
 so the SS_NEWUSER sys_status bit has no internal use (but is still set). This
 change increments the new user counter sooner (at account creation, rather
 than logoff) and includes calls to the system.new_user() method in the stats.

---
 src/sbbs3/main.cpp  | 30 ++++++++----------------------
 src/sbbs3/userdat.c | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp
index 1ef66a6b72..369bf0c803 100644
--- a/src/sbbs3/main.cpp
+++ b/src/sbbs3/main.cpp
@@ -2867,17 +2867,9 @@ void sbbs_t::logoffstats()
 			errormsg(WHERE,ERR_OPEN,str,O_RDWR);
 			return; 
 		}
-		lseek(file,12L,SEEK_SET);   /* Skip timestamp, logons and logons today */
-		read(file,&stats.timeon,4);   /* Total time on system  */
-		read(file,&stats.ttoday,4); /* Time today on system  */
-		read(file,&stats.uls,4);        /* Uploads today         */
-		read(file,&stats.ulb,4);        /* Upload bytes today    */
-		read(file,&stats.dls,4);        /* Downloads today       */
-		read(file,&stats.dlb,4);        /* Download bytes today  */
-		read(file,&stats.ptoday,4); 	/* Posts today			 */
-		read(file,&stats.etoday,4); /* Emails today          */
-		read(file,&stats.ftoday,4); /* Feedback sent today  */
-		read(file,&stats.nusers,2); /* New users today		*/
+		memset(&stats,0,sizeof(stats));
+		lseek(file,4L,SEEK_SET);   /* Skip timestamp, logons and logons today */
+		read(file,&stats,sizeof(stats));  
 
 		if(!(useron.rest&FLAG('Q'))) {	/* Don't count QWKnet nodes */
 			stats.timeon+=(now-logontime)/60;
@@ -2890,20 +2882,14 @@ void sbbs_t::logoffstats()
 		stats.dlb+=logon_dlb;
 		stats.etoday+=logon_emails;
 		stats.ftoday+=logon_fbacks;
+
+#if 0 // This is now handled in newuserdat()
 		if(sys_status&SS_NEWUSER)
 			stats.nusers++;
+#endif
 
-		lseek(file,12L,SEEK_SET);
-		write(file,&stats.timeon,4);	/* Total time on system  */
-		write(file,&stats.ttoday,4);    /* Time today on system  */
-		write(file,&stats.uls,4);       /* Uploads today         */
-		write(file,&stats.ulb,4);       /* Upload bytes today    */
-		write(file,&stats.dls,4);       /* Downloads today       */
-		write(file,&stats.dlb,4);       /* Download bytes today  */
-		write(file,&stats.ptoday,4);    /* Posts today           */
-		write(file,&stats.etoday,4);    /* Emails today          */
-		write(file,&stats.ftoday,4);	/* Feedback sent today	 */
-		write(file,&stats.nusers,2);	/* New users today		 */
+		lseek(file,4L,SEEK_SET);
+		write(file,&stats,sizeof(stats));
 		close(file); 
 	}
 }
diff --git a/src/sbbs3/userdat.c b/src/sbbs3/userdat.c
index acd0adb017..788a507fb2 100644
--- a/src/sbbs3/userdat.c
+++ b/src/sbbs3/userdat.c
@@ -1744,12 +1744,14 @@ int DLLCALL newuserdat(scfg_t* cfg, user_t* user)
 	char	str[MAX_PATH+1];
 	char	tmp[128];
 	int		c;
+	int		i;
 	int		err;
 	int		file;
 	int		unum=1;
 	int		last;
 	long	misc;
 	FILE*	stream;
+	stats_t	stats;
 
 	sprintf(str,"%suser/name.dat",cfg->data_dir);
 	if(fexist(str)) {
@@ -1811,6 +1813,22 @@ int DLLCALL newuserdat(scfg_t* cfg, user_t* user)
 	sprintf(str,"%suser/%04u.sig",cfg->data_dir,user->number); /* delete signature */
 	remove(str);
 
+	/* Update daily statistics database (for system and node) */
+
+	for(i=0;i<2;i++) {
+		sprintf(str,"%sdsts.dab",i ? cfg->ctrl_dir : cfg->node_dir);
+		if((file=nopen(str,O_RDWR))==-1) {
+			return(errno); 
+		}
+		memset(&stats,0,sizeof(stats));
+		lseek(file,4L,SEEK_SET);   /* Skip timestamp */
+		read(file,&stats,sizeof(stats));  
+		stats.nusers++;
+		lseek(file,4L,SEEK_SET);
+		write(file,&stats,sizeof(stats));
+		close(file); 
+	}
+
 	return(0);
 }
 
-- 
GitLab