lobby

package
v0.0.0-...-937b28e Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: GPL-3.0 Imports: 21 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

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

func BroadcastLobbyToUser(lobby *Lobby, steamid string)

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 MapRegionFormatExists(mapName, region string, lobbytype format.Format) bool

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

func GetLobbyByID(id uint) (*Lobby, error)

GetLobbyByID returns lobby object, without the ServerInfo object inside it.

func GetLobbyByIDServer

func GetLobbyByIDServer(id uint) (*Lobby, error)

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

func (lobby *Lobby) AddPlayer(p *player.Player, slot int, password string) error

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

func (lobby *Lobby) AddSpectator(player *player.Player) error

AddSpectator adds a given player as a lobby spectator

func (*Lobby) AfterPlayerNotInGameFunc

func (lobby *Lobby) AfterPlayerNotInGameFunc(player *player.Player, d time.Duration, f func())

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

func (lobby *Lobby) BanPlayer(player *player.Player)

BanPlayer bans a given player from the lobby

func (*Lobby) Close

func (lobby *Lobby) Close(doRPC, matchEnded bool)

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

func (lobby *Lobby) CreateLock()

CreateLock creates a lock for lobby

func (*Lobby) CurrentState

func (l *Lobby) CurrentState() State

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 *Lobby) DiscordNotif(msg string)

func (*Lobby) DownloadDemo

func (lobby *Lobby) DownloadDemo(context *servemetf.Context)

func (*Lobby) FillSubstitute

func (lobby *Lobby) FillSubstitute(slot int) error

FillSubstitute marks the substitute reocrd for the given slot as true, and Broadcasts the updated sub list

func (*Lobby) FitsRequirements

func (l *Lobby) FitsRequirements(player *player.Player, slot int) (bool, error)

FitsRequirements checks if the player fits the requirement to be added to the given slot in the lobby

func (*Lobby) GetAllSlots

func (lobby *Lobby) GetAllSlots() []LobbySlot

GetAllSlots returns a list of all occupied slots in the lobby

func (*Lobby) GetPlayerIDBySlot

func (lobby *Lobby) GetPlayerIDBySlot(slot int) (uint, error)

GetPlayerIDBySlot returns the ID of the player occupying the slot number

func (*Lobby) GetPlayerNumber

func (lobby *Lobby) GetPlayerNumber() int

GetPlayerNumber returns the number of occupied slots in the lobby

func (*Lobby) GetPlayerSlot

func (lobby *Lobby) GetPlayerSlot(player *player.Player) (int, error)

GetPlayerSlot returns the slot number if the player occupies a slot int eh lobby

func (*Lobby) GetPlayerSlotObj

func (lobby *Lobby) GetPlayerSlotObj(player *player.Player) (*LobbySlot, error)

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

func (lobby *Lobby) GetUnreadyPlayers() (players []*player.Player)

GetUnreadyPlayers returns a list of unready players in the lobby. only used when lobby state == LobbyStateReadyingUp

func (*Lobby) HasPlayer

func (lobby *Lobby) HasPlayer(player *player.Player) bool

HasPlayer returns true if the given player occupies a slot in the lobby

func (*Lobby) HasRequirements

func (lobby *Lobby) HasRequirements() bool

func (*Lobby) HasSlotRequirement

func (lobby *Lobby) HasSlotRequirement(slot int) bool

HasSlotRequirement returns true if the given slot in the lobby has a requirement

func (*Lobby) IsEnoughPlayers

func (lobby *Lobby) IsEnoughPlayers(n int) bool

func (*Lobby) IsEveryoneReady

func (lobby *Lobby) IsEveryoneReady() bool

IsEveryoneReady returns whether all players have readied up.

func (*Lobby) IsFull

func (lobby *Lobby) IsFull() bool

IsFull returns whether all lobby spots have been filled

func (*Lobby) IsPlayerBanned

func (lobby *Lobby) IsPlayerBanned(player *player.Player) bool

IsPlayerBanned returns whether the given player is banned from joining the lobby.

func (*Lobby) IsPlayerInGame

func (lobby *Lobby) IsPlayerInGame(player *player.Player) bool

IsPlayerInGame returns true if the player is in-game

func (*Lobby) IsPlayerInMumble

func (lobby *Lobby) IsPlayerInMumble(player *player.Player) bool

func (*Lobby) IsPlayerReady

