Skip to content

Commit

Permalink
bug: added new game to waiting list
Browse files Browse the repository at this point in the history
  • Loading branch information
FeroxFoxxo committed Aug 4, 2024
1 parent 9fb1ec8 commit 55db25b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Server.Web/Enums/Role.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Server.Web.Enums;
public enum Role
{
Unknown,
Pilot,
Chemist,
Engineer
Expand Down
7 changes: 6 additions & 1 deletion Server.Web/World/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,8 +69,11 @@ public Game(IHubContext<GameHub, IGamePlayer> 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);
Expand Down Expand Up @@ -115,6 +118,7 @@ public async Task<bool> 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;
Expand Down Expand Up @@ -148,6 +152,7 @@ public async Task<bool> 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;
Expand Down
2 changes: 0 additions & 2 deletions Server.Web/World/Lobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public async Task<int> AddPlayerToGameAsync(HubCallerContext hubCallerContext, s

LinkGameToPlayer(hubCallerContext, game);

await game.CheckAndSendState();

return game.ConnectionToId[hubCallerContext.ConnectionId];
}

Expand Down

0 comments on commit 55db25b

Please sign in to comment.