From 90dca37d446eb7ed50b8aa1511daf70788c7dc25 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 15 May 2024 19:45:35 +0200 Subject: [PATCH] fix board state when reconnecting and set access headers --- api/handler/handler.go | 2 ++ chess/game.go | 2 +- chess/player.go | 5 ++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/handler/handler.go b/api/handler/handler.go index 6b03eea..886e099 100644 --- a/api/handler/handler.go +++ b/api/handler/handler.go @@ -58,6 +58,7 @@ func GetLobbyForPassphraseHandler(c *gin.Context) { ID: &lobby.Uuid, } + c.Header("Access-Control-Allow-Origin", "*") c.IndentedJSON(http.StatusOK, lobbyInfo) } @@ -84,6 +85,7 @@ func JoinPrivateGame(c *gin.Context) { _, found = lobby.GetPlayerByUUID(*req.PlayerID) } if found { + c.Header("Access-Control-Allow-Origin", "*") c.IndentedJSON( http.StatusOK, api.PlayerInfo{ diff --git a/chess/game.go b/chess/game.go index 4cefb64..6212c8b 100644 --- a/chess/game.go +++ b/chess/game.go @@ -220,5 +220,5 @@ func (game *Game) playerDisconnected(p *Player) { } func (game *Game) SetWebsocketConnectionFor(ctx context.Context, p *Player, ws *gorillaws.Conn) { - p.SetWebsocketConnectionAndSendBoardState(ctx, ws, game.board.PGN(), game.board.colorToMove) + p.SetWebsocketConnectionAndSendBoardState(ctx, ws, &game.board) } diff --git a/chess/player.go b/chess/player.go index ea8d6b5..cc663ae 100644 --- a/chess/player.go +++ b/chess/player.go @@ -41,11 +41,10 @@ func (p *Player) SetWebsocketConnection(ctx context.Context, ws *gorillaws.Conn) func (p *Player) SetWebsocketConnectionAndSendBoardState( ctx context.Context, ws *gorillaws.Conn, - boardPosition string, - turnColor types.ChessColor, + board *Board, ) { p.SetWebsocketConnection(ctx, ws) - p.SendBoardState(types.Move{}, boardPosition, turnColor) + p.SendBoardState(board.getLastMove(), board.PGN(), board.colorToMove) } func (p *Player) SetColor(color types.ChessColor) {