Documentation
¶
Index ¶
- Variables
- func BroadcastLobby(lobby *Lobby)
- func BroadcastLobbyList()
- func BroadcastLobbyToUser(lobby *Lobby, steamid string)
- func BroadcastSubList()
- func CreateLocks()
- func DeleteUnusedServers()
- func MapRegionFormatExists(mapName, region string, lobbytype format.Format) bool
- func RestoreServemeChecks()
- type ClassDetails
- type Lobby
- func (lobby *Lobby) AddPlayer(p *player.Player, slot int, password string) error
- func (lobby *Lobby) AddSpectator(player *player.Player) error
- func (lobby *Lobby) AfterPlayerNotInGameFunc(player *player.Player, d time.Duration, f func())
- func (lobby *Lobby) BanPlayer(player *player.Player)
- func (lobby *Lobby) Close(doRPC, matchEnded bool)
- func (lobby *Lobby) CreateLock()
- func (l *Lobby) CurrentState() State
- func (lobby *Lobby) Delete()
- func (lobby *Lobby) DiscordNotif(msg string)
- func (lobby *Lobby) DownloadDemo(context *servemetf.Context)
- func (lobby *Lobby) FillSubstitute(slot int) error
- func (l *Lobby) FitsRequirements(player *player.Player, slot int) (bool, error)
- func (lobby *Lobby) GetAllSlots() []LobbySlot
- func (lobby *Lobby) GetPlayerIDBySlot(slot int) (uint, error)
- func (lobby *Lobby) GetPlayerNumber() int
- func (lobby *Lobby) GetPlayerSlot(player *player.Player) (int, error)
- func (lobby *Lobby) GetPlayerSlotObj(player *player.Player) (*LobbySlot, error)
- func (lobby *Lobby) GetSlotRequirement(slot int) (*Requirement, error)
- func (lobby *Lobby) GetUnreadyPlayers() (players []*player.Player)
- func (lobby *Lobby) HasPlayer(player *player.Player) bool
- func (lobby *Lobby) HasRequirements() bool
- func (lobby *Lobby) HasSlotRequirement(slot int) bool
- func (lobby *Lobby) IsEnoughPlayers(n int) bool
- func (lobby *Lobby) IsEveryoneReady() bool
- func (lobby *Lobby) IsFull() bool
- func (lobby *Lobby) IsPlayerBanned(player *player.Player) bool
- func (lobby *Lobby) IsPlayerInGame(player *player.Player) bool
- func (lobby *Lobby) IsPlayerInMumble(player *player.Player) bool
- func (lobby *Lobby) IsPlayerReady(player *player.Player) (bool, error)
- func (lobby *Lobby) IsSlotFilled(slot int) bool
- func (lobby *Lobby) IsSlotOccupied(slot int) bool
- func (lobby *Lobby) Lock()
- func (lobby *Lobby) OnChange(base bool)
- func (lobby *Lobby) ReadyPlayer(player *player.Player) error
- func (lobby *Lobby) ReadyUpTimeLeft() int64
- func (lobby *Lobby) RemovePlayer(player *player.Player) error
- func (lobby *Lobby) RemoveSpectator(player *player.Player, broadcast bool) error
- func (lobby *Lobby) RemoveUnreadyPlayers(spec bool) error
- func (lobby *Lobby) RequiredPlayers() int
- func (lobby *Lobby) Save() error
- func (l *Lobby) ServemeCheck(context *servemetf.Context)
- func (lobby *Lobby) SetInGame(player *player.Player) error
- func (lobby *Lobby) SetInMumble(player *player.Player) error
- func (lobby *Lobby) SetNotInGame(player *player.Player) error
- func (lobby *Lobby) SetNotInMumble(player *player.Player) error
- func (l *Lobby) SetState(s State)
- func (lobby *Lobby) SetupServer() error
- func (lobby *Lobby) ShuffleAllSlots() error
- func (lobby *Lobby) SlotNeedsSubstitute(slot int) (needsSub bool)
- func (lobby *Lobby) Start()
- func (lobby *Lobby) Substitute(player *player.Player)
- func (lobby *Lobby) Unlock()
- func (lobby *Lobby) UnreadyAllPlayers() error
- func (lobby *Lobby) UnreadyPlayer(player *player.Player) error
- func (lobby *Lobby) UpdateHours(logsID int) error
- func (lobby *Lobby) UpdateStats()
- type LobbyConnectData
- type LobbyData
- type LobbyEvent
- type LobbyListData
- type LobbySlot
- type Requirement
- type SlotDetails
- type SpecDetails
- type State
- type SubstituteData
- type TwitchRestriction
- Bugs
Constants ¶
This section is empty.
Variables ¶
var ( ErrLobbyNotFound = errors.New("Could not find lobby with given ID") ErrLobbyBan = errors.New("You have been banned from this lobby") ErrBadSlot = errors.New("That slot does not exist") ErrFilled = errors.New("That slot has been filled") ErrNotWhitelisted = errors.New("You are not allowed in this lobby") ErrInvalidPassword = errors.New("Incorrect slot password") ErrNeedsSub = errors.New("This slot needs a substitute") ErrReqHours = errors.New("You do not have sufficient hours to join that slot") ErrReqLobbies = errors.New("You have not played sufficient lobbies to join that slot") ErrReqReliability = errors.New("You have insufficient reliability to join that slot") )
Functions ¶
func BroadcastLobby ¶
func BroadcastLobby(lobby *Lobby)
BroadcastLobby broadcasts the lobby to the lobby's public room (id_public)
func BroadcastLobbyList ¶
func BroadcastLobbyList()
BroadcastLobbyList broadcasts the lobby list to all users
func BroadcastLobbyToUser ¶
BroadcastLobbyToUser broadcasts the lobby to the a user with the given steamID
func BroadcastSubList ¶
func BroadcastSubList()
BroadcastSubList broadcasts a the subtitute list to the room 0_public
func CreateLocks ¶
func CreateLocks()
CreateLocks creates locks for all lobbies that haven't ended yet
func DeleteUnusedServers ¶
func DeleteUnusedServers()
DeleteUnusedServerRecords checks all server records in the DB and deletes them if the corresponsing lobby is closed
func MapRegionFormatExists ¶
func RestoreServemeChecks ¶
func RestoreServemeChecks()
Types ¶
type ClassDetails ¶
type ClassDetails struct { Blu SlotDetails `json:"blu"` Class string `json:"class"` Red SlotDetails `json:"red"` }
type Lobby ¶
type Lobby struct { gorm.Model State State Mode string // Game Mode MapName string // Map Name Type format.Format // League config used League string RegionCode string // Region Code ("na", "eu", etc) RegionName string // Region Name ("North America", "Europe", etc) Mumble bool // Whether mumble is required Discord bool // Whether discord is used DiscordRedChannel string DiscordBluChannel string Slots []LobbySlot `gorm:"ForeignKey:LobbyID"` // List of occupied slots RegionLock bool PlayerWhitelist string // URL of steam group TwitchChannel string // twitch channel, slots will be restricted TwitchRestriction TwitchRestriction // restricted to either followers or subs ServemeID int // if serveme was used to get this server, stores the server ID // Team name aliases RedTeamName string BluTeamName string // TF2 Server Info ServerInfo gameserver.ServerRecord `gorm:"ForeignKey:ServerInfoID"` ServerInfoID uint Whitelist string //whitelist.tf ID Spectators []player.Player `gorm:"many2many:spectators_players_lobbies"` // List of spectators BannedPlayers []player.Player `gorm:"many2many:banned_players_lobbies"` // List of Banned Players CreatedBySteamID string // SteamID of the lobby leader/creator ReadyUpTimestamp int64 // (Unix) Timestamp at which the ready up timeout started MatchEnded bool // if true, the lobby ended with the match ending in the game server LogstfID int // logs.tf id (only when match ends) }
Lobby represents a Lobby
func GetLobbyByID ¶
GetLobbyByID returns lobby object, without the ServerInfo object inside it.
func GetLobbyByIDServer ¶
GetLobbyByIdServer returns the lobby object, plus the ServerInfo object inside it
func GetWaitingLobbies ¶
func GetWaitingLobbies() (lobbies []*Lobby)
GetWaitingLobbies returns a list of lobby objects that haven't been filled yet
func NewLobby ¶
func NewLobby(mapName string, lobbyType format.Format, league string, serverInfo gameserver.ServerRecord, whitelist string, mumble bool, whitelistGroup string) *Lobby
Returns a new lobby object with the given parameters Call CreateLock after saving this lobby.
func (*Lobby) AddPlayer ¶
AddPlayer adds the given player to lobby, If the player occupies a slot in the lobby already, switch slots. If the player is in another lobby, removes them from that lobby before adding them.
func (*Lobby) AddSpectator ¶
AddSpectator adds a given player as a lobby spectator
func (*Lobby) AfterPlayerNotInGameFunc ¶
AfterPlayerNotInGameFunc waits the duration to elapse, and if the given player is still not in the game server, calls f in it's own goroutine.
func (*Lobby) Close ¶
Close closes the lobby, which has the following effects:
All unfilled substitutes for the lobby are "filled" (ie, their filled field is set to true) The corresponding ServerRecord is deleted
If rpc == true, the log listener in Pauling for the corresponding server is stopped, this is used when the lobby is closed manually by a player
func (*Lobby) CurrentState ¶
CurrentState returns the lobby's current state. It's meant to be used for old lobby objects which might have their state change while the object hasn't been updated.
func (*Lobby) Delete ¶
func (lobby *Lobby) Delete()
Delete removes the lobby object from the database. Closed lobbies aren't deleted, this function is used for lobbies where the game server had an error while being setup.
func (*Lobby) DiscordNotif ¶
func (*Lobby) DownloadDemo ¶
func (*Lobby) FillSubstitute ¶
FillSubstitute marks the substitute reocrd for the given slot as true, and Broadcasts the updated sub list
func (*Lobby) FitsRequirements ¶
FitsRequirements checks if the player fits the requirement to be added to the given slot in the lobby
func (*Lobby) GetAllSlots ¶
GetAllSlots returns a list of all occupied slots in the lobby
func (*Lobby) GetPlayerIDBySlot ¶
GetPlayerIDBySlot returns the ID of the player occupying the slot number
func (*Lobby) GetPlayerNumber ¶
GetPlayerNumber returns the number of occupied slots in the lobby
func (*Lobby) GetPlayerSlot ¶
GetPlayerSlot returns the slot number if the player occupies a slot int eh lobby
func (*Lobby) GetPlayerSlotObj ¶
GetPlayerSlotObj returns the LobbySlot object if the given player occupies a slot in the lobby.
func (*Lobby) GetSlotRequirement ¶
func (lobby *Lobby) GetSlotRequirement(slot int) (*Requirement, error)
GetSlotRequirement returns the slot requirement for the lobby lobby
func (*Lobby) GetUnreadyPlayers ¶
GetUnreadyPlayers returns a list of unready players in the lobby. only used when lobby state == LobbyStateReadyingUp
func (*Lobby) HasRequirements ¶
func (*Lobby) HasSlotRequirement ¶
HasSlotRequirement returns true if the given slot in the lobby has a requirement
func (*Lobby) IsEnoughPlayers ¶
func (*Lobby) IsEveryoneReady ¶
IsEveryoneReady returns whether all players have readied up.
func (*Lobby) IsPlayerBanned ¶
IsPlayerBanned returns whether the given player is banned from joining the lobby.
func (*Lobby) IsPlayerInGame ¶
IsPlayerInGame returns true if the player is in-game
func (*Lobby) IsPlayerReady ¶
IsPlayerReady returns true if the given player is ready
func (*Lobby) IsSlotFilled ¶
IsSlotFilled returns whether the given slot (by number) is occupied by a player
func (*Lobby) IsSlotOccupied ¶
IsSlotOccupied returns whether the given slot is occupied by a player.
func (*Lobby) Lock ¶
func (lobby *Lobby) Lock()
Lock aquires the lock for the given lobby. Be careful while using Lock outside of models, improper usage could result in deadlocks
func (*Lobby) OnChange ¶
OnChange broadcasts the given lobby to other players. If base is true, broadcasts the lobby list too.
func (*Lobby) ReadyPlayer ¶
ReadyPlayer readies up given player, use when lobby.State == LobbyStateWaiting
func (*Lobby) ReadyUpTimeLeft ¶
ReadyUpTimeLeft returns the amount of time left to ready up before a player is kicked. Use when a player reconnects while lobby.State == LobbyStateReadyingUp and the player isn't ready
func (*Lobby) RemovePlayer ¶
RemovePlayer removes a given player from the lobby
func (*Lobby) RemoveSpectator ¶
RemoveSpectator removes the given player from the lobby spectators list. If broadcast, then broadcast the change to other players
func (*Lobby) RemoveUnreadyPlayers ¶
RemoveUnreadyPlayers removes players who haven't removed. If spec == true, move them to spectators
func (*Lobby) RequiredPlayers ¶
func (*Lobby) ServemeCheck ¶
ServemeCheck checks the status of the serveme reservation for the lobby (if any) every 10 seconds in a goroutine, and closes the lobby if it has ended
func (*Lobby) SetInMumble ¶
SetInMumble sets the in-mumble status of the given player to true
func (*Lobby) SetNotInGame ¶
SetNotInGame sets the in-game status of the given player to false
func (*Lobby) SetNotInMumble ¶
SetNotInMumble sets the in-mumble status of the given player to false
func (*Lobby) SetupServer ¶
SetupServer setups the TF2 server for the lobby, creates the mumble channels for it
func (*Lobby) ShuffleAllSlots ¶
GetAllSlots returns a list of all occupied slots in the lobby
func (*Lobby) SlotNeedsSubstitute ¶
SlotNeedsSubstitute returns true if the given slot needs a substitute
func (*Lobby) Start ¶
func (lobby *Lobby) Start()
Start sets lobby.State to LobbyStateInProgress, calls SubNotInGamePlayers after 5 minutes
func (*Lobby) Substitute ¶
Substitute sets the needs_sub column of the given slot to true, and broadcasts the new substitute list
func (*Lobby) UnreadyAllPlayers ¶
UnreadyAllPlayers unreadies all players in the lobby
func (*Lobby) UnreadyPlayer ¶
UnreadyPlayer unreadies given player, use when lobby.State == LobbyStateWaiting
func (*Lobby) UpdateHours ¶
func (*Lobby) UpdateStats ¶
func (lobby *Lobby) UpdateStats()
UpdateStats updates the PlayerStats records for all players in the lobby (increments the relevent lobby type field by one). Used when the lobby successfully ends.
type LobbyConnectData ¶
type LobbyConnectData struct { ID uint `json:"id"` Time int64 `json:"time"` Pass string `json:"password"` Game struct { Host string `json:"host"` } `json:"game"` Mumble struct { Address string `json:"address"` Port string `json:"port"` Password string `json:"password"` Channel string `json:"channel"` } `json:"mumble"` DiscordChannel string `json:"discordChannel"` }
func DecorateLobbyConnect ¶
func DecorateLobbyConnect(lob *Lobby, player *player.Player, slot int) LobbyConnectData
type LobbyData ¶
type LobbyData struct { ID uint `json:"id"` Mode string `json:"gamemode"` Type string `json:"type"` Players int `json:"players"` Map string `json:"map"` League string `json:"league"` Mumble bool `json:"mumbleRequired"` Discord bool `json:"discord"` MaxPlayers int `json:"maxPlayers"` TwitchChannel string `json:"twitchChannel"` TwitchRestriction string `json:"twitchRestriction"` RegionLock bool `json:"regionLock"` SteamGroup string `json:"steamGroup"` RedTeamName string `json:"redTeamName"` BluTeamName string `json:"bluTeamName"` Region struct { Name string `json:"name"` Code string `json:"code"` } `json:"region"` Classes []ClassDetails `json:"classes"` Leader player.Player `json:"leader"` CreatedAt int64 `json:"createdAt"` State int `json:"state"` WhitelistID string `json:"whitelistId"` Spectators []SpecDetails `json:"spectators,omitempty"` }
func DecorateLobbyData ¶
func DecorateLobbyListData ¶
func (LobbyData) SendToPlayer ¶
type LobbyEvent ¶
type LobbyEvent struct { ID uint `json:"id"` Kicked bool `json:"kick,omitempty"` // true if player was kicked NotReady bool `json:"notReady,omitempty"` // true if player removed for not being ready }
func DecorateLobbyClosed ¶
func DecorateLobbyClosed(lobby *Lobby) LobbyEvent
func DecorateLobbyJoin ¶
func DecorateLobbyJoin(lobby *Lobby) LobbyEvent
type LobbyListData ¶
type LobbyListData struct {
Lobbies []LobbyData `json:"lobbies,omitempty"`
}
type LobbySlot ¶
type LobbySlot struct { ID uint `gorm:"primary_key"` CreatedAt time.Time UpdatedAt time.Time LobbyID uint //ID of the player occupying the slot PlayerID uint //Slot number Slot int //Denotes if the player is ready Ready bool //Denotes if the player is in game InGame bool //true if the player is in the game server InMumble bool //true if the player is in the mumble channel for the lobby NeedsSub bool //true if the slot needs a subtitute player }
Represents an occupied player slot in a lobby
type Requirement ¶
type Requirement struct { ID uint `json:"-"` LobbyID uint `json:"-"` Slot int `json:"-"` // if -1, applies to all slots Hours int `json:"hours"` // minimum hours needed Lobbies int `json:"lobbies"` // minimum lobbies played Reliability float64 `json:"reliability"` // minimum reliability needed Password string `json:"-"` // Slot password, if any }
Requirement stores a requirement for a particular slot in a lobby
func NewRequirement ¶
func NewRequirement(lobbyID uint, slot int, hours int, lobbies int) *Requirement
func (*Requirement) Save ¶
func (r *Requirement) Save()
type SlotDetails ¶
type SlotDetails struct { Slot int `json:"slot"` Filled bool `json:"filled"` Player *player.Player `json:"player,omitempty"` Ready *bool `json:"ready,omitempty"` InGame *bool `json:"ingame,omitempty"` InMumble *bool `json:"inmumble,omitempty"` Requirements *Requirement `json:"requirements,omitempty"` Password bool `json:"password"` }
type SpecDetails ¶
type SubstituteData ¶
type SubstituteData struct { LobbyID uint `json:"id"` Format string `json:"type"` MapName string `json:"map"` Region struct { Name string `json:"name"` Code string `json:"code"` } `json:"region"` RegionLock bool `json:"regionLock"` Mumble bool `json:"mumbleRequired"` Team string `sql:"-" json:"team"` Class string `sql:"-" json:"class"` TwitchChannel string `json:"twitchChannel"` TwitchRestriction string `json:"twitchRestriction"` SteamGroup string `json:"steamGroup"` Password bool `json:"password"` }
func DecorateSubstitute ¶
func DecorateSubstitute(slot *LobbySlot) SubstituteData
func DecorateSubstituteList ¶
func DecorateSubstituteList() []SubstituteData
type TwitchRestriction ¶
type TwitchRestriction int
const ( TwitchSubscribers TwitchRestriction = iota TwitchFollowers )
func (TwitchRestriction) String ¶
func (t TwitchRestriction) String() string
Notes ¶
Bugs ¶
FitsRequirements doesn't check reliability