fix board state when reconnecting and set access headers

This commit is contained in:
Marco 2024-05-15 19:45:35 +02:00
parent 682ce8437b
commit 90dca37d44
3 changed files with 5 additions and 4 deletions

View File

@ -58,6 +58,7 @@ func GetLobbyForPassphraseHandler(c *gin.Context) {
ID: &lobby.Uuid, ID: &lobby.Uuid,
} }
c.Header("Access-Control-Allow-Origin", "*")
c.IndentedJSON(http.StatusOK, lobbyInfo) c.IndentedJSON(http.StatusOK, lobbyInfo)
} }
@ -84,6 +85,7 @@ func JoinPrivateGame(c *gin.Context) {
_, found = lobby.GetPlayerByUUID(*req.PlayerID) _, found = lobby.GetPlayerByUUID(*req.PlayerID)
} }
if found { if found {
c.Header("Access-Control-Allow-Origin", "*")
c.IndentedJSON( c.IndentedJSON(
http.StatusOK, http.StatusOK,
api.PlayerInfo{ api.PlayerInfo{

View File

@ -220,5 +220,5 @@ func (game *Game) playerDisconnected(p *Player) {
} }
func (game *Game) SetWebsocketConnectionFor(ctx context.Context, p *Player, ws *gorillaws.Conn) { 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)
} }

View File

@ -41,11 +41,10 @@ func (p *Player) SetWebsocketConnection(ctx context.Context, ws *gorillaws.Conn)
func (p *Player) SetWebsocketConnectionAndSendBoardState( func (p *Player) SetWebsocketConnectionAndSendBoardState(
ctx context.Context, ctx context.Context,
ws *gorillaws.Conn, ws *gorillaws.Conn,
boardPosition string, board *Board,
turnColor types.ChessColor,
) { ) {
p.SetWebsocketConnection(ctx, ws) 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) { func (p *Player) SetColor(color types.ChessColor) {