2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * timestamp.c: Timestamp writer/maintainer thread
30 * Known contributors to this file:
39 #include "empthread.h"
41 #include "prototypes.h"
49 extern s_char *timestampfil;
50 extern int updating_mob;
51 struct mob_acc_globals timestamps;
58 /* logerror("Updating timestamp file at %s", ctime(&now));*/
60 if ((fp = fopen(timestampfil, "r+")) == NULL) {
62 if ((fp = fopen(timestampfil, "r+b")) == NULL) {
64 logerror("Unable to edit timestamp file.");
68 fread(×tamps, sizeof(timestamps), 1, fp);
69 timestamps.timestamp = now;
71 fwrite(×tamps, sizeof(timestamps), 1, fp);
73 if (!gamehours(now, hour)) {
74 if (updating_mob == 1) {
76 logerror("Turning off mobility updating (gamehours).");
79 } else if (updating_mob == 1 && now < timestamps.starttime) {
80 logerror("Turning off mobility updating at %s", ctime(&now));
83 } else if (updating_mob == 0 && now >= timestamps.starttime) {
84 logerror("Turning on mobility updating at %s", ctime(&now));
88 now = now + 180; /* Every 3 minutes */
98 extern s_char *timestampfil;
99 extern int updating_mob;
100 struct mob_acc_globals timestamps;
102 time_t lastsavedtime;
106 /* During downtime, we don't want mobility to accrue. So, we look
107 at the timestamp file, and determine how far forward to push
112 if ((fp = fopen(timestampfil, "r+")) == NULL) {
114 if ((fp = fopen(timestampfil, "r+b")) == NULL) {
116 logerror("Unable to edit timestamp file.");
119 fread(×tamps, sizeof(timestamps), 1, fp);
120 lastsavedtime = timestamps.timestamp;
121 timestamps.timestamp = now;
123 fwrite(×tamps, sizeof(timestamps), 1, fp);
127 logerror("Adjusting timestamps at %s",ctime(&now));
128 logerror("(was %s)",ctime(&lastsavedtime));
129 /* Update the timestamps to this point in time */
130 update_timestamps(lastsavedtime);
132 logerror("Done at %s", ctime(&now));
134 if (now >= timestamps.starttime && gamehours(now, hour)) {
135 logerror("Turning on mobility updating.");
138 logerror("Turning off mobility updating.");