GameService

class GameService(storage: GameStorageType? = null, params: StorageParams? = null) : GameServiceImpl

Primary implementation of the game service for managing game state persistence. Provides integration with various storage backends (file system, MongoDB) and handles game state synchronization, player management, and storage operations.

Constructors

Link copied to clipboard
constructor(storage: GameStorageType? = null, params: StorageParams? = null)

Properties

Link copied to clipboard

The storage type to use (FILE_STORAGE or DATABASE_STORAGE).

Functions

Link copied to clipboard
open suspend override fun closeService()

Closes the service and releases any held resources. Should be called when the service is no longer needed.

Link copied to clipboard
open suspend override fun delete(gameName: String)

Deletes a game from storage.

Link copied to clipboard
open suspend override fun getAllGameNames(): List<String>

Retrieves all game names stored in the configured storage backend.

Link copied to clipboard
open override fun getStorageTypeName(): String

Gets the name of the storage type being used by this service.

Link copied to clipboard
open suspend override fun hardLoad(id: String): GameState?

Directly loads a game state from storage by its identifier.

Link copied to clipboard
open suspend override fun hardSave(id: String, gameState: GameState)

Directly saves a game state to storage under the given identifier.

Link copied to clipboard
open suspend override fun hasAllPlayers(game: Game): Boolean

Checks if all required players have joined the game.

Link copied to clipboard
open suspend override fun new(gameName: String, gameStateProvider: () -> GameState)

Creates a new game entry in storage.

Link copied to clipboard
open suspend override fun refresh(game: Game): Game

Refreshes the game state by loading the latest version from storage. Updates the game instance with any changes made by other players.

Link copied to clipboard
open suspend override fun refreshBase(game: Game): GameState?

Loads the base game state from storage without game instance wrapping.

Link copied to clipboard
open suspend override fun runStorageHealthCheck()

Runs a health check on the storage system to verify it's functioning correctly. Creates, reads, updates, and deletes a test game state.

Link copied to clipboard
open suspend override fun saveEndGame(game: Game)

Saves the final game state at the end of a game session. Handles cleanup and proper storage of winner information.

Link copied to clipboard
open suspend override fun saveOnlyBoard(gameName: String?, gameState: GameState?)

Saves only the board state and last player to storage. Used during gameplay to persist moves without modifying player information.