shuffle
parent
ceeeb8fe4b
commit
39ab01525f
|
|
@ -151,43 +151,9 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
|
||||||
case "/gm/rpc/status":
|
case "/gm/rpc/status":
|
||||||
v01.serveGMStatus(w, r)
|
v01.serveGMStatus(w, r)
|
||||||
case "/gm/rpc/broadcastSomeoneSaidAlias":
|
case "/gm/rpc/broadcastSomeoneSaidAlias":
|
||||||
v01.cfg.Quiet = true
|
v01.serveGMSomeoneSaidAlias(w, r)
|
||||||
for k, v := range v01.cfg.Users {
|
|
||||||
v.Message = v.Alias
|
|
||||||
v.Alias = ""
|
|
||||||
v01.cfg.Users[k] = v
|
|
||||||
}
|
|
||||||
v01.servePutBroadcastValue(fmt.Sprintf("<<SOMEONE SAID %q>>", strings.ToUpper(r.URL.Query().Get("message"))))
|
|
||||||
case "/gm/rpc/fillNonPlayerAliases":
|
case "/gm/rpc/fillNonPlayerAliases":
|
||||||
b, _ := io.ReadAll(r.Body)
|
v01.serveGMFillNonPlayerAliases(w, r)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "/gm/rpc/vote":
|
case "/gm/rpc/vote":
|
||||||
panic("TODO stash user:votedForUser")
|
panic("TODO stash user:votedForUser")
|
||||||
case "/gm/rpc/elect":
|
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("<<SOMEONE SAID %q>>", 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) {
|
func (v01 *V01) serveGMShuffle(w http.ResponseWriter, 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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue