player

package
v0.0.0-...-a29ef8a Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2016 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPlayerInReportedSlot = errors.New("Player in reported slot")
View Source
var ErrPlayerNotFound = errors.New("Player not found")

Functions

This section is empty.

Types

type BanType

type BanType int
const (
	BanJoin BanType = iota
	BanCreate
	BanChat
	BanFull
	BanJoinMumble
)

func (BanType) String

func (t BanType) String() string

type JSONFields

type JSONFields struct {
	PlaceholderLobbiesPlayed *int      `sql:"-" json:"lobbiesPlayed"`
	PlaceholderTags          *[]string `sql:"-" json:"tags"`
	PlaceholderRoleStr       *string   `sql:"-" json:"role"`
	//PlaceholderLobbies       *[]LobbyData `sql:"-" json:"lobbies"`
	PlaceholderStats *PlayerStats `sql:"-" json:"stats"`
	PlaceholderBans  []*PlayerBan `sql:"-" json:"bans"`
}

these are fields sent to clients and aren't used by Helen (hence ignored by ORM). Use (*Player).SetPlayerProfile and (*Player).SetPlayerSummary to set them. pointers allow un-needed structs to be set to null, so null is sent instead of the zeroed struct

type Player

type Player struct {
	ID                    uint      `gorm:"primary_key" json:"id"`
	CreatedAt             time.Time `json:"createdAt"`
	ProfileUpdatedAt      time.Time `json:"-"`
	StreamStatusUpdatedAt time.Time `json:"-"`

	SteamID string      `sql:"not null;unique" json:"steamid"` // Players steam ID
	Stats   PlayerStats `json:"-"`
	StatsID uint        `json:"-"`

	// info from steam api
	Avatar     string             `json:"avatar"`
	Profileurl string             `json:"profileUrl"`
	GameHours  int                `json:"gameHours"`
	Name       string             `json:"name"`              // Player name
	Role       authority.AuthRole `sql:"default:0" json:"-"` // Role is player by default

	Settings postgres.Hstore `json:"-"`

	MumbleUsername string `sql:"unique"`
	MumbleAuthkey  string `sql:"not null;unique" json:"-"`

	TwitchAccessToken string `json:"-"`
	TwitchName        string `json:"twitchName"`
	IsStreaming       bool   `json:"isStreaming"`

	ExternalLinks postgres.Hstore `json:"external_links,omitempty"`

	JSONFields
}

Player represents a player object

func GetPlayerByID

func GetPlayerByID(ID uint) (*Player, error)

Get a player by it's ID

func GetPlayerBySteamID

func GetPlayerBySteamID(steamid string) (*Player, error)

Get a player object by it's Steam id

func GetPlayerWithStats

func GetPlayerWithStats(steamid string) (*Player, error)

Get a player object by it's Steam ID, with the Stats field

func NewPlayer

func NewPlayer(steamId string) (*Player, error)

Create a new player with the given steam id. Use (*Player).Save() to save the player object.

func (*Player) Alias

func (p *Player) Alias() string

if the player has an alias, return that. Else, return their steam name

func (*Player) BanUntil

func (player *Player) BanUntil(tim time.Time, t BanType, reason string, bannedBy uint) error

func (*Player) DecoratePlayerTags

func (p *Player) DecoratePlayerTags() []string

func (*Player) GenAuthKey

func (player *Player) GenAuthKey() string

func (*Player) GetActiveBan

func (player *Player) GetActiveBan(banType BanType) (*PlayerBan, error)

func (*Player) GetActiveBans

func (player *Player) GetActiveBans() ([]*PlayerBan, error)

func (*Player) GetAllBans

func (player *Player) GetAllBans() ([]*PlayerBan, error)

func (*Player) GetLobbyID

func (player *Player) GetLobbyID(excludeInProgress bool) (uint, error)

Get the ID of the lobby the player occupies a slot in. Only works for lobbies which aren't closed (LobbyStateEnded). If excludeInProgress, exclude lobbies which are in progress

func (*Player) GetSetting

func (player *Player) GetSetting(key string) string

func (*Player) GetSpectatingIds

func (player *Player) GetSpectatingIds() ([]uint, error)

