diff --git a/cmd/mothd/state.go b/cmd/mothd/state.go index b0e4726..c5d8f47 100644 --- a/cmd/mothd/state.go +++ b/cmd/mothd/state.go @@ -438,6 +438,10 @@ type DevelState struct { // NewDevelState returns a new state object that can be used by the development server. // +// The main thing this provides is the ability to register a team with any team ID. +// If a team ID is provided that wasn't recognized by the underlying StateProvider, +// it is associated with a team named "". +// // This makes it possible to use the server without having to register a team. func NewDevelState(sp StateProvider) *DevelState { return &DevelState{sp} @@ -446,10 +450,22 @@ func NewDevelState(sp StateProvider) *DevelState { // TeamName returns a valid team name for any teamID // // If one's registered, it will use it. -// Otherwise, it returns sprintf("Devel Server Team %s", teamID) +// Otherwise, it returns "" func (ds *DevelState) TeamName(teamID string) (string, error) { if name, err := ds.StateProvider.TeamName(teamID); err == nil { return name, nil } return fmt.Sprintf("«devel:%s»", teamID), nil } + +// SetTeamName associates a team name with any teamID +// +// If the underlying StateProvider returns any sort of error, +// this returns ErrAlreadyRegistered, +// so the user can join a pre-existing team for whatever ID the provide. +func (ds *DevelState) SetTeamName(teamID, teamName string) error { + if err := ds.StateProvider.SetTeamName(teamID, teamName); err != nil { + return ErrAlreadyRegistered + } + return nil +} diff --git a/cmd/mothd/state_test.go b/cmd/mothd/state_test.go index 1d88953..5b890a7 100644 --- a/cmd/mothd/state_test.go +++ b/cmd/mothd/state_test.go @@ -269,6 +269,11 @@ func TestStateMaintainer(t *testing.T) { func TestDevelState(t *testing.T) { s := NewTestState() ds := NewDevelState(s) + if err := ds.SetTeamName("boog", "The Boog Team"); err != ErrAlreadyRegistered { + t.Error("Registering a team that doesn't exist", err) + } else if err == nil { + t.Error("Registering a team that doesn't exist didn't return ErrAlreadyRegistered") + } if n, err := ds.TeamName("boog"); err != nil { t.Error("Devel State returned error on team name lookup") } else if n != "«devel:boog»" {