towerfall

package
v0.0.0-...-afdd1b7 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTourmamentRunning = errors.New("no tournament is running")
View Source
var ErrPublisherDisabled = errors.New("publisher is disabled")

Functions

This section is empty.

Types

type Config

type Config struct {
	Production bool   `json:"production"`
	PerishKey  string `json:"perish_key"`

	Server   *ServerConfig   `yaml:"server" json:"server"`
	Database *DatabaseConfig `yaml:"database" json:"database"`
	Discord  *DiscordConfig  `yaml:"discord" json:"discord"`
	Rabbit   *RabbitConfig   `yaml:"rabbit" json:"rabbit"`

	Log *zap.Logger `json:"-"`
	// contains filtered or unexported fields
}

func ParseConfig

func ParseConfig() *Config

func (*Config) HasRabbit

func (c *Config) HasRabbit() bool

HasRabbit returns if we can talk to the Rabbit server or not

func (*Config) Print

func (c *Config) Print()

Print prints a visualization of what's going on

type Database

type Database struct {
	// contains filtered or unexported fields
}
var DB *Database

func NewDatabase

func NewDatabase(c *Config, wb *messages.WebsocketBroker) (*Database, error)

NewDatabase sets up the database reader and writer

func (*Database) AddPerson

func (d *Database) AddPerson(p *models.Person) error

AddPerson adds a person into the DB

func (*Database) AddPlayer

func (d *Database) AddPlayer(t *models.Tournament, ps *models.PlayerSummary) error

AddPlayer adds a player object to the tournament

func (*Database) AutoplayMatch

func (d *Database) AutoplayMatch(m *models.Match) error

AutoplayMatch replays an old match on top of an unplayed one

func (*Database) ClearTestTournaments

func (d *Database) ClearTestTournaments() error

ClearTestTournaments deletes any tournament that doesn't begin with "DrunkenFall"

func (*Database) Close

func (d *Database) Close() error

Close closes the database

func (*Database) CurrentMatch

func (d *Database) CurrentMatch(t *models.Tournament) (*models.Match, error)

CurrentMatch returns the currently running match

func (*Database) DisablePerson

func (d *Database) DisablePerson(id uint) error

DisablePerson disables or re-enables a person

func (*Database) GetAllRunnerups

func (d *Database) GetAllRunnerups(t *models.Tournament) ([]*models.PlayerSummary, error)

GetAllRunnerups gets all the runnerups that aren't already booked into matches

func (*Database) GetCurrentTournament

func (d *Database) GetCurrentTournament() (*models.Tournament, error)

GetCurrentTournament gets the currently running tournament

func (*Database) GetLeaderboard

func (d *Database) GetLeaderboard() ([]*models.LeaderboardPlayer, error)

GetLeaderboard gets the leaderboard

func (*Database) GetLeaderboardPlayer

func (d *Database) GetLeaderboardPlayer(id int) (*models.LeaderboardPlayer, error)

GetLeaderboardPlayer gets a single person from the leaderboard

func (*Database) GetLeague

func (d *Database) GetLeague(id uint) (*models.League, error)

GetLeague gets a single League

func (*Database) GetLeagues

func (d *Database) GetLeagues() ([]*models.League, error)

GetLeagues gets all the leagues

func (*Database) GetMatch

func (d *Database) GetMatch(id uint) (*models.Match, error)

GetMatch gets a match

func (*Database) GetMatches

func (d *Database) GetMatches(t *models.Tournament, kind string) ([]*models.Match, error)

GetMatches gets a slice of matches based on a kind

func (*Database) GetOrCreatePerson

func (d *Database) GetOrCreatePerson(pa *models.PersonAuth) (*models.Person, error, bool)

GetOrCreatePerson gets or creates a new person from a Auth user body

func (*Database) GetOverview

func (d *Database) GetOverview(t *models.Tournament) ([]*models.Summary, error)

GetOverview gets the overview

func (*Database) GetPeople

func (d *Database) GetPeople(all bool) ([]*models.Person, error)

GetPeople loads the people from the database

func (*Database) GetPerson

func (d *Database) GetPerson(id uint) (*models.Person, error)

GetPerson gets a Person{} from the DB

func (*Database) GetPersonFromFacebook

func (d *Database) GetPersonFromFacebook(oauth string) (*models.Person, error)

GetPersonFromFacebook gets a Person{} from a Facebook auth request

func (*Database) GetPlayerState

func (d *Database) GetPlayerState(m *models.Match, idx int) (*models.PlayerState, error)

GetPlayerState gets the player state for a player

func (*Database) GetPlayerStates

func (d *Database) GetPlayerStates(m *models.Match) ([]*models.PlayerState, error)

GetPlayerStates gets the players for all players in a match

func (*Database) GetPlayerSummaries

func (d *Database) GetPlayerSummaries(t *models.Tournament) ([]*models.PlayerSummary, error)

GetPlayerSummaries gets all player summaries for a tourmanent

func (*Database) GetPlayerSummary

func (d *Database) GetPlayerSummary(t *models.Tournament, pid uint) (*models.PlayerSummary, error)

GetPlayerSummary gets a single player summary for a tourmanent

