-
Notifications
You must be signed in to change notification settings - Fork 0
Server Side Communication Specifications
This document provides an overview of the server-side communication specifications to help you understand the server's functionality and how it interacts with the client. The server is comprised of two main components: the GamePlayController
and the RoomController
.
The GamePlayController
is responsible for managing game-related functionality, such as starting turns, rolling dice, rerolling dice, choosing score categories, and updating scorecards.
The GamePlayController
handles incoming messages from clients based on their message types:
-
messages.TurnStarted
: Starts a new turn for a player in a room. -
messages.DiceRolled
: Rolls dice for a player in a room. -
messages.RerollDice
: Rerolls dice for a player in a room, based on the held dice indices. -
messages.ChooseCategory
: Allows a player to choose a score category for their turn.
The RoomController
is responsible for managing rooms and players, including creating rooms, joining rooms, listing rooms, and leaving rooms.
The RoomController
handles incoming messages from clients based on their message types:
-
messages.CreateRoom
: Creates a new room and adds the player to it. -
messages.JoinRoom
: Adds a player to an existing room. -
messages.ListRooms
: Sends a list of available rooms to a player. -
messages.LeaveRoom
: Removes a player from a room.
Rooms are managed using the RoomManager
, which provides functions to create, join, list, and leave rooms, as well as to retrieve and destroy rooms. The RoomController
uses these functions to update the room state and notify players about changes.
When the required number of players (2) has joined a room, the RoomController
starts the game by calling the StartGame
function, which sets the gameStarted
flag to true
for the room and sends a messages.GameStarted
message to all players in the room. The game begins with the first player's turn.
When a client sends a message to the server, the server processes the message based on its type and updates the game state accordingly. The server then sends messages back to the clients to notify them of any changes. This back-and-forth communication continues throughout the game, ensuring that all clients are kept up to date with the game's progress.
To implement the client-side functionality, you need to handle the incoming messages from the server and update the client's state based on the received information. For example, when you receive a messages.GameStarted
message, you can send a messages.TurnStarted
message back to the server to initiate the first player's turn.