Send join and leave events to spectators
This commit is contained in:
parent
e8fb2fd4d2
commit
667d0e9ba0
1 changed files with 27 additions and 10 deletions
|
@ -195,20 +195,18 @@ func (g *serverGame) addClient(client *serverClient) (spectator bool) {
|
|||
|
||||
var playerNumber int
|
||||
defer func() {
|
||||
ev := &bgammon.EventJoined{
|
||||
GameID: g.id,
|
||||
PlayerNumber: 1,
|
||||
}
|
||||
ev.Player = string(client.name)
|
||||
client.sendEvent(ev)
|
||||
g.sendBoard(client)
|
||||
|
||||
if playerNumber == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
{
|
||||
ev := &bgammon.EventJoined{
|
||||
GameID: g.id,
|
||||
PlayerNumber: 1,
|
||||
}
|
||||
ev.Player = string(client.name)
|
||||
client.sendEvent(ev)
|
||||
g.sendBoard(client)
|
||||
}
|
||||
|
||||
opponent := g.opponent(client)
|
||||
if opponent != nil {
|
||||
ev := &bgammon.EventJoined{
|
||||
|
@ -220,6 +218,18 @@ func (g *serverGame) addClient(client *serverClient) (spectator bool) {
|
|||
g.sendBoard(opponent)
|
||||
}
|
||||
|
||||
{
|
||||
ev := &bgammon.EventJoined{
|
||||
GameID: g.id,
|
||||
PlayerNumber: client.playerNumber,
|
||||
}
|
||||
ev.Player = string(client.name)
|
||||
for _, spectator := range g.spectators {
|
||||
spectator.sendEvent(ev)
|
||||
g.sendBoard(spectator)
|
||||
}
|
||||
}
|
||||
|
||||
if playerNumber == 1 {
|
||||
g.rejoin1 = true
|
||||
} else {
|
||||
|
@ -281,6 +291,13 @@ func (g *serverGame) removeClient(client *serverClient) {
|
|||
}
|
||||
}
|
||||
|
||||
for _, spectator := range g.spectators {
|
||||
spectator.sendEvent(ev)
|
||||
if !spectator.json {
|
||||
g.sendBoard(spectator)
|
||||
}
|
||||
}
|
||||
|
||||
client.playerNumber = 0
|
||||
}()
|
||||
switch {
|
||||
|
|
Loading…
Reference in a new issue