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 GetIPAddressFromRequest(request *http.Request) string
- func GetPlayer(lobby *game.Lobby, r *http.Request) *game.Player
- func GetPlayername(request *http.Request) string
- func GetUserSession(request *http.Request) (uuid.UUID, error)
- func ParseBoolean(valueName string, 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 SetUsersessionCookie(w http.ResponseWriter, player *game.Player)
- func WriteObject(player *game.Player, object easyjson.Marshaler) error
- func WritePreparedMessage(player *game.Player, message *gws.Broadcaster) error
- 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 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 GetIPAddressFromRequest ¶
GetIPAddressFromRequest extracts the clients IP address from the request. This function respects forwarding headers.
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 SetUsersessionCookie ¶
func SetUsersessionCookie(w http.ResponseWriter, player *game.Player)
SetUsersessionCookie takes the players usersession and sets it as a cookie.
func WriteObject ¶ added in v0.8.3
func WritePreparedMessage ¶ added in v0.8.3
func WritePreparedMessage(player *game.Player, message *gws.Broadcaster) error
Types ¶
type LobbyData ¶
type LobbyData struct { game.SettingBounds game.EditableLobbySettings LobbyID string `json:"lobbyId"` // DrawingBoardBaseWidth is the internal canvas width and is needed for // correctly up- / downscaling drawing instructions. DrawingBoardBaseWidth int `json:"drawingBoardBaseWidth"` // DrawingBoardBaseHeight is the internal canvas height and is needed for // correctly up- / downscaling drawing instructions. DrawingBoardBaseHeight int `json:"drawingBoardBaseHeight"` // MinBrushSize is the minimum amount of pixels the brush can draw in. MinBrushSize int `json:"minBrushSize"` // MaxBrushSize is the maximum amount of pixels the brush can draw in. MaxBrushSize int `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"` }
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.
func CreateLobbyData ¶
CreateLobbyData creates a ready to use LobbyData object containing data from the passed Lobby.
func (LobbyData) MarshalEasyJSON ¶ added in v0.8.3
MarshalEasyJSON supports easyjson.Marshaler interface
func (LobbyData) MarshalJSON ¶ added in v0.8.3
MarshalJSON supports json.Marshaler interface
func (*LobbyData) UnmarshalEasyJSON ¶ added in v0.8.3
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*LobbyData) UnmarshalJSON ¶ added in v0.8.3
UnmarshalJSON supports json.Unmarshaler interface
type LobbyEntries ¶ added in v0.8.3
type LobbyEntries []*LobbyEntry
func (LobbyEntries) MarshalEasyJSON ¶ added in v0.8.3
func (v LobbyEntries) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (LobbyEntries) MarshalJSON ¶ added in v0.8.3
func (v LobbyEntries) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*LobbyEntries) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *LobbyEntries) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*LobbyEntries) UnmarshalJSON ¶ added in v0.8.3
func (v *LobbyEntries) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type LobbyEntry ¶
type LobbyEntry struct { LobbyID string `json:"lobbyId"` Wordpack string `json:"wordpack"` 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.
func (LobbyEntry) MarshalEasyJSON ¶ added in v0.8.3
func (v LobbyEntry) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (LobbyEntry) MarshalJSON ¶ added in v0.8.3
func (v LobbyEntry) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*LobbyEntry) UnmarshalEasyJSON ¶ added in v0.8.3
func (v *LobbyEntry) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*LobbyEntry) UnmarshalJSON ¶ added in v0.8.3
func (v *LobbyEntry) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
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
SetupRoutes registers the /v1/ endpoints with the http package.