func (*Database) GetPlayoffRunnerups

func (d *Database) GetPlayoffRunnerups(t *models.Tournament) ([]*models.PlayerSummary, error)

GetPlayoffRunnerups gets the runnerups in the playoffs

func (*Database) GetQueuedPlayers

func (d *Database) GetQueuedPlayers(t *models.Tournament) ([]*models.Person, error)

GetQueuedPlayers returns a list of all the players that are queued for the tournament

func (*Database) GetScores

func (d *Database) GetScores(t *models.Tournament) ([]*models.Score, error)

GetScores gets the scores

func (*Database) GetTournament

func (d *Database) GetTournament(id uint) (*models.Tournament, error)

GetTournament gets a tournament by id, or returns the cached one if there is one

func (*Database) GetTournamentLeaderboard

func (d *Database) GetTournamentLeaderboard(tm *models.Tournament) ([]*models.TournamentLeaderboardPlayer, error)

GetTournamentLeaderboard gets the leaderboard

func (*Database) GetTournaments

func (d *Database) GetTournaments() ([]*models.Tournament, error)

func (*Database) IsInTournament

func (d *Database) IsInTournament(t *models.Tournament, p *models.Person) (bool, error)

IsInTournament returns if the player is in the tournament or not

func (*Database) NewTournament

func (d *Database) NewTournament(t *models.Tournament) error

SaveTournament stores the current state of the tournaments into the db

func (*Database) NextMatch

func (d *Database) NextMatch(t *models.Tournament) (*models.Match, error)

NextMatch the next playable match of a tournament

func (*Database) QueueMessage

func (d *Database) QueueMessage(msg *messages.IncomingGameMessage) error

QueueMessage

func (*Database) RemovePlayer

func (d *Database) RemovePlayer(ps *models.PlayerSummary) error

RemovePlayer removes a player from a tourmament

func (*Database) ReplayRound

func (d *Database) ReplayRound() error

ReplayRound replays a single round.

Intended to be run inside of a goroutine - it will replay in real time.

func (*Database) ResetMatch

func (d *Database) ResetMatch(m *models.Match) error

ResetMatch resets a match

func (*Database) SaveMatch

func (d *Database) SaveMatch(m *models.Match) error

SaveMatch saves a match

func (*Database) SavePerson

func (d *Database) SavePerson(p *models.Person) error

SavePerson stores a person into the DB

func (*Database) SaveTournament

func (d *Database) SaveTournament(t *models.Tournament) error

SaveTournament stores the current state of the tournaments into the db

func (*Database) StoreMessage

func (d *Database) StoreMessage(m *models.Match, msg *messages.IncomingGameMessage) error

StoreMessage stores a message for a match

func (*Database) TogglePlayer

func (d *Database) TogglePlayer(t *models.Tournament, id uint) error

TogglePlayer toggles a player in a tournament

func (*Database) UsurpTournament

func (d *Database) UsurpTournament(t *models.Tournament, x int) error

UsurpTournament adds testing players

type DatabaseConfig

type DatabaseConfig struct {
	Host     string `yaml:"host" json:"host"`
	Name     string `yaml:"name" json:"name"`
	User     string `yaml:"user" json:"user"`
	Password string `yaml:"password" json:"-"` // JSON disabled to not log the password
	Verbose  bool   `yaml:"verbose" json:"verbose"`
}

DatabaseConfig unsurprisingly contains the database configuration

type DiscordConfig

type DiscordConfig struct {
	Key      string `yaml:"key" json:"key"`
	Secret   string `yaml:"secret" json:"secret"`
	Callback string `yaml:"callback" json:"callback"`
}

DiscordConfig unsurprisingly contains the Discord configuration

type Listener

type Listener struct {
	DB *Database
	// contains filtered or unexported fields
}

func NewListener

func NewListener(conf *Config, db *Database) (*Listener, error)

NewListener sets up a new listener

func (*Listener) Serve

func (l *Listener) Serve()

type LogHook

type LogHook struct {
	// contains filtered or unexported fields
}

func (LogHook) AfterQuery

func (l LogHook) AfterQuery(event *pg.QueryEvent)

func (LogHook) BeforeQuery

func (l LogHook) BeforeQuery(event *pg.QueryEvent)

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

func NewPublisher

func NewPublisher(conf *Config) (*Publisher, error)

NewPublisher sets up a new listener

func (*Publisher) Publish

func (p *Publisher) Publish(kind string, data interface{}) error

Publish sends a message on the default exchange to the currently configured queue

func (*Publisher) SendTournamentComplete

func (p *Publisher) SendTournamentComplete(t *models.Tournament) error

SendTournamentComplete sends the tournament ended message

type RabbitConfig

type RabbitConfig struct {
	URL      string `yaml:"url" json:"url"`
	Incoming string `yaml:"incoming" json:"incoming"`
	Outgoing string `yaml:"outgoing" json:"outgoing"`
}

RabbitConfig unsurprisingly contains the RabbitMQ configuration

type ServerConfig

type ServerConfig struct {
	Port int    `yaml:"port" json:"port"`
	Mode string `yaml:"mode" json:"mode"`
}

ServerConfig contains the http server configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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