Skip to content

Commit

Permalink
fix(server): statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
Veradictus committed Sep 27, 2023
1 parent daa457c commit 3d7669d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/server/src/game/entity/character/player/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export default class Statistics {
public resources: { [key: string]: number } = {};
public drops: { [key: string]: number } = {};

public creationTime = Date.now(); // Time of game's creation.
public creationTime = this.getTime(); // Time of game's creation.
public totalTimePlayed = 0; // Total time played in milliseconds.
public averageTimePlayed = 0;
public lastLogin = Date.now();
public lastLogin = this.getTime();
public loginCount = 1;

// Class variables for calculating login time, etc.
public loginTime = Date.now(); // Time when player logged in.
public loginTime = this.getTime(); // Time when player logged in.

public constructor(private player: Player) {}

Expand Down Expand Up @@ -148,7 +148,7 @@ export default class Statistics {

public serialize(): StatisticsData {
// Serializing also gets treated as a logging out event, so we calculate stuff here.
this.lastLogin = Date.now();
this.lastLogin = this.getTime();
this.totalTimePlayed += Date.now() - this.loginTime; // add time played to total time played.
this.calculateAverageTimePlayed();

Expand All @@ -167,4 +167,14 @@ export default class Statistics {
cheater: this.player.isCheater()
};
}

/**
* Gets the UNIX epoch time in seconds. This is because storing seconds
* is easier for the database (as it can cause later down the line.)
* @returns The current UNIX epoch time in seconds.
*/

private getTime(): number {
return Math.floor(Date.now() / 1000);
}
}

0 comments on commit 3d7669d

Please sign in to comment.