Lobby

The lobby is the core of the game hosting platform. It is responsible for tracking

  • user token balances

  • the availability of different games

  • queues

  • settlement of completed games

Game Room Registration

The manager of the lobby (OptiSwap, in this case) is in charge of registering games. They need to understand the appropriate token integrations and play modes so that the user is presented with valid and descriptive options.

Registering a game adds a key to the map:

HashMap<Text, GameRoom>

where GameRoom is:

  public type GameRoom = {
    game: GameInterface;
    token: Principal;
    queue: GameQueue;
  };

Already at this point we've got multiple possibilities for a given Game. For example, with the same underlying Tic-Tac-Toe implementation we could call

registerGame("Low-Stakes HOGE Tic-Tac-Toe", ...)
registerGame("High-Stakes HOGE Tic-Tac-Toe", ...)
registerGame("Low-Stakes SHIB Tic-Tac-Toe", ...)
registerGame("High-Stakes SHIB Tic-Tac-Toe", ...)

to provide a range of offerings for holders of different tokens with different risk appetites.

Deposit

ICRC token deposits are done in the standard approve + deposit workflow. Users receive a corresponding credit in the internal accounting system.

Withdraw

Tokens credited to the user's account can be withdrawn at any time.

Join Queue

If the user has a sufficient token balance then they can request to join the queue for any of the registered game rooms. If the queue is valid and the game is ready to start then the lobby will initiate it.

Finalize Game

Once the game session is complete, the lobby finalizes the session to settle the bookkeeping. The game reports out the resulting stakes for all the players, and their balances are changed accordingly. The lobby makes checks on the resulting balances to ensure the game has accounted correctly for every entry.

Last updated