game

package
v0.8.19 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DrawingBoardBaseWidth  = 1600
	DrawingBoardBaseHeight = 900
	MinBrushSize           = 8
	MaxBrushSize           = 32
)
View Source
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.

View Source
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.

View Source
const (
	EqualGuess   = 0
	CloseGuess   = 1
	DistantGuess = 2
)
View Source
const MaxPlayerNameLength int = 30

MaxPlayerNameLength defines how long a string can be at max when used as the playername.

Variables

View Source
var (
	EventTypeKickVote          = "kick-vote"
	EventTypeNameChange        = "name-change"
	EventTypeMessage           = "message"
	EventTypeLine              = "line"
	EventTypeFill              = "fill"
	EventTypeClearDrawingBoard = "clear-drawing-board"
)

Events that are bidirectional.

View Source
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) },
		},
	}
)
View Source
var ChillScoring = &adjustableScoringAlgorithm{
	identifier:                  "chill",
	baseScore:                   100.0,
	maxBonusBaseScore:           100.0,
	bonusBaseScoreDeclineFactor: 2.0,
	maxHintBonusScore:           60.0,
}
View Source
var CompetitiveScoring = &adjustableScoringAlgorithm{
	identifier:                  "competitive",
	baseScore:                   10.0,
	maxBonusBaseScore:           290.0,
	bonusBaseScoreDeclineFactor: 3.0,
	maxHintBonusScore:           120.0,
}
View Source
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",
}
View Source
var SupportedScoreCalculations = []string{
	"chill",
	"competitive",
}

Functions

func CheckGuess added in v0.8.7

func CheckGuess(a, b string) int

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 ExcludePlayer(toExclude *Player) func(*Player) bool

func GetRandomWords

func GetRandomWords(wordCount int, lobby *Lobby) []string

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 IsAllowedToSeeHints(player *Player) bool

func IsAllowedToSeeRevealedHints added in v0.8.11

func IsAllowedToSeeRevealedHints(player *Player) bool

func SanitizeName

func SanitizeName(name string) string

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

type Event struct {
	Data any    `json:"data"`
	Type string `json:"type"`
}

Event contains an eventtype and optionally any data.

func (Event) MarshalEasyJSON added in v0.8.3

func (v Event) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Event) MarshalJSON added in v0.8.3

func (v Event) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Event) UnmarshalEasyJSON added in v0.8.3

func (v *Event) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Event) UnmarshalJSON added in v0.8.3

func (v *Event) UnmarshalJSON(data []byte) error

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

func (v FillEvent) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (FillEvent) MarshalJSON added in v0.8.3

func (v FillEvent) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*FillEvent) UnmarshalEasyJSON added in v0.8.3

func (v *FillEvent) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*FillEvent) UnmarshalJSON added in v0.8.3

func (v *FillEvent) UnmarshalJSON(data []byte) error

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

func (v KickVote) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (KickVote) MarshalJSON added in v0.8.3

func (v KickVote) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*KickVote) UnmarshalEasyJSON added in v0.8.3

func (v *KickVote) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*KickVote) UnmarshalJSON added in v0.8.3

func (v *KickVote) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type LanguageData added in v0.8.7

type LanguageData struct {
	Lowercaser   func() cases.Caser
	LanguageCode string
}

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

func (v LineEvent) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (LineEvent) MarshalJSON added in v0.8.3

func (v LineEvent) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*LineEvent) UnmarshalEasyJSON added in v0.8.3

func (v *LineEvent) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*LineEvent) UnmarshalJSON added in v0.8.3

func (v *LineEvent) UnmarshalJSON(data []byte) error

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

func (lobby *Lobby) AppendFill(fill *FillEvent)

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

func (lobby *Lobby) AppendLine(line *LineEvent)

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) Broadcast

func (lobby *Lobby) Broadcast(data easyjson.Marshaler)

func (*Lobby) CanIPConnect

func (lobby *Lobby) CanIPConnect(address string) bool

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) Drawer added in v0.8.3

func (lobby *Lobby) Drawer() *Player

func (*Lobby) GetAvailableWordHints

func (lobby *Lobby) GetAvailableWordHints(player *Player) []*WordHint

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

func (lobby *Lobby) GetConnectedPlayerCount() int

GetConnectedPlayerCount returns the amount of player that have currently established a socket connection.

func (*Lobby) GetOccupiedPlayerSlots

func (lobby *Lobby) GetOccupiedPlayerSlots() int

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) GetPlayer

func (lobby *Lobby) GetPlayer(userSession uuid.UUID) *Player

GetPlayer searches for a player, identifying them by usersession.

func (*Lobby) GetPlayers

func (lobby *Lobby) GetPlayers() []*Player

func (*Lobby) HandleEvent

func (lobby *Lobby) HandleEvent(eventType string, payload []byte, player *Player) error

func (*Lobby) HasConnectedPlayers

func (lobby *Lobby) HasConnectedPlayers() bool

func (*Lobby) HasFreePlayerSlot

func (lobby *Lobby) HasFreePlayerSlot() bool

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) IsPublic

func (lobby *Lobby) IsPublic() bool

func (*Lobby) JoinPlayer

func (lobby *Lobby) JoinPlayer(name string) *Player

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 *Lobby) OnPlayerConnectUnsynchronized(player *Player)

func (*Lobby) OnPlayerDisconnect

func (lobby *Lobby) OnPlayerDisconnect(player *Player)

func (*Lobby) SendYourTurnEvent added in v0.8.19

func (lobby *Lobby) SendYourTurnEvent(player *Player)

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

func (v NextTurn) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (NextTurn) MarshalJSON added in v0.8.3

func (v NextTurn) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*NextTurn) UnmarshalEasyJSON added in v0.8.3

func (v *NextTurn) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*NextTurn) UnmarshalJSON added in v0.8.3

func (v *NextTurn) UnmarshalJSON(data []byte) error

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

func (player *Player) GetLastKnownAddress() string

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

func (player *Player) GetWebsocket() *gws.Conn

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

func (v Player) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Player) MarshalJSON added in v0.8.3

func (v Player) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Player) SetLastKnownAddress

func (player *Player) SetLastKnownAddress(address string)

SetLastKnownAddress sets the last known IP-Address used for an HTTP request. Can be retrieved via GetLastKnownAddress().

func (*Player) SetWebsocket

func (player *Player) SetWebsocket(socket *gws.Conn)

SetWebsocket sets the given connection as the players websocket connection.

func (*Player) UnmarshalEasyJSON added in v0.8.3

func (v *Player) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Player) UnmarshalJSON added in v0.8.3

func (v *Player) UnmarshalJSON(data []byte) error

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

type WordChosen struct {
	TimeLeft int         `json:"timeLeft"`
	Hints    []*WordHint `json:"hints"`
}

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

type WordHint struct {
	Character rune `json:"character"`
	Underline bool `json:"underline"`
}

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

func (v WordHint) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (WordHint) MarshalJSON added in v0.8.3

func (v WordHint) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*WordHint) UnmarshalEasyJSON added in v0.8.3

func (v *WordHint) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*WordHint) UnmarshalJSON added in v0.8.3

func (v *WordHint) UnmarshalJSON(data []byte) error

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

func (v YourTurn) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (YourTurn) MarshalJSON added in v0.8.19

func (v YourTurn) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*YourTurn) UnmarshalEasyJSON added in v0.8.19

func (v *YourTurn) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*YourTurn) UnmarshalJSON added in v0.8.19

func (v *YourTurn) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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