broadcast isnt a user

master v0.1.10
bel 2023-04-01 11:31:03 -06:00
parent 9de8c91544
commit 3c70e42819
5 changed files with 29 additions and 26 deletions

View File

@ -9,11 +9,16 @@ import (
type ( type (
config struct { config struct {
lock *sync.Mutex lock *sync.Mutex
Feedback configFeedback Feedback configFeedback
Users map[string]configUser Users map[string]configUser
Players []configPlayer Players []configPlayer
Quiet bool Quiet bool
Broadcast configBroadcast
}
configBroadcast struct {
Message string
} }
configFeedback struct { configFeedback struct {

View File

@ -79,7 +79,8 @@ func (v01 *V01) serveHTTP(w http.ResponseWriter, r *http.Request) {
func (v01 *V01) getUserFeedback(w http.ResponseWriter, r *http.Request) { func (v01 *V01) getUserFeedback(w http.ResponseWriter, r *http.Request) {
user, ok := v01.cfg.Users[r.URL.Query().Get("user")] user, ok := v01.cfg.Users[r.URL.Query().Get("user")]
if !ok { if !ok {
user = v01.cfg.Users["broadcast"] w.Write([]byte(v01.cfg.Broadcast.Message))
return
} }
w.Write([]byte(user.State.Message)) w.Write([]byte(user.State.Message))
} }
@ -90,9 +91,7 @@ func (v01 *V01) servePutBroadcast(w http.ResponseWriter, r *http.Request) {
} }
func (v01 *V01) servePutBroadcastValue(v string) { func (v01 *V01) servePutBroadcastValue(v string) {
u := v01.cfg.Users["broadcast"] v01.cfg.Broadcast.Message = v
u.State.Message = v
v01.cfg.Users["broadcast"] = u
} }
func (v01 *V01) serveConfig(w http.ResponseWriter, r *http.Request) { func (v01 *V01) serveConfig(w http.ResponseWriter, r *http.Request) {

View File

@ -183,10 +183,8 @@ func TestServeGM(t *testing.T) {
}, },
Message: "if someone else says 'driver', then you get to play", Message: "if someone else says 'driver', then you get to play",
}}, }},
"broadcast": configUser{State: configUserState{
Message: ":)",
}},
} }
v01.cfg.Broadcast.Message = ":)"
do(v01, "/gm/rpc/broadcastSomeoneSaidAlias", "") do(v01, "/gm/rpc/broadcastSomeoneSaidAlias", "")
if !v01.cfg.Quiet { if !v01.cfg.Quiet {
t.Error(v01.cfg.Quiet) t.Error(v01.cfg.Quiet)
@ -196,7 +194,7 @@ func TestServeGM(t *testing.T) {
} else if v.State.GM.LastAlias != "driver" { } else if v.State.GM.LastAlias != "driver" {
t.Error(v.State.GM.LastAlias) t.Error(v.State.GM.LastAlias)
} }
if bc := v01.cfg.Users["broadcast"]; bc.State.Message == ":)" { if bc := v01.cfg.Broadcast.Message; bc == ":)" {
t.Error(bc) t.Error(bc)
} }
}) })
@ -342,8 +340,8 @@ func TestServeGM(t *testing.T) {
} else if v01.cfg.Users["zach"].State.Player != 1 { } else if v01.cfg.Users["zach"].State.Player != 1 {
t.Error(v01.cfg.Users["zach"].State.Player) t.Error(v01.cfg.Users["zach"].State.Player)
} }
if v01.cfg.Users["broadcast"].State.Message != `bel is now player 0 and zach is now player 1` { if v01.cfg.Broadcast.Message != `bel is now player 0 and zach is now player 1` {
t.Error(v01.cfg.Users["broadcast"].State.Message) t.Error(v01.cfg.Broadcast)
} }
}) })
@ -367,8 +365,8 @@ func TestServeGM(t *testing.T) {
} else if result["zach"] != 1 { } else if result["zach"] != 1 {
t.Error(result) t.Error(result)
} }
if !strings.HasSuffix(v01.cfg.Users["broadcast"].State.Message, `is now player 1`) || strings.Contains(v01.cfg.Users["broadcast"].State.Message, ",") { if !strings.HasSuffix(v01.cfg.Broadcast.Message, `is now player 1`) || strings.Contains(v01.cfg.Broadcast.Message, ",") {
t.Error(v01.cfg.Users["broadcast"].State.Message) t.Error(v01.cfg.Broadcast.Message)
} }
assignments := map[int]int{} assignments := map[int]int{}
for _, v := range v01.cfg.Users { for _, v := range v01.cfg.Users {
@ -376,7 +374,7 @@ func TestServeGM(t *testing.T) {
} }
if len(assignments) != 2 { if len(assignments) != 2 {
t.Error(assignments) t.Error(assignments)
} else if assignments[0] != 3 { } else if assignments[0] != 2 {
t.Error(assignments[0]) t.Error(assignments[0])
} else if assignments[1] != 1 { } else if assignments[1] != 1 {
t.Error(assignments[1]) t.Error(assignments[1])
@ -402,8 +400,8 @@ func TestServeGM(t *testing.T) {
} else if result["zach"] != 1 { } else if result["zach"] != 1 {
t.Error(result) t.Error(result)
} }
if !strings.HasSuffix(v01.cfg.Users["broadcast"].State.Message, `is now player 1`) || strings.Contains(v01.cfg.Users["broadcast"].State.Message, ",") { if bc := v01.cfg.Broadcast.Message; !strings.HasSuffix(bc, `is now player 1`) || strings.Contains(bc, ",") {
t.Error(v01.cfg.Users["broadcast"].State.Message) t.Error(bc)
} }
assignments := map[int]int{} assignments := map[int]int{}
for _, v := range v01.cfg.Users { for _, v := range v01.cfg.Users {
@ -411,7 +409,7 @@ func TestServeGM(t *testing.T) {
} }
if len(assignments) != 2 { if len(assignments) != 2 {
t.Error(assignments) t.Error(assignments)
} else if assignments[0] != 2 { } else if assignments[0] != 1 {
t.Error(assignments[0]) t.Error(assignments[0])
} else if assignments[1] != 1 { } else if assignments[1] != 1 {
t.Error(assignments[1]) t.Error(assignments[1])
@ -433,7 +431,7 @@ func TestServeGM(t *testing.T) {
if v01.cfg.Quiet { if v01.cfg.Quiet {
t.Error(v01.cfg.Quiet) t.Error(v01.cfg.Quiet)
} }
if len(v01.cfg.Users) != 3 { if len(v01.cfg.Users) != 2 {
t.Error(v01.cfg.Users) t.Error(v01.cfg.Users)
} else if len(v01.cfg.Players) != 2 { } else if len(v01.cfg.Players) != 2 {
t.Error(v01.cfg.Users) t.Error(v01.cfg.Users)
@ -482,7 +480,7 @@ func TestServeGM(t *testing.T) {
t.Error(v01.cfg.Quiet) t.Error(v01.cfg.Quiet)
} }
if len(v01.cfg.Users) != c.users+1 { if len(v01.cfg.Users) != c.users {
t.Error(v01.cfg.Users) t.Error(v01.cfg.Users)
} else if len(v01.cfg.Players) != c.players { } else if len(v01.cfg.Players) != c.players {
t.Error(v01.cfg.Users) t.Error(v01.cfg.Users)

View File

@ -1,6 +1,8 @@
feedback: feedback:
addr: :17071 addr: :17071
ttsurl: http://localhost:15002 ttsurl: http://localhost:15002
broadcast:
message: hi
users: users:
bel: bel:
state: state:

View File

@ -91,9 +91,8 @@ func TestV01Feedback(t *testing.T) {
state: state:
player: 2 player: 2
message: to bel message: to bel
broadcast: broadcast:
state: message: to everyone
message: to everyone
players: players:
- transformation: - transformation:
w: t w: t