From 55db25be0e4225879a5decb899de5c915d19efe4 Mon Sep 17 00:00:00 2001 From: "feroxfoxxo@gmail.com" Date: Sun, 4 Aug 2024 14:44:06 +1200 Subject: [PATCH] bug: added new game to waiting list --- Server.Web/Enums/Role.cs | 1 + Server.Web/World/Game.cs | 7 ++++++- Server.Web/World/Lobby.cs | 2 -- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Server.Web/Enums/Role.cs b/Server.Web/Enums/Role.cs index 671625c..d6f79e2 100644 --- a/Server.Web/Enums/Role.cs +++ b/Server.Web/Enums/Role.cs @@ -1,6 +1,7 @@ namespace Server.Web.Enums; public enum Role { + Unknown, Pilot, Chemist, Engineer diff --git a/Server.Web/World/Game.cs b/Server.Web/World/Game.cs index a40bc85..956f6eb 100644 --- a/Server.Web/World/Game.cs +++ b/Server.Web/World/Game.cs @@ -30,7 +30,7 @@ public class Game public StateModel StateModel => new () { - InternalRoles = IdToPlayer.ToDictionary(x => x.Value.Role, x => x.Value), + InternalRoles = IdToPlayer.Where(x => x.Key > 0).ToDictionary(x => x.Value.Role, x => x.Value), InternalGameState = state, Resources = Resources, CurrentSequence = CurrentSequence @@ -69,8 +69,11 @@ public Game(IHubContext hubContext, _config = config; RoomCode = GenerateInviteCode(); + Group = hubContext.Clients.Group(RoomCode); + _lobby.WaitingGames[RoomCode] = this; + for (var i = 0; i < config.MaxPlayersPerGame; i++) { _playerSlots.Writer.TryWrite(0); @@ -115,6 +118,7 @@ public async Task AddControllerAsync(string connectionId) await _hubContext.Groups.AddToGroupAsync(connectionId, RoomCode); await _hubContext.Clients.GroupExcept(RoomCode, connectionId).WriteMessage(new MessageModel($"The controller has joined game {RoomCode}", Color.DarkGreen)); + await CheckAndSendState(); return true; @@ -148,6 +152,7 @@ public async Task AddPlayerAsync(string connectionId, string username) await _hubContext.Groups.AddToGroupAsync(connectionId, RoomCode); await _hubContext.Clients.GroupExcept(RoomCode, connectionId).WriteMessage(new MessageModel($"A new player joined game {RoomCode}", Color.Green)); + await CheckAndSendState(); var waitingForPlayers = true; diff --git a/Server.Web/World/Lobby.cs b/Server.Web/World/Lobby.cs index f480076..508729d 100644 --- a/Server.Web/World/Lobby.cs +++ b/Server.Web/World/Lobby.cs @@ -31,8 +31,6 @@ public async Task AddPlayerToGameAsync(HubCallerContext hubCallerContext, s LinkGameToPlayer(hubCallerContext, game); - await game.CheckAndSendState(); - return game.ConnectionToId[hubCallerContext.ConnectionId]; }