diff --git a/CHANGELOG.md b/CHANGELOG.md index bdfa3a4..c2a0ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [v4.0.0-rc2] - Unreleased ### Fixed - Multiple bugs preventing production server from working properly +- CI builds should be working now +- Team registration now correctly writes names to files ## [v4.0-rc1] - 2020-10-13 ### Changed diff --git a/cmd/mothd/httpd.go b/cmd/mothd/httpd.go index 922f047..87f8acf 100644 --- a/cmd/mothd/httpd.go +++ b/cmd/mothd/httpd.go @@ -110,6 +110,12 @@ func (h *HTTPServer) StateHandler(mh MothRequestHandler, w http.ResponseWriter, // RegisterHandler handles attempts to register a team func (h *HTTPServer) RegisterHandler(mh MothRequestHandler, w http.ResponseWriter, req *http.Request) { teamName := req.FormValue("name") + teamName = strings.TrimSpace(teamName) + if teamName == "" { + jsend.Sendf(w, jsend.Fail, "empty name", "Team name may not be empty") + return + } + if err := mh.Register(teamName); err == ErrAlreadyRegistered { jsend.Sendf(w, jsend.Success, "already registered", "Team ID has already been registered") } else if err != nil { diff --git a/cmd/mothd/httpd_test.go b/cmd/mothd/httpd_test.go index 8c0b8b3..2ec8e25 100644 --- a/cmd/mothd/httpd_test.go +++ b/cmd/mothd/httpd_test.go @@ -66,7 +66,7 @@ func TestHttpd(t *testing.T) { t.Error("Register failed") } -thatt if r := hs.TestRequest("/register", map[string]string{"name": "GoTeam"}); r.Result().StatusCode != 200 { + if r := hs.TestRequest("/register", map[string]string{"name": "GoTeam"}); r.Result().StatusCode != 200 { t.Error(r.Result()) } else if r.Body.String() != `{"status":"success","data":{"short":"already registered","description":"Team ID has already been registered"}}` { t.Error("Register failed", r.Body.String()) diff --git a/cmd/mothd/state.go b/cmd/mothd/state.go index 0270bf9..ed10197 100644 --- a/cmd/mothd/state.go +++ b/cmd/mothd/state.go @@ -151,14 +151,16 @@ func (s *State) SetTeamName(teamID, teamName string) error { } teamFilename := filepath.Join("teams", teamID) - teamFile, err := s.Fs.OpenFile(teamFilename, os.O_CREATE|os.O_EXCL, 0644) + teamFile, err := s.Fs.OpenFile(teamFilename, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0644) if os.IsExist(err) { return ErrAlreadyRegistered } else if err != nil { return err } defer teamFile.Close() + log.Println("Setting team name to:", teamName, teamFilename, teamFile) fmt.Fprintln(teamFile, teamName) + teamFile.Close() return nil } diff --git a/cmd/mothd/state_test.go b/cmd/mothd/state_test.go index 7c6e156..2cbae4b 100644 --- a/cmd/mothd/state_test.go +++ b/cmd/mothd/state_test.go @@ -55,12 +55,18 @@ func TestState(t *testing.T) { t.Errorf("Setting bad team ID didn't raise an error") } - if err := s.SetTeamName(teamID, "My Team"); err != nil { - t.Errorf("Setting team name: %v", err) + teamName := "My Team" + if err := s.SetTeamName(teamID, teamName); err != nil { + t.Errorf("Setting team name: %w", err) } if err := s.SetTeamName(teamID, "wat"); err == nil { t.Errorf("Registering team a second time didn't fail") } + if name, err := s.TeamName(teamID); err != nil { + t.Error(err) + } else if name != teamName { + t.Error("Incorrect team name:", name) + } category := "poot" points := 3928 diff --git a/cmd/transpile/main.go b/cmd/transpile/main.go index 82f034b..e8f8331 100644 --- a/cmd/transpile/main.go +++ b/cmd/transpile/main.go @@ -147,9 +147,13 @@ func (t *T) DumpMothball() error { var w io.Writer c := transpile.NewFsCategory(t.fs, "") - if t.filename == "" { + + removeOnError := false + switch t.filename { + case "", "-": w = t.Stdout - } else { + default: + removeOnError = true log.Println("Writing mothball to", t.filename) outf, err := t.BaseFs.Create(t.filename) if err != nil { @@ -159,6 +163,9 @@ func (t *T) DumpMothball() error { w = outf } if err := transpile.Mothball(c, w); err != nil { + if removeOnError { + t.BaseFs.Remove(t.filename) + } return err } return nil diff --git a/theme/scoreboard.js b/theme/scoreboard.js index c5b64f1..104efcb 100644 --- a/theme/scoreboard.js +++ b/theme/scoreboard.js @@ -13,6 +13,8 @@ function scoreboardInit() { ] function update(state) { + window.state = state + for (let rotate of document.querySelectorAll(".rotate")) { rotate.appendChild(rotate.firstElementChild) }