fix(lobby): ready status anzeigen und Spielstart absichern
This commit is contained in:
@@ -110,6 +110,8 @@ public class GameHub : Hub
|
||||
await Groups.AddToGroupAsync(connectionId, game.LobbyCode);
|
||||
|
||||
await Clients.Caller.SendAsync("LobbyCreated", new { GameId = game.Id, LobbyCode = game.LobbyCode });
|
||||
var gameState = await _gameService.GetGameStateAsync(game.Id);
|
||||
await Clients.Caller.SendAsync("PlayerJoined", gameState);
|
||||
_logger.LogInformation("Lobby {LobbyCode} created by user {UserId}", game.LobbyCode, userId);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
|
||||
@@ -81,6 +81,9 @@ public class GameService : IGameService
|
||||
if (game.Players.Count < 2)
|
||||
throw new InvalidOperationException("At least 2 players are required to start the game");
|
||||
|
||||
if (game.Players.Any(player => !player.IsReady))
|
||||
throw new InvalidOperationException("All players must be ready to start the game");
|
||||
|
||||
game.Status = GameStatus.InProgress;
|
||||
game.StartedAt = DateTime.UtcNow;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user