socketModels

package
v0.0.0-...-659eabc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2017 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package socketModels contains the structures used to allow socketModels real-time communication with the system.

Index

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 NewSocketHub

func NewSocketHub() SocketHub

NewSocketHub creates a new Hub for a room.

func (*SocketHub) AddClient

func (receiver *SocketHub) AddClient(client *websocket.Conn, player userDataStructs.Player)

AddClient adds a connection to the hub, linking it with the player.

func (*SocketHub) Broadcast

func (receiver *SocketHub) Broadcast(message interface{}) []error

Broadcast sends to all connected peers a message.

func (*SocketHub) CurrentPlayer

func (receiver *SocketHub) CurrentPlayer() userDataStructs.Player

CurrentPlayer gets the current player which is in turn.

func (*SocketHub) GetConnectedPlayer

func (receiver *SocketHub) 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 (*SocketHub) IsPlayerTurn

func (receiver *SocketHub) 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 (*SocketHub) NextTurn

func (receiver *SocketHub) NextTurn()

NextTurn passes the turn to the nest player.

func (*SocketHub) SetFirstTurn

func (receiver *SocketHub) SetFirstTurn(conn *websocket.Conn) error

SetFirstTurn sets, if possible, the first player's turn, otherwise it returns an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL