Send resigned player in win event

This commit is contained in:
Trevor Slocum 2024-11-18 01:14:17 -08:00
parent a318a6a901
commit 1188379900
4 changed files with 35 additions and 29 deletions

View file

@ -110,8 +110,9 @@ type EventFailedOk struct {
type EventWin struct {
Event
Points int8
Rating int
Points int8
Rating int
Resigned string
}
type EventSettings struct {

View file

@ -210,6 +210,9 @@ func (c *serverClient) sendEvent(e interface{}) {
case *bgammon.EventFailedOk:
c.Write([]byte(fmt.Sprintf("failedok %s", ev.Reason)))
case *bgammon.EventWin:
if ev.Resigned != "" {
c.Write([]byte(fmt.Sprintf(gotext.GetD(c.language, "%s resigned."), ev.Resigned)))
}
if ev.Points > 1 {
c.Write([]byte(fmt.Sprintf("win %s wins %d points!", ev.Player, ev.Points)))
} else {

View file

@ -710,17 +710,16 @@ func (g *serverGame) handleWin() bool {
log.Fatalf("failed to record game result: %s", err)
}
if !reset {
// Record match.
ratingDelta, err := recordMatchResult(g, matchTypeCasual)
if err != nil {
log.Fatalf("failed to record match result: %s", err)
}
winEvent.Rating = ratingDelta
} else {
if reset {
// Reset game and continue match.
g.Reset()
g.replay = g.replay[:0]
} else {
// Record match.
winEvent.Rating, err = recordMatchResult(g, matchTypeCasual)
if err != nil {
log.Fatalf("failed to record match result: %s", err)
}
}
// Refresh cached ratings.
@ -733,8 +732,8 @@ func (g *serverGame) handleWin() bool {
// Send board and win events.
g.eachClient(func(client *serverClient) {
g.sendBoard(client, false)
client.sendEvent(winEvent)
g.sendBoard(client, false)
})
return true
}

View file

@ -714,6 +714,7 @@ COMMANDS:
clientGame.Winner = opponent.playerNumber
clientGame.NextPartialTurn(opponent.playerNumber)
// TODO Remove when most users are running Boxcars v1.4.7+
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Declined double offer."))
clientGame.opponent(cmd.client).sendNotice(fmt.Sprintf(gotext.GetD(clientGame.opponent(cmd.client).language, "%s declined double offer."), cmd.client.name))
@ -725,6 +726,7 @@ COMMANDS:
clientGame.Winner = opponent.playerNumber
clientGame.NextPartialTurn(opponent.playerNumber)
// TODO Remove when most users are running Boxcars v1.4.7+
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Resigned."))
clientGame.opponent(cmd.client).sendNotice(fmt.Sprintf(gotext.GetD(clientGame.opponent(cmd.client).language, "%s resigned."), cmd.client.name))
@ -749,36 +751,37 @@ COMMANDS:
log.Fatalf("failed to record game result: %s", err)
}
if !reset {
ratingDelta, err := recordMatchResult(clientGame, matchTypeCasual)
if err != nil {
log.Fatalf("failed to record match result: %s", err)
}
winEvent = &bgammon.EventWin{
Rating: ratingDelta,
}
if clientGame.Points > 1 {
winEvent.Points = clientGame.DoubleValue
}
if clientGame.Winner == 1 {
winEvent.Player = clientGame.Player1.Name
} else {
winEvent.Player = clientGame.Player2.Name
}
winEvent = &bgammon.EventWin{}
if clientGame.Winner == 1 {
winEvent.Player = clientGame.Player1.Name
winEvent.Resigned = clientGame.Player2.Name
} else {
winEvent.Player = clientGame.Player2.Name
winEvent.Resigned = clientGame.Player1.Name
}
if clientGame.Points > 1 {
winEvent.Points = clientGame.DoubleValue
}
}
if reset {
// Reset game and continue match.
clientGame.Reset()
clientGame.replay = clientGame.replay[:0]
} else {
// Record match.
var err error
winEvent.Rating, err = recordMatchResult(clientGame, matchTypeCasual)
if err != nil {
log.Fatalf("failed to record match result: %s", err)
}
}
clientGame.eachClient(func(client *serverClient) {
clientGame.sendBoard(client, false)
if winEvent != nil {
client.sendEvent(winEvent)
}
clientGame.sendBoard(client, false)
})
case bgammon.CommandRoll, "r":
if clientGame == nil {