guthls

package
v0.0.0-...-f3e09a6 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GlobalStats

type GlobalStats struct {
	Players   int
	TotalTime Seconds
}

GlobalStats is the global statistics of the server.

type Leaderboard

type Leaderboard []UserLeaderboard

Leaderboard describes a leaderboard.

type LeaderboardQueryFlags

type LeaderboardQueryFlags uint8

LeaderboardQueryFlags contains flags for querying additional information from the database along with the leaderboard.

const (
	LeaderboardQueryUser LeaderboardQueryFlags = 1 << iota
	LeaderboardQueryRank
)

func NewLeaderboardQueryFlags

func NewLeaderboardQueryFlags(flags []LeaderboardQueryFlags) LeaderboardQueryFlags

NewLeaderboardQueryFlags ORs the flags together.

type MySQLProvider

type MySQLProvider struct {
	*sql.DB
}

MySQLProvider provides a provider implementation to get the leaderboard from the MySQL server.

func NewMySQLProvider

func NewMySQLProvider(dsn string) (*MySQLProvider, error)

NewMySQLProvider creates a new MySQLProvider.

func (*MySQLProvider) GlobalStats

func (p *MySQLProvider) GlobalStats() (*GlobalStats, error)

GlobalStats implements Provider.

func (*MySQLProvider) Leaderboard

func (p *MySQLProvider) Leaderboard(f ...LeaderboardQueryFlags) (Leaderboard, error)

Leaderboard implements Provider.

func (*MySQLProvider) LeaderboardForUser

func (p *MySQLProvider) LeaderboardForUser(steamID SteamID, f ...LeaderboardQueryFlags) (*UserLeaderboard, error)

LeaderboardForUser implements Provider.

func (*MySQLProvider) User

func (p *MySQLProvider) User(steamID SteamID) (*User, error)

User implements Provider.

func (*MySQLProvider) Users

func (p *MySQLProvider) Users() ([]User, error)

Users implements Provider.

type Provider

type Provider interface {
	// User gets a user by Steam ID.
	User(SteamID) (*User, error)
	// Users gets all users.
	Users() ([]User, error)
	// LeaderboardForUser gets the user's leaderboard entry by Steam ID.
	LeaderboardForUser(SteamID, ...LeaderboardQueryFlags) (*UserLeaderboard, error)
	// Leaderboard gets the entire leaderboard. The returned leaderboard is
	// guaranteed to be sorted by Level then XP. If fetchUser is true, then the
	// returned UserLeaderboard instances should have the User field filled.
	Leaderboard(...LeaderboardQueryFlags) (Leaderboard, error)
	// GlobalStats gets the global server statistics.
	GlobalStats() (*GlobalStats, error)
}

Provider describes the database getters.

type Seconds

type Seconds int

Seconds is a number type that represents a second duration.

func (Seconds) Duration

func (s Seconds) Duration() time.Duration

Duration converts seconds to time.Duration.

type SteamID

type SteamID string

SteamID is a player's Steam ID.

func (SteamID) ProfileURL

func (id SteamID) ProfileURL() string

ProfileURL returns the profile URL for the Steam ID. If the SteamID is invalid, then an empty string is returned.

type UnixTime

type UnixTime int64

UnixTime is a number type that represents the Unix timestamp.

func (UnixTime) Time

func (t UnixTime) Time() time.Time

Time converts the Unix timestamp to time.Time.

type User

type User struct {
	SteamID    SteamID
	PlayerName string
	Team       string
	TotalTime  Seconds
	LastVisit  UnixTime
}

User is a player, or a row in the utime (or utime_server) table.

type UserLeaderboard

type UserLeaderboard struct {
	SteamID SteamID
	XP      int
	Level   int

	User *User  // only if LeaderboardQueryUser
	Rank string // only if LeaderboardQueryRank
}

UserLeaderboard describes a player in the leaderboard (or a row in the guth-ls table).

type UserTimes

type UserTimes []User

UserTimes contains multiple users.

Jump to

Keyboard shortcuts

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