Skip to content

Commit

Permalink
Merge pull request #22 from hubastard/master
Browse files Browse the repository at this point in the history
branch update
  • Loading branch information
Baldie-dev authored Apr 12, 2021
2 parents bcd5047 + b10541d commit 7884ea8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion NebulaHost/MultiplayerHostSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void StartServer(int port, bool loadSaveFile = false)
{
SaveManager.LoadServerData();
}
SaveManager.SaveOnExit = true;
PacketProcessor = new NetPacketProcessor();
StatisticsManager = new StatisticsManager();

Expand Down Expand Up @@ -158,7 +159,10 @@ protected override void OnClose(CloseEventArgs e)
return;

NebulaModel.Logger.Log.Info($"Client disconnected: {Context.UserEndPoint}, reason: {e.Reason}");
playerManager.PlayerDisconnected(new NebulaConnection(Context.WebSocket, Context.UserEndPoint, packetProcessor));
UnityDispatchQueue.RunOnMainThread(() =>
{
playerManager.PlayerDisconnected(new NebulaConnection(Context.WebSocket, Context.UserEndPoint, packetProcessor));
});
}

protected override void OnError(ErrorEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void ProcessPacket(CreatePrebuildsRequest packet, NebulaConnection conn)
planet.physics = new PlanetPhysics(planet);
planet.physics.Init();
}
if (AccessTools.Field(typeof(CargoTraffic), "beltRenderingBatch").GetValue(planet.factory.cargoTraffic) == null)
{
planet.factory.cargoTraffic.CreateRenderingBatches();
}
pab.CreatePrebuilds();
FactoryManager.EventFromServer = false;
FactoryManager.EventFactory = null;
Expand Down
3 changes: 2 additions & 1 deletion NebulaHost/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SaveManager
private const string FILE_EXTENSION = ".server";
private static string lastFileName = "";

public static bool SaveOnExit = false;
public static void SaveServerData(string saveName)
{
string path = GameConfig.gameSaveFolder + saveName + FILE_EXTENSION;
Expand All @@ -27,7 +28,7 @@ public static void SaveServerData(string saveName)
data.Value.Serialize(netDataWriter);
}
//Add host's data
netDataWriter.Put(CryptoUtils.GetCurrentUserPublicKeyHash());
netDataWriter.Put(CryptoUtils.GetCurrentUserPublicKeyHash());
LocalPlayer.Data.Serialize(netDataWriter);

File.WriteAllBytes(path, netDataWriter.Data);
Expand Down
2 changes: 1 addition & 1 deletion NebulaModel/Networking/NebulaConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public NebulaConnection(WebSocket peerSocket, IPEndPoint peerEndpoint, NetPacket
}
else
{
Log.Warn($"Cannot send packet {packet?.GetType()} to a closed connection {peerSocket?.Url}");
Log.Warn($"Cannot send packet {packet?.GetType()} to a closed connection {peerEndpoint}");
}
}

Expand Down
3 changes: 2 additions & 1 deletion NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class GameSave_Patch
[HarmonyPatch("SaveCurrentGame")]
public static bool SaveCurrentGame_Prefix(string saveName)
{
if (SimulatedWorld.Initialized && LocalPlayer.IsMasterClient)
if (SaveManager.SaveOnExit || SimulatedWorld.Initialized && LocalPlayer.IsMasterClient)
{
SaveManager.SaveServerData(saveName);
SaveManager.SaveOnExit = false;
}

if (SimulatedWorld.Initialized && !LocalPlayer.IsMasterClient)
Expand Down

0 comments on commit 7884ea8

Please sign in to comment.