Move stuff around
This commit is contained in:
parent
8e1cb8ac2a
commit
075b8259be
@ -62,7 +62,8 @@ import kotlin.collections.ArrayList
|
||||
|
||||
object Starbound : ISBFileLocator {
|
||||
const val ENGINE_VERSION = "0.0.1"
|
||||
const val PROTOCOL_VERSION = 1
|
||||
const val NATIVE_PROTOCOL_VERSION = 748
|
||||
const val LEGACY_PROTOCOL_VERSION = 747
|
||||
const val TICK_TIME_ADVANCE = 1.0 / 60.0
|
||||
const val TICK_TIME_ADVANCE_NANOS = (TICK_TIME_ADVANCE * 1_000_000_000L).toLong()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ru.dbotthepony.kstarbound.client.network
|
||||
package ru.dbotthepony.kstarbound.client
|
||||
|
||||
import io.netty.bootstrap.Bootstrap
|
||||
import io.netty.channel.Channel
|
||||
@ -8,7 +8,6 @@ import io.netty.channel.local.LocalAddress
|
||||
import io.netty.channel.local.LocalChannel
|
||||
import io.netty.channel.socket.nio.NioSocketChannel
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.client.StarboundClient
|
||||
import ru.dbotthepony.kstarbound.network.Connection
|
||||
import ru.dbotthepony.kstarbound.network.ConnectionSide
|
||||
import ru.dbotthepony.kstarbound.network.ConnectionType
|
@ -54,7 +54,6 @@ import ru.dbotthepony.kstarbound.client.gl.shader.UberShader
|
||||
import ru.dbotthepony.kstarbound.client.gl.vertex.GeometryType
|
||||
import ru.dbotthepony.kstarbound.client.gl.vertex.VertexBuilder
|
||||
import ru.dbotthepony.kstarbound.client.input.UserInput
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.server.network.packets.TrackedPositionPacket
|
||||
import ru.dbotthepony.kstarbound.client.render.Camera
|
||||
import ru.dbotthepony.kstarbound.client.render.Font
|
||||
@ -84,7 +83,6 @@ import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.ForkJoinPool
|
||||
import java.util.concurrent.ForkJoinWorkerThread
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.locks.LockSupport
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.IntConsumer
|
||||
@ -914,6 +912,7 @@ class StarboundClient private constructor(val clientID: Int) : Closeable {
|
||||
if (world != null && Starbound.initialized)
|
||||
world.think()
|
||||
|
||||
activeConnection?.flush()
|
||||
return true
|
||||
}
|
||||
|
||||
@ -946,9 +945,7 @@ class StarboundClient private constructor(val clientID: Int) : Closeable {
|
||||
|
||||
val activeConnection = activeConnection
|
||||
|
||||
if (activeConnection != null) {
|
||||
activeConnection.send(TrackedPositionPacket(camera.pos))
|
||||
}
|
||||
activeConnection?.send(TrackedPositionPacket(camera.pos))
|
||||
|
||||
uberShaderPrograms.forValidRefs { it.viewMatrix = viewportMatrixScreen }
|
||||
fontShaderPrograms.forValidRefs { it.viewMatrix = viewportMatrixScreen }
|
||||
@ -972,6 +969,8 @@ class StarboundClient private constructor(val clientID: Int) : Closeable {
|
||||
|
||||
executeQueuedTasks()
|
||||
|
||||
activeConnection?.flush()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.client.network.packets
|
||||
|
||||
import ru.dbotthepony.kommons.io.readCollection
|
||||
import ru.dbotthepony.kommons.io.writeCollection
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
import ru.dbotthepony.kstarbound.io.readChunkPos
|
||||
import ru.dbotthepony.kstarbound.io.writeVec2i
|
||||
|
@ -1,13 +1,12 @@
|
||||
package ru.dbotthepony.kstarbound.client.network.packets
|
||||
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
import ru.dbotthepony.kstarbound.io.readChunkPos
|
||||
import ru.dbotthepony.kstarbound.io.writeVec2i
|
||||
import ru.dbotthepony.kstarbound.world.ChunkPos
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
class ForgetChunkPacket(val pos: ChunkPos) : IClientPacket {
|
||||
constructor(stream: DataInputStream) : this(stream.readChunkPos())
|
||||
|
@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.client.network.packets
|
||||
|
||||
import ru.dbotthepony.kommons.io.readUUID
|
||||
import ru.dbotthepony.kommons.io.writeUUID
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
|
@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.client.network.packets
|
||||
|
||||
import ru.dbotthepony.kommons.io.readUUID
|
||||
import ru.dbotthepony.kommons.io.writeUUID
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.world.ClientWorld
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
import ru.dbotthepony.kstarbound.world.World
|
||||
|
@ -1,6 +1,6 @@
|
||||
package ru.dbotthepony.kstarbound.client.network.packets
|
||||
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
import java.io.DataOutputStream
|
||||
|
||||
|
@ -3,7 +3,7 @@ package ru.dbotthepony.kstarbound.client.network.packets
|
||||
import com.google.gson.JsonObject
|
||||
import ru.dbotthepony.kommons.io.readUUID
|
||||
import ru.dbotthepony.kommons.io.writeUUID
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.json.readJsonObject
|
||||
import ru.dbotthepony.kstarbound.json.writeJsonObject
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
|
@ -2,8 +2,8 @@ package ru.dbotthepony.kstarbound.network
|
||||
|
||||
import io.netty.buffer.ByteBuf
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrayList
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.server.ServerConnection
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import kotlin.reflect.KClass
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder
|
||||
import io.netty.channel.Channel
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter
|
||||
import io.netty.channel.ChannelOption
|
||||
import io.netty.channel.nio.NioEventLoopGroup
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.network.packets.DisconnectPacket
|
||||
@ -36,6 +37,7 @@ abstract class Connection(val side: ConnectionSide, val type: ConnectionType, va
|
||||
|
||||
fun bind(channel: Channel) {
|
||||
check(this.channel == null) { "Already having channel bound" }
|
||||
channel.config().setOption(ChannelOption.TCP_NODELAY, true)
|
||||
this.channel = channel
|
||||
|
||||
if (side == ConnectionSide.SERVER)
|
||||
@ -65,20 +67,20 @@ abstract class Connection(val side: ConnectionSide, val type: ConnectionType, va
|
||||
val channel = channel ?: throw IllegalStateException("No network channel is bound")
|
||||
|
||||
if (type == ConnectionType.NETWORK) {
|
||||
channel.pipeline().addLast(PacketRegistry.Inbound(side))
|
||||
channel.pipeline().addLast(PacketRegistry.NATIVE.Inbound(side))
|
||||
} else {
|
||||
channel.pipeline().addLast(PacketRegistry.InboundValidator(side))
|
||||
channel.pipeline().addLast(PacketRegistry.NATIVE.InboundValidator(side))
|
||||
}
|
||||
|
||||
channel.pipeline().addLast(this)
|
||||
|
||||
if (type == ConnectionType.NETWORK) {
|
||||
channel.pipeline().addLast(PacketRegistry.Outbound(side))
|
||||
channel.pipeline().addLast(PacketRegistry.NATIVE.Outbound(side))
|
||||
|
||||
channel.pipeline().addFirst(DatagramEncoder)
|
||||
channel.pipeline().addFirst(DatagramDecoder())
|
||||
} else {
|
||||
channel.pipeline().addLast(PacketRegistry.OutboundValidator(side))
|
||||
channel.pipeline().addLast(PacketRegistry.NATIVE.OutboundValidator(side))
|
||||
}
|
||||
|
||||
inGame()
|
||||
@ -87,12 +89,12 @@ abstract class Connection(val side: ConnectionSide, val type: ConnectionType, va
|
||||
fun send(packet: IPacket) {
|
||||
val channel = channel ?: throw IllegalStateException("No network channel is bound")
|
||||
channel.write(packet)
|
||||
channel.flush()
|
||||
}
|
||||
|
||||
fun sendNoFlush(packet: IPacket) {
|
||||
fun sendAndFlush(packet: IPacket) {
|
||||
val channel = channel ?: throw IllegalStateException("No network channel is bound")
|
||||
channel.write(packet)
|
||||
channel.flush()
|
||||
}
|
||||
|
||||
fun flush() {
|
||||
|
@ -21,7 +21,7 @@ import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
object PacketRegistry {
|
||||
class PacketRegistry {
|
||||
private val packets = ArrayList<Type<*>>()
|
||||
private val clazz2Type = Reference2ObjectOpenHashMap<KClass<*>, Type<*>>()
|
||||
|
||||
@ -47,7 +47,7 @@ object PacketRegistry {
|
||||
return add(T::class, reader, direction)
|
||||
}
|
||||
|
||||
class Inbound(val side: ConnectionSide) : ChannelInboundHandlerAdapter() {
|
||||
inner class Inbound(val side: ConnectionSide) : ChannelInboundHandlerAdapter() {
|
||||
override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
|
||||
if (msg is ByteBuf) {
|
||||
val packetType = msg.readUnsignedByte().toInt()
|
||||
@ -74,7 +74,7 @@ object PacketRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
class InboundValidator(val side: ConnectionSide) : ChannelInboundHandlerAdapter() {
|
||||
inner class InboundValidator(val side: ConnectionSide) : ChannelInboundHandlerAdapter() {
|
||||
override fun channelRead(ctx: ChannelHandlerContext, msg: Any) {
|
||||
val type = clazz2Type[msg::class]
|
||||
|
||||
@ -92,7 +92,7 @@ object PacketRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
class Outbound(val side: ConnectionSide) : ChannelOutboundHandlerAdapter() {
|
||||
inner class Outbound(val side: ConnectionSide) : ChannelOutboundHandlerAdapter() {
|
||||
override fun write(ctx: ChannelHandlerContext, msg: Any, promise: ChannelPromise) {
|
||||
val type = clazz2Type[msg::class]
|
||||
|
||||
@ -109,7 +109,7 @@ object PacketRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
class OutboundValidator(val side: ConnectionSide) : ChannelOutboundHandlerAdapter() {
|
||||
inner class OutboundValidator(val side: ConnectionSide) : ChannelOutboundHandlerAdapter() {
|
||||
override fun write(ctx: ChannelHandlerContext, msg: Any, promise: ChannelPromise) {
|
||||
val type = clazz2Type[msg::class]
|
||||
|
||||
@ -123,16 +123,22 @@ object PacketRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
private val LOGGER = LogManager.getLogger()
|
||||
companion object {
|
||||
private val LOGGER = LogManager.getLogger()
|
||||
|
||||
init {
|
||||
add(::DisconnectPacket)
|
||||
add(::JoinWorldPacket)
|
||||
add(::ChunkCellsPacket)
|
||||
add(::ForgetChunkPacket)
|
||||
add(::TrackedPositionPacket)
|
||||
add(::TrackedSizePacket)
|
||||
add(::SpawnWorldObjectPacket)
|
||||
add(::ForgetEntityPacket)
|
||||
val NATIVE = PacketRegistry()
|
||||
val LEGACY = PacketRegistry()
|
||||
val HANDSHAKE = PacketRegistry()
|
||||
|
||||
init {
|
||||
NATIVE.add(::DisconnectPacket)
|
||||
NATIVE.add(::JoinWorldPacket)
|
||||
NATIVE.add(::ChunkCellsPacket)
|
||||
NATIVE.add(::ForgetChunkPacket)
|
||||
NATIVE.add(::TrackedPositionPacket)
|
||||
NATIVE.add(::TrackedSizePacket)
|
||||
NATIVE.add(::SpawnWorldObjectPacket)
|
||||
NATIVE.add(::ForgetEntityPacket)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter
|
||||
import ru.dbotthepony.kommons.io.readUUID
|
||||
import ru.dbotthepony.kommons.io.writeUUID
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.client.network.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.client.ClientConnection
|
||||
import ru.dbotthepony.kstarbound.network.Connection
|
||||
import ru.dbotthepony.kstarbound.network.IClientPacket
|
||||
import ru.dbotthepony.kstarbound.network.IConnectionDetails
|
||||
@ -17,7 +17,7 @@ import ru.dbotthepony.kstarbound.network.IPacket
|
||||
import ru.dbotthepony.kstarbound.network.IServerPacket
|
||||
import ru.dbotthepony.kstarbound.network.readUTF
|
||||
import ru.dbotthepony.kstarbound.network.writeUTF
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.server.ServerConnection
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import java.util.UUID
|
||||
@ -64,7 +64,7 @@ class HelloListener(val connection: Connection, private val channel: Channel) :
|
||||
fun sendHello(uuid: UUID, username: String = "", password: String = ""): HelloListener {
|
||||
val buf = channel.config().allocator.buffer()
|
||||
buf.writeUTF("KSTARBOUND HELLO")
|
||||
HelloPacket(Starbound.PROTOCOL_VERSION, Starbound.ENGINE_VERSION, username, password, uuid).write(DataOutputStream(ByteBufOutputStream(buf)))
|
||||
HelloPacket(Starbound.NATIVE_PROTOCOL_VERSION, Starbound.ENGINE_VERSION, username, password, uuid).write(DataOutputStream(ByteBufOutputStream(buf)))
|
||||
channel.write(buf)
|
||||
channel.flush()
|
||||
return this
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ru.dbotthepony.kstarbound.server.network
|
||||
package ru.dbotthepony.kstarbound.server
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap
|
||||
import io.netty.channel.Channel
|
||||
@ -9,9 +9,7 @@ import io.netty.channel.local.LocalServerChannel
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import ru.dbotthepony.kstarbound.network.Connection
|
||||
import ru.dbotthepony.kstarbound.network.ConnectionSide
|
||||
import ru.dbotthepony.kstarbound.network.ConnectionType
|
||||
import ru.dbotthepony.kstarbound.server.StarboundServer
|
||||
import java.io.Closeable
|
||||
import java.net.SocketAddress
|
||||
import java.util.*
|
@ -1,7 +1,6 @@
|
||||
package ru.dbotthepony.kstarbound.server.network
|
||||
package ru.dbotthepony.kstarbound.server
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
|
||||
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
@ -16,7 +15,6 @@ import ru.dbotthepony.kstarbound.network.ConnectionSide
|
||||
import ru.dbotthepony.kstarbound.network.ConnectionType
|
||||
import ru.dbotthepony.kstarbound.network.IServerPacket
|
||||
import ru.dbotthepony.kstarbound.network.packets.HelloPacket
|
||||
import ru.dbotthepony.kstarbound.server.StarboundServer
|
||||
import ru.dbotthepony.kstarbound.server.world.ServerWorld
|
||||
import ru.dbotthepony.kstarbound.world.ChunkPos
|
||||
import ru.dbotthepony.kstarbound.world.IChunkListener
|
||||
@ -117,6 +115,7 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn
|
||||
}
|
||||
|
||||
fun tick() {
|
||||
channel?.flush()
|
||||
val world = world
|
||||
|
||||
if (world == null) {
|
@ -1,9 +1,6 @@
|
||||
package ru.dbotthepony.kstarbound.server
|
||||
|
||||
import ru.dbotthepony.kommons.util.MailboxExecutorService
|
||||
import ru.dbotthepony.kstarbound.client.network.packets.JoinWorldPacket
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerChannels
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.server.world.ServerWorld
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
|
@ -2,7 +2,7 @@ package ru.dbotthepony.kstarbound.server.network.packets
|
||||
|
||||
import ru.dbotthepony.kommons.vector.Vector2d
|
||||
import ru.dbotthepony.kstarbound.network.IServerPacket
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.server.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.io.readVec2d
|
||||
import ru.dbotthepony.kstarbound.io.writeVec2d
|
||||
import java.io.DataInputStream
|
||||
|
@ -1,7 +1,7 @@
|
||||
package ru.dbotthepony.kstarbound.server.network.packets
|
||||
|
||||
import ru.dbotthepony.kstarbound.network.IServerPacket
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.server.ServerConnection
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
|
||||
|
@ -3,20 +3,15 @@ package ru.dbotthepony.kstarbound.server.world
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectFunction
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap
|
||||
import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
|
||||
import ru.dbotthepony.kommons.collect.chainOptionalFutures
|
||||
import ru.dbotthepony.kommons.util.KOptional
|
||||
import ru.dbotthepony.kstarbound.Starbound
|
||||
import ru.dbotthepony.kstarbound.client.network.packets.JoinWorldPacket
|
||||
import ru.dbotthepony.kstarbound.server.StarboundServer
|
||||
import ru.dbotthepony.kstarbound.server.network.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.server.ServerConnection
|
||||
import ru.dbotthepony.kstarbound.util.ExecutionSpinner
|
||||
import ru.dbotthepony.kstarbound.world.ChunkPos
|
||||
import ru.dbotthepony.kstarbound.world.ICellChangeListener
|
||||
import ru.dbotthepony.kstarbound.world.IChunkListener
|
||||
import ru.dbotthepony.kstarbound.world.IEntityAdditionListener
|
||||
import ru.dbotthepony.kstarbound.world.IEntityRemovalListener
|
||||
import ru.dbotthepony.kstarbound.world.World
|
||||
import ru.dbotthepony.kstarbound.world.WorldGeometry
|
||||
import ru.dbotthepony.kstarbound.world.api.ImmutableCell
|
||||
@ -48,7 +43,7 @@ class ServerWorld(
|
||||
internalPlayers.add(player)
|
||||
player.world?.removePlayer(player)
|
||||
player.world = this
|
||||
player.send(JoinWorldPacket(this))
|
||||
player.sendAndFlush(JoinWorldPacket(this))
|
||||
return true
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user