]> git.pond.sub.org Git - empserver/blob - src/scripts/nightly/patches/All/emptime.c.patch
Correct the emptime.c.patch for player.c
[empserver] / src / scripts / nightly / patches / All / emptime.c.patch
1 diff --git a/include/emptime.h b/include/emptime.h
2 new file mode 100644
3 index 0000000..a83b29d
4 --- /dev/null
5 +++ b/include/emptime.h
6 @@ -0,0 +1,42 @@
7 +/*
8 + *  Empire - A multi-player, client/server Internet based war game.
9 + *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
10 + *                           Ken Stevens, Steve McClure
11 + *
12 + *  This program is free software; you can redistribute it and/or modify
13 + *  it under the terms of the GNU General Public License as published by
14 + *  the Free Software Foundation; either version 2 of the License, or
15 + *  (at your option) any later version.
16 + *
17 + *  This program is distributed in the hope that it will be useful,
18 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 + *  GNU General Public License for more details.
21 + *
22 + *  You should have received a copy of the GNU General Public License
23 + *  along with this program; if not, write to the Free Software
24 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25 + *
26 + *  ---
27 + *
28 + *  See files README, COPYING and CREDITS in the root of the source
29 + *  tree for related information and legal notices.  It is expected
30 + *  that future projects/authors will amend these files as needed.
31 + *
32 + *  ---
33 + *
34 + *  emptime.h: Time functions for regression testing and
35 + *             replaying journals.
36 + *
37 + *  Known contributors to this file:
38 + *     Ron Koenderink, 2008
39 + */
40 +
41 +#ifndef EMPTIME_H
42 +#define EMPTIME_H
43 +
44 +#include <time.h>
45 +
46 +#define empire_time(expr) emp_time((expr), __FUNCTION__)
47 +extern time_t emp_time(time_t *, const char []);
48 +#endif
49 diff --git a/include/commands.h b/include/commands.h
50 index 594d263..0b22f09 100644
51 --- a/include/commands.h
52 +++ b/include/commands.h
53 @@ -34,6 +34,7 @@
54  #ifndef COMMANDS_H
55  #define COMMANDS_H
56  
57 +#include "emptime.h"
58  #include "file.h"
59  #include "nat.h"
60  #include "player.h"
61 diff --git a/src/lib/commands/buy.c b/src/lib/commands/buy.c
62 index 7e4daf0..6e244cf 100644
63 --- a/src/lib/commands/buy.c
64 +++ b/src/lib/commands/buy.c
65 @@ -170,7 +170,7 @@ buy(void)
66      if (bid > 0.04 + comm.com_price) {
67         comm.com_price = bid;
68         /* Add five minutes to the time if less than 5 minutes */
69 -       time(&now);
70 +       empire_time(&now);
71         if (((MARK_DELAY - (now - comm.com_markettime)) < 300) &&
72             comm.com_maxbidder != player->cnum) {
73             comm.com_markettime += 300;
74 @@ -212,7 +212,7 @@ check_market(void)
75      for (n = 0; getcomm(n, &comm); n++) {
76         if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
77             continue;
78 -       (void)time(&now);
79 +       (void)empire_time(&now);
80         tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0;
81         if (tleft < 0)
82             tleft = 0;
83 diff --git a/src/lib/commands/coll.c b/src/lib/commands/coll.c
84 index 3fcb48f..2183d98 100644
85 --- a/src/lib/commands/coll.c
86 +++ b/src/lib/commands/coll.c
87 @@ -71,7 +71,7 @@ coll(void)
88      }
89      /* If we got here, we check to see if it's been defaulted on.  We
90         already know it's owed to this player. */
91 -    owed = loan_owed(&loan, time(&now));
92 +    owed = loan_owed(&loan, empire_time(&now));
93      if (now <= loan.l_duedate) {
94         pr("There has been no default on loan %d\n", arg);
95         return RET_FAIL;
96 @@ -124,7 +124,7 @@ coll(void)
97         caploss(&sect, loan.l_lonee, "that was %s's capital!\n");
98      putsect(&sect);
99      nreport(player->cnum, N_SEIZE_SECT, loan.l_lonee, 1);
100 -    owed = loan_owed(&loan, time(&now));
101 +    owed = loan_owed(&loan, empire_time(&now));
102      if (pay >= owed) {
103         loan.l_status = LS_FREE;
104         loan.l_ldur = 0;
105 @@ -135,7 +135,7 @@ coll(void)
106            xyas(sect.sct_x, sect.sct_y, loan.l_lonee), arg);
107         pr("That loan is now considered repaid.\n");
108      } else {
109 -       (void)time(&loan.l_lastpay);
110 +       (void)empire_time(&loan.l_lastpay);
111         owed -= pay;
112         loan.l_amtdue = (long)owed;
113         pay += loan.l_amtpaid;
114 diff --git a/src/lib/commands/cons.c b/src/lib/commands/cons.c
115 index d67e64e..30d1ca1 100644
116 --- a/src/lib/commands/cons.c
117 +++ b/src/lib/commands/cons.c
118 @@ -229,7 +229,7 @@ loan_accept(struct ltcomstr *ltcp)
119      putnat(lender);
120      player->dolcost -= lp->l_amtdue;
121      lp->l_amtpaid = 0;
122 -    (void)time(&lp->l_lastpay);
123 +    (void)empire_time(&lp->l_lastpay);
124      lp->l_duedate = lp->l_ldur * 86400 + lp->l_lastpay;
125      lp->l_status = LS_SIGNED;
126      if (!putloan(ltcp->num, lp)) {
127 diff --git a/src/lib/commands/dump.c b/src/lib/commands/dump.c
128 index 3ad1f21..fa009f0 100644
129 --- a/src/lib/commands/dump.c
130 +++ b/src/lib/commands/dump.c
131 @@ -241,7 +241,7 @@ dump(void)
132  
133      if (player->god)
134         pr("   ");
135 -    time(&now);
136 +    empire_time(&now);
137      pr("DUMP SECTOR %ld\n", (long)now);
138      if (player->god)
139         pr("own ");
140 diff --git a/src/lib/commands/fina.c b/src/lib/commands/fina.c
141 index a6add31..e458c28 100644
142 --- a/src/lib/commands/fina.c
143 +++ b/src/lib/commands/fina.c
144 @@ -55,7 +55,7 @@ fina(void)
145      }
146      if (!snxtitem(&ni, EF_LOAN, "*", NULL))
147         return RET_SYN;
148 -    (void)time(&now);
149 +    (void)empire_time(&now);
150      pr("\n");
151      pr("             -= Empire Financial Status Report =- \n");
152      pr("                  ");
153 diff --git a/src/lib/commands/flash.c b/src/lib/commands/flash.c
154 index 787e4a4..8517ccb 100644
155 --- a/src/lib/commands/flash.c
156 +++ b/src/lib/commands/flash.c
157 @@ -122,7 +122,7 @@ sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
158      int sent = 0;
159      struct natstr *wto;
160  
161 -    time(&now);
162 +    empire_time(&now);
163      tm = localtime(&now);
164      for (other = player_next(0); other != 0; other = player_next(other)) {
165         if (other->state != PS_PLAYING)
166 diff --git a/src/lib/commands/head.c b/src/lib/commands/head.c
167 index 2b1c148..e0ddb7a 100644
168 --- a/src/lib/commands/head.c
169 +++ b/src/lib/commands/head.c
170 @@ -66,7 +66,7 @@ head(void)
171      struct nstr_item nstr;
172      int i, n;
173  
174 -    (void)time(&now);
175 +    (void)empire_time(&now);
176      natp = getnatp(player->cnum);
177      if (player->argp[1] != 0 && *player->argp[1] != 0) {
178         news_per = days(atoi(player->argp[1]));
179 diff --git a/src/lib/commands/ldump.c b/src/lib/commands/ldump.c
180 index 930810f..16dcf0c 100644
181 --- a/src/lib/commands/ldump.c
182 +++ b/src/lib/commands/ldump.c
183 @@ -157,7 +157,7 @@ ldump(void)
184  
185      if (player->god)
186         pr("   ");
187 -    time(&now);
188 +    empire_time(&now);
189      pr("DUMP LAND UNITS %ld\n", (long)now);
190      if (player->god)
191         pr("own ");
192 diff --git a/src/lib/commands/lost.c b/src/lib/commands/lost.c
193 index ad76e59..c302f21 100644
194 --- a/src/lib/commands/lost.c
195 +++ b/src/lib/commands/lost.c
196 @@ -51,7 +51,7 @@ lost(void)
197  
198      prdate();
199      nlost = 0;
200 -    time(&now);
201 +    empire_time(&now);
202      pr("DUMP LOST ITEMS %ld\n", (long)now);
203      if (player->god)
204         pr("owner ");
205 diff --git a/src/lib/commands/mark.c b/src/lib/commands/mark.c
206 index f857444..6ec322d 100644
207 --- a/src/lib/commands/mark.c
208 +++ b/src/lib/commands/mark.c
209 @@ -74,7 +74,7 @@ pr_mark(struct comstr *comm)
210      time_t now;
211      double tleft;
212  
213 -    (void)time(&now);
214 +    (void)empire_time(&now);
215      tleft = MARK_DELAY / 3600.0 - (now - comm->com_markettime) / 3600.0;
216      if (tleft < 0.0)
217         tleft = 0.0;
218 diff --git a/src/lib/commands/ndump.c b/src/lib/commands/ndump.c
219 index 927db4f..d081d13 100644
220 --- a/src/lib/commands/ndump.c
221 +++ b/src/lib/commands/ndump.c
222 @@ -50,7 +50,7 @@ ndump(void)
223      prdate();
224      if (player->god)
225         pr("   ");
226 -    time(&now);
227 +    empire_time(&now);
228      pr("DUMP NUKES %ld\n", (long)now);
229      if (player->god)
230         pr("own ");
231 diff --git a/src/lib/commands/news.c b/src/lib/commands/news.c
232 index 0095170..e365be2 100644
233 --- a/src/lib/commands/news.c
234 +++ b/src/lib/commands/news.c
235 @@ -65,7 +65,7 @@ news(void)
236         return RET_SYN;
237      memset(page_has_news, 0, sizeof(page_has_news));
238      memset(sectors_taken, 0, sizeof(sectors_taken));
239 -    (void)time(&now);
240 +    (void)empire_time(&now);
241      natp = getnatp(player->cnum);
242      then = natp->nat_newstim;
243      if (player->argp[1]) {
244 diff --git a/src/lib/commands/offe.c b/src/lib/commands/offe.c
245 index 01570b5..01c40c6 100644
246 --- a/src/lib/commands/offe.c
247 +++ b/src/lib/commands/offe.c
248 @@ -127,7 +127,7 @@ do_treaty(void)
249         pr("Bad treaty duration.\n");
250         return RET_SYN;
251      }
252 -    (void)time(&now);
253 +    (void)empire_time(&now);
254      snxtitem_all(&nstr, EF_TREATY);
255      while (nxtitem(&nstr, &trty)) {
256         if (trty.trt_status == TS_FREE) {
257 @@ -228,7 +228,7 @@ do_loan(void)
258      loan.l_ldur = MIN(dur, 127);
259      loan.l_amtpaid = 0;
260      loan.l_amtdue = amt;
261 -    (void)time(&loan.l_lastpay);
262 +    (void)empire_time(&loan.l_lastpay);
263      loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
264      if (!putloan(nstr.cur, &loan)) {
265         logerror("do_loan: can't save loan");
266 diff --git a/src/lib/commands/pdump.c b/src/lib/commands/pdump.c
267 index 48f0f4d..51578b1 100644
268 --- a/src/lib/commands/pdump.c
269 +++ b/src/lib/commands/pdump.c
270 @@ -119,7 +119,7 @@ pdump(void)
271  
272      if (player->god)
273         pr("   ");
274 -    time(&now);
275 +    empire_time(&now);
276      pr("DUMP PLANES %ld\n", (long)now);
277      if (player->god)
278         pr("own ");
279 diff --git a/src/lib/commands/play.c b/src/lib/commands/play.c
280 index a4ab28a..eb5c9f6 100644
281 --- a/src/lib/commands/play.c
282 +++ b/src/lib/commands/play.c
283 @@ -96,7 +96,7 @@ play_list(struct player *joe)
284         }
285      }
286  
287 -    time(&now);
288 +    empire_time(&now);
289      pr("%-9.9s %3d %32.32s %2d:%02d %4lds",
290         cname(joe->cnum),
291         joe->cnum,
292 diff --git a/src/lib/commands/powe.c b/src/lib/commands/powe.c
293 index 2367002..74cf745 100644
294 --- a/src/lib/commands/powe.c
295 +++ b/src/lib/commands/powe.c
296 @@ -87,7 +87,7 @@ powe(void)
297                 pr("\n  power new is disabled, using the last report.\n\n");
298             else {
299                 gen_power(powbuf, save);
300 -               pow_time = time(NULL);
301 +               pow_time = empire_time(NULL);
302                 power_generated = 1;
303             }
304         }
305 diff --git a/src/lib/commands/rea.c b/src/lib/commands/rea.c
306 index 5de2bb2..f9d7c71 100644
307 --- a/src/lib/commands/rea.c
308 +++ b/src/lib/commands/rea.c
309 @@ -76,7 +76,7 @@ rea(void)
310      int readit;
311      int may_delete = 1; /* may messages be deleted? */
312  
313 -    now = time(NULL);
314 +    now = empire_time(NULL);
315  
316      if (*player->argp[0] == 'w') {
317         kind = "announcement";
318 @@ -188,7 +188,7 @@ rea(void)
319                 (void)fflush(telfp);
320                 (void)fseek(telfp, (long)size, SEEK_SET);
321                 size = filelen;
322 -               now = time(NULL);
323 +               now = empire_time(NULL);
324                 goto more;
325             }
326             if (*kind == 'a') {
327 diff --git a/src/lib/commands/repa.c b/src/lib/commands/repa.c
328 index 77a4734..c9b4079 100644
329 --- a/src/lib/commands/repa.c
330 +++ b/src/lib/commands/repa.c
331 @@ -76,7 +76,7 @@ repa(void)
332      if (payment <= 0)
333         return RET_SYN;
334  
335 -    newdue = (long)ceil(loan_owed(&loan, time(&now)) - payment);
336 +    newdue = (long)ceil(loan_owed(&loan, empire_time(&now)) - payment);
337      if (newdue < 0) {
338         pr("You don't owe that much.\n");
339         return RET_FAIL;
340 diff --git a/src/lib/commands/rese.c b/src/lib/commands/rese.c
341 index bfb64d2..7ffcf5d 100644
342 --- a/src/lib/commands/rese.c
343 +++ b/src/lib/commands/rese.c
344 @@ -131,7 +131,7 @@ rese(void)
345         return RET_OK;
346      }
347      comm.com_price = price;
348 -    (void)time(&now);
349 +    (void)empire_time(&now);
350      comm.com_markettime = now;
351      if (!putcomm(number_set, &comm)) {
352         pr("Problems with the commodities file, Call the Deity\n");
353 diff --git a/src/lib/commands/sdump.c b/src/lib/commands/sdump.c
354 index 95899e5..f52bcb9 100644
355 --- a/src/lib/commands/sdump.c
356 +++ b/src/lib/commands/sdump.c
357 @@ -143,7 +143,7 @@ sdump(void)
358  
359      if (player->god)
360         pr("   ");
361 -    time(&now);
362 +    empire_time(&now);
363      pr("DUMP SHIPS %ld\n", (long)now);
364      if (player->god)
365         pr("own ");
366 diff --git a/src/lib/commands/sell.c b/src/lib/commands/sell.c
367 index e6ad4ea..78dd5fc 100644
368 --- a/src/lib/commands/sell.c
369 +++ b/src/lib/commands/sell.c
370 @@ -143,7 +143,7 @@ sell(void)
371             if (comm.com_owner == 0)
372                 break;
373         }
374 -       (void)time(&now);
375 +       (void)empire_time(&now);
376         ef_blank(EF_COMM, ii, &comm);
377         comm.com_type = ip->i_uid;
378         comm.com_owner = player->cnum;
379 diff --git a/src/lib/commands/set.c b/src/lib/commands/set.c
380 index dcda303..e93d7ba 100644
381 --- a/src/lib/commands/set.c
382 +++ b/src/lib/commands/set.c
383 @@ -130,7 +130,7 @@ set(void)
384             trade.trd_owner = player->cnum;
385             trade.trd_unitid = ni.cur;
386             trade.trd_price = price;
387 -           (void)time(&now);
388 +           (void)empire_time(&now);
389             trade.trd_markettime = now;
390             trade.trd_maxbidder = player->cnum;
391             puttrade(id, &trade);
392 diff --git a/src/lib/commands/shark.c b/src/lib/commands/shark.c
393 index ec38b3c..bc4af9a 100644
394 --- a/src/lib/commands/shark.c
395 +++ b/src/lib/commands/shark.c
396 @@ -72,7 +72,7 @@ shark(void)
397         return RET_FAIL;
398      }
399      /* If we got here, we check to see if it's been defaulted on. */
400 -    owed = loan_owed(&loan, time(&now));
401 +    owed = loan_owed(&loan, empire_time(&now));
402      if (now <= loan.l_duedate) {
403         pr("There has been no default on loan %d\n", arg);
404         return RET_FAIL;
405 diff --git a/src/lib/commands/trad.c b/src/lib/commands/trad.c
406 index 5b0af58..e3a440b 100644
407 --- a/src/lib/commands/trad.c
408 +++ b/src/lib/commands/trad.c
409 @@ -97,7 +97,7 @@ trad(void)
410             continue;
411         };
412         pr(" %3d ", ni.cur);
413 -       (void)time(&now);
414 +       (void)empire_time(&now);
415         tleft =
416             TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0;
417         if (tleft < 0.0)
418 @@ -252,7 +252,7 @@ trad(void)
419      }
420      if (bid > trade.trd_price) {
421         /* Add five minutes to the time if less than 5 minutes left. */
422 -       time(&now);
423 +       empire_time(&now);
424         if (((TRADE_DELAY - (now - trade.trd_markettime)) < 300) &&
425             trade.trd_maxbidder != player->cnum)
426             trade.trd_markettime += 300;
427 @@ -306,7 +306,7 @@ check_trade(void)
428         if (trade.trd_owner == trade.trd_maxbidder)
429             continue;
430  
431 -       (void)time(&now);
432 +       (void)empire_time(&now);
433         tleft =
434             TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0;
435         if (tleft < 0.0)
436 diff --git a/src/lib/commands/turn.c b/src/lib/commands/turn.c
437 index 640cef8..d5d9c19 100644
438 --- a/src/lib/commands/turn.c
439 +++ b/src/lib/commands/turn.c
440 @@ -74,7 +74,7 @@ turn(void)
441      else
442         pr("Enter a new message of the day.\n");
443  
444 -    time(&tgm.tel_date);
445 +    empire_time(&tgm.tel_date);
446      tgm.tel_length = getele("The World", msgbuf);
447      if (tgm.tel_length < 0) {
448         pr("Ignored\n");
449 diff --git a/src/lib/commands/upda.c b/src/lib/commands/upda.c
450 index 3ba68a1..0508a63 100644
451 --- a/src/lib/commands/upda.c
452 +++ b/src/lib/commands/upda.c
453 @@ -50,7 +50,7 @@ upda(void)
454      if (updates_disabled())
455         pr("UPDATES ARE DISABLED!\n");
456  
457 -    (void)time(&now);
458 +    (void)empire_time(&now);
459      next = update_time[0];
460      if (next) {
461         pr("\nUpdates occur at times specified by the ETU rates.\n\n");
462 diff --git a/src/lib/commands/vers.c b/src/lib/commands/vers.c
463 index 6e618c0..9e90299 100644
464 --- a/src/lib/commands/vers.c
465 +++ b/src/lib/commands/vers.c
466 @@ -54,7 +54,7 @@ vers(void)
467  {
468      time_t now;
469  
470 -    (void)time(&now);
471 +    (void)empire_time(&now);
472      pr("%s\n\n", version);
473      pr("The following parameters have been set for this game:\n");
474      pr("World size is %d by %d.\n", WORLD_X, WORLD_Y);
475 diff --git a/src/lib/common/file.c b/src/lib/common/file.c
476 index 8b0962f..e289f2f 100644
477 --- a/src/lib/common/file.c
478 +++ b/src/lib/common/file.c
479 @@ -40,6 +40,7 @@
480  #include <sys/stat.h>
481  #include <sys/types.h>
482  #include <unistd.h>
483 +#include "emptime.h"
484  #include "file.h"
485  #include "match.h"
486  #include "misc.h"
487 @@ -424,7 +425,7 @@ do_write(struct empfile *ep, void *buf, int id, int count)
488         return -1;
489  
490      if (ep->flags & EFF_TYPED) {
491 -       now = ep->flags & EFF_NOTIME ? (time_t)-1 : time(NULL);
492 +       now = ep->flags & EFF_NOTIME ? (time_t)-1 : empire_time(NULL);
493         for (i = 0; i < count; i++) {
494             /*
495              * TODO Oopses here could be due to bad data corruption.
496 diff --git a/src/lib/common/game.c b/src/lib/common/game.c
497 index 0800d62..48c5401 100644
498 --- a/src/lib/common/game.c
499 +++ b/src/lib/common/game.c
500 @@ -44,6 +44,7 @@
501  #include <config.h>
502  
503  #include <math.h>
504 +#include "emptime.h"
505  #include "file.h"
506  #include "game.h"
507  #include "optlist.h"
508 @@ -81,7 +82,7 @@ game_note_bsanct(void)
509      struct gamestr *game = getgamep();
510  
511      if (game->game_rt == 0) {
512 -       game->game_rt = time(NULL);
513 +       game->game_rt = empire_time(NULL);
514         putgame();
515      }
516  }
517 @@ -130,7 +131,7 @@ game_tick_tick(void)
518      double dsecs, s_p_etu;
519      int detu;
520  
521 -    dsecs = time(NULL) - game->game_rt;
522 +    dsecs = empire_time(NULL) - game->game_rt;
523      if (CANT_HAPPEN(dsecs < 0))
524         dsecs = 0;
525      s_p_etu = secs_per_etu(game);
526 diff --git a/src/lib/common/wantupd.c b/src/lib/common/wantupd.c
527 index 07c3db0..03e3e0a 100644
528 --- a/src/lib/common/wantupd.c
529 +++ b/src/lib/common/wantupd.c
530 @@ -34,6 +34,7 @@
531  #include <config.h>
532  
533  #include <time.h>
534 +#include "emptime.h"
535  #include "file.h"
536  #include "game.h"
537  #include "misc.h"
538 @@ -102,7 +103,7 @@ demand_check(void)
539  int
540  demandupdatecheck(void)
541  {
542 -    time_t now = time(NULL);
543 +    time_t now = empire_time(NULL);
544  
545      return update_demand == UPD_DEMAND_ASYNC
546         && !updates_disabled()
547 diff --git a/src/lib/common/xdump.c b/src/lib/common/xdump.c
548 index 5d131c9..2ee5f79 100644
549 --- a/src/lib/common/xdump.c
550 +++ b/src/lib/common/xdump.c
551 @@ -77,6 +77,7 @@
552  
553  #include <ctype.h>
554  #include <limits.h>
555 +#include "emptime.h"
556  #include "file.h"
557  #include "nat.h"
558  #include "xdump.h"
559 @@ -263,7 +264,7 @@ xdhdr(struct xdstr *xd, char *name, int meta)
560      } else
561         xd->pr("XDUMP %s%s %ld\n",
562                meta ? "meta " : "",
563 -              name, (long)time(NULL));
564 +              name, (long)empire_time(NULL));
565  }
566  
567  /*
568 diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c
569 index b55f29b..9440a63 100644
570 --- a/src/lib/empthread/lwp.c
571 +++ b/src/lib/empthread/lwp.c
572 @@ -37,6 +37,7 @@
573  #include <signal.h>
574  #include <time.h>
575  #include "empthread.h"
576 +#include "emptime.h"
577  #include "misc.h"
578  
579  /* Flags that were passed to empth_init() */
580 @@ -136,7 +137,7 @@ empth_wait_for_signal(void)
581      for (;;) {
582         err = lwpSigWait(&set, &sig);
583         if (CANT_HAPPEN(err)) {
584 -           time(&now);
585 +           empire_time(&now);
586             lwpSleepUntil(now + 60);
587             continue;
588         }
589 diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c
590 index 4056c36..a4c4428 100644
591 --- a/src/lib/empthread/ntthread.c
592 +++ b/src/lib/empthread/ntthread.c
593 @@ -62,6 +62,7 @@
594  #include "unistd.h"
595  #include "misc.h"
596  #include "empthread.h"
597 +#include "emptime.h"
598  #include "prototypes.h"
599  #include "server.h"
600  
601 @@ -637,7 +638,7 @@ empth_wakeup(empth_t *pThread)
602  int
603  empth_sleep(time_t until)
604  {
605 -    long lSec = until - time(0) > 0 ? until - time(0) : 0;
606 +    long lSec = until - empire_time(0) > 0 ? until - empire_time(0) : 0;
607      empth_t *pThread = TlsGetValue(dwTLSIndex);
608      int iReturn = 0;
609  
610 @@ -651,7 +652,7 @@ empth_sleep(time_t until)
611  
612         loc_debug("sleep done. Waiting to run.");
613         loc_RunThisThread(NULL);
614 -    } while (!iReturn && ((lSec = until - time(0)) > 0));
615 +    } while (!iReturn && ((lSec = until - empire_time(0)) > 0));
616  
617      return iReturn;
618  }
619 diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c
620 index 3f56fbc..1a1078c 100644
621 --- a/src/lib/empthread/pthread.c
622 +++ b/src/lib/empthread/pthread.c
623 @@ -53,6 +53,7 @@
624  
625  #include "misc.h"
626  #include "empthread.h"
627 +#include "emptime.h"
628  #include "prototypes.h"
629  
630  #define EMPTH_KILLED  1
631 @@ -378,10 +379,10 @@ empth_sleep(time_t until)
632      struct timeval tv;
633      int res;
634  
635 -    empth_status("going to sleep %ld sec", until - time(0));
636 +    empth_status("going to sleep %ld sec", until - empire_time(0));
637      pthread_mutex_unlock(&mtx_ctxsw);
638      do {
639 -       tv.tv_sec = until - time(NULL);
640 +       tv.tv_sec = until - empire_time(NULL);
641         tv.tv_usec = 0;
642         res = select(0, NULL, NULL, NULL, &tv);
643      } while (res < 0 && ctx->state == 0);
644 diff --git a/src/lib/gen/emptime.c b/src/lib/gen/emptime.c
645 new file mode 100644
646 index 0000000..855de99
647 --- /dev/null
648 +++ b/src/lib/gen/emptime.c
649 @@ -0,0 +1,51 @@
650 +/*
651 + *  Empire - A multi-player, client/server Internet based war game.
652 + *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
653 + *                           Ken Stevens, Steve McClure
654 + *
655 + *  This program is free software; you can redistribute it and/or modify
656 + *  it under the terms of the GNU General Public License as published by
657 + *  the Free Software Foundation; either version 2 of the License, or
658 + *  (at your option) any later version.
659 + *
660 + *  This program is distributed in the hope that it will be useful,
661 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
662 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
663 + *  GNU General Public License for more details.
664 + *
665 + *  You should have received a copy of the GNU General Public License
666 + *  along with this program; if not, write to the Free Software
667 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
668 + *
669 + *  ---
670 + *
671 + *  See files README, COPYING and CREDITS in the root of the source
672 + *  tree for related information and legal notices.  It is expected
673 + *  that future projects/authors will amend these files as needed.
674 + *
675 + *  ---
676 + *
677 + *  emptime.c: Time functions for regression testing and
678 + *             replaying journals.
679 + *
680 + *  Known contributors to this file:
681 + *     Ron Koenderink, 2008
682 + */
683 +
684 +#include <stdio.h>
685 +#include <string.h>
686 +#include "emptime.h"
687 +
688 +time_t
689 +emp_time(time_t * time_ptr, const char function[])
690 +{
691 +    static time_t now = (time_t)100L;
692 +
693 +    if (strcmp(function, "update_main") == 0)
694 +       now += 100L;
695 +
696 +    if (time_ptr != NULL)
697 +       *time_ptr = now;
698 +
699 +    return now;
700 +}
701 diff --git a/src/lib/gen/log.c b/src/lib/gen/log.c
702 index 7f57182..bc78466 100644
703 --- a/src/lib/gen/log.c
704 +++ b/src/lib/gen/log.c
705 @@ -41,6 +41,7 @@
706  #include <sys/stat.h>
707  #include <time.h>
708  #include <unistd.h>
709 +#include "emptime.h"
710  #include "misc.h"
711  #include "optlist.h"
712  #include "player.h"
713 @@ -116,7 +117,7 @@ logerror(char *format, ...)
714      p[1] = 0;
715      fputs(msg, stderr);
716      if (logfd >= 0) {
717 -       time(&now);
718 +       empire_time(&now);
719         memcpy(buf, ctime(&now), ctime_len);
720         buf[ctime_len] = ' ';
721         write(logfd, buf, strlen(buf));
722 diff --git a/src/lib/lwp/sel.c b/src/lib/lwp/sel.c
723 index 2cafa08..988d091 100644
724 --- a/src/lib/lwp/sel.c
725 +++ b/src/lib/lwp/sel.c
726 @@ -39,6 +39,7 @@
727  #include <sys/time.h>
728  #include <time.h>
729  #include <unistd.h>
730 +#include "emptime.h"
731  #include "lwp.h"
732  #include "lwpint.h"
733  #include "prototypes.h"
734 @@ -144,7 +145,7 @@ lwpWakeupSleep(void)
735      struct lwpProc *proc;
736  
737      if (LwpDelayq.head) {
738 -       now = time(NULL);
739 +       now = empire_time(NULL);
740         save.tail = save.head = 0;
741         while (NULL != (proc = lwpGetFirst(&LwpDelayq))) {
742             if (now >= proc->runtime) {
743 @@ -175,7 +176,7 @@ lwpSleepUntil(time_t until)
744      int res;
745  
746      lwpStatus(LwpCurrent, "sleeping for %ld sec",
747 -             (long)(until - time(NULL)));
748 +             (long)(until - empire_time(NULL)));
749      LwpCurrent->runtime = until;
750      if (LwpMaxfd == 0 && LwpDelayq.head == 0) {
751         /* select process is sleeping until first waiter arrives */
752 @@ -219,7 +220,7 @@ lwpSelect(void *arg)
753         tv.tv_sec = 1000000;
754         tv.tv_usec = 0;
755         if (LwpDelayq.head) {
756 -           time(&now);
757 +           empire_time(&now);
758             proc = LwpDelayq.head;
759             for (; proc != 0; proc = proc->next) {
760                 delta = proc->runtime - now;
761 diff --git a/src/lib/player/accept.c b/src/lib/player/accept.c
762 index 3106849..726b5fc 100644
763 --- a/src/lib/player/accept.c
764 +++ b/src/lib/player/accept.c
765 @@ -45,6 +45,7 @@
766  
767  #include "empio.h"
768  #include "empthread.h"
769 +#include "emptime.h"
770  #include "file.h"
771  #include "misc.h"
772  #include "nat.h"
773 @@ -91,7 +92,7 @@ player_new(int s)
774         emp_insque(&lp->queue, &Players);
775         lp->cnum = NATID_BAD;
776         lp->curid = -1;
777 -       time(&lp->curup);
778 +       empire_time(&lp->curup);
779      }
780      return lp;
781  }
782 diff --git a/src/lib/player/player.c b/src/lib/player/player.c
783 index 513382b..4b97be7 100644
784 --- a/src/lib/player/player.c
785 +++ b/src/lib/player/player.c
786 @@ -40,6 +40,7 @@
787  #include "com.h"
788  #include "empio.h"
789  #include "empthread.h"
790 +#include "emptime.h"
791  #include "file.h"
792  #include "journal.h"
793  #include "misc.h"
794 @@ -65,8 +66,8 @@ player_main(struct player *p)
795  
796      p->state = PS_PLAYING;
797      player = p;
798 -    time(&player->lasttime);
799 -    time(&player->curup);
800 +    empire_time(&player->lasttime);
801 +    empire_time(&player->curup);
802      show_motd();
803      if (init_nats() < 0) {
804         pr("Server confused, try again later\n");
805 @@ -100,7 +101,7 @@ player_main(struct player *p)
806      strcpy(natp->nat_hostname, player->hostname);
807      strcpy(natp->nat_hostaddr, player->hostaddr);
808  
809 -    time(&natp->nat_last_login);
810 +    empire_time(&natp->nat_last_login);
811      putnat(natp);
812      journal_login();
813      if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
814 @@ -123,7 +124,7 @@ player_main(struct player *p)
815       * randomly round up to the nearest minute,
816       * charging at least 15 seconds.
817       */
818 -    time(&natp->nat_last_logout);
819 +    empire_time(&natp->nat_last_logout);
820      secs = MAX(natp->nat_last_logout - player->lasttime, 15);
821      natp->nat_minused += secs / 60;
822      secs = secs % 60;
823 @@ -182,7 +183,7 @@ status(void)
824      if (!(old_nstat & MONEY) && (player->nstat & MONEY))
825         pr("You are no longer broke!\n");
826  
827 -    time(&player->curup);
828 +    empire_time(&player->curup);
829      minute = (player->curup - player->lasttime) / 60;
830      if (minute > 0) {
831         player->minleft -= minute;
832 diff --git a/src/lib/player/recvclient.c b/src/lib/player/recvclient.c
833 index ab4ef69..8934189 100644
834 --- a/src/lib/player/recvclient.c
835 +++ b/src/lib/player/recvclient.c
836 @@ -35,6 +35,7 @@
837  #include <config.h>
838  
839  #include "empio.h"
840 +#include "emptime.h"
841  #include "journal.h"
842  #include "player.h"
843  #include "prototypes.h"
844 @@ -102,7 +103,7 @@ recvclient(char *cmd, int size)
845              * check errors; oops once, then slow it down drastically.
846              */
847             CANT_HAPPEN(player->recvfail == 256);
848 -           empth_sleep(time(NULL) + 60);
849 +           empth_sleep(empire_time(NULL) + 60);
850         }
851         return player->eof ? -1 : -2;
852      }
853 diff --git a/src/lib/subs/disloan.c b/src/lib/subs/disloan.c
854 index 9a6c670..9d7b6ba 100644
855 --- a/src/lib/subs/disloan.c
856 +++ b/src/lib/subs/disloan.c
857 @@ -46,6 +46,7 @@
858  
859  #include <config.h>
860  
861 +#include "emptime.h"
862  #include "file.h"
863  #include "loan.h"
864  #include "nat.h"
865 @@ -64,7 +65,7 @@ disloan(int n, struct lonstr *loan)
866         return 0;
867      if (loan->l_loner != player->cnum && loan->l_lonee != player->cnum)
868         return 0;
869 -    (void)time(&now);
870 +    (void)empire_time(&now);
871      pr("\nLoan #%d from %s to", n, cname(loan->l_loner));
872      pr(" %s\n", cname(loan->l_lonee));
873      if (loan->l_status == LS_PROPOSED) {
874 diff --git a/src/lib/subs/distrea.c b/src/lib/subs/distrea.c
875 index bfb182c..45f80ae 100644
876 --- a/src/lib/subs/distrea.c
877 +++ b/src/lib/subs/distrea.c
878 @@ -33,6 +33,7 @@
879  
880  #include <config.h>
881  
882 +#include "emptime.h"
883  #include "file.h"
884  #include "nat.h"
885  #include "player.h"
886 @@ -51,7 +52,7 @@ distrea(int n, struct trtstr *tp)
887      if (tp->trt_cna != player->cnum &&
888         tp->trt_cnb != player->cnum && !player->god)
889         return 0;
890 -    (void)time(&now);
891 +    (void)empire_time(&now);
892      if (now > tp->trt_exp) {
893         tp->trt_status = TS_FREE;
894         if (!puttre(n, tp)) {
895 diff --git a/src/lib/subs/journal.c b/src/lib/subs/journal.c
896 index 4f553c5..c8bb70c 100644
897 --- a/src/lib/subs/journal.c
898 +++ b/src/lib/subs/journal.c
899 @@ -57,6 +57,7 @@
900  #include <time.h>
901  #include "misc.h"
902  #include "empthread.h"
903 +#include "emptime.h"
904  #include "journal.h"
905  #include "optlist.h"
906  #include "player.h"
907 @@ -83,7 +84,7 @@ journal_entry(char *fmt, ...)
908      unsigned char *p;
909  
910      if (journal) {
911 -       time(&now);
912 +       empire_time(&now);
913         fprintf(journal, "%.24s %10.10s ",
914                 ctime(&now), empth_name(empth_self()));
915  
916 diff --git a/src/lib/subs/lostsub.c b/src/lib/subs/lostsub.c
917 index 2d0d046..8b2ea25 100644
918 --- a/src/lib/subs/lostsub.c
919 +++ b/src/lib/subs/lostsub.c
920 @@ -34,6 +34,7 @@
921  
922  #include <config.h>
923  
924 +#include "emptime.h"
925  #include "file.h"
926  #include "lost.h"
927  #include "misc.h"
928 @@ -124,7 +125,7 @@ findlost(short type, natid owner, short id, coord x, coord y, int free)
929  void
930  delete_old_lostitems(void)
931  {
932 -    time_t expiry_time = time(NULL) - hours(lost_keep_hours);
933 +    time_t expiry_time = empire_time(NULL) - hours(lost_keep_hours);
934      struct loststr lost;
935      int i;
936  
937 diff --git a/src/lib/subs/nreport.c b/src/lib/subs/nreport.c
938 index 2e83326..5600a5a 100644
939 --- a/src/lib/subs/nreport.c
940 +++ b/src/lib/subs/nreport.c
941 @@ -36,6 +36,7 @@
942  
943  #include <config.h>
944  
945 +#include "emptime.h"
946  #include "file.h"
947  #include "nat.h"
948  #include "news.h"
949 @@ -96,7 +97,7 @@ delete_old_news(void)
950      struct nwsstr news;
951  
952      /* skip over expired news */
953 -    expiry_time = time(NULL) - days(news_keep_days);
954 +    expiry_time = empire_time(NULL) - days(news_keep_days);
955      for (i = 0; getnews(i, &news); i++) {
956         if (news.nws_vrb == 0 || news.nws_when >= expiry_time)
957             break;
958 @@ -156,7 +157,7 @@ ncache(int actor, int event, int victim, int times)
959      int i;
960      int oldslot;
961      time_t oldtime;
962 -    time_t now = time(NULL);
963 +    time_t now = empire_time(NULL);
964  
965      oldslot = -1;
966      oldtime = 0x7fffffff;
967 diff --git a/src/lib/subs/pr.c b/src/lib/subs/pr.c
968 index 628d831..44f03f0 100644
969 --- a/src/lib/subs/pr.c
970 +++ b/src/lib/subs/pr.c
971 @@ -55,6 +55,7 @@
972  #include <stdlib.h>
973  #include "com.h"
974  #include "empio.h"
975 +#include "emptime.h"
976  #include "file.h"
977  #include "misc.h"
978  #include "nat.h"
979 @@ -193,7 +194,7 @@ pr_wall(char *format, ...)
980      struct player *p;
981      va_list ap;
982  
983 -    time(&now);
984 +    empire_time(&now);
985      tm = localtime(&now);
986      n = sprintf(buf, "BROADCAST from %s @ %02d:%02d: ",
987                 getnatp(0)->nat_cnam, tm->tm_hour, tm->tm_min);
988 @@ -374,7 +375,7 @@ prmptrd(char *prompt, char *buf, int size)
989      pr_id(player, C_FLUSH, "%s\n", prompt);
990      if ((r = recvclient(buf, size)) < 0)
991         return r;
992 -    time(&player->curup);
993 +    empire_time(&player->curup);
994      if (*buf == 0)
995         return 1;
996      if (player->flags & PF_UTF8)
997 @@ -403,7 +404,7 @@ uprmptrd(char *prompt, char *buf, int size)
998      pr_id(player, C_FLUSH, "%s\n", prompt);
999      if ((r = recvclient(buf, size)) < 0)
1000         return r;
1001 -    time(&player->curup);
1002 +    empire_time(&player->curup);
1003      if (*buf == 0)
1004         return 1;
1005      if (player->flags & PF_UTF8)
1006 @@ -419,7 +420,7 @@ prdate(void)
1007  {
1008      time_t now;
1009  
1010 -    (void)time(&now);
1011 +    (void)empire_time(&now);
1012      pr(ctime(&now));
1013  }
1014  
1015 @@ -479,7 +480,7 @@ PRdate(natid cn)
1016  {
1017      time_t now;
1018  
1019 -    (void)time(&now);
1020 +    (void)empire_time(&now);
1021      PR(cn, ctime(&now));
1022  }
1023  
1024 diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c
1025 index ac3125b..afb0e81 100644
1026 --- a/src/lib/subs/show.c
1027 +++ b/src/lib/subs/show.c
1028 @@ -42,6 +42,7 @@
1029  #endif
1030  
1031  #include <math.h>
1032 +#include "emptime.h"
1033  #include "file.h"
1034  #include "game.h"
1035  #include "item.h"
1036 @@ -616,7 +617,7 @@ show_updates(int n)
1037      int demand = 0;
1038      int i;
1039  
1040 -    pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
1041 +    pr("%s, Turn %d, ETU %d\n", fmttime2822(empire_time(NULL)),
1042         game->game_turn, game->game_tick);
1043  
1044      if (update_time[0]) {
1045 diff --git a/src/lib/subs/trechk.c b/src/lib/subs/trechk.c
1046 index e77e2b0..84a78d1 100644
1047 --- a/src/lib/subs/trechk.c
1048 +++ b/src/lib/subs/trechk.c
1049 @@ -41,6 +41,7 @@
1050  
1051  #include <config.h>
1052  
1053 +#include "emptime.h"
1054  #include "file.h"
1055  #include "nat.h"
1056  #include "news.h"
1057 @@ -65,7 +66,7 @@ trechk(natid actor, natid victim, int provision)
1058  
1059      if (!opt_TREATIES)
1060         return 1;
1061 -    (void)time(&now);
1062 +    (void)empire_time(&now);
1063      broken = 0;
1064      applied = 0;
1065      for (cn = 0; cn < MAXNOC; cn++)
1066 diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c
1067 index 5bcce21..c45d024 100644
1068 --- a/src/lib/subs/wu.c
1069 +++ b/src/lib/subs/wu.c
1070 @@ -37,6 +37,7 @@
1071  #include <stdarg.h>
1072  #include <sys/uio.h>
1073  #include <unistd.h>
1074 +#include "emptime.h"
1075  #include "file.h"
1076  #include "misc.h"
1077  #include "nat.h"
1078 @@ -143,7 +144,7 @@ typed_wu(natid from, natid to, char *message, int type)
1079      }
1080      memset(&tel, 0, sizeof(tel));
1081      tel.tel_from = from;
1082 -    (void)time(&tel.tel_date);
1083 +    (void)empire_time(&tel.tel_date);
1084      len = strlen(message);
1085      if (CANT_HAPPEN(len > MAXTELSIZE)) {
1086         len = MAXTELSIZE;
1087 diff --git a/src/lib/update/anno.c b/src/lib/update/anno.c
1088 index f07d441..1daf258 100644
1089 --- a/src/lib/update/anno.c
1090 +++ b/src/lib/update/anno.c
1091 @@ -41,6 +41,7 @@
1092  #endif
1093  #include <stdio.h>
1094  #include <time.h>
1095 +#include "emptime.h"
1096  #include "tel.h"
1097  #include "update.h"
1098  
1099 @@ -60,7 +61,7 @@ delete_old_announcements(void)
1100      if (anno_keep_days < 0)
1101         return;
1102  
1103 -    time(&now);
1104 +    empire_time(&now);
1105      old = now - days(anno_keep_days);
1106      logerror("Deleting annos older than %s", ctime(&old));
1107  
1108 diff --git a/src/lib/update/main.c b/src/lib/update/main.c
1109 index 32fa059..3ac6ce5 100644
1110 --- a/src/lib/update/main.c
1111 +++ b/src/lib/update/main.c
1112 @@ -38,6 +38,7 @@
1113  
1114  #include "budg.h"
1115  #include "empthread.h"
1116 +#include "emptime.h"
1117  #include "game.h"
1118  #include "journal.h"
1119  #include "player.h"
1120 @@ -64,7 +65,7 @@ update_main(void)
1121      struct natstr *np;
1122  
1123      logerror("production update (%d etus)", etu);
1124 -    game_record_update(time(NULL));
1125 +    game_record_update(empire_time(NULL));
1126      journal_update(etu);
1127  
1128      /* First, make sure all mobility is updated correctly. */
1129 diff --git a/src/lib/update/mobility.c b/src/lib/update/mobility.c
1130 index 95a81aa..674e999 100644
1131 --- a/src/lib/update/mobility.c
1132 +++ b/src/lib/update/mobility.c
1133 @@ -35,6 +35,7 @@
1134  
1135  #include <config.h>
1136  
1137 +#include "emptime.h"
1138  #include "game.h"
1139  #include "land.h"
1140  #include "plane.h"
1141 @@ -130,7 +131,7 @@ mob_sect(void)
1142      int n, etus;
1143      time_t now;
1144  
1145 -    time(&now);
1146 +    empire_time(&now);
1147      for (n = 0; NULL != (sp = getsectid(n)); n++) {
1148         sp->sct_timestamp = now;
1149         if (opt_MOB_ACCESS)
1150 @@ -167,7 +168,7 @@ mob_ship(void)
1151      int n, etus;
1152      time_t now;
1153  
1154 -    time(&now);
1155 +    empire_time(&now);
1156      for (n = 0; NULL != (sp = getshipp(n)); n++) {
1157         sp->shp_timestamp = now;
1158         if (opt_MOB_ACCESS)
1159 @@ -202,7 +203,7 @@ mob_land(void)
1160      int n, etus;
1161      time_t now;
1162  
1163 -    time(&now);
1164 +    empire_time(&now);
1165      for (n = 0; NULL != (lp = getlandp(n)); n++) {
1166         lp->lnd_timestamp = now;
1167         if (opt_MOB_ACCESS)
1168 @@ -251,7 +252,7 @@ mob_plane(void)
1169      int n, etus;
1170      time_t now;
1171  
1172 -    time(&now);
1173 +    empire_time(&now);
1174      for (n = 0; NULL != (pp = getplanep(n)); n++) {
1175         pp->pln_timestamp = now;
1176         if (opt_MOB_ACCESS)
1177 diff --git a/src/server/main.c b/src/server/main.c
1178 index 1f66f98..c887868 100644
1179 --- a/src/server/main.c
1180 +++ b/src/server/main.c
1181 @@ -54,6 +54,7 @@
1182  
1183  #include "empio.h"
1184  #include "empthread.h"
1185 +#include "emptime.h"
1186  #include "file.h"
1187  #include "journal.h"
1188  #include "land.h"
1189 @@ -148,7 +149,7 @@ main(int argc, char **argv)
1190  #endif
1191      char *config_file = NULL;
1192      int op, idx, sig;
1193 -    unsigned seed = time(NULL);
1194 +    unsigned seed = empire_time(NULL);
1195  
1196      oops_handler = ignore;
1197  
1198 diff --git a/src/server/marketup.c b/src/server/marketup.c
1199 index 925c844..f684909 100644
1200 --- a/src/server/marketup.c
1201 +++ b/src/server/marketup.c
1202 @@ -35,6 +35,7 @@
1203  #include <config.h>
1204  
1205  #include "empthread.h"
1206 +#include "emptime.h"
1207  #include "file.h"
1208  #include "optlist.h"
1209  #include "player.h"
1210 @@ -52,7 +53,7 @@ market_update(void *unused)
1211      player->god = 1;
1212  
1213      for (;;) {
1214 -       time(&now);
1215 +       empire_time(&now);
1216         check_market();
1217         check_trade();
1218         now += 300;             /* Every 5 minutes */
1219 diff --git a/src/server/shutdown.c b/src/server/shutdown.c
1220 index 0bf3290..0ad337b 100644
1221 --- a/src/server/shutdown.c
1222 +++ b/src/server/shutdown.c
1223 @@ -36,6 +36,7 @@
1224  
1225  #include <time.h>
1226  #include "empthread.h"
1227 +#include "emptime.h"
1228  #include "file.h"
1229  #include "nat.h"
1230  #include "prototypes.h"
1231 @@ -94,7 +95,7 @@ shutdown_sequence(void *unused)
1232  
1233      while (shutdown_pending > 0) {
1234         --shutdown_pending;
1235 -       time(&now);
1236 +       empire_time(&now);
1237         if (shutdown_pending <= 1440) { /* one day */
1238             if (shutdown_pending == 0) {
1239                 shutdwn(0);
1240 diff --git a/src/server/update.c b/src/server/update.c
1241 index 28cb077..0521f6f 100644
1242 --- a/src/server/update.c
1243 +++ b/src/server/update.c
1244 @@ -42,6 +42,7 @@
1245  #endif
1246  #include <time.h>
1247  #include "empthread.h"
1248 +#include "emptime.h"
1249  #include "game.h"
1250  #include "misc.h"
1251  #include "optlist.h"
1252 @@ -70,7 +71,7 @@ update_init(void)
1253      struct player *dp;
1254      int stacksize;
1255  
1256 -    update_schedule_anchor = (time(NULL) + 59) / 60 * 60;
1257 +    update_schedule_anchor = (empire_time(NULL) + 59) / 60 * 60;
1258      if (update_get_schedule() < 0)
1259         exit(1);
1260  
1261 @@ -98,7 +99,7 @@ update_init(void)
1262  static int
1263  update_get_schedule(void)
1264  {
1265 -    time_t now = time(NULL);
1266 +    time_t now = empire_time(NULL);
1267  
1268      if (read_schedule(schedulefil, update_time,
1269                       sizeof(update_time) / sizeof(*update_time),
1270 @@ -136,10 +137,10 @@ update_sched(void *unused)
1271         } else {
1272             logerror("No update scheduled");
1273             /* want to sleep forever, but empthread doesn't provide that */
1274 -           while (empth_sleep(time(NULL) + (60 * 60 * 24)) >= 0) ;
1275 +           while (empth_sleep(empire_time(NULL) + (60 * 60 * 24)) >= 0) ;
1276         }
1277  
1278 -       now = time(NULL);
1279 +       now = empire_time(NULL);
1280         if (next_update != 0 && now >= next_update) {
1281             /* scheduled update time reached */
1282             if (now >= next_update + 60)
1283 diff --git a/src/util/empsched.c b/src/util/empsched.c
1284 index 1ac1cdc..d51694c 100644
1285 --- a/src/util/empsched.c
1286 +++ b/src/util/empsched.c
1287 @@ -36,6 +36,7 @@
1288  #include <unistd.h>
1289  #include <stdio.h>
1290  #include <time.h>
1291 +#include "emptime.h"
1292  #include "optlist.h"
1293  #include "prototypes.h"
1294  #include "version.h"
1295 @@ -102,7 +103,7 @@ main(int argc, char *argv[])
1296      else
1297         in_file = argv[optind];
1298  
1299 -    anchor = (time(NULL) + 59) / 60 * 60;
1300 +    anchor = (empire_time(NULL) + 59) / 60 * 60;
1301      if (read_schedule(in_file, sched, n + 1, 0, anchor) < 0)
1302         exit(1);
1303  
1304 diff --git a/src/util/fairland.c b/src/util/fairland.c
1305 index 77a5a53..ffdc5c5 100644
1306 --- a/src/util/fairland.c
1307 +++ b/src/util/fairland.c
1308 @@ -70,6 +70,7 @@ static int quiet = 0;
1309  #include <stdarg.h>
1310  #include <stdio.h>
1311  #include <unistd.h>
1312 +#include "emptime.h"
1313  #include "file.h"
1314  #include "misc.h"
1315  #include "nat.h"
1316 @@ -183,7 +184,7 @@ main(int argc, char *argv[])
1317      int i = 0;
1318  
1319      program_name = argv[0];
1320 -    rnd_seed = time(NULL);
1321 +    rnd_seed = empire_time(NULL);
1322  
1323      while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {
1324         switch (opt) {