Update EventLeft

This commit is contained in:
Trevor Slocum 2023-09-11 19:59:31 -07:00
parent 522bec484d
commit f63bd90964
4 changed files with 25 additions and 30 deletions

View file

@ -14,8 +14,8 @@ All commands and events are separated by newlines.
- `login [username] [password]`
- Log in to bgammon. A random username is assigned when none is provided.
- This must be the first command sent when a client connects to bgammon.
- Usernames must contain at least one non-numeric character.
- This (or `loginjson`) must be the first command sent when a client connects to bgammon.
- Aliases: `l`
- `loginjson [username] [password]`
@ -32,15 +32,15 @@ formatted responses are more easily parsed by computers.
- Aliases: `h`
- `list`
- List all games.
- List all matches.
- Aliases: `ls`
- `create <public/private> [password]`
- List all games.
- Create a match.
- Aliases: `c`
- `join <id>/<username> [password]`
- Join game by game ID or by player.
- Join match by match ID or by player.
- Aliases: `j`
- `roll`
@ -65,12 +65,12 @@ formatted responses are more easily parsed by computers.
- `say <message>`
- Send a chat message.
- This command can only be used after creating or joining a game.
- This command can only be used after creating or joining a match.
- Aliases: `s`
- `board`
- Print current game state in human-readable form.
- This command is not normally used, as the game state is provided in JSON format.
- Print current match state in human-readable form.
- This command is not normally used, as the match state is provided in JSON format.
- Aliases: `b`
- `pong <message>`
@ -101,32 +101,32 @@ This document lists events in human-readable format.
- Initial welcome message sent by the server. It provides instructions on how to log in.
- This message does not normally need to be displayed when using a graphical client.
- `welcome <name:text> there are <clients:integer> clients playing <games:integer> games.`
- `welcome <name:text> there are <clients:integer> clients playing <games:integer> matches.`
- Initial message sent by the server.
- `notice <message:line>`
- Server message. This should always be displayed to the user.
- `liststart Games list:`
- Start of games list.
- `liststart Matches list:`
- Start of matches list.
- `game <id:integer> <password:boolean> <players:integer> <name:line>`
- Game description.
- Match description.
- `listend End of games list.`
- End of games list.
- `listend End of matches list.`
- End of matches list.
- `joined <id:integer> <playerNumber:integer> <playerName:text>`
- Sent after successfully creating or joining a game, and when another player
joins a game you are in.
- Sent after successfully creating or joining a match, and when another player
joins a match you are in.
- The server will always send a `board` event immediately after `joined` to
provide clients with the initial game state.
provide clients with the initial match state.
- `failedjoin <message:line>`
- Sent after failing to join a game.
- Sent after failing to join a match.
- `parted <gameID:integer> <gameID:integer>`
- Sent after leaving a game.
- `left <username:text>`
- Sent after leaving a match.
- `json <message:line>`
- Server confirmation of client requested JSON formatting.

View file

@ -75,7 +75,7 @@ func (c *serverClient) sendEvent(e interface{}) {
// Human-readable messages.
switch ev := e.(type) {
case *bgammon.EventWelcome:
c.Write([]byte(fmt.Sprintf("welcome %s there are %d clients playing %d games.", ev.PlayerName, ev.Clients, ev.Games)))
c.Write([]byte(fmt.Sprintf("welcome %s there are %d clients playing %d matches.", ev.PlayerName, ev.Clients, ev.Games)))
case *bgammon.EventHelp:
c.Write([]byte("helpstart Help text:"))
c.Write([]byte(fmt.Sprintf("help %s", ev.Message)))
@ -87,25 +87,25 @@ func (c *serverClient) sendEvent(e interface{}) {
case *bgammon.EventSay:
c.Write([]byte(fmt.Sprintf("say %s %s", ev.Player, ev.Message)))
case *bgammon.EventList:
c.Write([]byte("liststart Games list:"))
c.Write([]byte("liststart Matches list:"))
for _, g := range ev.Games {
password := 0
if g.Password {
password = 1
}
name := "Game"
name := "(No name)"
if g.Name != "" {
name = g.Name
}
c.Write([]byte(fmt.Sprintf("game %d %d %d %s", g.ID, password, g.Players, name)))
}
c.Write([]byte("listend End of games list."))
c.Write([]byte("listend End of matches list."))
case *bgammon.EventJoined:
c.Write([]byte(fmt.Sprintf("joined %d %d %s", ev.GameID, ev.PlayerNumber, ev.Player)))
case *bgammon.EventFailedJoin:
c.Write([]byte(fmt.Sprintf("failedjoin %s", ev.Reason)))
case *bgammon.EventLeft:
c.Write([]byte(fmt.Sprintf("left %d %d %s", ev.GameID, ev.PlayerNumber, ev.Player)))
c.Write([]byte(fmt.Sprintf("left %s", ev.Player)))
case *bgammon.EventRolled:
c.Write([]byte(fmt.Sprintf("rolled %s %d %d", ev.Player, ev.Roll1, ev.Roll2)))
case *bgammon.EventFailedRoll:

View file

@ -211,10 +211,7 @@ func (g *serverGame) removeClient(client *serverClient) {
return
}
ev := &bgammon.EventLeft{
GameID: g.id,
PlayerNumber: client.playerNumber,
}
ev := &bgammon.EventLeft{}
ev.Player = string(client.name)
client.sendEvent(ev)

View file

@ -66,8 +66,6 @@ type EventFailedJoin struct {
type EventLeft struct {
Event
GameID int
PlayerNumber int
}
type EventFailedLeave struct {