backend

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: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CookieStoreName = "user-session"
	CookieStoreKey  = []byte("dtf")
)

Setup variables for the cookies.

Functions

func HasPermission

func HasPermission(c *gin.Context, lvl int) bool

HasPermission checks that the user is allowed to do an action

func RequestLogger

func RequestLogger(log *zap.Logger) gin.HandlerFunc

Types

type AuthResponse

type AuthResponse struct {
	Authenticated bool `json:"authenticated"`
}

AuthResponse returns boolean if we are authenticated or not

type EndQualifyingRequest

type EndQualifyingRequest struct {
	Time time.Time `json:"time"`
}

type FakeNameResponse

type FakeNameResponse struct {
	Name    string `json:"name"`
	Numeral string `json:"numeral"`
}

type HTTPError

type HTTPError struct {
	Message string `json:"message"`
	Error   string `json:"error"`
}

In lack of a better place to put them, set response types here

type HTTPResponse

type HTTPResponse struct {
}

HTTPResponse is a generic empty response

type LeagueListResponse

type LeagueListResponse struct {
	Leagues []*models.League `json:"leagues"`
}

LeagueListResponse is a list of League objects

type LeagueResponse

type LeagueResponse struct {
	League *models.League `json:"league"`
}

LeagueResponse is a single League

type MatchesResponse

type MatchesResponse struct {
	Matches []*models.Match `json:"matches"`
}

MatchesResponse is a list of matches

type NewRequest

type NewRequest struct {
	Name      string    `json:"name" binding:"required"`
	ID        string    `json:"id" binding:"required"`
	Scheduled time.Time `json:"scheduled" binding:"required"`
	Cover     string    `json:"cover"`
	Fake      bool      `json:"fake"`
	Kind      string    `json:"kind" form:",default=headhunters"`
}

NewRequest is the request to make a new tournament

type PeopleResponse

type PeopleResponse struct {
	People      []*models.Person            `json:"people"`
	Leaderboard []*models.LeaderboardPlayer `json:"leaderboard"`
}

PeopleResponse is a list of everyone registered in the app, with a leaderboard

type PerishRequest

type PerishRequest struct {
	Key string `json:"key"`
}

PerishRequest is the request for the server to go die

type PersonResponse

type PersonResponse struct {
	Person      *models.Person            `json:"person"`
	Leaderboard *models.LeaderboardPlayer `json:"leaderboard"`
}

PesonResponse is like PeopleResponse, but for a single person

type PlayerSummariesResponse

type PlayerSummariesResponse struct {
	PlayerSummaries []*models.PlayerSummary `json:"player_summaries"`
}

PlayerSummariesResponse is a list PlayerSummary objects

type ScoreResponse

type ScoreResponse struct {
	Scores []*models.Score `json:"scores"`
}

ScoreResponse is a list of Score objects

type Server

type Server struct {
	DB *towerfall.Database
	// contains filtered or unexported fields
}

Server is an abstraction that runs a web interface

var Global *Server

func NewServer

func NewServer(config *towerfall.Config, db *towerfall.Database, wb *messages.WebsocketBroker) *Server

NewServer instantiates a server with an active database

func (*Server) AddMessageToQueue

func (s *Server) AddMessageToQueue(c *gin.Context)

AddMessageToQueue godoc @Summary Adds a message into the current match @Description This is a tool to simulate input from the game. @Description It literally just accepts the JSON body of the POST @Tags testing @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/message [post]

func (*Server) AutoplayMatchHandler

func (s *Server) AutoplayMatchHandler(c *gin.Context)

AutoplayMatchHandler godoc @Summary Replays a real match on a testing match, completing it in full @Tags testing @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/autoplay/ [get]

func (*Server) BuildRouter

func (s *Server) BuildRouter(wb *messages.WebsocketBroker) *gin.Engine

BuildRouter sets up the routes

func (*Server) ClearTournamentHandler

func (s *Server) ClearTournamentHandler(c *gin.Context)

ClearTournamentHandler godoc @Summary Removes all test tournaments @Description Any tournament that does not start with "DrunkenFall" is removed. @Description Returns a list of the remaining tournaments. @Tags testing @Accept json @Produce json @Success 200 {object} backend.TournamentListResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/ [delete]

func (*Server) CreditsHandler

func (s *Server) CreditsHandler(c *gin.Context)

CreditsHandler godoc @Summary Returns the data needed for the credits roll @Tags tournament @Accept json @Produce json @Success 200 {object} models.Credits @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/credits/ [get]

func (*Server) DBLoginHandler

func (s *Server) DBLoginHandler(c *gin.Context)

func (*Server) DisableHandler

func (s *Server) DisableHandler(c *gin.Context)

DisableHandler godoc @Summary Disables or enables players @Tags user @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /user/disable/{person} [get]

func (*Server) EndQualifyingHandler

func (s *Server) EndQualifyingHandler(c *gin.Context)

