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:
Jonas
2026-03-05 22:07:48 +01:00
parent 0eed8020b8
commit 34f683854b
3 changed files with 17 additions and 10 deletions
+10 -3
View File
@@ -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)