Documentation ¶
Overview ¶
Package socketModels contains the structures used to allow socketModels real-time communication with the system.
Index ¶
- type ServerRoom
- func (receiver *ServerRoom) AddPlayer(player userDataStructs.Player, socket *websocket.Conn) error
- func (receiver *ServerRoom) BroadcastNewMove(Move map[string]interface{}, result gameServerLogic.Result) []error
- func (receiver *ServerRoom) BroadcastRoomUpdate(typeOfUpdate string) []error
- func (receiver *ServerRoom) CurrentPlayer() userDataStructs.Player
- func (receiver *ServerRoom) GetConnectedPlayer(conn *websocket.Conn) (userDataStructs.Player, bool)
- func (receiver *ServerRoom) IsFull() bool
- func (receiver *ServerRoom) IsPlayerTurn(conn *websocket.Conn) bool
- func (receiver *ServerRoom) NextTurn()
- func (receiver *ServerRoom) SendMoveRejected(dest *websocket.Conn, CustomData map[string]interface{}) error
- func (receiver *ServerRoom) SetFirstTurn(conn *websocket.Conn) error
- type SocketHub
- func (receiver *SocketHub) AddClient(client *websocket.Conn, player userDataStructs.Player)
- func (receiver *SocketHub) Broadcast(message interface{}) []error
- func (receiver *SocketHub) CurrentPlayer() userDataStructs.Player
- func (receiver *SocketHub) GetConnectedPlayer(conn *websocket.Conn) (userDataStructs.Player, bool)
- func (receiver *SocketHub) IsPlayerTurn(conn *websocket.Conn) bool
- func (receiver *SocketHub) NextTurn()
- func (receiver *SocketHub) SetFirstTurn(conn *websocket.Conn) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ServerRoom ¶
type ServerRoom struct { ID int64 //ID of the room. PlayersLeft int64 //missing players to complete the room. MatchStarted bool //Match started. // contains filtered or unexported fields }
ServerRoom represents a lobby on the server.
func NewServerRoom ¶
func NewServerRoom(roomID int64, maxPlayers int64) *ServerRoom
NewServerRoom creates a new server room with the specified parameters.
func (*ServerRoom) AddPlayer ¶
func (receiver *ServerRoom) AddPlayer(player userDataStructs.Player, socket *websocket.Conn) error
AddPlayer Adds a player to the room.
func (*ServerRoom) BroadcastNewMove ¶
func (receiver *ServerRoom) BroadcastNewMove(Move map[string]interface{}, result gameServerLogic.Result) []error
BroadcastNewMove sends a new move to connected players
func (*ServerRoom) BroadcastRoomUpdate ¶
func (receiver *ServerRoom) BroadcastRoomUpdate(typeOfUpdate string) []error
BroadcastRoomUpdate sends a message to update room of all connected peers.
func (*ServerRoom) CurrentPlayer ¶
func (receiver *ServerRoom) CurrentPlayer() userDataStructs.Player
CurrentPlayer gets the current player which is in turn.
func (*ServerRoom) GetConnectedPlayer ¶
func (receiver *ServerRoom) GetConnectedPlayer(conn *websocket.Conn) (userDataStructs.Player, bool)
GetConnectedPlayer gets the player connected with the specified socket from this struct. If not found second return value is set to false.
func (*ServerRoom) IsFull ¶
func (receiver *ServerRoom) IsFull() bool
IsFull returns true if it is not possible to add other players, false otherwise.
func (*ServerRoom) IsPlayerTurn ¶
func (receiver *ServerRoom) IsPlayerTurn(conn *websocket.Conn) bool
IsPlayerTurn returns true if the requesting connection's player is the one who has permission to play for this turn, false otherwise.
func (*ServerRoom) NextTurn ¶
func (receiver *ServerRoom) NextTurn()
NextTurn passes the turn to the nest player.
func (*ServerRoom) SendMoveRejected ¶
func (receiver *ServerRoom) SendMoveRejected(dest *websocket.Conn, CustomData map[string]interface{}) error
SendMoveRejected sends to the player which made an invalid move a notification.
func (*ServerRoom) SetFirstTurn ¶
func (receiver *ServerRoom) SetFirstTurn(conn *websocket.Conn) error
SetFirstTurn sets, if possible, the first player's turn, otherwise it returns an error.
type SocketHub ¶
type SocketHub struct { Clients map[*websocket.Conn]userDataStructs.Player //Represents the pool of connected clients. Turns []*websocket.Conn //Represents the keys used to get the turns during a match. CurrentTurnIndex int //Represents the index in turns array to tell which player must make the move. }
SocketHub represents a hub with multiple connections to clients.
func (*SocketHub) CurrentPlayer ¶
func (receiver *SocketHub) CurrentPlayer() userDataStructs.Player
CurrentPlayer gets the current player which is in turn.
func (*SocketHub) GetConnectedPlayer ¶
GetConnectedPlayer gets the player connected with the specified socket from this struct. If not found second return value is set to false.
func (*SocketHub) IsPlayerTurn ¶
IsPlayerTurn returns true if the requesting connection's player is the one who has permission to play for this turn, false otherwise.