diff --git a/src/device/input/parse/v01/server.go b/src/device/input/parse/v01/server.go index 6793073..f4a2b89 100644 --- a/src/device/input/parse/v01/server.go +++ b/src/device/input/parse/v01/server.go @@ -151,43 +151,9 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) { case "/gm/rpc/status": v01.serveGMStatus(w, r) case "/gm/rpc/broadcastSomeoneSaidAlias": - v01.cfg.Quiet = true - for k, v := range v01.cfg.Users { - v.Message = v.Alias - v.Alias = "" - v01.cfg.Users[k] = v - } - v01.servePutBroadcastValue(fmt.Sprintf("<>", strings.ToUpper(r.URL.Query().Get("message")))) + v01.serveGMSomeoneSaidAlias(w, r) case "/gm/rpc/fillNonPlayerAliases": - 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 n < 1 { - w.WriteHeader(http.StatusNoContent) - return - } - if len(pool) < 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 - } - } + v01.serveGMFillNonPlayerAliases(w, r) case "/gm/rpc/vote": panic("TODO stash user:votedForUser") case "/gm/rpc/elect": @@ -227,6 +193,48 @@ func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) { }) } +func (v01 *V01) serveGMSomeoneSaidAlias(w http.ResponseWriter, r *http.Request) { + v01.cfg.Quiet = true + for k, v := range v01.cfg.Users { + v.Message = v.Alias + v.Alias = "" + v01.cfg.Users[k] = v + } + v01.servePutBroadcastValue(fmt.Sprintf("<>", strings.ToUpper(r.URL.Query().Get("message")))) +} + +func (v01 *V01) serveGMFillNonPlayerAliases(w http.ResponseWriter, r *http.Request) { + 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 n < 1 { + w.WriteHeader(http.StatusNoContent) + return + } + if len(pool) < 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 + } + } +} + func (v01 *V01) serveGMShuffle(w http.ResponseWriter, r *http.Request) { poolSize := len(v01.cfg.Users) if altSize := len(v01.cfg.Players); altSize > poolSize {