]> jfr.im git - irc/gameservirc.git/commitdiff
Redid the midnight code to use struct tm's tm_mday integer var instead of doing calcu...
authorkainazzzo <redacted>
Mon, 1 Mar 2004 06:39:04 +0000 (06:39 +0000)
committerkainazzzo <redacted>
Mon, 1 Mar 2004 06:39:04 +0000 (06:39 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@118 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/extern.h
gameserv/gameserv.cpp
gameserv/tcpclient.cpp

index 477dc85a5af2f80b781410df6f0032ffacbf978e..06c3dc8c28522d8783df112730fd74dc3529ce84 100644 (file)
 #endif
 
 
-// The timestamp from load time to be compared against the current midnight time.
-E long timestamp;
-E void save_timestamp();
-E void load_timestamp();
-E long int midnight(long int offset = 8);
+E int day;
+E void save_day();
+E void load_day();
 
 // The socket
 E int sock;
index 6ab518d1485078314c24c64788932aeeaa204e12..ddfea6975e13311b058e66a5d74eafda8aa84cf3 100644 (file)
@@ -148,13 +148,18 @@ void gameserv(char *source, char *buf)
        log("Source: %s  Command: %s", source, cmd);
     #endif
 
-    long int mn = midnight() - 12 * 3600; // 12 noon ;)
+    struct tm *tm;
+    time_t ti;
+    time(&ti);
+    tm = localtime(&ti);
 
-    if (mn > timestamp)
+    int curday = tm->tm_mday;
+
+    if (curday != day)
     {
         refreshall();
-        timestamp = mn;
-       save_timestamp();
+        day = curday;
+       save_day();
     }
 
     if (strnicmp(cmd, "\1PING", 6) == 0)
index 12e86cc430c0f954f22abdfd9e30b595e26b5385..fa50bcbf27e6f5b2b69c67084c0763a99dbc1a1b 100644 (file)
@@ -39,12 +39,12 @@ char *PACKAGE = "GameServ";
 char *VERSION = "1.1.8";
 
 int sock;
-long timestamp;
+int day;
 
 List<aClient> clients;
 
-void save_timestamp();
-void load_timestamp();
+void save_day();
+void load_day();
 
 // Make this a daemon
 int daemon(int nochdir, int noclose);
@@ -127,7 +127,7 @@ int main()
 
   init_masters();
   load_gs_dbase();
-  load_timestamp();
+  load_day();
   long int loadtime = time(NULL);
   long int currentTime;
   long int oldTime = loadtime;
@@ -351,7 +351,7 @@ int main()
   end:
 
   save_gs_dbase();
-  save_timestamp();
+  save_day();
 
   delete_monsters();
   delete_masters();
@@ -481,55 +481,56 @@ aClient *findbynick(const char *nick)
     return client;    
 }
 
-void load_timestamp()
+void load_day()
 {
     ifstream infile;
 
-    infile.open(".gstimestamp");
+    infile.open(".gsday");
 
     if (infile.fail())
     {
        #ifdef DEBUGMODE
-           log("Error opening .gstimestamp");
+           log("Error opening .gsday");
        #endif
 
        generate:
         #ifdef DEBUGMODE
-           log("Generating new timestamp");
+           log("Generating new day");
        #endif
-       timestamp = midnight();
-        save_timestamp();
+       struct tm *tm;
+       time_t ti;
+       time(&ti);
+       tm = localtime(&ti);
+
+       day = tm->tm_mday;
+
+        save_day();
        return;
     }
 
-    infile >> timestamp;
+    infile >> day;
     infile.close();
-    if (timestamp < 1000000)
+    if (day < 1 || day > 31)
        goto generate;
 }
 
-void save_timestamp()
+void save_day()
 {
     ofstream outfile;
 
-    outfile.open(".gstimestamp");
+    outfile.open(".gsday");
 
     if (outfile.fail())
     {
-       log("Error creating new file .gstimestamp");
+       log("Error creating new file .gsday");
        return;
     }
 
-    outfile << timestamp << endl;
+    outfile << day << endl;
 
     outfile.close();
 }
 
-long int midnight(long int offset)
-{
-    return (time(NULL) - (time(NULL) % 86400)) + (offset * 3600);
-}
-
 /* daemon() - detach process from user and disappear into the background
  * returns -1 on failure, but you can't do much except exit in that case
  * since we may already have forked. This is based on the BSD version,