finish client & server communicate
finish database
This commit is contained in:
@@ -9,7 +9,7 @@ import io.netty.channel.SimpleChannelInboundHandler
|
||||
@Sharable
|
||||
object ClusterPacketHandler : SimpleChannelInboundHandler<BungeePacket>() {
|
||||
override fun channelRead0(ctx: ChannelHandlerContext, msg: BungeePacket) {
|
||||
debug("call event")
|
||||
// debug("call event")
|
||||
PacketReceiveEvent(ctx.channel(), msg).callEvent()
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,8 @@ class ClusterMsgCodec(private val current: NetworkRegistry.PacketDirection) : By
|
||||
}
|
||||
|
||||
override fun decode(ctx: ChannelHandlerContext, `in`: ByteBuf, out: MutableList<Any>) {
|
||||
debug("decode packet")
|
||||
val id = `in`.readInt()
|
||||
val packet = NetworkRegistry.getPacketByID(current, id)
|
||||
debug(packet.toString())
|
||||
packet.decode(`in`)
|
||||
out.add(packet)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cc.maxmc.msm.common.network.netty
|
||||
|
||||
import cc.maxmc.msm.common.network.BungeePacket
|
||||
import cc.maxmc.msm.common.network.packet.CPacketAPICallback
|
||||
import cc.maxmc.msm.common.network.packet.CPacketDebug
|
||||
import cc.maxmc.msm.common.network.packet.PPacketAPICall
|
||||
import cc.maxmc.msm.common.network.packet.PPacketDebug
|
||||
import cc.maxmc.msm.common.utils.debug
|
||||
import com.google.common.collect.HashBiMap
|
||||
@@ -11,9 +13,16 @@ object NetworkRegistry {
|
||||
private val childBoundMap = HashBiMap.create<Int, Class<out BungeePacket>>()
|
||||
|
||||
init {
|
||||
debug("init registry")
|
||||
registerPacket(PacketDirection.PARENT_BOUND, PPacketDebug::class.java)
|
||||
registerPacket(PacketDirection.PARENT_BOUND, PPacketAPICall.PPacketCallGetPlayerServer::class.java)
|
||||
registerPacket(PacketDirection.PARENT_BOUND, PPacketAPICall.PPacketCallContainPlayer::class.java)
|
||||
registerPacket(PacketDirection.PARENT_BOUND, PPacketAPICall.PPacketCallInformEnd::class.java)
|
||||
registerPacket(PacketDirection.PARENT_BOUND, PPacketAPICall.PPacketCallGetServer::class.java)
|
||||
registerPacket(PacketDirection.CHILD_BOUND, CPacketDebug::class.java)
|
||||
registerPacket(PacketDirection.CHILD_BOUND, CPacketAPICallback.CPacketCallbackGetPlayerServer::class.java)
|
||||
registerPacket(PacketDirection.CHILD_BOUND, CPacketAPICallback.CPacketCallbackContainPlayer::class.java)
|
||||
registerPacket(PacketDirection.CHILD_BOUND, CPacketAPICallback.CPacketCallbackInformEnd::class.java)
|
||||
registerPacket(PacketDirection.CHILD_BOUND, CPacketAPICallback.CPacketCallbackGetServer::class.java)
|
||||
}
|
||||
|
||||
private fun registerPacket(direction: PacketDirection, packet: Class<out BungeePacket>) {
|
||||
@@ -27,9 +36,7 @@ object NetworkRegistry {
|
||||
}
|
||||
|
||||
fun getPacketID(side: PacketDirection, packet: BungeePacket): Int {
|
||||
debug("start get PID")
|
||||
val map = if (side == PacketDirection.PARENT_BOUND) childBoundMap else parentBoundMap
|
||||
debug("map use $map")
|
||||
return map.inverse()[packet::class.java] ?: throw IllegalStateException("Packet does not in registry.")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package cc.maxmc.msm.common.network.packet
|
||||
|
||||
import cc.maxmc.msm.api.misc.ServerInfo
|
||||
import cc.maxmc.msm.common.network.BungeePacket
|
||||
import cc.maxmc.msm.common.utils.readServerInfo
|
||||
import cc.maxmc.msm.common.utils.writeServerInfo
|
||||
import io.netty.buffer.ByteBuf
|
||||
import net.md_5.bungee.protocol.DefinedPacket
|
||||
import java.util.*
|
||||
|
||||
sealed class CPacketAPICallback(
|
||||
var uid: UUID
|
||||
) : BungeePacket() {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
DefinedPacket.writeUUID(uid, buf)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
uid = DefinedPacket.readUUID(buf)
|
||||
}
|
||||
|
||||
class CPacketCallbackGetServer(
|
||||
var serverInfo: ServerInfo = ServerInfo(),
|
||||
uid: UUID = UUID.randomUUID()
|
||||
) : CPacketAPICallback(uid = uid) {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
buf.writeServerInfo(serverInfo)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
serverInfo = buf.readServerInfo()
|
||||
}
|
||||
}
|
||||
|
||||
class CPacketCallbackInformEnd(
|
||||
uid: UUID = UUID.randomUUID()
|
||||
) : CPacketAPICallback(uid = uid)
|
||||
|
||||
class CPacketCallbackGetPlayerServer(
|
||||
var serverInfo: ServerInfo,
|
||||
uid: UUID = UUID.randomUUID()
|
||||
) : CPacketAPICallback(uid = uid) {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
buf.writeServerInfo(serverInfo)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
serverInfo = buf.readServerInfo()
|
||||
}
|
||||
}
|
||||
|
||||
class CPacketCallbackContainPlayer(
|
||||
var value: Boolean,
|
||||
uid: UUID = UUID.randomUUID()
|
||||
) : CPacketAPICallback(uid = uid) {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
buf.writeBoolean(value)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
value = buf.readBoolean()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,9 @@ import cc.maxmc.msm.common.network.BungeePacket
|
||||
import io.netty.buffer.ByteBuf
|
||||
|
||||
data class CPacketDebug(
|
||||
var content: String
|
||||
var content: String = ""
|
||||
) : BungeePacket() {
|
||||
|
||||
constructor() : this("")
|
||||
|
||||
override fun encode(buf: ByteBuf) {
|
||||
val array = content.encodeToByteArray()
|
||||
buf.writeInt(array.size)
|
||||
@@ -17,6 +15,8 @@ data class CPacketDebug(
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
val size = buf.readInt()
|
||||
content = buf.readBytes(size).array().decodeToString()
|
||||
val encoded = ByteArray(size)
|
||||
buf.readBytes(encoded)
|
||||
content = encoded.decodeToString()
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package cc.maxmc.msm.common.network.packet
|
||||
|
||||
import cc.maxmc.msm.common.network.BungeePacket
|
||||
import cc.maxmc.msm.common.utils.debug
|
||||
import io.netty.buffer.ByteBuf
|
||||
|
||||
data class PPacketDebug(
|
||||
@@ -9,11 +8,9 @@ data class PPacketDebug(
|
||||
) : BungeePacket() {
|
||||
|
||||
override fun encode(buf: ByteBuf) {
|
||||
debug("start packet encode")
|
||||
val array = content.encodeToByteArray()
|
||||
buf.writeInt(array.size)
|
||||
buf.writeBytes(array)
|
||||
debug("end packet encode")
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
|
||||
@@ -9,8 +9,8 @@ fun log(msg: String) {
|
||||
|
||||
val debug = true
|
||||
|
||||
fun debug(msg: String) {
|
||||
if (debug) {
|
||||
log("§fDEBUG | §7$msg")
|
||||
}
|
||||
}
|
||||
//fun debug(msg: String) {
|
||||
// if (debug) {
|
||||
// log("§fDEBUG | §7$msg")
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user