diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt index 35c27d3e..d12e828a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt @@ -40,7 +40,6 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn var tracker: ServerWorldTracker? = null var worldStartAcknowledged = false var returnWarp: WarpAction? = null - var systemWorld: ServerSystemWorld? = null val world: ServerWorld? get() = tracker?.world @@ -193,7 +192,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn val params = GlobalDefaults.universeServer.findStarterWorldParameters // visit all since sparsingly trying to find specific world is not healthy performance wise - var found = server.universe.findRandomWorld(params.tries, params.range, visitAll = true, predicate = { + val found = server.universe.findRandomWorld(params.tries, params.range, visitAll = true, predicate = { if (++visited % 600 == 0) { LOGGER.info("Still finding starter world for ${alias()}...") } @@ -232,7 +231,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn LOGGER.info("Found appropriate starter world at $found for ${alias()}") var world = server.loadSystemWorld(found.location).await() - var ship = world.addClient(this).await() + var ship = world.addClient(this, location = SystemWorldLocation.Celestial(found)).await() shipWorld.sky.stopFlyingAt(ship.location.skyParameters(world)) shipCoordinate = found @@ -241,12 +240,10 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn while (true) { val (system, location) = flyShipQueue.receive() - val currentSystem = systemWorld - - if (system == currentSystem?.location) { + if (system == world.location) { // fly ship in current system currentFlightJob?.cancel() - val flight = currentSystem.flyShip(this, location) + val flight = world.flyShip(this, location) shipWorld.mailbox.execute { shipWorld.sky.startFlying(false) @@ -254,7 +251,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn currentFlightJob = scope.launch { val coords = flight.await() - val action = coords.orbitalAction(currentSystem) + val action = coords.orbitalAction(world) orbitalWarpAction = action for (client in shipWorld.clients) { @@ -281,6 +278,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn continue currentFlightJob?.cancel() + world.removeClient(this) shipWorld.mailbox.execute { shipWorld.sky.startFlying(true) @@ -290,15 +288,12 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn val newSystem = server.loadSystemWorld(system) shipCoordinate = UniversePos(system) - orbitalWarpAction = KOptional() for (client in shipWorld.clients) { client.client.orbitalWarpAction = KOptional() } - delay((GlobalDefaults.universeServer.queuedFlightWaitTime * 1000L).toLong()) - world = newSystem.await() ship = world.addClient(this).await() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt index 0c82c4cd..7131daaf 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt @@ -91,9 +91,6 @@ class ServerSystemWorld : SystemWorld { if (location == SystemWorldLocation.Transit) location = SystemWorldLocation.Position(randomArrivalPosition()) - client.systemWorld?.removeClient(client) - client.systemWorld = this - val objects = entities.values.map { it.writeNetwork(client.isLegacy) } val ships = ships.values.map { it.writeNetwork(client.isLegacy) } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt index 2bee1a21..a4ebf9d8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerWorldTracker.kt @@ -146,7 +146,7 @@ class ServerWorldTracker(val world: ServerWorld, val client: ServerConnection, p } run { - if (skyUpdateWaitTicks++ >= 4) { + if (skyUpdateWaitTicks++ >= 20) { val (data, version) = world.sky.networkedGroup.write(skyVersion, isLegacy = client.isLegacy) skyVersion = version send(EnvironmentUpdatePacket(data, ByteArrayList())) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Sky.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Sky.kt index 691c8b7c..7c8ebf55 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/Sky.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/Sky.kt @@ -112,7 +112,9 @@ class Sky() { fun stopFlyingAt(destination: SkyParameters) { this.destination = destination - skyType = SkyType.ORBITAL + + if (skyType != SkyType.WARP) + skyType = SkyType.ORBITAL } private var lastFlyingType = FlyingType.NONE diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/SystemWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/SystemWorld.kt index ba283bf4..9a72e33a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/SystemWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/SystemWorld.kt @@ -218,7 +218,7 @@ abstract class SystemWorld(val location: Vector3i, val clock: Clock, val univers // systemLocation should not be interpolated // if it's stale it can point to a removed system object var location by networkedData(location, SystemWorldLocation.CODEC, SystemWorldLocation.LEGACY_CODEC).also { networkGroup.upstream.add(it, false) } - var destination by networkedData(location, SystemWorldLocation.CODEC, SystemWorldLocation.LEGACY_CODEC).also { networkGroup.upstream.add(it, false) } + var destination by networkedData(SystemWorldLocation.Transit, SystemWorldLocation.CODEC, SystemWorldLocation.LEGACY_CODEC).also { networkGroup.upstream.add(it, false) } var xPosition by networkedFloat().also { networkGroup.upstream.add(it); it.interpolator = Interpolator.Linear } var yPosition by networkedFloat().also { networkGroup.upstream.add(it); it.interpolator = Interpolator.Linear }