Documentation ¶
Index ¶
- Constants
- Variables
- func CheckGuess(a, b string) int
- func CreateLobby(desiredLobbyId uuid.UUID, playerName, chosenLanguage string, publicLobby bool, ...) (*Player, *Lobby, error)
- func ExcludePlayer(toExclude *Player) func(*Player) bool
- func GetRandomWords(wordCount int, lobby *Lobby) []string
- func IsAllowedToSeeHints(player *Player) bool
- func IsAllowedToSeeRevealedHints(player *Player) bool
- func SanitizeName(name string) string
- type EditableLobbySettings
- type Event
- type EventTypeOnly
- type FillEvent
- type GameOverEvent
- type IntDataEvent
- type KickVote
- type LanguageData
- type LineEvent
- type Lobby
- func (lobby *Lobby) AppendFill(fill *FillEvent)
- func (lobby *Lobby) AppendLine(line *LineEvent)
- func (lobby *Lobby) Broadcast(data easyjson.Marshaler)
- func (lobby *Lobby) CanIPConnect(address string) bool
- func (lobby *Lobby) ClearDrawing()
- func (lobby *Lobby) Drawer() *Player
- func (lobby *Lobby) GetAvailableWordHints(player *Player) []*WordHint
- func (lobby *Lobby) GetConnectedPlayerCount() int
- func (lobby *Lobby) GetOccupiedPlayerSlots() int
- func (lobby *Lobby) GetPlayer(userSession uuid.UUID) *Player
- func (lobby *Lobby) GetPlayers() []*Player
- func (lobby *Lobby) HandleEvent(eventType string, payload []byte, player *Player) error
- func (lobby *Lobby) HasConnectedPlayers() bool
- func (lobby *Lobby) HasFreePlayerSlot() bool
- func (lobby *Lobby) IsPublic() bool
- func (lobby *Lobby) JoinPlayer(name string) *Player
- func (lobby *Lobby) OnPlayerConnectUnsynchronized(player *Player)
- func (lobby *Lobby) OnPlayerDisconnect(player *Player)
- func (lobby *Lobby) SendYourTurnEvent(player *Player)
- func (lobby *Lobby) Shutdown()
- func (lobby *Lobby) Synchronized(logic func())
- type NameChangeEvent
- type NextTurn
- type OutgoingMessage
- type OwnerChangeEvent
- type Player
- func (player *Player) GetLastKnownAddress() string
- func (player *Player) GetUserSession() uuid.UUID
- func (player *Player) GetWebsocket() *gws.Conn
- func (v Player) MarshalEasyJSON(w *jwriter.Writer)
- func (v Player) MarshalJSON() ([]byte, error)
- func (player *Player) SetLastKnownAddress(address string)
- func (player *Player) SetWebsocket(socket *gws.Conn)
- func (v *Player) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *Player) UnmarshalJSON(data []byte) error
- type PlayerState
- type ReadyEvent
- type ScoreCalculation
- type SettingBounds
- type State
- type StringDataEvent
- type WordChosen
- type WordHint
- type YourTurn
Constants ¶
const ( DrawingBoardBaseWidth = 1600 DrawingBoardBaseHeight = 900 MinBrushSize = 8 MaxBrushSize = 32 )
const ( EventTypeStart = "start" EventTypeToggleReadiness = "toggle-readiness" EventTypeToggleSpectate = "toggle-spectate" EventTypeRequestDrawing = "request-drawing" EventTypeChooseWord = "choose-word" EventTypeUndo = "undo" )
Eevnts that are just incomming from the client.
const ( EventTypeUpdatePlayers = "update-players" EventTypeUpdateWordHint = "update-wordhint" EventTypeWordChosen = "word-chosen" EventTypeCorrectGuess = "correct-guess" EventTypeCloseGuess = "close-guess" EventTypeSystemMessage = "system-message" EventTypeNonGuessingPlayerMessage = "non-guessing-player-message" EventTypeReady = "ready" EventTypeGameOver = "game-over" EventTypeYourTurn = "your-turn" EventTypeNextTurn = "next-turn" EventTypeDrawing = "drawing" EventTypeDrawerKicked = "drawer-kicked" EventTypeOwnerChange = "owner-change" EventTypeLobbySettingsChanged = "lobby-settings-changed" EventTypeShutdown = "shutdown" EventTypeKeepAlive = "keep-alive" )
Events that are outgoing only.
const ( EqualGuess = 0 CloseGuess = 1 DistantGuess = 2 )
const MaxPlayerNameLength int = 30
MaxPlayerNameLength defines how long a string can be at max when used as the playername.
Variables ¶
var ( EventTypeKickVote = "kick-vote" EventTypeNameChange = "name-change" EventTypeMessage = "message" EventTypeLine = "line" EventTypeFill = "fill" EventTypeClearDrawingBoard = "clear-drawing-board" )
Events that are bidirectional.
var ( ErrUnknownWordList = errors.New("wordlist unknown") WordlistData = map[string]LanguageData{ "english_gb": { LanguageCode: "en_gb", Lowercaser: func() cases.Caser { return cases.Lower(language.BritishEnglish) }, }, "english": { LanguageCode: "en_us", Lowercaser: func() cases.Caser { return cases.Lower(language.AmericanEnglish) }, }, "italian": { LanguageCode: "it", Lowercaser: func() cases.Caser { return cases.Lower(language.Italian) }, }, "german": { LanguageCode: "de", Lowercaser: func() cases.Caser { return cases.Lower(language.German) }, }, "french": { LanguageCode: "fr", Lowercaser: func() cases.Caser { return cases.Lower(language.French) }, }, "dutch": { LanguageCode: "nl", Lowercaser: func() cases.Caser { return cases.Lower(language.Dutch) }, }, "ukrainian": { LanguageCode: "ua", Lowercaser: func() cases.Caser { return cases.Lower(language.Ukrainian) }, }, "russian": { LanguageCode: "ru", Lowercaser: func() cases.Caser { return cases.Lower(language.Russian) }, }, "polish": { LanguageCode: "pl", Lowercaser: func() cases.Caser { return cases.Lower(language.Polish) }, }, } )
var ChillScoring = &adjustableScoringAlgorithm{
identifier: "chill",
baseScore: 100.0,
maxBonusBaseScore: 100.0,
bonusBaseScoreDeclineFactor: 2.0,
maxHintBonusScore: 60.0,
}
var CompetitiveScoring = &adjustableScoringAlgorithm{
identifier: "competitive",
baseScore: 10.0,
maxBonusBaseScore: 290.0,
bonusBaseScoreDeclineFactor: 3.0,
maxHintBonusScore: 120.0,
}
var SupportedLanguages = map[string]string{
"english_gb": "English (GB)",
"english": "English (US)",
"italian": "Italian",
"german": "German",
"french": "French",
"dutch": "Dutch",
"ukrainian": "Ukrainian",
"russian": "Russian",
"polish": "Polish",
}
var SupportedScoreCalculations = []string{
"chill",
"competitive",
}
Functions ¶
func CheckGuess ¶ added in v0.8.7
CheckGuess compares the strings with eachother. Possible results:
- EqualGuess (0)
- CloseGuess (1)
- DistantGuess (2)
This works mostly like levensthein distance, but doesn't check further than to a distance of 2 and also handles transpositions where the runes are directly next to eachother.
func CreateLobby ¶
func CreateLobby( desiredLobbyId uuid.UUID, playerName, chosenLanguage string, publicLobby bool, drawingTime, rounds, maxPlayers, customWordsPerTurn, clientsPerIPLimit int, customWords []string, scoringCalculation ScoreCalculation, ) (*Player, *Lobby, error)
CreateLobby creates a new lobby including the initial player (owner) and optionally returns an error, if any occurred during creation.
func ExcludePlayer ¶
func GetRandomWords ¶
GetRandomWords gets a custom amount of 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 lobbies creator.
func IsAllowedToSeeHints ¶ added in v0.8.11
func IsAllowedToSeeRevealedHints ¶ added in v0.8.11
func SanitizeName ¶
SanitizeName removes invalid characters from the players name, resolves emoji codes, limits the name length and generates a new name if necessary.
Types ¶
type EditableLobbySettings ¶
type EditableLobbySettings struct { // CustomWords are additional words that will be used in addition to the // predefined words. // Public defines whether the lobby is being broadcast to clients asking // for available lobbies. Public bool `json:"public"` // MaxPlayers defines the maximum amount of players in a single lobby. MaxPlayers int `json:"maxPlayers"` CustomWordsPerTurn int `json:"customWordsPerTurn"` // ClientsPerIPLimit helps preventing griefing by reducing each player // to one tab per IP address. ClientsPerIPLimit int `json:"clientsPerIpLimit"` // Rounds defines how many iterations a lobby does before the game ends. // One iteration means every participant does one drawing. Rounds int `json:"rounds"` // DrawingTime is the amount of seconds that each player has available to // finish their drawing. DrawingTime int `json:"drawingTime"` }
EditableLobbySettings represents all lobby settings that are editable by the lobby owner after the lobby has already been opened.
func (EditableLobbySettings) MarshalEasyJSON ¶ added in v0.8.3
func (v EditableLobbySettings) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (EditableLobbySettings) MarshalJSON ¶ added in v0.8.3
func (v EditableLobbySettings) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*EditableLobbySettings) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *EditableLobbySettings) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*EditableLobbySettings) UnmarshalJSON ¶ added in v0.8.3
func (v *EditableLobbySettings) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type Event ¶
Event contains an eventtype and optionally any data.
func (Event) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (Event) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*Event) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Event) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type EventTypeOnly ¶ added in v0.8.3
type EventTypeOnly struct {
Type string `json:"type"`
}
func (EventTypeOnly) MarshalEasyJSON ¶ added in v0.8.3
func (v EventTypeOnly) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (EventTypeOnly) MarshalJSON ¶ added in v0.8.3
func (v EventTypeOnly) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*EventTypeOnly) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *EventTypeOnly) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*EventTypeOnly) UnmarshalJSON ¶ added in v0.8.3
func (v *EventTypeOnly) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type FillEvent ¶
type FillEvent struct { Data *struct { X uint16 `json:"x"` Y uint16 `json:"y"` // Color is a color index. This was previously an rgb value, but since // the values are always the same, using an index saves bandwidth. Color uint8 `json:"color"` } `json:"data"` Type string `json:"type"` }
func (FillEvent) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (FillEvent) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*FillEvent) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*FillEvent) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type GameOverEvent ¶
type GameOverEvent struct { *ReadyEvent PreviousWord string `json:"previousWord"` }
GameOverEvent is basically the ready event, but contains the last word. This is required in order to show the last player the word, in case they didn't manage to guess it in time. This is necessary since the last word is usually part of the "next-turn" event, which we don't send, since the game is over already.
func (GameOverEvent) MarshalEasyJSON ¶ added in v0.8.3
func (v GameOverEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (GameOverEvent) MarshalJSON ¶ added in v0.8.3
func (v GameOverEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*GameOverEvent) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *GameOverEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*GameOverEvent) UnmarshalJSON ¶ added in v0.8.3
func (v *GameOverEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type IntDataEvent ¶ added in v0.8.3
type IntDataEvent struct {
Data int `json:"data"`
}
func (IntDataEvent) MarshalEasyJSON ¶ added in v0.8.3
func (v IntDataEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (IntDataEvent) MarshalJSON ¶ added in v0.8.3
func (v IntDataEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*IntDataEvent) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *IntDataEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*IntDataEvent) UnmarshalJSON ¶ added in v0.8.3
func (v *IntDataEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type KickVote ¶
type KickVote struct { PlayerName string `json:"playerName"` PlayerID uuid.UUID `json:"playerId"` VoteCount int `json:"voteCount"` RequiredVoteCount int `json:"requiredVoteCount"` }
KickVote represents a players vote to kick another players. If the VoteCount is as great or greater than the RequiredVoteCount, the event indicates a successful kick vote. The voting is anonymous, meaning the voting player won't be exposed.
func (KickVote) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (KickVote) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*KickVote) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*KickVote) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type LanguageData ¶ added in v0.8.7
type LineEvent ¶
type LineEvent struct { Type string `json:"type"` // Data contains the coordinates, stroke width and color. The coors here // aren't uint16, as it allows us to easily allow implementing drawing on // the client, where the user drags the line over the canvas border. // If we were to not accept out of bounds values, the lines would be chopped // off before reaching the canvas border. Data struct { X int16 `json:"x"` Y int16 `json:"y"` X2 int16 `json:"x2"` Y2 int16 `json:"y2"` // Color is a color index. This was previously an rgb value, but since // the values are always the same, using an index saves bandwidth. Color uint8 `json:"color"` Width uint8 `json:"width"` } `json:"data"` }
func (LineEvent) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (LineEvent) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*LineEvent) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*LineEvent) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type Lobby ¶
type Lobby struct { // ID uniquely identified the Lobby. LobbyID string EditableLobbySettings // DrawingTimeNew is the new value of the drawing time. If a round is // already ongoing, we can't simply change the drawing time, as it would // screw with the score calculation of the current turn. DrawingTimeNew int CustomWords []string // Whether the game has started, is ongoing or already over. State State // Owner references the Player that currently owns the lobby. // Meaning this player has rights to restart or change certain settings. Owner *Player // ScoreCalculation decides how scores for both guessers and drawers are // determined. ScoreCalculation ScoreCalculation // 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 // Round is the round that the Lobby is currently in. This is a number // between 0 and Rounds. 0 indicates that it hasn't started yet. Round int Wordpack string // LastPlayerDisconnectTime is used to know since when a lobby is empty, in case // it is empty. LastPlayerDisconnectTime *time.Time WriteObject func(*Player, easyjson.Marshaler) error WritePreparedMessage func(*Player, *gws.Broadcaster) error // contains filtered or unexported fields }
Lobby represents a game session. It must not be sent via the API, as it exposes gameplay relevant information.
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) CanIPConnect ¶
CanIPConnect checks whether the IP is still allowed regarding the lobbies clients per IP address limit. This function should only be called for players that aren't already in the lobby.
func (*Lobby) ClearDrawing ¶
func (lobby *Lobby) ClearDrawing()
func (*Lobby) GetAvailableWordHints ¶
GetAvailableWordHints returns a WordHint array depending on the players game state, since people that are drawing or have already guessed correctly can see all hints.
func (*Lobby) GetConnectedPlayerCount ¶
GetConnectedPlayerCount returns the amount of player that have currently established a socket connection.
func (*Lobby) GetOccupiedPlayerSlots ¶
GetOccupiedPlayerSlots counts the available slots which can be taken by new players. Whether a slot is available is determined by the player count and whether a player is disconnect or furthermore how long they have been disconnected for. Therefore the result of this function will differ from Lobby.GetConnectedPlayerCount.
func (*Lobby) GetPlayers ¶
func (*Lobby) HandleEvent ¶
func (*Lobby) HasConnectedPlayers ¶
func (*Lobby) HasFreePlayerSlot ¶
HasFreePlayerSlot determines whether the lobby still has a slot for at least one more player. If a player has disconnected recently, the slot will be preserved for 5 minutes. This function should be used over Lobby.GetOccupiedPlayerSlots, as it is potentially faster.
func (*Lobby) JoinPlayer ¶
JoinPlayer creates a new player object using the given name and adds it to the lobbies playerlist. The new players is returned.
func (*Lobby) OnPlayerConnectUnsynchronized ¶
func (*Lobby) OnPlayerDisconnect ¶
func (*Lobby) SendYourTurnEvent ¶ added in v0.8.19
func (*Lobby) Shutdown ¶
func (lobby *Lobby) Shutdown()
Shutdown sends all players an event, indicating that the lobby will be shut down. The caller of this function should take care of not allowing new connections. Clients should gracefully disconnect.
func (*Lobby) Synchronized ¶
func (lobby *Lobby) Synchronized(logic func())
Synchronized allows running a function while keeping the lobby locked via it's own mutex. This is useful in order to avoid having to relock a lobby multiple times, which might cause unexpected inconsistencies.
type NameChangeEvent ¶
type NameChangeEvent struct { PlayerName string `json:"playerName"` PlayerID uuid.UUID `json:"playerId"` }
func (NameChangeEvent) MarshalEasyJSON ¶ added in v0.8.3
func (v NameChangeEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (NameChangeEvent) MarshalJSON ¶ added in v0.8.3
func (v NameChangeEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*NameChangeEvent) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *NameChangeEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*NameChangeEvent) UnmarshalJSON ¶ added in v0.8.3
func (v *NameChangeEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type NextTurn ¶
type NextTurn struct { // PreviousWord signals the last chosen word. If empty, no word has been // chosen. The client can now themselves whether there has been a previous // turn, by looking at the current gamestate. PreviousWord string `json:"previousWord"` Players []*Player `json:"players"` ChoiceTimeLeft int `json:"choiceTimeLeft"` Round int `json:"round"` }
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.
func (NextTurn) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (NextTurn) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*NextTurn) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*NextTurn) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type OutgoingMessage ¶ added in v0.8.3
type OutgoingMessage struct { // Content is the actual message text. Content string `json:"content"` // Author is the player / thing that wrote the message Author string `json:"author"` // AuthorID is the unique identifier of the authors player object. AuthorID uuid.UUID `json:"authorId"` }
OutgoingMessage represents a message in the chatroom.
func (OutgoingMessage) MarshalEasyJSON ¶ added in v0.8.3
func (v OutgoingMessage) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (OutgoingMessage) MarshalJSON ¶ added in v0.8.3
func (v OutgoingMessage) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*OutgoingMessage) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *OutgoingMessage) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*OutgoingMessage) UnmarshalJSON ¶ added in v0.8.3
func (v *OutgoingMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type OwnerChangeEvent ¶
type OwnerChangeEvent struct { PlayerName string `json:"playerName"` PlayerID uuid.UUID `json:"playerId"` }
func (OwnerChangeEvent) MarshalEasyJSON ¶ added in v0.8.3
func (v OwnerChangeEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (OwnerChangeEvent) MarshalJSON ¶ added in v0.8.3
func (v OwnerChangeEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*OwnerChangeEvent) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *OwnerChangeEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*OwnerChangeEvent) UnmarshalJSON ¶ added in v0.8.3
func (v *OwnerChangeEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type Player ¶
type Player struct { // Name is the players displayed name Name string `json:"name"` State PlayerState `json:"state"` // SpectateToggleRequested is used for state changes between spectator and // player. We want to prevent people from switching in and out of the Player // state. While this will allow people to skip being the drawer, it will // also cause them to lose points for that round. SpectateToggleRequested bool `json:"spectateToggleRequested"` // Rank is the current ranking of the player in his Lobby // Score is the points that the player got in the current Lobby. Score int `json:"score"` LastScore int `json:"lastScore"` Rank int `json:"rank"` // 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"` // ID uniquely identified the Player. ID uuid.UUID `json:"id"` // 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 ¶
func (player *Player) GetUserSession() uuid.UUID
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) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (Player) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
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.
func (*Player) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Player) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type PlayerState ¶
type PlayerState string
const ( Guessing PlayerState = "guessing" Drawing PlayerState = "drawing" Standby PlayerState = "standby" Ready PlayerState = "ready" Spectating PlayerState = "spectating" )
type ReadyEvent ¶ added in v0.8.10
type ReadyEvent struct { WordHints []*WordHint `json:"wordHints"` PlayerName string `json:"playerName"` Players []*Player `json:"players"` GameState State `json:"gameState"` CurrentDrawing []any `json:"currentDrawing"` PlayerID uuid.UUID `json:"playerId"` OwnerID uuid.UUID `json:"ownerId"` Round int `json:"round"` Rounds int `json:"rounds"` TimeLeft int `json:"timeLeft"` DrawingTimeSetting int `json:"drawingTimeSetting"` AllowDrawing bool `json:"allowDrawing"` }
ReadyEvent 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.
func (ReadyEvent) MarshalEasyJSON ¶ added in v0.8.10
func (v ReadyEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (ReadyEvent) MarshalJSON ¶ added in v0.8.10
func (v ReadyEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*ReadyEvent) UnmarshalEasyJSON ¶ added in v0.8.10
func (v *ReadyEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*ReadyEvent) UnmarshalJSON ¶ added in v0.8.10
func (v *ReadyEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type ScoreCalculation ¶ added in v0.8.19
type ScoreCalculation interface { Identifier() string CalculateGuesserScore(*Lobby) int CalculateDrawerScore(*Lobby) int }
ScoreCalculation allows having different scoring systems for
type SettingBounds ¶
type SettingBounds struct { MinDrawingTime int `json:"minDrawingTime" env:"MIN_DRAWING_TIME"` MaxDrawingTime int `json:"maxDrawingTime" env:"MAX_DRAWING_TIME"` MinRounds int `json:"minRounds" env:"MIN_ROUNDS"` MaxRounds int `json:"maxRounds" env:"MAX_ROUNDS"` MinMaxPlayers int `json:"minMaxPlayers" env:"MIN_MAX_PLAYERS"` MaxMaxPlayers int `json:"maxMaxPlayers" env:"MAX_MAX_PLAYERS"` MinClientsPerIPLimit int `json:"minClientsPerIpLimit" env:"MIN_CLIENTS_PER_IP_LIMIT"` MaxClientsPerIPLimit int `json:"maxClientsPerIpLimit" env:"MAX_CLIENTS_PER_IP_LIMIT"` MinCustomWordsPerTurn int `json:"minCustomWordsPerTurn" env:"MIN_CUSTOM_WORDS_PER_TURN"` MaxCustomWordsPerTurn int `json:"maxCustomWordsPerTurn" env:"MAX_CUSTOM_WORDS_PER_TURN"` }
SettingBounds defines the lower and upper bounds for the user-specified lobby creation input.
type State ¶ added in v0.8.3
type State string
const ( // Unstarted means the lobby has been opened but never started. Unstarted State = "unstarted" // Ongoing means the lobby has already been started. Ongoing State = "ongoing" // GameOver means that the lobby had been start, but the max round limit // has already been reached. GameOver State = "gameOver" )
type StringDataEvent ¶ added in v0.8.3
type StringDataEvent struct {
Data string `json:"data"`
}
func (StringDataEvent) MarshalEasyJSON ¶ added in v0.8.3
func (v StringDataEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (StringDataEvent) MarshalJSON ¶ added in v0.8.3
func (v StringDataEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*StringDataEvent) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *StringDataEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*StringDataEvent) UnmarshalJSON ¶ added in v0.8.3
func (v *StringDataEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type WordChosen ¶ added in v0.8.19
func (WordChosen) MarshalEasyJSON ¶ added in v0.8.19
func (v WordChosen) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (WordChosen) MarshalJSON ¶ added in v0.8.19
func (v WordChosen) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*WordChosen) UnmarshalEasyJSON ¶ added in v0.8.19
func (v *WordChosen) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*WordChosen) UnmarshalJSON ¶ added in v0.8.19
func (v *WordChosen) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type WordHint ¶
WordHint describes a character of the word that is to be guessed, whether the character should be shown and whether it should be underlined on the UI.
func (WordHint) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (WordHint) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*WordHint) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*WordHint) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type YourTurn ¶ added in v0.8.19
type YourTurn struct { TimeLeft int `json:"timeLeft"` PreSelectedWord int `json:"preSelectedWord"` Words []string `json:"words"` }
func (YourTurn) MarshalEasyJSON ¶ added in v0.8.19
MarshalEasyJSON supports easyjson.Marshaler interface
func (YourTurn) MarshalJSON ¶ added in v0.8.19
MarshalJSON supports json.Marshaler interface
func (*YourTurn) UnmarshalEasyJSON ¶ added in v0.8.19
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*YourTurn) UnmarshalJSON ¶ added in v0.8.19
UnmarshalJSON supports json.Unmarshaler interface