EndQualifyingHandler godoc @Summary Sets the cutoff time for the qualifying rounds @Description The cutoff time works so that the tournament will continue to schedule qualifying matches until the timestamp has passed. @Description This is a necessity due to the nature of always scheduling two // matches ahead. @Description Note that the 'time.Time' parameter called 'time' cannot be @Description documented at this time due to a swaggo error. @Tags tournament @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/endqualifying/ [post]

func (*Server) FakeNameHandler

func (s *Server) FakeNameHandler(c *gin.Context)

FakeNameHandler returns a fake name for a tournament

func (*Server) LeagueHandler

func (s *Server) LeagueHandler(c *gin.Context)

LeagueHandler godoc @Summary Get a single league @Tags league @Accept json @Produce json @Param id path int true "League ID" @Success 200 {object} backend.LeagueResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /leagues/{id}/ [get]

func (*Server) LeagueListHandler

func (s *Server) LeagueListHandler(c *gin.Context)

LeagueListHandler godoc @Summary Get all leagues @Description Returns a list of all leagues, with tournaments. Note that the @Description tournaments are not sorted, because the ORM is very good for such cases. @Tags league @Accept json @Produce json @Success 200 {object} backend.LeagueListResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /leagues/ [get]

func (*Server) LogoutHandler

func (s *Server) LogoutHandler(c *gin.Context)

LogoutHandler godoc @Summary Logs out the user @Tags user @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /user/logout/ [get]

func (*Server) MatchesHandler

func (s *Server) MatchesHandler(c *gin.Context)

MatchesHandler godoc @Summary Gets the matches for a tournament @Tags tournament @Accept json @Produce json @Success 200 {object} backend.MatchesResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/matches/ [get]

func (*Server) NewHandler

func (s *Server) NewHandler(c *gin.Context)

NewHandler shows the page to create a new tournament

func (*Server) OverviewHandler

func (s *Server) OverviewHandler(c *gin.Context)

OverviewHandler godoc @Summary Returns the player summaries for all the players in a tournament @Tags tournament @Accept json @Produce json @Success 200 {object} backend.SummariesResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/overview/ [get]

func (*Server) PeopleHandler

func (s *Server) PeopleHandler(c *gin.Context)

PeopleHandler godoc @Summary Returns a list of all the players registered in the app, including the leaderboard @Tags people @Accept json @Produce json @Success 200 {object} backend.PeopleResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /people/ [get]

func (*Server) PerishHandler

func (s *Server) PerishHandler(c *gin.Context)

LeagueHandler godoc @Summary Exit the application @Description This is used to trigger a restart and upgrade @Tags league @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 403 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /perish/ [post]

func (*Server) PersonFromSession

func (s *Server) PersonFromSession(c *gin.Context) (*models.Person, error)

PersonFromSession returns the Person{} object attached to the session

func (*Server) PersonHandler

func (s *Server) PersonHandler(c *gin.Context)

PersonHandler godoc @Summary Returns a single player, including their leaderboard data @Tags people @Accept json @Produce json @Success 200 {object} backend.PersonResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /people/{person} [get]

func (*Server) PlayerSummariesHandler

func (s *Server) PlayerSummariesHandler(c *gin.Context)

PlayerSummariesHandler godoc @Summary Returns the player summaries for all the players in a tournament @Tags tournament @Accept json @Produce json @Success 200 {object} backend.PlayerSummariesResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/players/ [get]

func (*Server) PlayoffRunnerupsHandler

func (s *Server) PlayoffRunnerupsHandler(c *gin.Context)

PlayoffRunnerupsHandler godoc @Summary Returns the current playoff runnerups for a tournament, in playing order @Description The scores are only for the playoffs and not for the full tournament. @Tags tournament @Accept json @Produce json @Success 200 {object} backend.PlayerSummariesResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/runnerups/playoffs/ [get]

func (*Server) PublishNext

func (s *Server) PublishNext(t *models.Tournament) error

PublishNext sends information about the next match to the game

It only does this if the match already has four players. If it does not, it's a semi that needs backfilling, and then the backfilling will make the publish. This should always be called before the match is started, so t.NextMatch() can always safely be used.

func (*Server) QueueHandler

func (s *Server) QueueHandler(c *gin.Context)

QueueHandler godoc @Summary Returns the current queue @Description TODO(thiderman): Don't return the leaderboard. @Tags tournament @Accept json @Produce json @Success 200 {object} backend.PeopleResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/queue/ [get]

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(c *gin.Context)

RegisterHandler godoc @Summary Adds a new user. @Description If a tournament is currently running, immediately add the user to there. @Tags user @Accept json @Produce json @Success 200 {object} models.Person @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /user/register/ [post]

func (*Server) ReplayRound

func (s *Server) ReplayRound(c *gin.Context)

ReplayRound godoc @Summary Replays a single round in real time @Description This is a tool to simulate input from the game, real time style. @Tags testing @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/round_replay [get]

func (*Server) RequireJudge

func (s *Server) RequireJudge() gin.HandlerFunc

func (*Server) RunnerupsHandler

func (s *Server) RunnerupsHandler(c *gin.Context)

