#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;
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)
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);
init_masters();
load_gs_dbase();
- load_timestamp();
+ load_day();
long int loadtime = time(NULL);
long int currentTime;
long int oldTime = loadtime;
end:
save_gs_dbase();
- save_timestamp();
+ save_day();
delete_monsters();
delete_masters();
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,