From 7fc2eec35f011c6fa1dd1932621b596efbe47d45 Mon Sep 17 00:00:00 2001 From: Donaldson Date: Thu, 30 Dec 2021 12:17:17 -0800 Subject: [PATCH] * Add message write handler * Add stub documentation for new required functions --- cmd/mothd/server.go | 31 ++++++++++++++++++++++++++----- cmd/mothd/state_filesystem.go | 12 ++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cmd/mothd/server.go b/cmd/mothd/server.go index 608e6d6..aec758f 100644 --- a/cmd/mothd/server.go +++ b/cmd/mothd/server.go @@ -53,11 +53,32 @@ type ThemeProvider interface { // StateProvider defines what's required to provide MOTH state. type StateProvider interface { - Messages() string - PointsLog() award.List - TeamName(teamID string) (string, error) - SetTeamName(teamID, teamName string) error - AwardPoints(teamID string, cat string, points int) error + Messages() string // GET /admin/state/messages + SetMessages(string) error // POST /admin/state/messages + + PointsLog() award.List // GET /admin/state/points + AwardPoints(teamID string, cat string, points int) error // POST /admin/state/points + // AwardPoints(teamID string, cat string, points int, when int64) error // POST /admin/state/points + // Points(teamID string, cat string, points int) bool // Check if point entry exists // HEAD /admin/state/points/// + // Points(teamID string, cat string, points int, when int64) bool // Check if point entry exists // HEAD /admin/state/points//// + // RemovePoints(teamID string, cat string, points int) error // DELETE /admin/state/points/// + // RemovePoints(teamID string, cat string, points int, when int64) error // DELETE /admin/state/points//// + // SetPoints(award.List) error // PUT /admin/state/points + + + // TeamIDs() []string // GET /admin/state/team_ids + // SetTeamIDs([] string) error // PUT /admin/state/team_ids + // AddTeamID(teamID string) error // POST /admin/state/team_ids/ + // RemoveTeamID(teamID string) error // DELETE /admin/state/team_ids/ + // TeamID(teamID string) bool // HEAD /admin/state/team_ids/ + + // TeamNames() (map[string]string, error) // GET /admin/state/teams + // SetTeamNames(map[string]string) error // PUT /admin/state/teams + TeamName(teamID string) (string, error) // GET /admin/state/teams/id/ + // TeamIDFromName(teamName string) (string, error) // GET /admin/state/teams/name/ + SetTeamName(teamID, teamName string) error // POST /admin/state/teams/id// + // DeleteTeamName(teamID string) error // DELETE /admin/state/teams/id/, /admin/state/teams/name/ + LogEvent(event, participantID, teamID, cat string, points int, extra ...string) Maintainer } diff --git a/cmd/mothd/state_filesystem.go b/cmd/mothd/state_filesystem.go index 9d11621..0130452 100644 --- a/cmd/mothd/state_filesystem.go +++ b/cmd/mothd/state_filesystem.go @@ -191,6 +191,18 @@ func (s *State) Messages() string { return s.messages } +// SetMessages sets the current message +func (s *State) SetMessages(message string) error { + s.lock.Lock() + defer s.lock.Unlock() + + err := afero.WriteFile(s, "messages.html", []byte(message), 0600) + + s.refreshNow <- true + + return err +} + // AwardPoints gives points to teamID in category. // This doesn't attempt to ensure the teamID has been registered. // It first checks to make sure these are not duplicate points.