From cacee5f35eeba0a17b1a2202db08512dea49eb8b Mon Sep 17 00:00:00 2001 From: starfish <50672801+starfi5h@users.noreply.github.com> Date: Wed, 17 Jan 2024 00:39:30 +0800 Subject: [PATCH] Clean up --- NebulaAPI/DataStructures/ConcurrentPlayerCollection.cs | 6 ++++-- NebulaAPI/GameState/INetworkProvider.cs | 4 +++- .../Serialization/LiteNetLib/NetSerializer.cs | 6 +++--- .../Planet/FactoryLoadRequestProcessor.cs | 9 ++++++--- .../PacketProcessors/Routers/StarBroadcastProcessor.cs | 2 +- .../Session/LobbyUpdateCombatValuesProcessor.cs | 2 +- NebulaPatcher/NebulaPlugin.cs | 2 +- NebulaPatcher/Patches/Dynamic/GameData_Patch.cs | 10 ++++------ NebulaWorld/MultiplayerSession.cs | 5 ----- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/NebulaAPI/DataStructures/ConcurrentPlayerCollection.cs b/NebulaAPI/DataStructures/ConcurrentPlayerCollection.cs index 0f437d8bc..60851a712 100644 --- a/NebulaAPI/DataStructures/ConcurrentPlayerCollection.cs +++ b/NebulaAPI/DataStructures/ConcurrentPlayerCollection.cs @@ -11,9 +11,11 @@ public class ConcurrentPlayerCollection { private class ReducedConcurrentDictionary : ConcurrentDictionary { +#pragma warning disable CA1822 // These are disabled as they create a new snapshot copy of the existing values. - public ICollection Keys => throw new InvalidOperationException("Accessing keys directly is not allowed."); - public ICollection Values => throw new InvalidOperationException("Accessing keys directly is not allowed."); + public new ICollection Keys => throw new InvalidOperationException("Accessing keys directly is not allowed."); + public new ICollection Values => throw new InvalidOperationException("Accessing keys directly is not allowed."); +#pragma warning restore CA1822 } private readonly Dictionary> playerCollections = new() diff --git a/NebulaAPI/GameState/INetworkProvider.cs b/NebulaAPI/GameState/INetworkProvider.cs index 7bf4ad049..9815e94f2 100644 --- a/NebulaAPI/GameState/INetworkProvider.cs +++ b/NebulaAPI/GameState/INetworkProvider.cs @@ -9,7 +9,9 @@ namespace NebulaAPI.GameState; public interface INetworkProvider : IDisposable { - [Obsolete("Dev note: we need to move this out of the public API, but it'll need a lot of packet processor updates.")] + /// + /// (intneral use) + /// INetPacketProcessor PacketProcessor { get; } /// diff --git a/NebulaModel/Networking/Serialization/LiteNetLib/NetSerializer.cs b/NebulaModel/Networking/Serialization/LiteNetLib/NetSerializer.cs index 946fe044d..7c37cfda7 100644 --- a/NebulaModel/Networking/Serialization/LiteNetLib/NetSerializer.cs +++ b/NebulaModel/Networking/Serialization/LiteNetLib/NetSerializer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Net; using System.Reflection; @@ -224,7 +224,7 @@ public override void ReadList(TClass inf, NetDataReader r) { var itm = default(TProperty); itm.Deserialize(r); - if(i < listCount) + if (i < listCount) list[i] = itm; else list.Add(itm); @@ -490,7 +490,7 @@ public void Read(T obj, NetDataReader reader) var s = _serializers[i]; if (s.Type == CallType.Basic) s.Read(obj, reader); - else if(s.Type == CallType.Array) + else if (s.Type == CallType.Array) s.ReadArray(obj, reader); else s.ReadList(obj, reader); diff --git a/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs index af8fc6757..346adfae7 100644 --- a/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Planet/FactoryLoadRequestProcessor.cs @@ -35,9 +35,12 @@ protected override void ProcessPacket(FactoryLoadRequest packet, NebulaConnectio conn.SendPacket(new FactoryData(packet.PlanetID, data, planet.data.modData)); } - // Set requesting client status to connected player, so he can receive following update + // Update syncing player data (Connected player will be update by movement packets) var player = Multiplayer.Session.Server.Players.Get(conn, EConnectionStatus.Syncing); - player.Data.LocalPlanetId = packet.PlanetID; - player.Data.LocalStarId = GameMain.galaxy.PlanetById(packet.PlanetID).star.id; + if (player != null) + { + player.Data.LocalPlanetId = packet.PlanetID; + player.Data.LocalStarId = GameMain.galaxy.PlanetById(packet.PlanetID).star.id; + } } } diff --git a/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs b/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs index c2779c3d8..c53c5cabc 100644 --- a/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Routers/StarBroadcastProcessor.cs @@ -13,7 +13,7 @@ namespace NebulaNetwork.PacketProcessors.Routers; [RegisterPacketProcessor] -internal class StarBroadcastProcessor: PacketProcessor +internal class StarBroadcastProcessor : PacketProcessor { public StarBroadcastProcessor() { diff --git a/NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs b/NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs index ced45e03e..4a9483880 100644 --- a/NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/LobbyUpdateCombatValuesProcessor.cs @@ -10,7 +10,7 @@ namespace NebulaNetwork.PacketProcessors.Session { [RegisterPacketProcessor] - internal class LobbyUpdateCombatValuesProcessor:PacketProcessor + internal class LobbyUpdateCombatValuesProcessor : PacketProcessor { protected override void ProcessPacket(LobbyUpdateCombatValues packet, NebulaConnection conn) { diff --git a/NebulaPatcher/NebulaPlugin.cs b/NebulaPatcher/NebulaPlugin.cs index 18379bbf4..fe9555076 100644 --- a/NebulaPatcher/NebulaPlugin.cs +++ b/NebulaPatcher/NebulaPlugin.cs @@ -22,7 +22,7 @@ namespace NebulaPatcher; [BepInPlugin(PluginInfo.PLUGIN_ID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] -[BepInDependency("dsp.common - api.CommonAPI", BepInDependency.DependencyFlags.SoftDependency)] +[BepInDependency("dsp.common-api.CommonAPI", BepInDependency.DependencyFlags.SoftDependency)] public class NebulaPlugin : BaseUnityPlugin, IMultiplayerMod { private static int command_ups; diff --git a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs index 4cbd1df9b..e3d91175c 100644 --- a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs @@ -184,12 +184,10 @@ public static bool OnActivePlanetFactoryLoaded_Prefix(GameData __instance, Plane planet.onFactoryLoaded -= __instance.OnActivePlanetFactoryLoaded; - // If the game is still loading, we wait till the full loading is completed - if (Multiplayer.Session.IsGameLoaded) - { - Multiplayer.Session.Network.PacketProcessor.EnablePacketProcessing = true; - Log.Info("Resume PacketProcessor (OnActivePlanetFactoryLoaded)"); - } + // 1. First login and game is not loaded yet, but since client is still syncing, it's ok to resume + // 2. In game arrive to another planet, after factory model is loaded we can resume + Multiplayer.Session.Network.PacketProcessor.EnablePacketProcessing = true; + Log.Info("Resume PacketProcessor (OnActivePlanetFactoryLoaded)"); // Get the recieved bytes from the remote server that we will import if (Multiplayer.Session.Planets.PendingTerrainData.TryGetValue(planet.id, out var terrainBytes)) diff --git a/NebulaWorld/MultiplayerSession.cs b/NebulaWorld/MultiplayerSession.cs index bbcc2a2f4..15f1f9c0e 100644 --- a/NebulaWorld/MultiplayerSession.cs +++ b/NebulaWorld/MultiplayerSession.cs @@ -1,9 +1,7 @@ #region using System; -using JetBrains.Annotations; using NebulaAPI.GameState; -using NebulaModel; using NebulaModel.Logger; using NebulaModel.Networking; using NebulaWorld.Factory; @@ -156,7 +154,6 @@ public void Dispose() GC.SuppressFinalize(this); } - [Obsolete("Use Server or Client instead.")] public INetworkProvider Network { get; set; } public IServer Server { get; set; } @@ -181,8 +178,6 @@ public void OnGameLoadCompleted() Log.Info("Game load completed"); IsGameLoaded = true; DiscordManager.UpdateRichPresence(); - Multiplayer.Session.Network.PacketProcessor.EnablePacketProcessing = true; - Log.Info("OnGameLoadCompleted: Resume PacketProcessor"); if (Multiplayer.Session.LocalPlayer.IsHost) {