RunnerupsHandler godoc @Summary Returns the current runnerups for a tournament, in playing order @Tags tournament @Accept json @Produce json @Success 200 {object} backend.PlayerSummariesResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/runnerups/ [get]

func (*Server) ScoresHandler

func (s *Server) ScoresHandler(c *gin.Context)

ScoresHandler godoc @Summary Returns the player summaries for all the players in a tournament @Tags tournament @Accept json @Produce json @Success 200 {object} backend.ScoreResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/scores/ [get]

func (*Server) Serve

func (s *Server) Serve() error

Serve starts serving

func (*Server) SetTimeHandler

func (s *Server) SetTimeHandler(c *gin.Context)

SetTimeHandler godoc @Summary Sets the pause time for the next match @Tags tournament @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/time/{minutes} [get]

func (*Server) SettingsHandler

func (s *Server) SettingsHandler(c *gin.Context)

SettingsHandler godoc @Summary Updates settings @Tags user @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /user/settings/ [post]

func (*Server) StartPlayHandler

func (s *Server) StartPlayHandler(c *gin.Context)

StartPlayHandler godoc @Summary Sends a message to the game that it is time to start doing whatever is next. @Tags tournament @Accept json @Produce json @Success 200 {object} backend.StartPlayResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.StartPlayResponse @Router /tournaments/{id}/play/ [post]

func (*Server) StartTournamentHandler

func (s *Server) StartTournamentHandler(c *gin.Context)

StartTournamentHandler godoc @Summary ...it starts tournaments. What. ¯\_(ツ)_/¯ @Tags tournament @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/start/ [get]

func (*Server) ToggleHandler

func (s *Server) ToggleHandler(c *gin.Context)

ToggleHandler godoc @Summary Adds or removes a player from a tournament @Tags tournament @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/toggle/{person} [get]

func (*Server) TournamentHandler

func (s *Server) TournamentHandler(c *gin.Context)

TournamentHandler godoc @Summary Current state of a tournament @Description Gets the entire current state of the tournament @Tags tournament @Accept json @Produce json @Param id path int true "Tournament ID" @Success 200 {object} backend.TournamentResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/ [get]

func (*Server) TournamentLeaderboardHandler

func (s *Server) TournamentLeaderboardHandler(c *gin.Context)

TournamentLeaderboardHandler godoc @Summary Returns a special JSON view of the current leaderboard @Tags tournament @Accept json @Produce json @Success 200 {object} backend.TournamentLeaderboardResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/players/ [get]

func (*Server) TournamentListHandler

func (s *Server) TournamentListHandler(c *gin.Context)

TournamentListHandler godoc @Summary State of all tournaments @Description Returns a list of all tournaments @Tags tournament @Accept json @Produce json @Success 200 {object} backend.TournamentListResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/ [get]

func (*Server) UserHandler

func (s *Server) UserHandler(c *gin.Context)

UserHandler godoc @Summary Returns data about the current user @Tags user @Accept json @Produce json @Success 200 {object} models.Person @Failure 400 {object} backend.AuthResponse @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /user/ [get]

func (*Server) UsurpTournamentHandler

func (s *Server) UsurpTournamentHandler(c *gin.Context)

UsurpTournamentHandler godoc @Summary Adds random players to a tournament @Description Default is to add 8. @Tags testing @Accept json @Produce json @Success 200 {object} backend.HTTPResponse @Failure 400 {object} backend.HTTPError @Failure 404 {object} backend.HTTPError @Failure 500 {object} backend.HTTPError @Router /tournaments/{id}/usurp/ [get]

type SettingsPostRequest

type SettingsPostRequest struct {
	Name       string `json:"name"`
	Nick       string `json:"nick"`
	Color      string `json:"color"`
	ArcherType int    `json:"archer_type"`
}

SettingsPostRequest is a settings update, or a new user register

type StartPlayResponse

type StartPlayResponse struct {
	Sent bool `json:"sent"`
}

StartPlayResponse tells whether a start_play messages were sent or not

type SummariesResponse

type SummariesResponse struct {
	Summaries []*models.Summary `json:"summaries"`
}

SummariesResponse is a list of Summary objects

type TournamentLeaderboardResponse

type TournamentLeaderboardResponse struct {
	Players []*models.TournamentLeaderboardPlayer `json:"players"`
}

TournamentLeaderboardResponse is a list TournamentLeaderboardPlayer objects

type TournamentListResponse

type TournamentListResponse struct {
	Tournaments []*models.Tournament `json:"tournaments"`
}

TournamentListResponse is a list of Tournament objects

type TournamentResponse

type TournamentResponse struct {
	Tournament      *models.Tournament      `json:"tournament"`
	Matches         []*models.Match         `json:"matches"`
	PlayerSummaries []*models.PlayerSummary `json:"player_summaries"`
	Runnerups       []*models.PlayerSummary `json:"runnerups"`
	PlayerStates    []*models.PlayerState   `json:"player_states"`
}

TournamentResponse represents a single tournament, with matches, summaries, runnerups and states attached.

Jump to

Keyboard shortcuts

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