From: kainazzzo Date: Mon, 1 Mar 2004 06:39:04 +0000 (+0000) Subject: Redid the midnight code to use struct tm's tm_mday integer var instead of doing calcu... X-Git-Url: https://jfr.im/git/irc/gameservirc.git/commitdiff_plain/abbfcdb98cb62a64c07ec45e44d3cb60b0de4c17?hp=33ac4371df8917180a54eb3f79dfc5c1e2744156 Redid the midnight code to use struct tm's tm_mday integer var instead of doing calculations on time(NULL) git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@118 bc333340-6410-0410-a689-9d09f3c113fa --- diff --git a/gameserv/extern.h b/gameserv/extern.h index 477dc85..06c3dc8 100644 --- a/gameserv/extern.h +++ b/gameserv/extern.h @@ -25,11 +25,9 @@ #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; diff --git a/gameserv/gameserv.cpp b/gameserv/gameserv.cpp index 6ab518d..ddfea69 100644 --- a/gameserv/gameserv.cpp +++ b/gameserv/gameserv.cpp @@ -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) diff --git a/gameserv/tcpclient.cpp b/gameserv/tcpclient.cpp index 12e86cc..fa50bcb 100644 --- a/gameserv/tcpclient.cpp +++ b/gameserv/tcpclient.cpp @@ -39,12 +39,12 @@ char *PACKAGE = "GameServ"; char *VERSION = "1.1.8"; int sock; -long timestamp; +int day; List 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,