diff --git a/Fika.Core/Coop/Components/CoopHandler.cs b/Fika.Core/Coop/Components/CoopHandler.cs index 600f53d2..05ecd6b2 100644 --- a/Fika.Core/Coop/Components/CoopHandler.cs +++ b/Fika.Core/Coop/Components/CoopHandler.cs @@ -475,7 +475,9 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p null).Result; if (otherPlayer == null) + { return null; + } ((CoopPlayer)otherPlayer).NetId = netId; Logger.LogInfo($"SpawnObservedPlayer: {profile.Nickname} spawning with NetId {netId}"); @@ -494,7 +496,9 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p } if (!Singleton.Instance.RegisteredPlayers.Any(x => x.Profile.ProfileId == profile.ProfileId)) + { Singleton.Instance.RegisteredPlayers.Add(otherPlayer); + } foreach (CoopPlayer player in Players.Values) { diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 50ef6003..4bbf3fcc 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -369,7 +369,7 @@ private async Task CreateBot(Profile profile, Vector3 position) if (server.NetServer.ConnectedPeersCount > 0) { - await WaitForPlayersToLoadBotProfile(netId, profile); + await WaitForPlayersToLoadBotProfile(netId); } localPlayer = await CoopBot.CreateBot(num, position, Quaternion.identity, "Player", @@ -447,15 +447,21 @@ public void IncreaseLoadedPlayers(int netId) } } - private async Task WaitForPlayersToLoadBotProfile(int netId, Profile profile) + private async Task WaitForPlayersToLoadBotProfile(int netId) { botQueue.Add(netId, 0); - int waitTime = 0; + DateTime start = DateTime.Now; int connectedPeers = Singleton.Instance.NetServer.ConnectedPeersCount; - while (botQueue[netId] < connectedPeers || waitTime < 60) // ~15 second failsafe + while (botQueue[netId] < connectedPeers) { - waitTime++; + if (start.Subtract(DateTime.Now).TotalSeconds >= 30) // ~30 second failsafe + { + Logger.LogWarning("WaitForPlayersToLoadBotProfile: Took too long to receive all packets!"); + botQueue.Remove(netId); + return; + } + await Task.Delay(250); } diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 6851bf6a..b6a25dd2 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -376,7 +376,7 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) else if (packet.PacketType == EPackageType.LoadBot) { CoopGame coopGame = (CoopGame)Singleton.Instance; - coopGame.IncreaseLoadedPlayers(packet.NetId); + coopGame.IncreaseLoadedPlayers(packet.BotNetId); return; }