From b0db6145e85ea7cd346c33dc773d3432f758d9af Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 21 Dec 2022 23:12:19 +0100 Subject: [PATCH] Remove leading number from move message. --- server/chess_move.go | 10 +++++++--- server/game.go | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/chess_move.go b/server/chess_move.go index c802915..f101523 100644 --- a/server/chess_move.go +++ b/server/chess_move.go @@ -21,9 +21,13 @@ func parseMove(received string) (*chessMove, error) { splitReceived := strings.Split(received, " ") - realMoveString := splitReceived[1] - startSquareString := splitReceived[2] - endSquareString := splitReceived[3] + if len(splitReceived) != 3 { + return nil, errors.New("invalid move command") + } + + realMoveString := splitReceived[0] + startSquareString := splitReceived[1] + endSquareString := splitReceived[2] if strings.Compare(realMoveString, "mv") == 0 { move.realMove = true diff --git a/server/game.go b/server/game.go index 356820e..e93fc28 100644 --- a/server/game.go +++ b/server/game.go @@ -67,12 +67,13 @@ func (game *chessGame) handle() { return } move, err = parseMove(string(receivedMessage)) - log.Println("Player 1 moved: ", move) if err != nil { log.Println("Game: ", game.id, err) return } + log.Println("Player 1 moved: ", move) + gameState = CheckPlayerChange case CheckPlayerChange: