Skip to content

Commit

Permalink
Merge branch 'hubastard:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
limoka authored Sep 29, 2021
2 parents de81504 + 6d5dc41 commit 6cd0ab8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
</ItemGroup>

<ItemGroup Label="Dyson Sphere Program">
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" PrivateAssets="all" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" PrivateAssets="all" />
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-*" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" PrivateAssets="all" ExcludeAssets="runtime" />
<Reference Include="$(PropsheetPath)\Libs\UnityEngine.UI.dll" Private="false" SpecificVersion="true" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions NebulaNetwork/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ namespace NebulaNetwork
public class SaveManager
{
private const string FILE_EXTENSION = ".server";
private const ushort REVISION = 3;

public static void SaveServerData(string saveName)
{
string path = GameConfig.gameSaveFolder + saveName + FILE_EXTENSION;
IPlayerManager playerManager = Multiplayer.Session.Network.PlayerManager;
NetDataWriter netDataWriter = new NetDataWriter();
netDataWriter.Put(REVISION);

using (playerManager.GetSavedPlayerData(out Dictionary<string, IPlayerData> savedPlayerData))
{
Expand Down Expand Up @@ -89,13 +91,28 @@ public static void LoadServerData()

byte[] source = File.ReadAllBytes(path);
NetDataReader netDataReader = new NetDataReader(source);
try
{
ushort revision = netDataReader.GetUShort();
if (revision != REVISION)
{
throw new System.Exception();
}
}
catch (System.Exception)
{
NebulaModel.Logger.Log.Warn("Skipping server data from unsupported Nebula version...");
return;
}

int playerNum = netDataReader.GetInt();

using (playerManager.GetSavedPlayerData(out Dictionary<string, IPlayerData> savedPlayerData))
{
for (int i = 0; i < playerNum; i++)
{
string hash = netDataReader.GetString();

PlayerData playerData = netDataReader.Get<PlayerData>();
if (!savedPlayerData.ContainsKey(hash))
{
Expand Down

0 comments on commit 6cd0ab8

Please sign in to comment.