Send event when user fails to create a match

This commit is contained in:
Trevor Slocum 2024-11-18 16:34:40 -08:00
parent 1188379900
commit 1ea81e7242
6 changed files with 64 additions and 42 deletions

View file

@ -197,6 +197,9 @@ This document lists events in human-readable format.
- `listend End of matches list.`
- End of matches list.
- `failedcreate <message:line>`
- Sent after failing to create a match.
- `joined <id:integer> <playerNumber:integer> <playerName:text>`
- Sent after successfully creating or joining a match, and when another player
joins a match you are in.

View file

@ -43,26 +43,27 @@ const (
type EventType string
const (
EventTypeWelcome = "welcome"
EventTypeHelp = "help"
EventTypePing = "ping"
EventTypeNotice = "notice"
EventTypeSay = "say"
EventTypeList = "list"
EventTypeJoined = "joined"
EventTypeFailedJoin = "failedjoin"
EventTypeLeft = "left"
EventTypeFailedLeave = "failedleave"
EventTypeBoard = "board"
EventTypeRolled = "rolled"
EventTypeFailedRoll = "failedroll"
EventTypeMoved = "moved"
EventTypeFailedMove = "failedmove"
EventTypeFailedOk = "failedok"
EventTypeWin = "win"
EventTypeSettings = "settings"
EventTypeReplay = "replay"
EventTypeHistory = "history"
EventTypeWelcome = "welcome"
EventTypeHelp = "help"
EventTypePing = "ping"
EventTypeNotice = "notice"
EventTypeSay = "say"
EventTypeList = "list"
EventTypeFailedCreate = "failedcreate"
EventTypeJoined = "joined"
EventTypeFailedJoin = "failedjoin"
EventTypeLeft = "left"
EventTypeFailedLeave = "failedleave"
EventTypeBoard = "board"
EventTypeRolled = "rolled"
EventTypeFailedRoll = "failedroll"
EventTypeMoved = "moved"
EventTypeFailedMove = "failedmove"
EventTypeFailedOk = "failedok"
EventTypeWin = "win"
EventTypeSettings = "settings"
EventTypeReplay = "replay"
EventTypeHistory = "history"
)
var HelpText = map[string]string{

View file

@ -53,6 +53,11 @@ type EventList struct {
Games []GameListing
}
type EventFailedCreate struct {
Event
Reason string
}
type EventJoined struct {
Event
GameID int
@ -178,6 +183,8 @@ func DecodeEvent(message []byte) (interface{}, error) {
ev = &EventSay{}
case EventTypeList:
ev = &EventList{}
case EventTypeFailedCreate:
ev = &EventFailedCreate{}
case EventTypeJoined:
ev = &EventJoined{}
case EventTypeFailedJoin:

View file

@ -108,6 +108,8 @@ func (c *serverClient) sendEvent(e interface{}) {
ev.Type = bgammon.EventTypeSay
case *bgammon.EventList:
ev.Type = bgammon.EventTypeList
case *bgammon.EventFailedCreate:
ev.Type = bgammon.EventTypeFailedCreate
case *bgammon.EventJoined:
ev.Type = bgammon.EventTypeJoined
case *bgammon.EventFailedJoin:
@ -189,6 +191,8 @@ func (c *serverClient) sendEvent(e interface{}) {
c.Write([]byte(fmt.Sprintf("game %d %d %d %d %s", g.ID, password, g.Points, g.Players, name)))
}
c.Write([]byte("listend End of matches list."))
case *bgammon.EventFailedCreate:
c.Write([]byte(fmt.Sprintf("failedcreate %s", ev.Reason)))
case *bgammon.EventJoined:
c.Write([]byte(fmt.Sprintf("joined %d %d %s", ev.GameID, ev.PlayerNumber, ev.Player)))
case *bgammon.EventFailedJoin:

View file

@ -76,10 +76,13 @@ msgstr ""
msgid "Failed to change password: you are logged in as a guest."
msgstr ""
msgid "Failed to create match: Please leave the match you are in before creating another."
msgid "Failed to create match: %s"
msgstr ""
msgid "Failed to create match: The server is shutting down. Reason: %s"
msgid "Please leave the match you are in before creating another."
msgstr ""
msgid "The server is shutting down. Reason: %s"
msgstr ""
msgid "Failed to log in: %s"

View file

@ -432,24 +432,28 @@ COMMANDS:
case bgammon.CommandList, "ls":
s.sendMatchList(cmd.client)
case bgammon.CommandCreate, "c":
failCreate := func(message string) {
cmd.client.sendEvent(&bgammon.EventFailedCreate{
Reason: message,
})
// TODO Remove when most users are running Boxcars v1.4.7+
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Failed to create match: %s", message))
}
sendUsage := func() {
failCreate("To create a public match please specify whether it is public or private, and also specify how many points are needed to win the match. When creating a private match, a password must also be provided.")
}
if clientGame != nil {
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Failed to create match: Please leave the match you are in before creating another."))
failCreate(gotext.GetD(cmd.client.language, "Please leave the match you are in before creating another."))
continue
} else if !s.shutdownTime.IsZero() {
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Failed to create match: The server is shutting down. Reason: %s", s.shutdownReason))
failCreate(gotext.GetD(cmd.client.language, "The server is shutting down. Reason: %s", s.shutdownReason))
continue
}
sendUsage := func() {
cmd.client.sendNotice("To create a public match please specify whether it is public or private, and also specify how many points are needed to win the match. When creating a private match, a password must also be provided.")
}
if len(params) < 2 {
} else if len(params) < 2 {
sendUsage()
continue
}
if s.defcon < 3 && cmd.client.accountID == 0 {
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Due to ongoing abuse, some actions are restricted to registered users only. Please log in or register to avoid interruptions."))
} else if s.defcon < 3 && cmd.client.accountID == 0 {
failCreate(gotext.GetD(cmd.client.language, "Due to ongoing abuse, some actions are restricted to registered users only. Please log in or register to avoid interruptions."))
continue
}
@ -714,7 +718,7 @@ COMMANDS:
clientGame.Winner = opponent.playerNumber
clientGame.NextPartialTurn(opponent.playerNumber)
// TODO Remove when most users are running Boxcars v1.4.7+
// TODO Remove when most users are running Boxcars v1.4.6+
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))
@ -726,7 +730,7 @@ COMMANDS:
clientGame.Winner = opponent.playerNumber
clientGame.NextPartialTurn(opponent.playerNumber)
// TODO Remove when most users are running Boxcars v1.4.7+
// TODO Remove when most users are running Boxcars v1.4.6+
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))
@ -1169,7 +1173,7 @@ COMMANDS:
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Your opponent left the match."))
continue
} else if !s.shutdownTime.IsZero() {
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Failed to create match: The server is shutting down. Reason: %s", s.shutdownReason))
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Failed to create match: %s", gotext.GetD(cmd.client.language, "The server is shutting down. Reason: %s", s.shutdownReason)))
continue
} else if clientGame.rematch != 0 && clientGame.rematch != cmd.client.playerNumber {
s.gamesLock.Lock()
@ -1680,13 +1684,13 @@ COMMANDS:
}
clientGame.Turn = 1
clientGame.Roll1 = 1
clientGame.Roll2 = 2
clientGame.Roll1 = 5
clientGame.Roll2 = 5
clientGame.Roll3 = 0
clientGame.Variant = 1
clientGame.Player1.Entered = true
clientGame.Variant = bgammon.VariantAceyDeucey
clientGame.Player1.Entered = false
clientGame.Player2.Entered = true
clientGame.Board = []int8{0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, -3, 0, 0, -3, -6, -2, 0, 0, 0}
clientGame.Board = []int8{1, 2, 1, 3, 2, 2, 2, 0, 0, 0, -3, -7, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -3, 0, 0, -2}
log.Println(clientGame.Board[0:28])