diff --git a/PROTOCOL.md b/PROTOCOL.md index 116e3c9..8231c0b 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -4,6 +4,8 @@ Connect to `bgammon.org:1337` via TCP. All commands and events are separated by newlines. +When sending a password to the server, replace spaces with underscores. + ## User commands ### Format @@ -35,7 +37,7 @@ formatted responses are more easily parsed by computers. - List all matches. - Aliases: `ls` -- `create [password]` +- `create / [name]` - Create a match. - Aliases: `c` diff --git a/cmd/bgammon-server/server.go b/cmd/bgammon-server/server.go index c0a67c0..e59a0b4 100644 --- a/cmd/bgammon-server/server.go +++ b/cmd/bgammon-server/server.go @@ -338,7 +338,7 @@ COMMANDS: s.clientsLock.Unlock() continue } - password = bytes.Join(params[1:], []byte(" ")) + password = bytes.ReplaceAll(bytes.Join(params[1:], []byte(" ")), []byte("_"), []byte(" ")) } s.clientsLock.Unlock() @@ -473,7 +473,7 @@ COMMANDS: sendUsage() continue } - gamePassword = params[1] + gamePassword = bytes.ReplaceAll(params[1], []byte("_"), []byte(" ")) gameName = bytes.Join(params[2:], []byte(" ")) default: sendUsage() @@ -559,7 +559,8 @@ COMMANDS: continue } if g.id == joinGameID { - if len(g.password) != 0 && (len(params) < 2 || !bytes.Equal(g.password, bytes.Join(params[1:], []byte(" ")))) { + providedPassword := bytes.ReplaceAll(bytes.Join(params[1:], []byte(" ")), []byte("_"), []byte(" ")) + if len(g.password) != 0 && (len(params) < 2 || !bytes.Equal(g.password, providedPassword)) { cmd.client.sendEvent(&bgammon.EventFailedJoin{ Reason: "Invalid password.", }) @@ -857,7 +858,7 @@ COMMANDS: clientGame.Turn = 1 clientGame.Roll1 = 1 clientGame.Roll2 = 2 - clientGame.Board = []int{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0} + clientGame.Board = []int{0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0, 0} clientGame.eachClient(func(client *serverClient) { clientGame.sendBoard(client)