Skip to content

Commit fe5ef53

Browse files
authored
regression: fix prefab cache version check (SubnauticaNitrox#2674)
2 parents 32e9449 + 2e5febf commit fe5ef53

9 files changed

Lines changed: 49 additions & 57 deletions

File tree

Nitrox.Model/Helper/Reflect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static PropertyInfo Property<T>(Expression<Func<T, object>> expression)
7777
return (PropertyInfo)GetMemberInfo(expression);
7878
}
7979

80-
private static MemberInfo GetMemberInfo(LambdaExpression expression, Type implementingType = null)
80+
private static MemberInfo GetMemberInfo(LambdaExpression expression, Type? implementingType = null)
8181
{
8282
Expression currentExpression = expression.Body;
8383
while (true)

Nitrox.Server.Subnautica/Models/Commands/Core/HostToServerCommandContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal sealed record HostToServerCommandContext : ICommandContext
1212
public ILogger Logger { get; set; } = NullLogger.Instance;
1313
public CommandOrigin Origin { get; init; } = CommandOrigin.SERVER;
1414
public string OriginName => "SERVER";
15-
public SessionId OriginId { get; init; } = 0;
15+
public SessionId OriginId { get; init; } = SessionId.SERVER_ID;
1616
public Perms Permissions { get; init; } = Perms.HOST;
1717

1818
public HostToServerCommandContext(IPacketSender packetSender)

Nitrox.Server.Subnautica/Models/Communication/LiteNetLibServer.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Nitrox.Model.Packets.Core;
1313
using Nitrox.Server.Subnautica.Models.Administration;
1414
using Nitrox.Server.Subnautica.Models.AppEvents;
15+
using Nitrox.Server.Subnautica.Models.AppEvents.Core;
1516
using Nitrox.Server.Subnautica.Models.GameLogic;
1617
using Nitrox.Server.Subnautica.Models.Helper;
1718
using Nitrox.Server.Subnautica.Models.Packets.Core;
@@ -45,8 +46,10 @@ public LiteNetLibServer(PlayerManager playerManager, SessionManager sessionManag
4546
this.options = options;
4647
this.logger = logger;
4748
listener = new EventBasedNetListener();
48-
server = new NetManager(listener, NitroxEnvironment.IsReleaseMode ? new Crc32cLayer() : null) {
49-
UseNativeSockets = true, IPv6Enabled = true };
49+
server = new NetManager(listener, NitroxEnvironment.IsReleaseMode ? new Crc32cLayer() : null)
50+
{
51+
UseNativeSockets = true, IPv6Enabled = true
52+
};
5053
}
5154

5255
public Task StartAsync(CancellationToken cancellationToken)
@@ -181,7 +184,7 @@ public async Task<bool> KickPlayer(SessionId sessionId, string reason = "")
181184
return true;
182185
}
183186

