1 diff --git a/include/emptime.h b/include/emptime.h
5 +++ b/include/emptime.h
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
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.
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.
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
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.
34 + * emptime.h: Time functions for regression testing and
35 + * replaying journals.
37 + * Known contributors to this file:
38 + * Ron Koenderink, 2008
46 +#define empire_time(expr) emp_time((expr), __FUNCTION__)
47 +extern time_t emp_time(time_t *, const char []);
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
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) {
68 /* Add five minutes to the time if less than 5 minutes */
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)
79 + (void)empire_time(&now);
80 tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.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)
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);
96 @@ -124,7 +124,7 @@ coll(void)
97 caploss(§, loan.l_lonee, "that was %s's capital!\n");
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));
103 loan.l_status = LS_FREE;
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");
109 - (void)time(&loan.l_lastpay);
110 + (void)empire_time(&loan.l_lastpay);
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)
120 player->dolcost -= lp->l_amtdue;
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)
137 pr("DUMP SECTOR %ld\n", (long)now);
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)
146 if (!snxtitem(&ni, EF_LOAN, "*", NULL))
149 + (void)empire_time(&now);
151 pr(" -= Empire Financial Status Report =- \n");
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)
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;
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)
189 pr("DUMP LAND UNITS %ld\n", (long)now);
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)
202 pr("DUMP LOST ITEMS %ld\n", (long)now);
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)
214 + (void)empire_time(&now);
215 tleft = MARK_DELAY / 3600.0 - (now - comm->com_markettime) / 3600.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)
228 pr("DUMP NUKES %ld\n", (long)now);
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)
237 memset(page_has_news, 0, sizeof(page_has_news));
238 memset(sectors_taken, 0, sizeof(sectors_taken));
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");
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);
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)
276 pr("DUMP PLANES %ld\n", (long)now);
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)
289 pr("%-9.9s %3d %32.32s %2d:%02d %4lds",
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");
299 gen_power(powbuf, save);
300 - pow_time = time(NULL);
301 + pow_time = empire_time(NULL);
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)
311 int may_delete = 1; /* may messages be deleted? */
314 + now = empire_time(NULL);
316 if (*player->argp[0] == 'w') {
317 kind = "announcement";
318 @@ -188,7 +188,7 @@ rea(void)
320 (void)fseek(telfp, (long)size, SEEK_SET);
323 + now = empire_time(NULL);
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)
335 - newdue = (long)ceil(loan_owed(&loan, time(&now)) - payment);
336 + newdue = (long)ceil(loan_owed(&loan, empire_time(&now)) - payment);
338 pr("You don't owe that much.\n");
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)
347 comm.com_price = price;
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)
363 pr("DUMP SHIPS %ld\n", (long)now);
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)
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;
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)
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);
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)
414 + (void)empire_time(&now);
416 TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0;
418 @@ -252,7 +252,7 @@ trad(void)
420 if (bid > trade.trd_price) {
421 /* Add five minutes to the time if less than 5 minutes left. */
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)
432 + (void)empire_time(&now);
434 TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.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)
442 pr("Enter a new message of the day.\n");
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) {
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");
458 + (void)empire_time(&now);
459 next = update_time[0];
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)
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
480 #include <sys/stat.h>
481 #include <sys/types.h>
483 +#include "emptime.h"
487 @@ -424,7 +425,7 @@ do_write(struct empfile *ep, void *buf, int id, int count)
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++) {
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
504 +#include "emptime.h"
508 @@ -81,7 +82,7 @@ game_note_bsanct(void)
509 struct gamestr *game = getgamep();
511 if (game->game_rt == 0) {
512 - game->game_rt = time(NULL);
513 + game->game_rt = empire_time(NULL);
517 @@ -130,7 +131,7 @@ game_tick_tick(void)
518 double dsecs, s_p_etu;
521 - dsecs = time(NULL) - game->game_rt;
522 + dsecs = empire_time(NULL) - game->game_rt;
523 if (CANT_HAPPEN(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
534 +#include "emptime.h"
538 @@ -102,7 +103,7 @@ demand_check(void)
540 demandupdatecheck(void)
542 - time_t now = time(NULL);
543 + time_t now = empire_time(NULL);
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
555 +#include "emptime.h"
559 @@ -263,7 +264,7 @@ xdhdr(struct xdstr *xd, char *name, int meta)
561 xd->pr("XDUMP %s%s %ld\n",
563 - name, (long)time(NULL));
564 + name, (long)empire_time(NULL));
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
575 #include "empthread.h"
576 +#include "emptime.h"
579 /* Flags that were passed to empth_init() */
580 @@ -136,7 +137,7 @@ empth_wait_for_signal(void)
582 err = lwpSigWait(&set, &sig);
583 if (CANT_HAPPEN(err)) {
586 lwpSleepUntil(now + 60);
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
596 #include "empthread.h"
597 +#include "emptime.h"
598 #include "prototypes.h"
601 @@ -637,7 +638,7 @@ empth_wakeup(empth_t *pThread)
603 empth_sleep(time_t until)
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);
610 @@ -651,7 +652,7 @@ empth_sleep(time_t until)
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));
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
626 #include "empthread.h"
627 +#include "emptime.h"
628 #include "prototypes.h"
630 #define EMPTH_KILLED 1
631 @@ -378,10 +379,10 @@ empth_sleep(time_t until)
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);
639 - tv.tv_sec = until - time(NULL);
640 + tv.tv_sec = until - empire_time(NULL);
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
646 index 0000000..855de99
648 +++ b/src/lib/gen/emptime.c
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
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.
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.
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
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.
677 + * emptime.c: Time functions for regression testing and
678 + * replaying journals.
680 + * Known contributors to this file:
681 + * Ron Koenderink, 2008
686 +#include "emptime.h"
689 +emp_time(time_t * time_ptr, const char function[])
691 + static time_t now = (time_t)100L;
693 + if (strcmp(function, "update_main") == 0)
696 + if (time_ptr != NULL)
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
706 #include <sys/stat.h>
709 +#include "emptime.h"
713 @@ -116,7 +117,7 @@ logerror(char *format, ...)
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
727 #include <sys/time.h>
730 +#include "emptime.h"
733 #include "prototypes.h"
734 @@ -144,7 +145,7 @@ lwpWakeupSleep(void)
735 struct lwpProc *proc;
737 if (LwpDelayq.head) {
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)
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)
755 if (LwpDelayq.head) {
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
768 #include "empthread.h"
769 +#include "emptime.h"
773 @@ -91,7 +92,7 @@ player_new(int s)
774 emp_insque(&lp->queue, &Players);
775 lp->cnum = NATID_BAD;
778 + empire_time(&lp->curup);
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
789 #include "empthread.h"
790 +#include "emptime.h"
794 @@ -65,8 +66,8 @@ player_main(struct player *p)
796 p->state = PS_PLAYING;
798 - time(&player->lasttime);
799 - time(&player->curup);
800 + empire_time(&player->lasttime);
801 + empire_time(&player->curup);
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);
809 - time(&natp->nat_last_login);
810 + empire_time(&natp->nat_last_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.
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_timeused += secs;
823 @@ -182,7 +183,7 @@ status(void)
824 if (!(old_nstat & MONEY) && (player->nstat & MONEY))
825 pr("You are no longer broke!\n");
827 - time(&player->curup);
828 + empire_time(&player->curup);
829 second = player->curup - player->lasttime;
831 player->secleft -= second;
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
840 +#include "emptime.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.
847 CANT_HAPPEN(player->recvfail == 256);
848 - empth_sleep(time(NULL) + 60);
849 + empth_sleep(empire_time(NULL) + 60);
851 return player->eof ? -1 : -2;
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
861 +#include "emptime.h"
865 @@ -64,7 +65,7 @@ disloan(int n, struct lonstr *loan)
867 if (loan->l_loner != player->cnum && loan->l_lonee != player->cnum)
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
882 +#include "emptime.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)
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
902 #include "empthread.h"
903 +#include "emptime.h"
907 @@ -83,7 +84,7 @@ journal_entry(char *fmt, ...)
913 fprintf(journal, "%.24s %10.10s ",
914 ctime(&now), empth_name(empth_self()));
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
924 +#include "emptime.h"
928 @@ -124,7 +125,7 @@ findlost(short type, natid owner, short id, coord x, coord y, int free)
930 delete_old_lostitems(void)
932 - time_t expiry_time = time(NULL) - hours(lost_keep_hours);
933 + time_t expiry_time = empire_time(NULL) - hours(lost_keep_hours);
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
945 +#include "emptime.h"
949 @@ -96,7 +97,7 @@ delete_old_news(void)
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)
958 @@ -156,7 +157,7 @@ ncache(int actor, int event, int victim, int times)
962 - time_t now = time(NULL);
963 + time_t now = empire_time(NULL);
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
975 +#include "emptime.h"
979 @@ -193,7 +194,7 @@ pr_wall(char *format, ...)
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)
992 - time(&player->curup);
993 + empire_time(&player->curup);
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)
1001 - time(&player->curup);
1002 + empire_time(&player->curup);
1005 if (player->flags & PF_UTF8)
1006 @@ -419,7 +420,7 @@ prdate(void)
1011 + (void)empire_time(&now);
1015 @@ -479,7 +480,7 @@ PRdate(natid cn)
1020 + (void)empire_time(&now);
1021 PR(cn, ctime(&now));
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
1032 +#include "emptime.h"
1036 @@ -616,7 +617,7 @@ show_updates(int n)
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);
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
1053 +#include "emptime.h"
1057 @@ -65,7 +66,7 @@ trechk(natid actor, natid victim, int provision)
1062 + (void)empire_time(&now);
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
1072 #include <sys/uio.h>
1074 +#include "emptime.h"
1078 @@ -143,7 +144,7 @@ typed_wu(natid from, natid to, char *message, int type)
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)) {
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
1095 +#include "emptime.h"
1099 @@ -60,7 +61,7 @@ delete_old_announcements(void)
1100 if (anno_keep_days < 0)
1104 + empire_time(&now);
1105 old = now - days(anno_keep_days);
1106 logerror("Deleting annos older than %s", ctime(&old));
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
1115 #include "empthread.h"
1116 +#include "emptime.h"
1118 #include "journal.h"
1120 @@ -64,7 +65,7 @@ update_main(void)
1123 logerror("production update (%d etus)", etu);
1124 - game_record_update(time(NULL));
1125 + game_record_update(empire_time(NULL));
1126 journal_update(etu);
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
1137 +#include "emptime.h"
1141 @@ -130,7 +131,7 @@ mob_sect(void)
1146 + empire_time(&now);
1147 for (n = 0; NULL != (sp = getsectid(n)); n++) {
1148 sp->sct_timestamp = now;
1150 @@ -167,7 +168,7 @@ mob_ship(void)
1155 + empire_time(&now);
1156 for (n = 0; NULL != (sp = getshipp(n)); n++) {
1157 sp->shp_timestamp = now;
1159 @@ -202,7 +203,7 @@ mob_land(void)
1164 + empire_time(&now);
1165 for (n = 0; NULL != (lp = getlandp(n)); n++) {
1166 lp->lnd_timestamp = now;
1168 @@ -251,7 +252,7 @@ mob_plane(void)
1173 + empire_time(&now);
1174 for (n = 0; NULL != (pp = getplanep(n)); n++) {
1175 pp->pln_timestamp = now;
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
1184 #include "empthread.h"
1185 +#include "emptime.h"
1187 #include "journal.h"
1189 @@ -148,7 +149,7 @@ main(int argc, char **argv)
1191 char *config_file = NULL;
1193 - unsigned seed = time(NULL);
1194 + unsigned seed = empire_time(NULL);
1196 oops_handler = ignore;
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
1205 #include "empthread.h"
1206 +#include "emptime.h"
1208 #include "optlist.h"
1210 @@ -52,7 +53,7 @@ market_update(void *unused)
1215 + empire_time(&now);
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
1226 #include "empthread.h"
1227 +#include "emptime.h"
1230 #include "prototypes.h"
1231 @@ -94,7 +95,7 @@ shutdown_sequence(void *unused)
1233 while (shutdown_pending > 0) {
1236 + empire_time(&now);
1237 if (shutdown_pending <= 1440) { /* one day */
1238 if (shutdown_pending == 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
1247 #include "empthread.h"
1248 +#include "emptime.h"
1251 #include "optlist.h"
1252 @@ -70,7 +71,7 @@ update_init(void)
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)
1261 @@ -98,7 +99,7 @@ update_init(void)
1263 update_get_schedule(void)
1265 - time_t now = time(NULL);
1266 + time_t now = empire_time(NULL);
1268 if (read_schedule(schedulefil, update_time,
1269 sizeof(update_time) / sizeof(*update_time),
1270 @@ -136,10 +137,10 @@ update_sched(void *unused)
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) ;
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
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[])
1297 in_file = argv[optind];
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)
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;
1312 +#include "emptime.h"
1316 @@ -183,7 +184,7 @@ main(int argc, char *argv[])
1319 program_name = argv[0];
1320 - rnd_seed = time(NULL);
1321 + rnd_seed = empire_time(NULL);
1323 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {