tournament

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MaxDivisionNameLength = 24

Variables

This section is empty.

Functions

func AddDirectors

func AddDirectors(ctx context.Context, ts TournamentStore, us user.Store, id string, directors *ipc.TournamentPersons) error

func AddDivision

func AddDivision(ctx context.Context, ts TournamentStore, id string, division string) error

func AddPlayers

func AddPlayers(ctx context.Context, ts TournamentStore, us user.Store, id string, division string, players *ipc.TournamentPersons) error

func CheckIn

func CheckIn(ctx context.Context, ts TournamentStore, tid string, playerid string) error

func ClearReadyStates

func ClearReadyStates(ctx context.Context, ts TournamentStore, t *entity.Tournament,
	division, userID string, round, gameIndex int) error

func DeletePairings

func DeletePairings(ctx context.Context, ts TournamentStore, id string, division string, round int) error

func DivisionChannelName

func DivisionChannelName(tid, division string) string

DivisionChannelName returns a channel name that can be used for sending communications regarding a tournament and division.

func HandleTournamentGameEnded

func HandleTournamentGameEnded(ctx context.Context, ts TournamentStore, us user.Store,
	g *entity.Game) error

func IsFinished

func IsFinished(ctx context.Context, ts TournamentStore, id string) (bool, error)

func IsRoundComplete

func IsRoundComplete(ctx context.Context, ts TournamentStore, id string, division string, round int) (bool, error)

func IsStarted

func IsStarted(ctx context.Context, ts TournamentStore, id string) (bool, error)

func NewTournament

func NewTournament(ctx context.Context,
	tournamentStore TournamentStore,
	name string,
	description string,
	directors *ipc.TournamentPersons,
	ttype entity.CompetitionType,
	parent string,
	slug string,
) (*entity.Tournament, error)

func PairRound

func PairRound(ctx context.Context, ts TournamentStore, id string, division string, round int, preserveByes bool) error

func PairingsToResponse

func PairingsToResponse(id string, division string, pairings []*ipc.Pairing, standings map[int32]*ipc.RoundStandings) *ipc.DivisionPairingsResponse

func RemoveDirectors

func RemoveDirectors(ctx context.Context, ts TournamentStore, us user.Store, id string, directors *ipc.TournamentPersons) error

func RemoveDivision

func RemoveDivision(ctx context.Context, ts TournamentStore, id string, division string) error

func RemovePlayers

func RemovePlayers(ctx context.Context, ts TournamentStore, us user.Store, id string, division string, players *ipc.TournamentPersons) error

func SendTournamentMessage

func SendTournamentMessage(ctx context.Context, ts TournamentStore, id string, wrapped *entity.EventWrapper) error

SendTournamentMessage sends updated tournament information on the channel.

func SetDivisionControls

func SetDivisionControls(ctx context.Context, ts TournamentStore, id string, division string, controls *ipc.DivisionControls) error

func SetFinished

func SetFinished(ctx context.Context, ts TournamentStore, id string) error

func SetPairings

func SetPairings(ctx context.Context, ts TournamentStore, id string, division string, pairings []*pb.TournamentPairingRequest) error

SetPairings is only called by the API

func SetReadyForGame

func SetReadyForGame(ctx context.Context, ts TournamentStore, t *entity.Tournament,
	playerID, connID, division string,
	round, gameIndex int, unready bool) ([]string, bool, error)

func SetResult

func SetResult(ctx context.Context,
	ts TournamentStore,
	us user.Store,
	id string,
	division string,
	playerOneId string,
	playerTwoId string,
	playerOneScore int,
	playerTwoScore int,
	playerOneResult ipc.TournamentGameResult,
	playerTwoResult ipc.TournamentGameResult,
	reason ipc.GameEndReason,
	round int,
	gameIndex int,
	amendment bool,
	g *entity.Game) error

SetResult sets the result for the game. Note: playerOne and playerTwo went first and second, respectively.

func SetRoundControls

func SetRoundControls(ctx context.Context, ts TournamentStore, id string, division string, roundControls []*ipc.RoundControl) error

func SetSingleRoundControls

func SetSingleRoundControls(ctx context.Context, ts TournamentStore, id string, division string, round int, controls *ipc.RoundControl) error

func SetTournamentMetadata

func SetTournamentMetadata(ctx context.Context, ts TournamentStore, meta *pb.TournamentMetadata) error

func StartAllRoundCountdowns

func StartAllRoundCountdowns(ctx context.Context, ts TournamentStore, id string, round int) error

func StartRoundCountdown

func StartRoundCountdown(ctx context.Context, ts TournamentStore, id string,
	division string, round int) error

func TournamentDataResponse

func TournamentDataResponse(ctx context.Context, ts TournamentStore, id string) (*ipc.TournamentDataResponse, error)

func UncheckIn

func UncheckIn(ctx context.Context, ts TournamentStore, tid string) error

Types

type ClassicDivision

type ClassicDivision struct {
	TournamentName string                 `json:"tournamentName"`
	DivisionName   string                 `json:"divisionName"`
	Matrix         [][]string             `json:"matrix"`
	PairingMap     map[string]*pb.Pairing `json:"pairingMap"`
	// By convention, players should look like userUUID:username
	Players          *pb.TournamentPersons        `json:"players"`
	PlayerIndexMap   map[string]int32             `json:"pidxMap"`
	Standings        map[int32]*pb.RoundStandings `json:"standings"`
	RoundControls    []*pb.RoundControl           `json:"roundControls"`
	DivisionControls *pb.DivisionControls         `json:"divisionControls"`
	CurrentRound     int32                        `json:"currentRound"`
	PairingKeyInt    int                          `json:"pairingKeyInt"`
}

func NewClassicDivision

func NewClassicDivision(tournamentName string, divisionName string) *ClassicDivision

func (*ClassicDivision) AddPlayers

func (*ClassicDivision) ClearReadyStates

func (t *ClassicDivision) ClearReadyStates(playerID string, round, gameIndex int) ([]*pb.Pairing, error)

func (*ClassicDivision) DeletePairings

func (t *ClassicDivision) DeletePairings(round int) error

func (*ClassicDivision) GetCurrentRound

func (t *ClassicDivision) GetCurrentRound() int

func (*ClassicDivision) GetDivisionControls

func (t *ClassicDivision) GetDivisionControls() *pb.DivisionControls

func (*ClassicDivision) GetPlayers

func (t *ClassicDivision) GetPlayers() *pb.TournamentPersons

func (*ClassicDivision) GetStandings

func (t *ClassicDivision) GetStandings(round int) (*pb.RoundStandings, int, error)

func (*ClassicDivision) GetXHRResponse

func (t *ClassicDivision) GetXHRResponse() (*pb.TournamentDivisionDataResponse, error)

func (*ClassicDivision) IsFinished

func (t *ClassicDivision) IsFinished() (bool, error)

func (*ClassicDivision) IsRoundComplete

func (t *ClassicDivision) IsRoundComplete(round int) (bool, error)

func (*ClassicDivision) IsRoundReady

func (t *ClassicDivision) IsRoundReady(round int) (bool, error)

func (*ClassicDivision) IsRoundStartable

func (t *ClassicDivision) IsRoundStartable() error

func (*ClassicDivision) IsStartable

func (t *ClassicDivision) IsStartable() bool

func (*ClassicDivision) IsStarted

func (t *ClassicDivision) IsStarted() bool

func (*ClassicDivision) PairRound

func (t *ClassicDivision) PairRound(round int, preserveByes bool) (*pb.DivisionPairingsResponse, error)

func (*ClassicDivision) RecalculateStandings

func (t *ClassicDivision) RecalculateStandings() (*pb.DivisionPairingsResponse, error)

func (*ClassicDivision) RemovePlayers

func (t *ClassicDivision) RemovePlayers(persons *pb.TournamentPersons) (*pb.DivisionPairingsResponse, error)

func (*ClassicDivision) ResetToBeginning

func (t *ClassicDivision) ResetToBeginning() error

func (*ClassicDivision) SetDivisionControls

func (t *ClassicDivision) SetDivisionControls(divisionControls *pb.DivisionControls) (*pb.DivisionControls, map[int32]*pb.RoundStandings, error)

func (*ClassicDivision) SetPairing

func (t *ClassicDivision) SetPairing(playerOne string, playerTwo string, round int,
	selfPlayResult pb.TournamentGameResult) (*pb.DivisionPairingsResponse, error)

func (*ClassicDivision) SetReadyForGame

func (t *ClassicDivision) SetReadyForGame(playerID, connID string, round, gameIndex int, unready bool) ([]string, bool, error)

SetReadyForGame sets the playerID with the given connID to be ready for the game with the given 0-based round (and gameIndex, optionally). If `unready` is passed in, we make the player unready. It returns a list of playerId:username:connIDs involved in the game, a boolean saying if they're ready, and an optional error.