184-
public async Task OnEventAsync(ISessionCleaner.Args args)
187+
async Task IEvent<ISessionCleaner.Args>.OnEventAsync(ISessionCleaner.Args args)
185188
{
186189
Disconnect disconnect = new(args.Session.Id);
187190
await SendPacketToAllAsync(disconnect);

Nitrox.Server.Subnautica/Models/Resources/Parsers/PrefabPlaceholderGroupsResource.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,8 @@ private async Task CreateOrLoadPrefabCacheAsync(string nitroxCachePath)
149149
{
150150
logger.ZLogWarning($"An error occurred while deserializing the prefab cache. Re-creating it: {ex.Message:@Error}");
151151
}
152-
if (cache.HasValue)
152+
if (cache is { Version: CACHE_VERSION })
153153
{
154-
if (cache.Value.Version != CACHE_VERSION)
155-
{
156-
logger.ZLogInformation($"Found outdated cache ({cache.Value.Version}, expected {CACHE_VERSION})");
157-
}
158154
prefabPlaceholdersGroupPaths = cache.Value.PrefabPlaceholdersGroupPaths;
159155
randomPossibilitiesByClassId = cache.Value.RandomPossibilitiesByClassId;
160156
groupsByClassId = cache.Value.GroupsByClassId;
@@ -164,6 +160,10 @@ private async Task CreateOrLoadPrefabCacheAsync(string nitroxCachePath)
164160
// Fallback solution
165161
else
166162
{
163+
if (cache.HasValue)
164+
{
165+
logger.ZLogInformation($"Found outdated cache (is v{cache.Value.Version}, expected v{CACHE_VERSION})");
166+
}
167167
logger.ZLogInformation($"Building cache, this may take a while...");
168168
// Get all prefab-classIds linked to the (partial) bundle path
169169
string prefabDatabasePath = Path.Combine(options.Value.GetSubnauticaResourcesPath(), "StreamingAssets", "SNUnmanagedData", "prefabs.db");

Nitrox.Server.Subnautica/Services/PortForwardService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Nitrox.Server.Subnautica.Services;
77

88
/// <summary>
9-
/// Opens ports on network attached routers via <a href="https://en.wikipedia.org/wiki/Universal_Plug_and_Play">UPnP</a>.
9+
/// Uses <see cref="SubnauticaServerOptions"/> to automatically open server listening port on network router via <a href="https://en.wikipedia.org/wiki/Universal_Plug_and_Play">UPnP</a>.
1010
/// </summary>
1111
/// <remarks>
1212
/// By port forwarding, incoming connections will be forwarded to the host machine running the game server.<br /><br />

Nitrox.Test/Model/Platforms/OS/Windows/RegistryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nitrox.Model.Platforms.OS.Windows;
88
[SupportedOSPlatform("windows")]
99
public class RegistryTest
1010
{
11-
[OSTestMethod("windows")]
11+
[OSTestMethod(OperatingSystems.Windows)]
1212
public async Task WaitsForRegistryKeyToExist()
1313
{
1414
const string PATH_TO_KEY = @"SOFTWARE\Nitrox\test";
Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
11
namespace Nitrox.Test.Model.Platforms;
22

3+
/// <summary>
4+
/// Test method attribute, that will only run the test on the specified platform.
5+
/// </summary>
6+
/// <param name="platform">case-insensitive platform, i.e: linux, windows, osx</param>
37
[AttributeUsage(AttributeTargets.Method)]
4-
public class OSTestMethodAttribute : TestMethodAttribute
8+
internal sealed class OSTestMethodAttribute(OperatingSystems platform) : TestMethodAttribute
59
{
6-
public string Platform { get;}
7-
8-
/// <summary>
9-
/// Test method attribute, that will only run the test on the specified platform.
10-
/// </summary>
11-
/// <param name="platform">case insensitive platform, i.e: linux, windows, osx</param>
12-
public OSTestMethodAttribute(string platform)
13-
{
14-
Platform = platform;
15-
}
10+
private readonly OperatingSystems platform = platform;
1611

1712
public override TestResult[] Execute(ITestMethod testMethod)
1813
{
19-
if (!OperatingSystem.IsOSPlatform(Platform))
14+
if (!OperatingSystem.IsOSPlatform(GetPlatformString()))
2015
{
21-
return [
22-
new TestResult()
16+
return
17+
[
18+
new TestResult
2319
{
2420
Outcome = UnitTestOutcome.Inconclusive,
25-
TestContextMessages = $"This test can only be run on {Platform}"
21+
TestContextMessages = $"This test can only be run on {GetPlatformString()}"
2622
}
2723
];
2824
}
2925

3026
return base.Execute(testMethod);
3127
}
28+
29+
private string GetPlatformString() =>
30+
platform switch
31+
{
32+
OperatingSystems.Windows => "Windows",
33+
OperatingSystems.Linux => "Linux",
34+
OperatingSystems.OSX => "OSX",
35+
OperatingSystems.FreeBSD => "FreeBSD",
36+
_ => throw new InvalidOperationException($"Unknown platform {(int)platform}")
37+
};
3238
}

NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NitroxClient.GameLogic.Spawning.WorldEntities;
1212
/// This spawner can't hold a SpawnSync function because it is also responsible for spawning its children
1313
/// so the <see cref="SpawnAsync"/> function will still use sync spawning when possible and fall back to async when required.
1414
/// </remarks>
15-
public class PlaceholderGroupWorldEntitySpawner : IWorldEntitySpawner
15+
internal sealed class PlaceholderGroupWorldEntitySpawner : IWorldEntitySpawner
1616
{
1717
private readonly Entities entities;
1818
private readonly WorldEntitySpawnerResolver spawnerResolver;

NitroxClient/GameLogic/Spawning/WorldEntities/WorldEntitySpawnerResolver.cs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace NitroxClient.GameLogic.Spawning.WorldEntities;
66

7-
public class WorldEntitySpawnerResolver
7+
internal sealed class WorldEntitySpawnerResolver
88
{
99
private readonly DefaultWorldEntitySpawner defaultEntitySpawner = new();
1010

@@ -32,33 +32,16 @@ public WorldEntitySpawnerResolver(EntityMetadataManager entityMetadataManager, E
3232
creatureRespawnEntitySpawner = new CreatureRespawnEntitySpawner(simulationOwnership);
3333
}
3434

35-
public IWorldEntitySpawner ResolveEntitySpawner(WorldEntity entity)
36-
{
37-
switch (entity)
38-
{
39-
case PrefabPlaceholderEntity:
40-
return prefabPlaceholderEntitySpawner;
41-
case PlaceholderGroupWorldEntity:
42-
return placeholderGroupWorldEntitySpawner;
43-
case SerializedWorldEntity:
44-
return serializedWorldEntitySpawner;
45-
case GeyserWorldEntity:
46-
return geyserWorldEntitySpawner;
47-
case ReefbackEntity:
48-
return reefbackEntitySpawner;
49-
case ReefbackChildEntity:
50-
return reefbackChildEntitySpawner;
51-
case CreatureRespawnEntity:
52-
return creatureRespawnEntitySpawner;
53-
}
54-
55-
TechType techType = entity.TechType.ToUnity();
56-
57-
if (customSpawnersByTechType.TryGetValue(techType, out IWorldEntitySpawner value))
35+
public IWorldEntitySpawner ResolveEntitySpawner(WorldEntity entity) =>
36+
entity switch
5837
{
59-
return value;
60-
}
61-
62-
return defaultEntitySpawner;
63-
}
38+
PrefabPlaceholderEntity => prefabPlaceholderEntitySpawner,
39+
PlaceholderGroupWorldEntity => placeholderGroupWorldEntitySpawner,
40+
SerializedWorldEntity => serializedWorldEntitySpawner,
41+
GeyserWorldEntity => geyserWorldEntitySpawner,
42+
ReefbackEntity => reefbackEntitySpawner,
43+
ReefbackChildEntity => reefbackChildEntitySpawner,
44+
CreatureRespawnEntity => creatureRespawnEntitySpawner,
45+
_ => customSpawnersByTechType.GetValueOrDefault(entity.TechType.ToUnity(), defaultEntitySpawner)
46+
};
6447
}

0 commit comments

Comments
 (0)