Documentation
¶
Index ¶
- Variables
- func CreateLobby(playerName, language string, ...) (*Player, *Lobby, error)
- func GeneratePlayerName() string
- func GetRandomWords(lobby *Lobby) []string
- func HandleEvent(raw []byte, received *JSEvent, lobby *Lobby, player *Player) error
- func OnConnected(lobby *Lobby, player *Player)
- func OnDisconnected(lobby *Lobby, player *Player)
- func RemoveLobby(id string)
- type Fill
- type FillEvent
- type JSEvent
- type Line
- type LineEvent
- type Lobby
- func (lobby *Lobby) AppendFill(fill *FillEvent)
- func (lobby *Lobby) AppendLine(line *LineEvent)
- func (lobby *Lobby) ClearDrawing()
- func (lobby *Lobby) GetAvailableWordHints(player *Player) []*WordHint
- func (lobby *Lobby) GetPlayer(userSession string) *Player
- func (lobby *Lobby) HasConnectedPlayers() bool
- func (lobby *Lobby) JoinPlayer(playerName string) *Player
- type Message
- type NextTurn
- type Player
- func (player *Player) GetLastKnownAddress() string
- func (player *Player) GetUserSession() string
- func (player *Player) GetWebsocket() *websocket.Conn
- func (player *Player) GetWebsocketMutex() *sync.Mutex
- func (player *Player) SetLastKnownAddress(address string)
- func (player *Player) SetWebsocket(socket *websocket.Conn)
- type PlayerState
- type Ready
- type Rounds
- type SettingBounds
- type WordHint
Constants ¶
This section is empty.
Variables ¶
var ( LobbySettingBounds = &SettingBounds{ MinDrawingTime: 60, MaxDrawingTime: 300, MinRounds: 1, MaxRounds: 20, MinMaxPlayers: 2, MaxMaxPlayers: 24, MinClientsPerIPLimit: 1, MaxClientsPerIPLimit: 24, } SupportedLanguages = map[string]string{ "english": "English", "italian": "Italian", "german": "German", "french": "French", "dutch": "Dutch", } )
var SendDataToConnectedPlayers func(sender *Player, lobby *Lobby, data interface{})
var TriggerComplexUpdateEvent func(eventType string, data interface{}, lobby *Lobby)
var TriggerComplexUpdatePerPlayerEvent func(eventType string, data func(*Player) interface{}, lobby *Lobby)
var TriggerSimpleUpdateEvent func(eventType string, lobby *Lobby)
var WriteAsJSON func(player *Player, object interface{}) error
var WritePublicSystemMessage func(lobby *Lobby, text string)
Functions ¶
func CreateLobby ¶
func CreateLobby(playerName, language string, drawingTime, rounds, maxPlayers, customWordChance, clientsPerIPLimit int, customWords []string, enableVotekick bool) (*Player, *Lobby, error)
CreateLobby allows creating a lobby, optionally returning errors that occurred during creation.
func GeneratePlayerName ¶
func GeneratePlayerName() string
GeneratePlayerName creates a new playername. A so called petname. It consists of an adverb, an adjective and a animal name. The result can generally be trusted to be sane.
func GetRandomWords ¶
GetRandomWords gets 3 random words for the passed Lobby. The words will be chosen from the custom words and the default dictionary, depending on the settings specified by the Lobby-Owner.
func HandleEvent ¶
func OnConnected ¶
func OnDisconnected ¶
func RemoveLobby ¶
func RemoveLobby(id string)
RemoveLobby deletes a lobby, not allowing anyone to connect to it again.
Types ¶
type FillEvent ¶
LineEvent is basically the same as JSEvent, but with a specific Data type. We use this for reparsing as soon as we know that the type is right. It's a bit unperformant, but will do for now.
type JSEvent ¶
type JSEvent struct {
Type string `json:"type"`
Data interface{} `json:"data"`
}
JSEvent contains an eventtype and optionally any data.
type Line ¶
type Line struct {
FromX float32 `json:"fromX"`
FromY float32 `json:"fromY"`
ToX float32 `json:"toX"`
ToY float32 `json:"toY"`
Color string `json:"color"`
LineWidth float32 `json:"lineWidth"`
}
Line is the struct that a client send when drawing
type LineEvent ¶
LineEvent is basically the same as JSEvent, but with a specific Data type. We use this for reparsing as soon as we know that the type is right. It's a bit unperformant, but will do for now.
type Lobby ¶
type Lobby struct {
// ID uniquely identified the Lobby.
ID string
// DrawingTime is the amount of seconds that each player has available to
// finish their drawing.
DrawingTime int
// MaxRounds defines how many iterations a lobby does before the game ends.
// One iteration means every participant does one drawing.
MaxRounds int
// MaxPlayers defines the maximum amount of players in a single lobby.
MaxPlayers int
// CustomWords are additional words that will be used in addition to the
// predefined words.
CustomWords []string
Words []string
// Players references all participants of the Lobby.
Players []*Player
// Drawer references the Player that is currently drawing.
Drawer *Player
// Owner references the Player that created the lobby.
Owner *Player
// CurrentWord represents the word that was last selected. If no word has
// been selected yet or the round is already over, this should be empty.
CurrentWord string
// WordHints for the current word.
WordHints []*WordHint
// WordHintsShown are the same as WordHints with characters visible.
WordHintsShown []*WordHint
// Round is the round that the Lobby is currently in. This is a number
// between 0 and MaxRounds. 0 indicates that it hasn't started yet.
Round int
// WordChoice represents the current choice of words.
WordChoice []string
// RoundEndTime represents the time at which the current round will end.
// This is a UTC unix-timestamp in milliseconds.
RoundEndTime int64
CustomWordsChance int
ClientsPerIPLimit int
// CurrentDrawing represents the state of the current canvas. The elements
// consist of LineEvent and FillEvent. Please do not modify the contents
// of this array an only move AppendLine and AppendFill on the respective
// lobby object.
CurrentDrawing []interface{}
EnableVotekick bool
// contains filtered or unexported fields
}
Lobby represents a game session.
func (*Lobby) AppendFill ¶
AppendFill adds a fill direction to the current drawing. This exists in order to prevent adding arbitrary elements to the drawing, as the backing array is an empty interface type.
func (*Lobby) AppendLine ¶
AppendLine adds a line direction to the current drawing. This exists in order to prevent adding arbitrary elements to the drawing, as the backing array is an empty interface type.
func (*Lobby) ClearDrawing ¶
func (lobby *Lobby) ClearDrawing()
func (*Lobby) GetAvailableWordHints ¶
func (*Lobby) HasConnectedPlayers ¶
func (*Lobby) JoinPlayer ¶
type Message ¶
type Message struct {
// Author is the player / thing that wrote the message
Author string `json:"author"`
// Content is the actual message text.
Content string `json:"content"`
}
Message represents a message in the chatroom.
type NextTurn ¶
type NextTurn struct {
Round int `json:"round"`
Players []*Player `json:"players"`
RoundEndTime int `json:"roundEndTime"`
}
NextTurn represents the data necessary for displaying the lobby state right after a new turn started. Meaning that no word has been chosen yet and therefore there are no wordhints and no current drawing instructions.
type Player ¶
type Player struct {
// ID uniquely identified the Player.
ID string `json:"id"`
// Name is the players displayed name
Name string `json:"name"`
// Score is the points that the player got in the current Lobby.
Score int `json:"score"`
// Connected defines whether the players websocket connection is currently
// established. This has previously been in state but has been moved out
// in order to avoid losing the state on refreshing the page.
// While checking the websocket against nil would be enough, we still need
// this field for sending it via the APIs.
Connected bool `json:"connected"`
// Rank is the current ranking of the player in his Lobby
LastScore int `json:"lastScore"`
Rank int `json:"rank"`
State PlayerState `json:"state"`
// contains filtered or unexported fields
}
Player represents a participant in a Lobby.
func (*Player) GetLastKnownAddress ¶
GetLastKnownAddress returns the last known IP-Address used for an HTTP request.
func (*Player) GetUserSession ¶
GetUserSession returns the players current user session.
func (*Player) GetWebsocket ¶
GetWebsocket simply returns the players websocket connection. This method exists to encapsulate the websocket field and prevent accidental sending the websocket data via the network.
func (*Player) GetWebsocketMutex ¶
GetWebsocketMutex returns a mutex for locking the websocket connection. Since gorilla websockets shits it self when two calls happen at the same time, we need a mutex per player, since each player has their own socket. This getter extends to prevent accidentally sending the mutex via the network.
func (*Player) SetLastKnownAddress ¶
SetLastKnownAddress sets the last known IP-Address used for an HTTP request. Can be retrieved via GetLastKnownAddress().
func (*Player) SetWebsocket ¶
SetWebsocket sets the given connection as the players websocket connection.
type PlayerState ¶
type PlayerState int
const ( Guessing PlayerState = 0 Drawing PlayerState = 1 Standby PlayerState = 2 )
type Ready ¶
type Ready struct {
PlayerID string `json:"playerId"`
PlayerName string `json:"playerName"`
Drawing bool `json:"drawing"`
OwnerID string `json:"ownerId"`
Round int `json:"round"`
MaxRound int `json:"maxRounds"`
RoundEndTime int `json:"roundEndTime"`
WordHints []*WordHint `json:"wordHints"`
Players []*Player `json:"players"`
CurrentDrawing []interface{} `json:"currentDrawing"`
}
Ready represents the initial state that a user needs upon connection. This includes all the necessary things for properly running a client without receiving any more data.
type SettingBounds ¶
type SettingBounds struct {
MinDrawingTime int64
MaxDrawingTime int64
MinRounds int64
MaxRounds int64
MinMaxPlayers int64
MaxMaxPlayers int64
MinClientsPerIPLimit int64
MaxClientsPerIPLimit int64
}
SettingBounds defines the lower and upper bounds for the user-specified lobby creation input.