Rewrite accounting of play time
Replace daychange() and gettimeleft() by update_timeused_login(), update_timeused() and enforce_minimum_session_time(). The new code doesn't assume the day is always 24 hours long which can occur when transitioning into or out of DST and such. Logging in after more a multiple of 128 days now resets nat_timeused properly. Fix nat_timeused calculation on midnight rollover to include the time since midnight. struct natstr member nat_dayno and struct player member timeleft are now unused, remove them.
This commit is contained in:
parent
f46dc55254
commit
875a80d14f
8 changed files with 69 additions and 74 deletions
|
@ -780,7 +780,7 @@ index 3106849..726b5fc 100644
|
|||
return lp;
|
||||
}
|
||||
diff --git a/src/lib/player/player.c b/src/lib/player/player.c
|
||||
index 513382b..4b97be7 100644
|
||||
index f81e2f0..a9a1f74 100644
|
||||
--- a/src/lib/player/player.c
|
||||
+++ b/src/lib/player/player.c
|
||||
@@ -40,6 +40,7 @@
|
||||
|
@ -791,18 +791,16 @@ index 513382b..4b97be7 100644
|
|||
#include "file.h"
|
||||
#include "journal.h"
|
||||
#include "misc.h"
|
||||
@@ -65,8 +66,8 @@ player_main(struct player *p)
|
||||
@@ -64,7 +65,7 @@ player_main(struct player *p)
|
||||
|
||||
p->state = PS_PLAYING;
|
||||
player = p;
|
||||
- time(&player->lasttime);
|
||||
- time(&player->curup);
|
||||
+ empire_time(&player->lasttime);
|
||||
+ empire_time(&player->curup);
|
||||
update_timeused_login(player->curup);
|
||||
show_motd();
|
||||
if (init_nats() < 0) {
|
||||
pr("Server confused, try again later\n");
|
||||
@@ -100,7 +101,7 @@ player_main(struct player *p)
|
||||
@@ -98,7 +99,7 @@ player_main(struct player *p)
|
||||
strcpy(natp->nat_hostname, player->hostname);
|
||||
strcpy(natp->nat_hostaddr, player->hostaddr);
|
||||
|
||||
|
@ -811,24 +809,24 @@ index 513382b..4b97be7 100644
|
|||
putnat(natp);
|
||||
journal_login();
|
||||
if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
|
||||
@@ -123,7 +124,7 @@ player_main(struct player *p)
|
||||
* randomly round up to the nearest minute,
|
||||
* charging at least 15 seconds.
|
||||
*/
|
||||
@@ -117,7 +118,7 @@ player_main(struct player *p)
|
||||
}
|
||||
/* #*# I put the following line in to prevent server crash -KHS */
|
||||
natp = getnatp(player->cnum);
|
||||
- time(&natp->nat_last_logout);
|
||||
+ empire_time(&natp->nat_last_logout);
|
||||
secs = MAX(natp->nat_last_logout - player->lasttime, 15);
|
||||
natp->nat_timeused += secs;
|
||||
putnat(natp);
|
||||
@@ -182,7 +183,7 @@ status(void)
|
||||
update_timeused(natp->nat_last_logout);
|
||||
enforce_minimum_session_time();
|
||||
@@ -176,7 +177,7 @@ status(void)
|
||||
if (!(old_nstat & MONEY) && (player->nstat & MONEY))
|
||||
pr("You are no longer broke!\n");
|
||||
|
||||
- time(&player->curup);
|
||||
+ empire_time(&player->curup);
|
||||
second = player->curup - player->lasttime;
|
||||
if (second > 0) {
|
||||
player->timeleft -= second;
|
||||
update_timeused(player->curup);
|
||||
if (natp->nat_stat == STAT_ACTIVE &&
|
||||
natp->nat_timeused > m_m_p_d * 60) {
|
||||
diff --git a/src/lib/player/recvclient.c b/src/lib/player/recvclient.c
|
||||
index ab4ef69..8934189 100644
|
||||
--- a/src/lib/player/recvclient.c
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue