Use GameInformationDto for FieldUpdated events
Send a GameInformationDto from the GameManager when broadcasting FieldUpdated (includes players, current field, state and current turn) and move currentTurn toggle before the broadcast. Update client code (GameConnection and LocalGame) to accept GameInformationDto for FieldUpdated, rename handler to updateState and apply the full game state payload. This ensures clients receive consistent game metadata (including current turn) with each field update.
This commit is contained in:
@@ -77,7 +77,16 @@ public class GameManager(IGameRepository gameRepository, IHubContext<GameHubSock
|
||||
return;
|
||||
}
|
||||
|
||||
await hubContext.Clients.Group(game.Id).SendAsync("FieldUpdated", ConvertField(game.Field.CurrentField));
|
||||
game.CurrentTurn = game.CurrentTurn == 1 ? 2 : 1;
|
||||
var gameInfoDto = new GameInformationDto
|
||||
{
|
||||
Players = game?.Players,
|
||||
CurrentField = ConvertField(game?.Field.CurrentField),
|
||||
State = game?.State,
|
||||
CurrentTurn = game?.CurrentTurn ?? 0
|
||||
};
|
||||
|
||||
await hubContext.Clients.Group(game.Id).SendAsync("FieldUpdated", gameInfoDto);
|
||||
|
||||
var winResult = game.Field.CheckForWin();
|
||||
if (winResult != 0)
|
||||
@@ -104,8 +113,6 @@ public class GameManager(IGameRepository gameRepository, IHubContext<GameHubSock
|
||||
|
||||
ScheduleGameDeletion(game.Id, TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
game.CurrentTurn = game.CurrentTurn == 1 ? 2 : 1;
|
||||
}
|
||||
|
||||
public Task DisconnectedPlayer(string playerConnectionId)
|
||||
|
||||
Reference in New Issue
Block a user