Allow specifying match points
This commit is contained in:
parent
0bfb03f767
commit
f96a4fdb1a
5 changed files with 25 additions and 8 deletions
|
@ -37,7 +37,7 @@ formatted responses are more easily parsed by computers.
|
|||
- List all matches.
|
||||
- Aliases: `ls`
|
||||
|
||||
- `create <public>/<private [password]> [name]`
|
||||
- `create <public>/<private [password]> <points> [name]`
|
||||
- Create a match.
|
||||
- Aliases: `c`
|
||||
|
||||
|
@ -112,7 +112,7 @@ This document lists events in human-readable format.
|
|||
- `liststart Matches list:`
|
||||
- Start of matches list.
|
||||
|
||||
- `game <id:integer> <password:boolean> <players:integer> <name:line>`
|
||||
- `game <id:integer> <password:boolean> <points:integer> <players:integer> <name:line>`
|
||||
- Match description.
|
||||
|
||||
- `listend End of matches list.`
|
||||
|
|
|
@ -100,7 +100,7 @@ func (c *serverClient) sendEvent(e interface{}) {
|
|||
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(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.EventJoined:
|
||||
|
|
|
@ -442,6 +442,7 @@ COMMANDS:
|
|||
}
|
||||
ev.Games = append(ev.Games, bgammon.GameListing{
|
||||
ID: g.id,
|
||||
Points: g.Points,
|
||||
Password: len(g.password) != 0,
|
||||
Players: g.playerCount(),
|
||||
Name: string(g.name),
|
||||
|
@ -457,9 +458,9 @@ COMMANDS:
|
|||
}
|
||||
|
||||
sendUsage := func() {
|
||||
cmd.client.sendNotice("To create a public match please specify whether it is public or private. When creating a private match, a password must also be provided.")
|
||||
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) == 0 {
|
||||
if len(params) < 2 {
|
||||
sendUsage()
|
||||
continue
|
||||
}
|
||||
|
@ -467,21 +468,34 @@ COMMANDS:
|
|||
var gamePassword []byte
|
||||
gameType := bytes.ToLower(params[0])
|
||||
var gameName []byte
|
||||
var gamePoints []byte
|
||||
switch {
|
||||
case bytes.Equal(gameType, []byte("public")):
|
||||
gameName = bytes.Join(params[1:], []byte(" "))
|
||||
gamePoints = params[1]
|
||||
if len(params) > 2 {
|
||||
gameName = bytes.Join(params[2:], []byte(" "))
|
||||
}
|
||||
case bytes.Equal(gameType, []byte("private")):
|
||||
if len(params) < 2 {
|
||||
if len(params) < 3 {
|
||||
sendUsage()
|
||||
continue
|
||||
}
|
||||
gamePassword = bytes.ReplaceAll(params[1], []byte("_"), []byte(" "))
|
||||
gameName = bytes.Join(params[2:], []byte(" "))
|
||||
gamePoints = params[2]
|
||||
if len(params) > 3 {
|
||||
gameName = bytes.Join(params[3:], []byte(" "))
|
||||
}
|
||||
default:
|
||||
sendUsage()
|
||||
continue
|
||||
}
|
||||
|
||||
points, err := strconv.Atoi(string(gamePoints))
|
||||
if err != nil || points < 1 || points > 99 {
|
||||
sendUsage()
|
||||
continue
|
||||
}
|
||||
|
||||
// Set default game name.
|
||||
if len(bytes.TrimSpace(gameName)) == 0 {
|
||||
abbr := "'s"
|
||||
|
@ -494,6 +508,7 @@ COMMANDS:
|
|||
|
||||
g := newServerGame(<-s.newGameIDs)
|
||||
g.name = gameName
|
||||
g.Points = points
|
||||
g.password = gamePassword
|
||||
ok, reason := g.addClient(cmd.client)
|
||||
if !ok {
|
||||
|
|
1
event.go
1
event.go
|
@ -44,6 +44,7 @@ type GameListing struct {
|
|||
Event
|
||||
ID int
|
||||
Password bool
|
||||
Points int
|
||||
Players int
|
||||
Name string
|
||||
}
|
||||
|
|
1
game.go
1
game.go
|
@ -22,6 +22,7 @@ type Game struct {
|
|||
Roll1 int
|
||||
Roll2 int
|
||||
Moves [][]int // Pending moves.
|
||||
Points int
|
||||
|
||||
boardStates [][]int // One board state for each move to allow undoing a move.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue