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 811e1d4..d08ac40 100644
784 --- a/src/lib/player/player.c
785 +++ b/src/lib/player/player.c
789 #include "empthread.h"
790 +#include "emptime.h"
794 @@ -64,7 +65,7 @@ player_main(struct player *p)
796 p->state = PS_PLAYING;
798 - time(&player->curup);
799 + empire_time(&player->curup);
800 update_timeused_login(player->curup);
802 if (init_nats() < 0) {
803 @@ -115,7 +116,7 @@ player_main(struct player *p)
805 /* #*# I put the following line in to prevent server crash -KHS */
806 natp = getnatp(player->cnum);
807 - time(&natp->nat_last_logout);
808 + empire_time(&natp->nat_last_logout);
810 update_timeused(natp->nat_last_logout);
811 enforce_minimum_session_time();
812 @@ -134,7 +135,7 @@ command(void)
813 if (getcommand(player->combuf) < 0)
817 + now = empire_time(NULL);
818 update_timeused(now);
819 natp = getnatp(player->cnum);
820 if ((natp->nat_stat == STAT_ACTIVE || natp->nat_stat == STAT_SANCT)
821 @@ -186,7 +187,7 @@ status(void)
822 if (!(old_nstat & MONEY) && (player->nstat & MONEY))
823 pr("You are no longer broke!\n");
825 - time(&player->curup);
826 + empire_time(&player->curup);
827 update_timeused(player->curup);
828 if ((natp->nat_stat == STAT_ACTIVE || natp->nat_stat == STAT_SANCT)
829 && natp->nat_timeused > m_m_p_d * 60) {
830 diff --git a/src/lib/player/recvclient.c b/src/lib/player/recvclient.c
831 index ab4ef69..8934189 100644
832 --- a/src/lib/player/recvclient.c
833 +++ b/src/lib/player/recvclient.c
838 +#include "emptime.h"
841 #include "prototypes.h"
842 @@ -102,7 +103,7 @@ recvclient(char *cmd, int size)
843 * check errors; oops once, then slow it down drastically.
845 CANT_HAPPEN(player->recvfail == 256);
846 - empth_sleep(time(NULL) + 60);
847 + empth_sleep(empire_time(NULL) + 60);
849 return player->eof ? -1 : -2;
851 diff --git a/src/lib/subs/disloan.c b/src/lib/subs/disloan.c
852 index 9a6c670..9d7b6ba 100644
853 --- a/src/lib/subs/disloan.c
854 +++ b/src/lib/subs/disloan.c
859 +#include "emptime.h"
863 @@ -64,7 +65,7 @@ disloan(int n, struct lonstr *loan)
865 if (loan->l_loner != player->cnum && loan->l_lonee != player->cnum)
868 + (void)empire_time(&now);
869 pr("\nLoan #%d from %s to", n, cname(loan->l_loner));
870 pr(" %s\n", cname(loan->l_lonee));
871 if (loan->l_status == LS_PROPOSED) {
872 diff --git a/src/lib/subs/distrea.c b/src/lib/subs/distrea.c
873 index bfb182c..45f80ae 100644
874 --- a/src/lib/subs/distrea.c
875 +++ b/src/lib/subs/distrea.c
880 +#include "emptime.h"
884 @@ -51,7 +52,7 @@ distrea(int n, struct trtstr *tp)
885 if (tp->trt_cna != player->cnum &&
886 tp->trt_cnb != player->cnum && !player->god)
889 + (void)empire_time(&now);
890 if (now > tp->trt_exp) {
891 tp->trt_status = TS_FREE;
892 if (!puttre(n, tp)) {
893 diff --git a/src/lib/subs/journal.c b/src/lib/subs/journal.c
894 index 4f553c5..c8bb70c 100644
895 --- a/src/lib/subs/journal.c
896 +++ b/src/lib/subs/journal.c
900 #include "empthread.h"
901 +#include "emptime.h"
905 @@ -83,7 +84,7 @@ journal_entry(char *fmt, ...)
911 fprintf(journal, "%.24s %10.10s ",
912 ctime(&now), empth_name(empth_self()));
914 diff --git a/src/lib/subs/lostsub.c b/src/lib/subs/lostsub.c
915 index 2d0d046..8b2ea25 100644
916 --- a/src/lib/subs/lostsub.c
917 +++ b/src/lib/subs/lostsub.c
922 +#include "emptime.h"
926 @@ -124,7 +125,7 @@ findlost(short type, natid owner, short id, coord x, coord y, int free)
928 delete_old_lostitems(void)
930 - time_t expiry_time = time(NULL) - hours(lost_keep_hours);
931 + time_t expiry_time = empire_time(NULL) - hours(lost_keep_hours);
935 diff --git a/src/lib/subs/nreport.c b/src/lib/subs/nreport.c
936 index 2e83326..5600a5a 100644
937 --- a/src/lib/subs/nreport.c
938 +++ b/src/lib/subs/nreport.c
943 +#include "emptime.h"
947 @@ -96,7 +97,7 @@ delete_old_news(void)
950 /* skip over expired news */
951 - expiry_time = time(NULL) - days(news_keep_days);
952 + expiry_time = empire_time(NULL) - days(news_keep_days);
953 for (i = 0; getnews(i, &news); i++) {
954 if (news.nws_vrb == 0 || news.nws_when >= expiry_time)
956 @@ -156,7 +157,7 @@ ncache(int actor, int event, int victim, int times)
960 - time_t now = time(NULL);
961 + time_t now = empire_time(NULL);
964 oldtime = 0x7fffffff;
965 diff --git a/src/lib/subs/pr.c b/src/lib/subs/pr.c
966 index 628d831..44f03f0 100644
967 --- a/src/lib/subs/pr.c
968 +++ b/src/lib/subs/pr.c
973 +#include "emptime.h"
977 @@ -193,7 +194,7 @@ pr_wall(char *format, ...)
983 tm = localtime(&now);
984 n = sprintf(buf, "BROADCAST from %s @ %02d:%02d: ",
985 getnatp(0)->nat_cnam, tm->tm_hour, tm->tm_min);
986 @@ -374,7 +375,7 @@ prmptrd(char *prompt, char *buf, int size)
987 pr_id(player, C_FLUSH, "%s\n", prompt);
988 if ((r = recvclient(buf, size)) < 0)
990 - time(&player->curup);
991 + empire_time(&player->curup);
994 if (player->flags & PF_UTF8)
995 @@ -403,7 +404,7 @@ uprmptrd(char *prompt, char *buf, int size)
996 pr_id(player, C_FLUSH, "%s\n", prompt);
997 if ((r = recvclient(buf, size)) < 0)
999 - time(&player->curup);
1000 + empire_time(&player->curup);
1003 if (player->flags & PF_UTF8)
1004 @@ -419,7 +420,7 @@ prdate(void)
1009 + (void)empire_time(&now);
1013 @@ -479,7 +480,7 @@ PRdate(natid cn)
1018 + (void)empire_time(&now);
1019 PR(cn, ctime(&now));
1022 diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c
1023 index ac3125b..afb0e81 100644
1024 --- a/src/lib/subs/show.c
1025 +++ b/src/lib/subs/show.c
1030 +#include "emptime.h"
1034 @@ -616,7 +617,7 @@ show_updates(int n)
1038 - pr("%s, Turn %d, ETU %d\n", fmttime2822(time(NULL)),
1039 + pr("%s, Turn %d, ETU %d\n", fmttime2822(empire_time(NULL)),
1040 game->game_turn, game->game_tick);
1042 if (update_time[0]) {
1043 diff --git a/src/lib/subs/trechk.c b/src/lib/subs/trechk.c
1044 index e77e2b0..84a78d1 100644
1045 --- a/src/lib/subs/trechk.c
1046 +++ b/src/lib/subs/trechk.c
1051 +#include "emptime.h"
1055 @@ -65,7 +66,7 @@ trechk(natid actor, natid victim, int provision)
1060 + (void)empire_time(&now);
1063 for (cn = 0; cn < MAXNOC; cn++)
1064 diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c
1065 index 5bcce21..c45d024 100644
1066 --- a/src/lib/subs/wu.c
1067 +++ b/src/lib/subs/wu.c
1070 #include <sys/uio.h>
1072 +#include "emptime.h"
1076 @@ -143,7 +144,7 @@ typed_wu(natid from, natid to, char *message, int type)
1078 memset(&tel, 0, sizeof(tel));
1079 tel.tel_from = from;
1080 - (void)time(&tel.tel_date);
1081 + (void)empire_time(&tel.tel_date);
1082 len = strlen(message);
1083 if (CANT_HAPPEN(len > MAXTELSIZE)) {
1085 diff --git a/src/lib/update/anno.c b/src/lib/update/anno.c
1086 index f07d441..1daf258 100644
1087 --- a/src/lib/update/anno.c
1088 +++ b/src/lib/update/anno.c
1093 +#include "emptime.h"
1097 @@ -60,7 +61,7 @@ delete_old_announcements(void)
1098 if (anno_keep_days < 0)
1102 + empire_time(&now);
1103 old = now - days(anno_keep_days);
1104 logerror("Deleting annos older than %s", ctime(&old));
1106 diff --git a/src/lib/update/main.c b/src/lib/update/main.c
1107 index 32fa059..3ac6ce5 100644
1108 --- a/src/lib/update/main.c
1109 +++ b/src/lib/update/main.c
1113 #include "empthread.h"
1114 +#include "emptime.h"
1116 #include "journal.h"
1118 @@ -64,7 +65,7 @@ update_main(void)
1121 logerror("production update (%d etus)", etu);
1122 - game_record_update(time(NULL));
1123 + game_record_update(empire_time(NULL));
1124 journal_update(etu);
1126 /* First, make sure all mobility is updated correctly. */
1127 diff --git a/src/lib/update/mobility.c b/src/lib/update/mobility.c
1128 index 95a81aa..674e999 100644
1129 --- a/src/lib/update/mobility.c
1130 +++ b/src/lib/update/mobility.c
1135 +#include "emptime.h"
1139 @@ -130,7 +131,7 @@ mob_sect(void)
1144 + empire_time(&now);
1145 for (n = 0; NULL != (sp = getsectid(n)); n++) {
1146 sp->sct_timestamp = now;
1148 @@ -167,7 +168,7 @@ mob_ship(void)
1153 + empire_time(&now);
1154 for (n = 0; NULL != (sp = getshipp(n)); n++) {
1155 sp->shp_timestamp = now;
1157 @@ -202,7 +203,7 @@ mob_land(void)
1162 + empire_time(&now);
1163 for (n = 0; NULL != (lp = getlandp(n)); n++) {
1164 lp->lnd_timestamp = now;
1166 @@ -251,7 +252,7 @@ mob_plane(void)
1171 + empire_time(&now);
1172 for (n = 0; NULL != (pp = getplanep(n)); n++) {
1173 pp->pln_timestamp = now;
1175 diff --git a/src/server/main.c b/src/server/main.c
1176 index 1f66f98..c887868 100644
1177 --- a/src/server/main.c
1178 +++ b/src/server/main.c
1182 #include "empthread.h"
1183 +#include "emptime.h"
1185 #include "journal.h"
1187 @@ -148,7 +149,7 @@ main(int argc, char **argv)
1189 char *config_file = NULL;
1191 - unsigned seed = time(NULL);
1192 + unsigned seed = empire_time(NULL);
1194 oops_handler = ignore;
1196 diff --git a/src/server/marketup.c b/src/server/marketup.c
1197 index 925c844..f684909 100644
1198 --- a/src/server/marketup.c
1199 +++ b/src/server/marketup.c
1203 #include "empthread.h"
1204 +#include "emptime.h"
1206 #include "optlist.h"
1208 @@ -52,7 +53,7 @@ market_update(void *unused)
1213 + empire_time(&now);
1216 now += 300; /* Every 5 minutes */
1217 diff --git a/src/server/shutdown.c b/src/server/shutdown.c
1218 index 0bf3290..0ad337b 100644
1219 --- a/src/server/shutdown.c
1220 +++ b/src/server/shutdown.c
1224 #include "empthread.h"
1225 +#include "emptime.h"
1228 #include "prototypes.h"
1229 @@ -94,7 +95,7 @@ shutdown_sequence(void *unused)
1231 while (shutdown_pending > 0) {
1234 + empire_time(&now);
1235 if (shutdown_pending <= 1440) { /* one day */
1236 if (shutdown_pending == 0) {
1238 diff --git a/src/server/update.c b/src/server/update.c
1239 index 28cb077..0521f6f 100644
1240 --- a/src/server/update.c
1241 +++ b/src/server/update.c
1245 #include "empthread.h"
1246 +#include "emptime.h"
1249 #include "optlist.h"
1250 @@ -70,7 +71,7 @@ update_init(void)
1254 - update_schedule_anchor = (time(NULL) + 59) / 60 * 60;
1255 + update_schedule_anchor = (empire_time(NULL) + 59) / 60 * 60;
1256 if (update_get_schedule() < 0)
1259 @@ -98,7 +99,7 @@ update_init(void)
1261 update_get_schedule(void)
1263 - time_t now = time(NULL);
1264 + time_t now = empire_time(NULL);
1266 if (read_schedule(schedulefil, update_time,
1267 sizeof(update_time) / sizeof(*update_time),
1268 @@ -136,10 +137,10 @@ update_sched(void *unused)
1270 logerror("No update scheduled");
1271 /* want to sleep forever, but empthread doesn't provide that */
1272 - while (empth_sleep(time(NULL) + (60 * 60 * 24)) >= 0) ;
1273 + while (empth_sleep(empire_time(NULL) + (60 * 60 * 24)) >= 0) ;
1277 + now = empire_time(NULL);
1278 if (next_update != 0 && now >= next_update) {
1279 /* scheduled update time reached */
1280 if (now >= next_update + 60)
1281 diff --git a/src/util/empsched.c b/src/util/empsched.c
1282 index 1ac1cdc..d51694c 100644
1283 --- a/src/util/empsched.c
1284 +++ b/src/util/empsched.c
1289 +#include "emptime.h"
1290 #include "optlist.h"
1291 #include "prototypes.h"
1292 #include "version.h"
1293 @@ -102,7 +103,7 @@ main(int argc, char *argv[])
1295 in_file = argv[optind];
1297 - anchor = (time(NULL) + 59) / 60 * 60;
1298 + anchor = (empire_time(NULL) + 59) / 60 * 60;
1299 if (read_schedule(in_file, sched, n + 1, 0, anchor) < 0)
1302 diff --git a/src/util/fairland.c b/src/util/fairland.c
1303 index 77a5a53..ffdc5c5 100644
1304 --- a/src/util/fairland.c
1305 +++ b/src/util/fairland.c
1306 @@ -70,6 +70,7 @@ static int quiet = 0;
1310 +#include "emptime.h"
1314 @@ -183,7 +184,7 @@ main(int argc, char *argv[])
1317 program_name = argv[0];
1318 - rnd_seed = time(NULL);
1319 + rnd_seed = empire_time(NULL);
1321 while ((opt = getopt(argc, argv, "ae:hioqR:s:v")) != EOF) {