Documentation
¶
Index ¶
- Constants
- Variables
- func WrapVoteResults(result ...*SubmissionResult) (res []interface{})
- type Client
- type ClientArray
- type ClientMap
- type EnhancedPermission
- type Game
- func (g *Game) Broadcast(response *Response)
- func (g *Game) BroadcastExcept(conn *websocket.Conn, response *Response)
- func (g *Game) BroadcastTopicListToLeaders()
- func (g *Game) BroadcastWaitingFor()
- func (g *Game) BroadcastWaitingForAll()
- func (g *Game) BroadcastWaitingForNone()
- func (g *Game) CheckCycle(checkAutoSkip, force bool) (err error)
- func (g *Game) ClientByConnection(conn *websocket.Conn) *Client
- func (g *Game) FindNonLeaderClient() *Client
- func (g *Game) ForceEndGame(reason string) (err error)
- func (g *Game) ForceNextRound() (err error)
- func (g *Game) ForceShowVoteResults() (err error)
- func (g *Game) ForceStartVote() (err error)
- func (g *Game) IsEmpty() bool
- func (g *Game) KickClient(client *Client)
- func (g *Game) LeaveClient(client *Client, reason string)
- func (g *Game) Reset(purgeClients bool)
- func (g *Game) SetLeader(client *Client)
- func (g *Game) SetState(state util.GameState)
- func (g *Game) State() util.GameState
- func (g *Game) StatsForUser(user string) (res int)
- func (g *Game) WaitingForGIFSubmission(topic *Topic) (res ClientArray)
- func (g *Game) WaitingForVote(topic *Topic) (res ClientArray)
- type GamePreferences
- type Response
- func NewResponse(command string, args ...interface{}) *Response
- func NewResponseWithError(command string, err error, args ...interface{}) *Response
- func NewResponseWithWarn(command, warn string, args ...interface{}) *Response
- func PChangeRole(client *Client, role string) *Response
- func PChat(client *Client, message string) *Response
- func PGameEnd(reason string) *Response
- func PJoin(client *Client, game *Game) *Response
- func PList(clients ClientMap) *Response
- func PNextRound(description string, currentTopic, totalTopics int) *Response
- func PPlayerLeave(client *Client, reason string) *Response
- func PPreferences(pref *GamePreferences) *Response
- func PStart() *Response
- func PState(state util.GameState) *Response
- func PStats(game *Game) *Response
- func PSubmitGIF(client *Client) *Response
- func PTopicAdd(topic string) *Response
- func PTopicList(game *Game) *Response
- func PTopicRemove(topic string) *Response
- func PVersion() *Response
- func PVoteResults(results ...*SubmissionResult) *Response
- func PVoteStart(urls ...string) *Response
- func PWaitingFor(waitingFor ClientArray) *Response
- type Submission
- type SubmissionArray
- type SubmissionMap
- func (M SubmissionMap) AllExceptFrom(client *Client) (res SubmissionArray)
- func (M SubmissionMap) AsArray() (res SubmissionArray)
- func (M SubmissionMap) ByURL(url string) (*Submission, bool)
- func (M SubmissionMap) ByURLLoose(url string) (*Submission, bool, error)
- func (M SubmissionMap) HasSubmittedGIF(client *Client) (ok bool)
- func (M SubmissionMap) HasVoted(client *Client) bool
- type SubmissionResult
- type Topic
- type TopicArray
- func (T *TopicArray) Add(topic string)
- func (T *TopicArray) Clear()
- func (T *TopicArray) Delete(topic string)
- func (T TopicArray) Exists(topic string) bool
- func (T TopicArray) NextTopic() (*Topic, error)
- func (T TopicArray) PlayedTopicsCount() (count int)
- func (T TopicArray) RandomTopic() (*Topic, error)
- func (T TopicArray) Strings() (res []string)
Constants ¶
const ( PermissionListTopics = 1 << iota PermissionCreateTopics PermissionDeleteTopics )
Variables ¶
var DefaultPreferences = GamePreferences{ AutoSkip: true, MinPlayers: 3, MaxPlayers: 100, MinTopics: 1, MaxTopics: 30, ShuffleTopics: true, Permissions: 0, }
var ErrConnectionNil = errors.New("websocket connection was nil")
Functions ¶
func WrapVoteResults ¶
func WrapVoteResults(result ...*SubmissionResult) (res []interface{})
Types ¶
type ClientArray ¶
type ClientArray []*Client
func (ClientArray) Contains ¶
func (A ClientArray) Contains(client *Client) bool
func (*ClientArray) Delete ¶
func (A *ClientArray) Delete(client *Client)
func (ClientArray) Names ¶
func (A ClientArray) Names() (res []string)
type EnhancedPermission ¶
type EnhancedPermission uint8
type Game ¶
type Game struct {
ID string
Clients ClientMap
Topics TopicArray
CurrentTopic *Topic
LastInteraction time.Time
Preferences *GamePreferences
Password string
// contains filtered or unexported fields
}
func (*Game) BroadcastExcept ¶
BroadcastExcept sends a response to all clients except to a specific connection
func (*Game) BroadcastTopicListToLeaders ¶
func (g *Game) BroadcastTopicListToLeaders()
func (*Game) BroadcastWaitingFor ¶
func (g *Game) BroadcastWaitingFor()
func (*Game) BroadcastWaitingForAll ¶
func (g *Game) BroadcastWaitingForAll()
func (*Game) BroadcastWaitingForNone ¶
func (g *Game) BroadcastWaitingForNone()
func (*Game) CheckCycle ¶
CheckCycle checks if we're waiting for clients and if not, continue the game
func (*Game) FindNonLeaderClient ¶
func (*Game) ForceEndGame ¶
ForceEndGame ends the game
func (*Game) ForceNextRound ¶
ForceNextRound starts the next round if a topic is available
func (*Game) ForceShowVoteResults ¶
ForceShowVoteResults sends the voting results to all clients
func (*Game) ForceStartVote ¶
ForceStartVote starts the vote process of the previous submissions
func (*Game) KickClient ¶
func (*Game) LeaveClient ¶
LeaveClient removes a client from the game and sends a PLAYER_LEAVE message to all other players
func (*Game) Reset ¶
Reset resets the Topic.Played values, Game.CurrentTopic, Game.State() and purges (if purgeClients was set to true) all clients
func (*Game) SetLeader ¶
SetLeader sets the client as the sole leader and sends a CHANGE_ROLE message to all players with the old and the new leader.
func (*Game) SetState ¶
SetState sets the current GameState and broadcasts the change to all clients
func (*Game) StatsForUser ¶
func (*Game) WaitingForGIFSubmission ¶
func (g *Game) WaitingForGIFSubmission(topic *Topic) (res ClientArray)
WaitingForGIFSubmission returns all players we're currently waiting for
func (*Game) WaitingForVote ¶
func (g *Game) WaitingForVote(topic *Topic) (res ClientArray)
type GamePreferences ¶
type Response ¶
type Response struct {
Command string `json:"cmd"`
Args []interface{} `json:"args"`
Warn string `json:"warn"`
Success bool `json:"_s"`
Timestamp int64 `json:"_ts"`
}
func NewResponse ¶
func NewResponseWithError ¶
func NewResponseWithWarn ¶
func PChangeRole ¶
func PNextRound ¶
func PPlayerLeave ¶
func PPreferences ¶
func PPreferences(pref *GamePreferences) *Response
func PSubmitGIF ¶
func PTopicList ¶
func PTopicRemove ¶
func PVoteResults ¶
func PVoteResults(results ...*SubmissionResult) *Response
func PVoteStart ¶
func PWaitingFor ¶
func PWaitingFor(waitingFor ClientArray) *Response
type Submission ¶
type Submission struct {
Creator *Client
Voters ClientArray
URL string
}
func NewSubmission ¶
func NewSubmission(creator *Client, url string) *Submission
type SubmissionArray ¶
type SubmissionArray []*Submission
func (SubmissionArray) Results ¶
func (A SubmissionArray) Results() (res []*SubmissionResult)
func (SubmissionArray) URLs ¶
func (A SubmissionArray) URLs() (res []string)
type SubmissionMap ¶
type SubmissionMap map[string]*Submission
func (SubmissionMap) AllExceptFrom ¶
func (M SubmissionMap) AllExceptFrom(client *Client) (res SubmissionArray)
func (SubmissionMap) AsArray ¶
func (M SubmissionMap) AsArray() (res SubmissionArray)
func (SubmissionMap) ByURL ¶
func (M SubmissionMap) ByURL(url string) (*Submission, bool)
func (SubmissionMap) ByURLLoose ¶
func (M SubmissionMap) ByURLLoose(url string) (*Submission, bool, error)
func (SubmissionMap) HasSubmittedGIF ¶
func (M SubmissionMap) HasSubmittedGIF(client *Client) (ok bool)
func (SubmissionMap) HasVoted ¶
func (M SubmissionMap) HasVoted(client *Client) bool
type SubmissionResult ¶
type Topic ¶
type Topic struct {
Description string `json:"description,omitempty"`
Submissions SubmissionMap `json:"submissions,omitempty"`
Played bool `json:"played"`
}
type TopicArray ¶
type TopicArray []*Topic
func (*TopicArray) Add ¶
func (T *TopicArray) Add(topic string)
func (*TopicArray) Clear ¶
func (T *TopicArray) Clear()
func (*TopicArray) Delete ¶
func (T *TopicArray) Delete(topic string)
func (TopicArray) Exists ¶
func (T TopicArray) Exists(topic string) bool
func (TopicArray) NextTopic ¶
func (T TopicArray) NextTopic() (*Topic, error)
func (TopicArray) PlayedTopicsCount ¶
func (T TopicArray) PlayedTopicsCount() (count int)
func (TopicArray) RandomTopic ¶
func (T TopicArray) RandomTopic() (*Topic, error)
func (TopicArray) Strings ¶
func (T TopicArray) Strings() (res []string)