Get ID(s) of lobbies (which aren't clsoed) the player is spectating

func (*Player) HasCreatedLobby

func (p *Player) HasCreatedLobby() bool

func (*Player) HasSubscriptionProgram

func (p *Player) HasSubscriptionProgram() bool

IsSubscribed returns whether if the player has a Twitch subscription program. The player object should have a valid access token and twitch name

func (*Player) IsBanned

func (player *Player) IsBanned(t BanType) bool

func (*Player) IsBannedWithTime

func (player *Player) IsBannedWithTime(t BanType) (bool, time.Time)

func (*Player) IsFollowing

func (p *Player) IsFollowing(channel string) bool

IsFollowing returns whether the player has subscribed to the given Twitch channel. The player obejct should have a valid access token and twitch name

func (*Player) IsSpectatingID

func (player *Player) IsSpectatingID(lobbyid uint) bool

Return true if player is spectating a lobby with the given lobby ID

func (*Player) IsSubscribed

func (p *Player) IsSubscribed(channel string) bool

IsSubscribed returns whether if the player has subscribed to the given twitch channel. The player object should have a valid access token and twitch name

func (*Player) NewReport

func (player *Player) NewReport(rtype ReportType, lobbyid uint)

func (*Player) Save

func (player *Player) Save() error

Save any changes made to the player object

func (player *Player) SetExternalLinks()

func (*Player) SetMumbleUsername

func (player *Player) SetMumbleUsername(lobbyType format.Format, slot int)

func (*Player) SetPlayerProfile

func (p *Player) SetPlayerProfile()

func (*Player) SetPlayerSummary

func (p *Player) SetPlayerSummary()

func (*Player) SetSetting

func (player *Player) SetSetting(key string, value string)

func (*Player) Unban

func (player *Player) Unban(t BanType) error

func (*Player) UpdatePlayerInfo

func (player *Player) UpdatePlayerInfo() error

Retrieve the player's details using the Steam API. The object needs to be saved after this.

type PlayerBan

type PlayerBan struct {
	gorm.Model
	PlayerID uint   // ID of the player banned
	Player   Player `gorm:"ForeignKey:PlayerID"`

	BannedByPlayerID uint   // ID of the admin/mod who set ban
	BannedByPlayer   Player `gorm:"ForeignKey:BannedByPlayerID"`

	Type   BanType   // Ban type
	Until  time.Time // Time until which the ban is valid
	Reason string    // Reason for the ban
	Active bool      `sql:"default:true"` // Whether the ban is active
}

PlayerBan represents a player ban

func GetAllActiveBans

func GetAllActiveBans() []*PlayerBan

func GetAllBans

func GetAllBans() []*PlayerBan

func (*PlayerBan) MarshalJSON

func (ban *PlayerBan) MarshalJSON() ([]byte, error)

type PlayerStats

type PlayerStats struct {
	ID uint `json:"-"`

	Total                 int `sql:"-" json:"lobbiesPlayed"`
	PlayedSixesCount      int `sql:"played_sixes_count",default:"0" json:"playedSixesCount"`
	PlayedHighlanderCount int `sql:"played_highlander_count",default:"0" json:"playedHighlanderCount"`
	PlayedFoursCount      int `sql:"played_fours_count",json:"playedFoursCount" `
	PlayedUltiduoCount    int `sql:"played_ultiduo_count",json:"playedUltiduoCount"`
	PlayedBballCount      int `sql:"played_bball_count",json:"playedBballCount"`

	Scout         int           `json:"scout"`
	ScoutHours    time.Duration `json:"scoutHours"`
	Soldier       int           `json:"soldier"`
	SoldierHours  time.Duration `json:"soldierHours"`
	Pyro          int           `json:"pyro"`
	PyroHours     time.Duration `json:"pyroHours"`
	Engineer      int           `json:"engineer"`
	EngineerHours time.Duration `json:"engineerHours"`
	Heavy         int           `json:"heavy"`
	HeavyHours    time.Duration `json:"heavyHours"`
	Demoman       int           `json:"demoman"`
	DemoHours     time.Duration `json:"demomanHours"`
	Sniper        int           `json:"sniper"`
	SniperHours   time.Duration `json:"sniperHours"`
	Medic         int           `json:"medic"`
	MedicHours    time.Duration `json:"medicHours"`
	Spy           int           `json:"spy"`
	SpyHours      time.Duration `json:"spyHours"`

	Substitutes int `json:"substitutes"`
}

func NewStats

func NewStats() PlayerStats

func (*PlayerStats) IncreaseClassCount

func (ps *PlayerStats) IncreaseClassCount(f format.Format, slot int)

func (*PlayerStats) IncreaseSubCount

func (ps *PlayerStats) IncreaseSubCount()

func (*PlayerStats) PlayedCountIncrease

func (ps *PlayerStats) PlayedCountIncrease(lt format.Format)

func (*PlayerStats) Save

func (ps *PlayerStats) Save()

func (*PlayerStats) TotalLobbies

func (ps *PlayerStats) TotalLobbies() int

type Report

type Report struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time

	PlayerID uint
	LobbyID  uint
	Type     ReportType
}

type ReportType

type ReportType int
const (
	Substitute ReportType = iota //!sub
	Vote                         //!repped by other players
	RageQuit                     //rage quit
)

Jump to

Keyboard shortcuts

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