Documentation
¶
Overview ¶
Package api the public APIs for both the HTTP and the WS endpoints. These are being used by the official client and can also be used by third party clients. On top of that this package contains some util code regarding http/ws that can be used by other packages. In order to register the endpoints you have to call SetupRoutes.
Index ¶
- Variables
- func GetDiscordInstanceId(request *http.Request) string
- func GetIPAddressFromRequest(request *http.Request) string
- func GetLobbyId(request *http.Request) string
- func GetPlayer(lobby *game.Lobby, request *http.Request) *game.Player
- func GetPlayername(request *http.Request) string
- func GetUserSession(request *http.Request) (uuid.UUID, error)
- func ParseBoolean(valueName, value string) (bool, error)
- func ParseClientsPerIPLimit(cfg *config.Config, value string) (int, error)
- func ParseCustomWords(lowercaser cases.Caser, value string) ([]string, error)
- func ParseCustomWordsPerTurn(value string) (int, error)
- func ParseDrawingTime(cfg *config.Config, value string) (int, error)
- func ParseLanguage(value string) (*game.LanguageData, string, error)
- func ParseMaxPlayers(cfg *config.Config, value string) (int, error)
- func ParsePlayerName(value string) (string, error)
- func ParseRounds(cfg *config.Config, value string) (int, error)
- func ParseScoreCalculation(value string) (game.ScoreCalculation, error)
- func SetDiscordCookies(w http.ResponseWriter, request *http.Request)
- func SetGameplayCookies(w http.ResponseWriter, request *http.Request, player *game.Player, ...)
- func WriteObject(player *game.Player, object any) error
- func WritePreparedMessage(player *game.Player, message *gws.Broadcaster) error
- type GameConstants
- type LobbyData
- type LobbyEntries
- type LobbyEntry
- type V1Handler
Constants ¶
This section is empty.
Variables ¶
var ErrLobbyNotExistent = errors.New("the requested lobby doesn't exist")
var (
ErrPlayerNotConnected = errors.New("player not connected")
)
var GameConstantsData = &GameConstants{ DrawingBoardBaseWidth: game.DrawingBoardBaseWidth, DrawingBoardBaseHeight: game.DrawingBoardBaseHeight, MinBrushSize: game.MinBrushSize, MaxBrushSize: game.MaxBrushSize, CanvasColor: 0, SuggestedBrushSizes: SuggestedBrushSizes, }
var SuggestedBrushSizes = [4]uint8{8, 16, 24, 32}
SuggestedBrushSizes is suggested brush sizes value used for Lobbydata objects. A unit test makes sure these values are ordered and within the specified bounds.
Functions ¶
func GetDiscordInstanceId ¶ added in v0.9.0
func GetIPAddressFromRequest ¶
GetIPAddressFromRequest extracts the clients IP address from the request. This function respects forwarding headers.
func GetLobbyId ¶ added in v0.9.0
GetLobbyId returns either the lobby id from the URL or from a cookie.
func GetPlayer ¶
GetPlayer returns the player object that matches the usersession in the supplied HTTP request and lobby. If no user session is set, we return nil.
func GetPlayername ¶
GetPlayername either retrieves the playername from a cookie, the URL form. If no preferred name can be found, we return an empty string.
func GetUserSession ¶
GetUserSession accesses the usersession from an HTTP request and returns the session. The session can either be in the cookie or in the header. If no session can be found, an empty string is returned.
func ParseBoolean ¶
ParseBoolean checks whether the given value is either "true" or "false". The checks are case-insensitive. If an empty string is supplied, false is returned. All other invalid input will return an error.
func ParseClientsPerIPLimit ¶
ParseClientsPerIPLimit checks whether the given value is an integer between the lower and upper bound of maximum clients per IP. All other invalid input, including empty strings, will return an error.
func ParseCustomWords ¶
ParseCustomWords checks whether the given value is a string containing comma separated values (or a single word). Empty strings will return an empty (nil) array and no error. An error is only returned if there are empty words. For example these wouldn't parse:
wordone,,wordtwo , wordone,
func ParseCustomWordsPerTurn ¶ added in v0.8.3
ParseCustomWordsPerTurn checks whether the given value is an integer between 0 and 100. All other invalid input, including empty strings, will return an error.
func ParseDrawingTime ¶
ParseDrawingTime checks whether the given value is an integer between the lower and upper bound of drawing time. All other invalid input, including empty strings, will return an error.
func ParseLanguage ¶
func ParseLanguage(value string) (*game.LanguageData, string, error)
ParseLanguage checks whether the given value is part of the game.SupportedLanguages array. The input is trimmed and lowercased.
func ParseMaxPlayers ¶
ParseMaxPlayers checks whether the given value is an integer between the lower and upper bound of maximum players per lobby. All other invalid input, including empty strings, will return an error.
func ParsePlayerName ¶
ParsePlayerName checks if the given value is a valid playername. Currently this only includes checkin whether the value is empty or only consists of whitespace character.
func ParseRounds ¶
ParseRounds checks whether the given value is an integer between the lower and upper bound of rounds played. All other invalid input, including empty strings, will return an error.
func ParseScoreCalculation ¶ added in v0.8.19
func ParseScoreCalculation(value string) (game.ScoreCalculation, error)
func SetDiscordCookies ¶ added in v0.9.0
func SetDiscordCookies(w http.ResponseWriter, request *http.Request)
func SetGameplayCookies ¶ added in v0.9.0
func SetGameplayCookies( w http.ResponseWriter, request *http.Request, player *game.Player, lobby *game.Lobby, )
SetGameplayCookies takes the players usersession and lobby id and sets them as a cookie.
func WritePreparedMessage ¶ added in v0.8.3
func WritePreparedMessage(player *game.Player, message *gws.Broadcaster) error
Types ¶
type GameConstants ¶ added in v0.9.0
type GameConstants struct {
// DrawingBoardBaseWidth is the internal canvas width and is needed for
// correctly up- / downscaling drawing instructions.
DrawingBoardBaseWidth uint16 `json:"drawingBoardBaseWidth"`
// DrawingBoardBaseHeight is the internal canvas height and is needed for
// correctly up- / downscaling drawing instructions.
DrawingBoardBaseHeight uint16 `json:"drawingBoardBaseHeight"`
// MinBrushSize is the minimum amount of pixels the brush can draw in.
MinBrushSize uint8 `json:"minBrushSize"`
// MaxBrushSize is the maximum amount of pixels the brush can draw in.
MaxBrushSize uint8 `json:"maxBrushSize"`
// CanvasColor is the initially (empty) color of the canvas.
CanvasColor uint8 `json:"canvasColor"`
// SuggestedBrushSizes are suggestions for the different brush sizes
// that the user can choose between. These brushes are guaranteed to
// be ordered from low to high and stay with the bounds.
SuggestedBrushSizes [4]uint8 `json:"suggestedBrushSizes"`
}
GameConstants are values that are lobby-independent and can't be changed via settings, neither at compile time nor at startup time.
type LobbyData ¶
type LobbyData struct {
game.SettingBounds
game.EditableLobbySettings
*GameConstants
IsWordpackRtl bool
}
LobbyData is the data necessary for correctly configuring a lobby. While unofficial clients will probably need all of these values, the official webclient doesn't use all of them as of now.
type LobbyEntries ¶ added in v0.8.3
type LobbyEntries []*LobbyEntry
type LobbyEntry ¶
type LobbyEntry struct {
LobbyID string `json:"lobbyId"`
Wordpack string `json:"wordpack"`
Scoring string `json:"scoring"`
State game.State `json:"state"`
PlayerCount int `json:"playerCount"`
MaxPlayers int `json:"maxPlayers"`
Round int `json:"round"`
Rounds int `json:"rounds"`
DrawingTime int `json:"drawingTime"`
MaxClientsPerIP int `json:"maxClientsPerIp"`
CustomWords bool `json:"customWords"`
}
LobbyEntry is an API object for representing a join-able public lobby.
type V1Handler ¶ added in v0.8.5
type V1Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶ added in v0.8.5
func (*V1Handler) SetupRoutes ¶ added in v0.8.5
func (handler *V1Handler) SetupRoutes(rootPath string, register func(string, string, http.HandlerFunc))
SetupRoutes registers the /v1/ endpoints with the http package.