game

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 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"
	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"
	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 (
	LobbySettingBounds = SettingBounds{
		MinDrawingTime:        60,
		MaxDrawingTime:        300,
		MinRounds:             1,
		MaxRounds:             20,
		MinMaxPlayers:         2,
		MaxMaxPlayers:         24,
		MinClientsPerIPLimit:  1,
		MaxClientsPerIPLimit:  24,
		MinCustomWordsPerTurn: 1,
		MaxCustomWordsPerTurn: 3,
	}
	SupportedLanguages = map[string]string{
		"english_gb": "English (GB)",
		"english":    "English (US)",
		"italian":    "Italian",
		"german":     "German",
		"french":     "French",
		"dutch":      "Dutch",
		"ukrainian":  "Ukrainian",
	}
)
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) },
		},
	}
)

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(
	playerName, chosenLanguage string,
	publicLobby bool,
	drawingTime, rounds, maxPlayers, customWordsPerTurn, clientsPerIPLimit int,
	customWords []string,
) (*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 IsGuessing

func IsGuessing(player *Player) bool

func IsNotGuessing

func IsNotGuessing(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     float32  `json:"x"`
		Y     float32  `json:"y"`
		Color RGBColor `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 {
	*Ready
	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 struct {
		FromX     float32  `json:"fromX"`
		FromY     float32  `json:"fromY"`
		ToX       float32  `json:"toX"`
		ToY       float32  `json:"toY"`
		Color     RGBColor `json:"color"`
		LineWidth float32  `json:"lineWidth"`
	} `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

	// 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(playerName 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) 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"`
	Round        int       `json:"round"`
	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.

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"`
	// 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) GetWebsocketMutex

func (player *Player) GetWebsocketMutex() *sync.Mutex

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

type RGBColor

type RGBColor struct {
	R uint8 `json:"r"`
	G uint8 `json:"g"`
	B uint8 `json:"b"`
}

RGBColor represents a 24-bit color consisting of red, green and blue.

func (RGBColor) MarshalEasyJSON added in v0.8.3

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

MarshalEasyJSON supports easyjson.Marshaler interface

func (RGBColor) MarshalJSON added in v0.8.3

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

MarshalJSON supports json.Marshaler interface

func (*RGBColor) UnmarshalEasyJSON added in v0.8.3

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

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*RGBColor) UnmarshalJSON added in v0.8.3

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

UnmarshalJSON supports json.Unmarshaler interface

type Ready

type Ready 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"`
	RoundEndTime       int         `json:"roundEndTime"`
	DrawingTimeSetting int         `json:"drawingTimeSetting"`
	AllowDrawing       bool        `json:"allowDrawing"`
}

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.

func (Ready) MarshalEasyJSON added in v0.8.3

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

MarshalEasyJSON supports easyjson.Marshaler interface

func (Ready) MarshalJSON added in v0.8.3

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

MarshalJSON supports json.Marshaler interface

func (*Ready) UnmarshalEasyJSON added in v0.8.3

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

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Ready) UnmarshalJSON added in v0.8.3

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

UnmarshalJSON supports json.Unmarshaler interface

type SettingBounds

type SettingBounds struct {
	MinDrawingTime        int `json:"minDrawingTime"`
	MaxDrawingTime        int `json:"maxDrawingTime"`
	MinRounds             int `json:"minRounds"`
	MaxRounds             int `json:"maxRounds"`
	MinMaxPlayers         int `json:"minMaxPlayers"`
	MaxMaxPlayers         int `json:"maxMaxPlayers"`
	MinClientsPerIPLimit  int `json:"minClientsPerIpLimit"`
	MaxClientsPerIPLimit  int `json:"maxClientsPerIpLimit"`
	MinCustomWordsPerTurn int `json:"minCustomWordsPerTurn"`
	MaxCustomWordsPerTurn int `json:"maxCustomWordsPerTurn"`
}

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

Jump to

Keyboard shortcuts

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