func (lobby *Lobby) IsPlayerReady(player *player.Player) (bool, error)

IsPlayerReady returns true if the given player is ready

func (*Lobby) IsSlotFilled

func (lobby *Lobby) IsSlotFilled(slot int) bool

IsSlotFilled returns whether the given slot (by number) is occupied by a player

func (*Lobby) IsSlotOccupied

func (lobby *Lobby) IsSlotOccupied(slot int) bool

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

func (lobby *Lobby) OnChange(base bool)

OnChange broadcasts the given lobby to other players. If base is true, broadcasts the lobby list too.

func (*Lobby) ReadyPlayer

func (lobby *Lobby) ReadyPlayer(player *player.Player) error

ReadyPlayer readies up given player, use when lobby.State == LobbyStateWaiting

func (*Lobby) ReadyUpTimeLeft

func (lobby *Lobby) ReadyUpTimeLeft() int64

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

func (lobby *Lobby) RemovePlayer(player *player.Player) error

RemovePlayer removes a given player from the lobby

func (*Lobby) RemoveSpectator

func (lobby *Lobby) RemoveSpectator(player *player.Player, broadcast bool) error

RemoveSpectator removes the given player from the lobby spectators list. If broadcast, then broadcast the change to other players

func (*Lobby) RemoveUnreadyPlayers

func (lobby *Lobby) RemoveUnreadyPlayers(spec bool) error

RemoveUnreadyPlayers removes players who haven't removed. If spec == true, move them to spectators

func (*Lobby) RequiredPlayers

func (lobby *Lobby) RequiredPlayers() int

func (*Lobby) Save

func (lobby *Lobby) Save() error

Save saves changes made to lobby object to the DB

func (*Lobby) ServemeCheck

func (l *Lobby) ServemeCheck(context *servemetf.Context)

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

func (lobby *Lobby) SetInGame(player *player.Player) error

SetInGame sets the in-game status of the given player to true

func (*Lobby) SetInMumble

func (lobby *Lobby) SetInMumble(player *player.Player) error

SetInMumble sets the in-mumble status of the given player to true

func (*Lobby) SetNotInGame

func (lobby *Lobby) SetNotInGame(player *player.Player) error

SetNotInGame sets the in-game status of the given player to false

func (*Lobby) SetNotInMumble

func (lobby *Lobby) SetNotInMumble(player *player.Player) error

SetNotInMumble sets the in-mumble status of the given player to false

func (*Lobby) SetState

func (l *Lobby) SetState(s State)

func (*Lobby) SetupServer

func (lobby *Lobby) SetupServer() error

SetupServer setups the TF2 server for the lobby, creates the mumble channels for it

func (*Lobby) ShuffleAllSlots

func (lobby *Lobby) ShuffleAllSlots() error

GetAllSlots returns a list of all occupied slots in the lobby

func (*Lobby) SlotNeedsSubstitute

func (lobby *Lobby) SlotNeedsSubstitute(slot int) (needsSub bool)

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

func (lobby *Lobby) Substitute(player *player.Player)

Substitute sets the needs_sub column of the given slot to true, and broadcasts the new substitute list

func (*Lobby) Unlock

func (lobby *Lobby) Unlock()

Unlock releases the lock for the given lobby

func (*Lobby) UnreadyAllPlayers

func (lobby *Lobby) UnreadyAllPlayers() error

UnreadyAllPlayers unreadies all players in the lobby

func (*Lobby) UnreadyPlayer

func (lobby *Lobby) UnreadyPlayer(player *player.Player) error

UnreadyPlayer unreadies given player, use when lobby.State == LobbyStateWaiting

func (*Lobby) UpdateHours

func (lobby *Lobby) UpdateHours(logsID int) error

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 DecorateLobbyData(lobby *Lobby, playerInfo bool) LobbyData

func DecorateLobbyListData

func DecorateLobbyListData(lobbies []*Lobby, playerInfo bool) []LobbyData

func (LobbyData) Send

func (l LobbyData) Send()

func (LobbyData) SendToPlayer

func (l LobbyData) SendToPlayer(steamid string)

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 SpecDetails struct {
	Name    string `json:"name,omitempty"`
	SteamID string `json:"steamid,omitempty"`
}

type State

type State int
const (
	Initializing State = 0
	Waiting      State = 1
	ReadyingUp   State = 2
	InProgress   State = 3
	Ended        State = 5
)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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