Fix joining match

This commit is contained in:
Trevor Slocum 2023-09-30 13:50:31 -07:00
parent cc53c885e7
commit db3870b9fe
2 changed files with 16 additions and 8 deletions

View file

@ -372,8 +372,10 @@ COMMANDS:
rejoin = g.rejoin2
}
if rejoin {
g.addClient(cmd.client)
cmd.client.sendNotice(fmt.Sprintf("Rejoined match: %s", g.name))
ok, _ := g.addClient(cmd.client)
if ok {
cmd.client.sendNotice(fmt.Sprintf("Rejoined match: %s", g.name))
}
}
}
s.gamesLock.RUnlock()
@ -567,15 +569,16 @@ COMMANDS:
s.gamesLock.Unlock()
continue COMMANDS
}
ok, reason := g.addClient(cmd.client)
s.gamesLock.Unlock()
if !ok {
cmd.client.sendEvent(&bgammon.EventFailedJoin{
Reason: reason,
})
} else {
cmd.client.sendNotice(fmt.Sprintf("Joined match: %s", g.name))
}
s.gamesLock.Unlock()
cmd.client.sendNotice(fmt.Sprintf("Joined match: %s", g.name))
continue COMMANDS
}
}

11
game.go
View file

@ -137,6 +137,12 @@ func (g *Game) addMove(move []int) bool {
return true
}
// AddLocalMove adds a move without performing any validation. This is useful when
// adding a move locally while waiting for an EventBoard response from the server.
func (g *Game) AddLocalMove(move []int) bool {
return g.addMove(move)
}
func (g *Game) ExpandMove(move []int, currentSpace int, moves [][]int) ([][]int, bool) {
l := g.LegalMoves()
var hitMoves [][]int
@ -301,7 +307,6 @@ func (g *Game) LegalMoves() [][]int {
}
haveDiceRoll := func(from, to int) int {
// TODO diff needs to account for bar and home special spaces
diff := SpaceDiff(from, to)
var c int
for _, roll := range rolls {
@ -412,11 +417,11 @@ func (g *Game) LegalMoves() [][]int {
}
// Move normally.
lastSpace := 1
dir := -1
lastSpace := 1
if g.Turn == 2 {
lastSpace = 24
dir = 1
lastSpace = 24
}
g.iterateSpaces(space+dir, lastSpace, func(to int, spaceCount int) {