verbose user feedback
parent
342e2eef93
commit
0903c01b9a
|
|
@ -92,7 +92,13 @@ func (v01 *V01) getUserFeedback(w http.ResponseWriter, r *http.Request) {
|
||||||
msg = fmt.Sprintf("%s (Your secret word is '%s'. Make **someone else** say it!)", msg, alias)
|
msg = fmt.Sprintf("%s (Your secret word is '%s'. Make **someone else** say it!)", msg, alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte(msg))
|
w.Write([]byte(msg + "\n\n"))
|
||||||
|
v01.serveGMStatus(w)
|
||||||
|
|
||||||
|
if v01.cfg.Quiet {
|
||||||
|
w.Write([]byte("\n\n"))
|
||||||
|
v01.serveGMVoteRead(w)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v01 *V01) servePutBroadcast(w http.ResponseWriter, r *http.Request) {
|
func (v01 *V01) servePutBroadcast(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -170,7 +176,7 @@ func (v01 *V01) serveGlobalQueryRefresh(r *http.Request) {
|
||||||
func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
|
func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/gm/rpc/status":
|
case "/gm/rpc/status":
|
||||||
v01.serveGMStatus(w, r)
|
v01.serveGMStatus(w)
|
||||||
case "/gm/rpc/broadcastSomeoneSaidAlias":
|
case "/gm/rpc/broadcastSomeoneSaidAlias":
|
||||||
v01.serveGMSomeoneSaidAlias(w, r)
|
v01.serveGMSomeoneSaidAlias(w, r)
|
||||||
case "/gm/rpc/fillNonPlayerAliases":
|
case "/gm/rpc/fillNonPlayerAliases":
|
||||||
|
|
@ -192,7 +198,7 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) {
|
func (v01 *V01) serveGMStatus(w io.Writer) {
|
||||||
users := map[string]struct {
|
users := map[string]struct {
|
||||||
Lag time.Duration `yaml:"lag,omitempty"`
|
Lag time.Duration `yaml:"lag,omitempty"`
|
||||||
Player int `yaml:"player,omitempty"`
|
Player int `yaml:"player,omitempty"`
|
||||||
|
|
@ -291,28 +297,36 @@ func (v01 *V01) serveGMElect(w http.ResponseWriter, r *http.Request) {
|
||||||
func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
|
func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.URL.Query().Get("payload") {
|
switch r.URL.Query().Get("payload") {
|
||||||
case "":
|
case "":
|
||||||
counts := map[string]string{}
|
v01.serveGMVoteRead(w)
|
||||||
for k, v := range v01.cfg.Users {
|
|
||||||
if v.State.GM.Vote != "" {
|
|
||||||
counts[k] = "voted"
|
|
||||||
} else {
|
|
||||||
counts[k] = "voting"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
yaml.NewEncoder(w).Encode(counts)
|
|
||||||
default:
|
default:
|
||||||
voter := r.URL.Query().Get("user")
|
v01.serveGMVoteWrite(w, r)
|
||||||
candidate := r.URL.Query().Get("payload")
|
|
||||||
v, ok := v01.cfg.Users[voter]
|
|
||||||
if _, ok2 := v01.cfg.Users[candidate]; !ok || !ok2 {
|
|
||||||
http.Error(w, "bad voter/candidate", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
v.State.GM.Vote = candidate
|
|
||||||
v01.cfg.Users[voter] = v
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v01 *V01) serveGMVoteRead(w io.Writer) {
|
||||||
|
counts := map[string]string{}
|
||||||
|
for k, v := range v01.cfg.Users {
|
||||||
|
if v.State.GM.Vote != "" {
|
||||||
|
counts[k] = "voted"
|
||||||
|
} else {
|
||||||
|
counts[k] = "voting"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
yaml.NewEncoder(w).Encode(counts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v01 *V01) serveGMVoteWrite(w http.ResponseWriter, r *http.Request) {
|
||||||
|
voter := r.URL.Query().Get("user")
|
||||||
|
candidate := r.URL.Query().Get("payload")
|
||||||
|
v, ok := v01.cfg.Users[voter]
|
||||||
|
if _, ok2 := v01.cfg.Users[candidate]; !ok || !ok2 {
|
||||||
|
http.Error(w, "bad voter/candidate", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v.State.GM.Vote = candidate
|
||||||
|
v01.cfg.Users[voter] = v
|
||||||
|
}
|
||||||
|
|
||||||
func (v01 *V01) serveGMShuffle(r *http.Request) {
|
func (v01 *V01) serveGMShuffle(r *http.Request) {
|
||||||
poolSize := len(v01.cfg.Users)
|
poolSize := len(v01.cfg.Users)
|
||||||
if altSize := len(v01.cfg.Players); altSize > poolSize {
|
if altSize := len(v01.cfg.Players); altSize > poolSize {
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,8 @@ func TestV01Feedback(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
if string(b) != "to bel" {
|
if !strings.HasPrefix(string(b), "to bel") {
|
||||||
t.Error(b)
|
t.Error(string(b))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -135,8 +135,8 @@ func TestV01Feedback(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
if string(b) != "to everyone" {
|
if !strings.HasPrefix(string(b), "to everyone") {
|
||||||
t.Error(b)
|
t.Error(string(b))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -155,7 +155,7 @@ func TestV01Feedback(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
if string(b) != want {
|
if !strings.HasPrefix(string(b), want) {
|
||||||
t.Error(string(b))
|
t.Error(string(b))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue