diff --git a/Source/Common/Networking/State/ServerJoiningState.cs b/Source/Common/Networking/State/ServerJoiningState.cs index c97410d1..b2d2a392 100644 --- a/Source/Common/Networking/State/ServerJoiningState.cs +++ b/Source/Common/Networking/State/ServerJoiningState.cs @@ -29,10 +29,7 @@ protected override async Task RunState() if (Server.settings.pauseOnJoin) Server.commands.PauseAll(); - // On standalone, only request a fresh join point when another player is already active. - // For the normal first join, serve the persisted state immediately instead of blocking on WaitJoinPoint. - if ((Server.IsStandaloneServer && Server.PlayingPlayers.Any()) || - (!Server.IsStandaloneServer && Server.settings.autoJoinPoint.HasFlag(AutoJoinPointFlags.Join))) + if (!Server.IsStandaloneServer && Server.settings.autoJoinPoint.HasFlag(AutoJoinPointFlags.Join)) Server.worldData.TryStartJoinPointCreation(sourcePlayer: Player); Server.playerManager.OnJoin(Player); diff --git a/Source/Tests/ServerTest.cs b/Source/Tests/ServerTest.cs index 5727e2c1..4cfff8bd 100644 --- a/Source/Tests/ServerTest.cs +++ b/Source/Tests/ServerTest.cs @@ -96,6 +96,35 @@ public void LoadingStateHandlesKeepAliveWhileWaitingForJoinPoint() } } + [Test] + public void StandaloneJoinWithExistingPlayer_DoesNotStartJoinPoint() + { + var server = MakeServer(out var port); + server.IsStandaloneServer = true; + + var existingConn = new RecordingConnection("existing"); + existingConn.ChangeState(ConnectionStateEnum.ServerPlaying); + var existingPlayer = new ServerPlayer(100, existingConn); + existingConn.serverPlayer = existingPlayer; + server.playerManager.Players.Add(existingPlayer); + + ConnectClient(port, typeof(TestJoiningState)); + + var timeoutWatch = Stopwatch.StartNew(); + while (true) + { + if (server.playerManager.Players.Count == 1) + break; + + if (timeoutWatch.ElapsedMilliseconds > 2000) + Assert.Fail("Timeout"); + + Thread.Sleep(50); + } + + Assert.That(server.worldData.CreatingJoinPoint, Is.False); + } + private void ConnectClient(int port, Type joiningStateType) { var clientListener = new TestNetListener(joiningStateType);