Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Jan 16, 2024
1 parent 336d22c commit cacee5f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
6 changes: 4 additions & 2 deletions NebulaAPI/DataStructures/ConcurrentPlayerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public class ConcurrentPlayerCollection
{
private class ReducedConcurrentDictionary<TKey, TValue> : ConcurrentDictionary<TKey, TValue>
{
#pragma warning disable CA1822
// These are disabled as they create a new snapshot copy of the existing values.
public ICollection<TKey> Keys => throw new InvalidOperationException("Accessing keys directly is not allowed.");
public ICollection<TValue> Values => throw new InvalidOperationException("Accessing keys directly is not allowed.");
public new ICollection<TKey> Keys => throw new InvalidOperationException("Accessing keys directly is not allowed.");
public new ICollection<TValue> Values => throw new InvalidOperationException("Accessing keys directly is not allowed.");
#pragma warning restore CA1822
}

private readonly Dictionary<EConnectionStatus, ReducedConcurrentDictionary<INebulaConnection, INebulaPlayer>> playerCollections = new()
Expand Down
4 changes: 3 additions & 1 deletion NebulaAPI/GameState/INetworkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
/// <summary>
/// (intneral use)
/// </summary>
INetPacketProcessor PacketProcessor { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace NebulaNetwork.PacketProcessors.Routers;

[RegisterPacketProcessor]
internal class StarBroadcastProcessor: PacketProcessor<StarBroadcastPacket>
internal class StarBroadcastProcessor : PacketProcessor<StarBroadcastPacket>
{
public StarBroadcastProcessor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace NebulaNetwork.PacketProcessors.Session
{
[RegisterPacketProcessor]
internal class LobbyUpdateCombatValuesProcessor:PacketProcessor<LobbyUpdateCombatValues>
internal class LobbyUpdateCombatValuesProcessor : PacketProcessor<LobbyUpdateCombatValues>
{
protected override void ProcessPacket(LobbyUpdateCombatValues packet, NebulaConnection conn)
{
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/NebulaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 0 additions & 5 deletions NebulaWorld/MultiplayerSession.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#region

using System;
using JetBrains.Annotations;
using NebulaAPI.GameState;
using NebulaModel;
using NebulaModel.Logger;
using NebulaModel.Networking;
using NebulaWorld.Factory;
Expand Down Expand Up @@ -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; }
Expand All @@ -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)
{
Expand Down

0 comments on commit cacee5f

Please sign in to comment.