diff --git a/src/device/input/parse/v01/server.go b/src/device/input/parse/v01/server.go index 30b0312..4c110c2 100644 --- a/src/device/input/parse/v01/server.go +++ b/src/device/input/parse/v01/server.go @@ -159,7 +159,31 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) { } v01.servePutBroadcastValue(fmt.Sprintf("<>", strings.ToUpper(r.URL.Query().Get("message")))) case "/gm/rpc/fillNonPlayerAliases": - panic("TODO stash aliases") + b, _ := io.ReadAll(r.Body) + var pool []string + yaml.Unmarshal(b, &pool) + n := 0 + for _, v := range v01.cfg.Users { + if v.Player == 0 { + n += 1 + } + } + if len(b) < n { + http.Error(w, fmt.Sprintf("request body must contain a list of %v options", n), http.StatusBadRequest) + return + } + for i := 0; i < 100; i++ { + a, b := rand.Int()%len(pool), rand.Int()%len(pool) + pool[a], pool[b] = pool[b], pool[a] + } + i := 0 + for k, v := range v01.cfg.Users { + if v.Player == 0 { + v.Alias = pool[i] + v01.cfg.Users[k] = v + i += 1 + } + } case "/gm/rpc/vote": panic("TODO stash user:votedForUser") case "/gm/rpc/elect": diff --git a/src/device/input/parse/v01/server_test.go b/src/device/input/parse/v01/server_test.go index b564749..5e0776f 100644 --- a/src/device/input/parse/v01/server_test.go +++ b/src/device/input/parse/v01/server_test.go @@ -194,7 +194,24 @@ func TestServeGM(t *testing.T) { }) t.Run("fillNonPlayerAliases", func(t *testing.T) { - t.Error("not impl") + t.Run("happy", func(t *testing.T) { + v01 := NewV01(ctx, nil) + v01.cfg.Users = map[string]configUser{ + "bel": configUser{Player: 1}, + "zach": configUser{Player: 0}, + } + do(v01, "/gm/rpc/fillNonPlayerAliases", "[qt]") + if v := v01.cfg.Users["bel"]; v.Alias != "" { + t.Error(v.Alias) + } else if v.Player != 1 { + t.Error(v.Player) + } + if v := v01.cfg.Users["zach"]; v.Alias != "qt" { + t.Error(v.Alias) + } else if v.Player != 0 { + t.Error(v.Player) + } + }) }) t.Run("vote", func(t *testing.T) {