BoardGameClient

open class BoardGameClient

BoardGameClient for network communication in BGW applications. Inherit from this class and override its open functions. By default, these do nothing if not overridden.

Parameters

secret

The server secret.

networkLoggingBehavior

The desired network logging verbosity. Default: NetworkLogging.NO_LOGGING.

Functions

Link copied to clipboard
fun connect(): Boolean

Connects to the remote server, blocking.

Link copied to clipboard
fun createGame(gameID: String, greetingMessage: String)

Creates a new game session on the server by sending a CreateGameMessage. The session ID will be set automatically and returned through the onCreateGameResponse.

fun createGame(    gameID: String,     sessionID: String,     greetingMessage: String)

Creates a new game session on the server by sending a CreateGameMessage.

Link copied to clipboard
fun disconnect()

Disconnects from the remote server.

Link copied to clipboard
fun joinGame(sessionID: String, greetingMessage: String)

Joins an existing game session on the server by sending a JoinGameMessage.

Link copied to clipboard
fun leaveGame(goodbyeMessage: String)

Leaves the current game session by sending a LeaveGameMessage.

Link copied to clipboard
open fun onClose(    code: Int,     reason: String,     remote: Boolean)

Called after the websocket connection has been closed.

Link copied to clipboard
open fun onCreateGameResponse(response: CreateGameResponse)

Called when server sent a CreateGameResponse after a CreateGameMessage was sent.

Link copied to clipboard
open fun onError(throwable: Throwable)

Called when an error occurred. By default, this method throws the incoming exception. Override to implement error handling.

Link copied to clipboard
open fun onGameActionReceived(message: GameAction, sender: String)

Called when an opponent sent a GameActionMessage. This method is supposed to act as a fallback solution if not for all Subclasses of GameAction a dedicated handler was registered using GameActionReceiver annotation.

Link copied to clipboard
open fun onGameActionResponse(response: GameActionResponse)

Called when server sent a GameActionResponse after a GameActionMessage was sent.

Link copied to clipboard
open fun onJoinGameResponse(response: JoinGameResponse)

Called when server sent a JoinGameResponse after a JoinGameMessage was sent.

Link copied to clipboard
open fun onLeaveGameResponse(response: LeaveGameResponse)

Called when server sent a LeaveGameResponse after a LeaveGameMessage was sent.

Link copied to clipboard
open fun onOpen()

Called after an opening handshake has been performed.

Link copied to clipboard
open fun onPlayerJoined(notification: PlayerJoinedNotification)

Called when a player joined the session and the server sent a PlayerJoinedNotification.

Link copied to clipboard
open fun onPlayerLeft(notification: PlayerLeftNotification)

Called when a player left the session and the server sent a PlayerLeftNotification.

Link copied to clipboard
open fun onSpectatorJoined(notification: SpectatorJoinedNotification)

Called when a spectator joined the session and the server sent a SpectatorJoinedNotification.

Link copied to clipboard
open fun onSpectatorJoinGameResponse(response: SpectatorJoinGameResponse)

Called when server sent a SpectatorJoinGameResponse after a SpectatorJoinGameMessage was sent.

Link copied to clipboard
fun sendGameActionMessage(payload: GameAction)

Sends a GameActionMessage to all connected players.

Link copied to clipboard
fun spectateGame(sessionID: String, greetingMessage: String)

Joins an existing game session as a spectator on the server by sending a SpectatorJoinGameMessage.

Properties

Link copied to clipboard
val host: String

The server ip or hostname.

Link copied to clipboard
val isOpen: Boolean

Returns the current state of connection.

Link copied to clipboard
val playerName: String

The player name.