Class PhaserGameServer

A GameServer subclass for Phaser games. This class adds some additional methods for managing synchronized data managers, which are the primary way to do multiplayer communication.

Hierarchy (view full)

Constructors

Accessors

  • get postId(): string
  • This is a helper method to get the current post id.

    Returns string

  • get reddit(): RedditAPIClient
  • This is a helper method to get the Reddit API client. You can use this to interact with Reddit.

    Returns RedditAPIClient

  • get redis(): RedisClient
  • This is a helper method to get the Redis client. All of your game state should be stored in Redis.

    Returns RedisClient

  • get userId(): null | string
  • This is a helper method to get the current user id. This will be null if the user is not logged in, or if this is a TimerEvent handler.

    Returns null | string

Methods

  • This must be called to build the game server. This will add the game server to the Devvit instance.

    Returns typeof Devvit

    The Devvit instance with the game server added.

  • Called when a player writes to a synchronized data manager from the client. Override this method to do permission checks or other setup. In particular, you can check this.userId, etc, to see if the player is allowed to write to this data. If not, throw an error to prevent the write.

    Parameters

    Returns Promise<void>

  • Called when a player creates a synchronized data manager from the client. Override this method to do permission checks or other setup. In particular, you can check this.userId, etc, to see if the player is allowed to view this data. If not, throw an error to prevent the creation.

    Parameters

    Returns Promise<void>

  • This method is called when a message is received from the broadcast channel. By default, this will send the message to the webview. You can override this method to customize the behavior.

    Parameters

    Returns Promise<any>

  • This gets called whenever a timer event is triggered. You can use this to update the game state, broadcast changes, etc. By default, this method broadcasts the timer event to the postId channel.

    Parameters

    Returns Promise<void>

  • This method is called when a message is received from the webview. You can use this to update the game state. By default, this method will broadcast the message to the postId channel. You can override this method to customize the behavior.

    Parameters

    • msg: JSONValue

      The message that was sent from the webview.

    Returns Promise<any>

  • Assuming you're in an individual user's context, you can use this method to send a message to the webview. If you're in a more global context, like a timer event, there won't be a webview to send a message to, so this will do nothing.

    Parameters

    • msg: JSONValue

      The message to send to the webview. This should be a JSONable object.

    Returns Promise<any>

  • Schedules a recurring timer event on the server. You should prefer this to naive setInterval, if you want a long-running interval. This method will handle server restarts and other issues that could cause a naive setInterval to drift or stop.

    Parameters

    • name: string

      Unique identifier for the timer, used for cancellation

    • millis: number

      Interval in milliseconds between timer events

    • Optional data: JSONValue

      Optional data to pass to the timer event

    Returns Promise<TimerEvent>

    A TimerEvent object representing the scheduled timer

    Throws

    Error if no postId is present in the context

  • Schedules a one-time timer event. You should prefer this to naive setTimeout, if you want a long-running timer. This method will handle server restarts and other issues that could cause a naive setTimeout to drift or stop.

    Parameters

    • name: string

      Unique identifier for the timer, used for cancellation

    • millis: number

      Delay in milliseconds before the timer fires

    • Optional data: JSONValue

      Optional data to pass to the timer event

    Returns Promise<TimerEvent>

    A TimerEvent object representing the scheduled timer

    Throws

    Error if no postId is present in the context