diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerChannels.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerChannels.kt index a2e23bd6..1d0af071 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerChannels.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerChannels.kt @@ -49,6 +49,10 @@ class ServerChannels(val server: StarboundServer) : Closeable { return connections.firstOrNull { it.connectionID == id } } + fun connectionByUUID(id: UUID): ServerConnection? { + return connections.firstOrNull { it.uuid == id } + } + private fun cycleConnectionID(): Int { val v = ++nextConnectionID and MAX_PLAYERS diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt index 28b77415..a047ef33 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt @@ -17,6 +17,7 @@ import ru.dbotthepony.kommons.vector.Vector3i import ru.dbotthepony.kstarbound.Globals import ru.dbotthepony.kstarbound.defs.WarpAction import ru.dbotthepony.kstarbound.defs.WarpAlias +import ru.dbotthepony.kstarbound.defs.WarpMode import ru.dbotthepony.kstarbound.defs.WorldID import ru.dbotthepony.kstarbound.defs.world.CelestialParameters import ru.dbotthepony.kstarbound.defs.world.VisitableWorldParameters @@ -167,6 +168,16 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn try { world.acceptClient(this, request).await() + + if (resolve is WorldID.ShipWorld) { + val connection = server.channels.connectionByUUID(resolve.uuid) + + if (connection != null) { + orbitalWarpAction = connection.currentOrbitalWarpAction + } + } else { + orbitalWarpAction = KOptional() + } } catch (err: Throwable) { send(PlayerWarpResultPacket(false, request, false)) @@ -186,6 +197,8 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn flyShipQueue.trySend(system to location) } + private var currentOrbitalWarpAction = KOptional>() + // coordinates ship flight private suspend fun shipFlightEventLoop() { shipWorld.sky.startFlying(true, true) @@ -194,7 +207,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn LOGGER.info("Finding starter world for ${alias()}...") val params = Globals.universeServer.findStarterWorldParameters - // visit all since sparsingly trying to find specific world is not healthy performance wise + // visit all since randomly trying to find specific world is not healthy performance wise val found = server.universe.findRandomWorld(params.tries, params.range, visitAll = true, predicate = { if (++visited % 600 == 0) { LOGGER.info("Still finding starter world for ${alias()}...") @@ -264,7 +277,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn currentFlightJob = scope.launch { val coords = flight.await() val action = coords.orbitalAction(world) - orbitalWarpAction = action + currentOrbitalWarpAction = action for (client in shipWorld.clients) { client.client.orbitalWarpAction = action @@ -277,7 +290,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn } } - orbitalWarpAction = KOptional() + currentOrbitalWarpAction = KOptional() for (client in shipWorld.clients) { client.client.orbitalWarpAction = KOptional() @@ -300,7 +313,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn val newSystem = server.loadSystemWorld(system) shipCoordinate = UniversePos(system) - orbitalWarpAction = KOptional() + currentOrbitalWarpAction = KOptional() for (client in shipWorld.clients) { client.client.orbitalWarpAction = KOptional()