A singleton class game#time which keeps the official Server and World time stamps. Uses a basic implementation of https://www.geeksforgeeks.org/cristians-algorithm/ for synchronization.

Properties

_time: {
    clientTime: number;
    serverTime: number;
    worldTime: number;
}

The most recently synchronized timestamps retrieved from the server.

Type declaration

  • clientTime: number
  • serverTime: number
  • worldTime: number
_dt: number

The average one-way latency across the most recent 5 trips

_dts: number[]

The most recent five synchronization durations

SYNC_INTERVAL_MS: number = ...

The amount of time to delay before re-syncing the official server time.

Accessors

  • get serverTime(): number
  • The current server time based on the last synchronization point and the approximated one-way latency.

    Returns number

  • get worldTime(): number
  • The current World time based on the last recorded value of the core.time setting

    Returns number

Methods

  • Advance the game time by a certain number of seconds

    Parameters

    • seconds: number

      The number of seconds to advance (or rewind if negative) by

    • Optional options: object

      Additional options passed to game.settings.set

    Returns Promise<number>

    The new game time

  • Synchronize the local client game time with the official time kept by the server

    Parameters

    • socket: Socket

      The connected server Socket instance

    Returns Promise<GameTime>

  • Handle follow-up actions when the official World time is changed

    Parameters

    • worldTime: number

      The new canonical World time.

    • options: object

      Options passed from the requesting client where the change was made

    • userId: string

      The ID of the User who advanced the time

    Returns void