mirror of https://github.com/dirtbags/moth.git
I think we have a working server, folks
This commit is contained in:
parent
3eafa7a328
commit
c3cf75fc90
|
@ -45,6 +45,7 @@ type StateProvider interface {
|
|||
PointsLog() []*Award
|
||||
TeamName(teamId string) (string, error)
|
||||
SetTeamName(teamId, teamName string) error
|
||||
AwardPoints(teamId string, cat string, points int) error
|
||||
Component
|
||||
}
|
||||
|
||||
|
@ -82,19 +83,22 @@ type MothRequestHandler struct {
|
|||
}
|
||||
|
||||
func (mh *MothRequestHandler) PuzzlesOpen(cat string, points int, path string) (ReadSeekCloser, time.Time, error) {
|
||||
// XXX: Make sure this puzzle is unlocked
|
||||
export := mh.ExportAllState()
|
||||
fmt.Println(export.Puzzles)
|
||||
for _, p := range export.Puzzles[cat] {
|
||||
fmt.Println(points, p)
|
||||
if p == points {
|
||||
return mh.Puzzles.Open(cat, points, path)
|
||||
}
|
||||
}
|
||||
|
||||
return nil, time.Time{}, fmt.Errorf("Puzzle locked")
|
||||
}
|
||||
|
||||
func (mh *MothRequestHandler) ThemeOpen(path string) (ReadSeekCloser, time.Time, error) {
|
||||
return mh.Theme.Open(path)
|
||||
}
|
||||
|
||||
func (mh *MothRequestHandler) xxxTeamName() string {
|
||||
teamName, _ := mh.State.TeamName(mh.teamId)
|
||||
return teamName
|
||||
}
|
||||
|
||||
func (mh *MothRequestHandler) Register(teamName string) error {
|
||||
// XXX: Should we just return success if the team is already registered?
|
||||
// XXX: Should this function be renamed to Login?
|
||||
|
@ -105,10 +109,18 @@ func (mh *MothRequestHandler) Register(teamName string) error {
|
|||
}
|
||||
|
||||
func (mh *MothRequestHandler) CheckAnswer(cat string, points int, answer string) error {
|
||||
return mh.Puzzles.CheckAnswer(cat, points, answer)
|
||||
if err := mh.Puzzles.CheckAnswer(cat, points, answer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func (mh *MothRequestHandler) ExportState() *StateExport {
|
||||
if err := mh.State.AwardPoints(mh.teamId, cat, points); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mh *MothRequestHandler) ExportAllState() *StateExport {
|
||||
export := StateExport{}
|
||||
|
||||
teamName, _ := mh.State.TeamName(mh.teamId)
|
||||
|
@ -142,8 +154,6 @@ func (mh *MothRequestHandler) ExportState() *StateExport {
|
|||
|
||||
|
||||
export.Puzzles = make(map[string][]int)
|
||||
|
||||
//XXX: move to brains.go
|
||||
for _, category := range mh.Puzzles.Inventory() {
|
||||
// Append sentry (end of puzzles)
|
||||
allPuzzles := append(category.Puzzles, 0)
|
||||
|
@ -162,3 +172,17 @@ func (mh *MothRequestHandler) ExportState() *StateExport {
|
|||
|
||||
return &export
|
||||
}
|
||||
|
||||
func (mh *MothRequestHandler) ExportState() *StateExport {
|
||||
export := mh.ExportAllState()
|
||||
|
||||
// We don't give this out to just anybody,
|
||||
// because back when we did,
|
||||
// we got a bad reputation on some secretive blacklist,
|
||||
// and now the Navy can't register for events.
|
||||
if export.TeamNames["self"] == "" {
|
||||
export.Puzzles = map[string][]int{}
|
||||
}
|
||||
|
||||
return export
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ func (s *State) UpdateEnabled() {
|
|||
|
||||
// Returns team name given a team ID.
|
||||
func (s *State) TeamName(teamId string) (string, error) {
|
||||
// XXX: directory traversal
|
||||
teamFile := filepath.Join("teams", teamId)
|
||||
teamNameBytes, err := afero.ReadFile(s, teamFile)
|
||||
teamName := strings.TrimSpace(string(teamNameBytes))
|
||||
|
|
|
@ -144,7 +144,6 @@ function showPuzzles() {
|
|||
|
||||
document.getElementById("login").style.display = "none"
|
||||
document.getElementById("puzzles").appendChild(spinner)
|
||||
heartbeat()
|
||||
}
|
||||
|
||||
async function fetchAll(puzzles) {
|
||||
|
@ -191,6 +190,7 @@ function login(e) {
|
|||
sessionStorage.id = teamId
|
||||
sessionStorage.pid = participantId
|
||||
showPuzzles()
|
||||
heartbeat()
|
||||
} else {
|
||||
toast(obj.data.description)
|
||||
}
|
||||
|
@ -211,10 +211,6 @@ function login(e) {
|
|||
}
|
||||
|
||||
function init() {
|
||||
// Already signed in?
|
||||
if (sessionStorage.id) {
|
||||
showPuzzles()
|
||||
}
|
||||
heartbeat()
|
||||
setInterval(e => heartbeat(), 40000)
|
||||
|
||||
|
|
Loading…
Reference in New Issue