func (*ClassicDivision) SetRoundControls

func (t *ClassicDivision) SetRoundControls(roundControls []*pb.RoundControl) (*pb.DivisionPairingsResponse, []*pb.RoundControl, error)

func (*ClassicDivision) SetSingleRoundControls

func (t *ClassicDivision) SetSingleRoundControls(round int, controls *pb.RoundControl) (*pb.RoundControl, error)

func (*ClassicDivision) StartRound

func (t *ClassicDivision) StartRound(checkForStartable bool) error

func (*ClassicDivision) SubmitResult

func (t *ClassicDivision) SubmitResult(round int,
	p1 string,
	p2 string,
	p1Score int,
	p2Score int,
	p1Result pb.TournamentGameResult,
	p2Result pb.TournamentGameResult,
	reason pb.GameEndReason,
	amend bool,
	gameIndex int,
	gid string) (*pb.DivisionPairingsResponse, error)

type PlayerSorter

type PlayerSorter []*pb.TournamentPerson

func (PlayerSorter) Len

func (a PlayerSorter) Len() int

func (PlayerSorter) Less

func (a PlayerSorter) Less(i, j int) bool

func (PlayerSorter) Swap

func (a PlayerSorter) Swap(i, j int)

type TournamentService

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

TournamentService is a Twirp service that contains functions that allow directors to interact with their tournaments

func NewTournamentService

func NewTournamentService(ts TournamentStore, us user.Store) *TournamentService

NewTournamentService creates a Twirp TournamentService

func (*TournamentService) AddDirectors

func (*TournamentService) AddDivision

func (*TournamentService) AddPlayers

func (*TournamentService) CheckIn

CheckIn does not require director permission.

func (*TournamentService) CreateClubSession

func (*TournamentService) FinishTournament

func (*TournamentService) GetRecentClubSessions

func (ts *TournamentService) GetRecentClubSessions(ctx context.Context, req *pb.RecentClubSessionsRequest) (*pb.ClubSessionsResponse, error)

func (*TournamentService) GetTournament

func (*TournamentService) GetTournamentMetadata

func (*TournamentService) NewTournament

func (*TournamentService) PairRound

func (*TournamentService) RecentGames

func (*TournamentService) RemoveDirectors

func (ts *TournamentService) RemoveDirectors(ctx context.Context, req *ipc.TournamentPersons) (*pb.TournamentResponse, error)

func (*TournamentService) RemoveDivision

func (*TournamentService) RemovePlayers

func (*TournamentService) SetDivisionControls

func (ts *TournamentService) SetDivisionControls(ctx context.Context, req *ipc.DivisionControls) (*pb.TournamentResponse, error)

func (*TournamentService) SetEventChannel

func (ts *TournamentService) SetEventChannel(c chan *entity.EventWrapper)

func (*TournamentService) SetPairing

func (*TournamentService) SetResult

func (*TournamentService) SetRoundControls

func (*TournamentService) SetSingleRoundControls

func (ts *TournamentService) SetSingleRoundControls(ctx context.Context, req *pb.SingleRoundControlsRequest) (*pb.TournamentResponse, error)

func (*TournamentService) SetTournamentMetadata

func (*TournamentService) StartRoundCountdown

func (*TournamentService) UncheckIn

func (*TournamentService) UnstartTournament

type TournamentStore

type TournamentStore interface {
	Get(context.Context, string) (*entity.Tournament, error)
	GetBySlug(context.Context, string) (*entity.Tournament, error)
	Set(context.Context, *entity.Tournament) error
	Create(context.Context, *entity.Tournament) error
	GetRecentGames(ctx context.Context, tourneyID string, numGames int, offset int) (*pb.RecentGamesResponse, error)
	Unload(context.Context, string)
	SetTournamentEventChan(c chan<- *entity.EventWrapper)
	TournamentEventChan() chan<- *entity.EventWrapper
	ListAllIDs(context.Context) ([]string, error)

	GetRecentClubSessions(ctx context.Context, clubID string, numSessions int, offset int) (*pb.ClubSessionsResponse, error)
	AddRegistrants(ctx context.Context, tid string, userIDs []string, division string) error
	RemoveRegistrants(ctx context.Context, tid string, userIDs []string, division string) error
	RemoveRegistrantsForTournament(ctx context.Context, tid string) error
	ActiveTournamentsFor(ctx context.Context, userID string) ([][2]string, error)
}

Jump to

Keyboard shortcuts

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