init structure
init protocol
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
group = "cc.maxmc.msm.common"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
|
||||
compileOnly("net.md-5:bungeecord-proxy:1.19-R0.1-SNAPSHOT") {
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cc.maxmc.msm.common
|
||||
|
||||
import cc.maxmc.msm.common.network.ClusterMsgCodec
|
||||
import io.netty.channel.Channel
|
||||
import net.md_5.bungee.BungeeCord
|
||||
|
||||
object PacketInjector {
|
||||
private val bungee = BungeeCord.getInstance()
|
||||
private val field = bungee::class.java.getDeclaredField("listeners").also {
|
||||
it.isAccessible = true
|
||||
}
|
||||
|
||||
fun inject() {
|
||||
val channel = getChannel()
|
||||
channel.pipeline().addFirst("ClusterMsgCodec", ClusterMsgCodec)
|
||||
}
|
||||
|
||||
private fun getChannel(): Channel {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val channelList = field.get(bungee) as Collection<Channel>
|
||||
while (true) {
|
||||
return channelList.firstOrNull() ?: continue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cc.maxmc.msm.common.network
|
||||
|
||||
import io.netty.buffer.ByteBuf
|
||||
|
||||
interface BungeePacket: Cloneable {
|
||||
fun encode(buf: ByteBuf)
|
||||
|
||||
fun decode(buf: ByteBuf)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cc.maxmc.msm.common.network
|
||||
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.channel.ChannelHandlerContext
|
||||
import io.netty.handler.codec.ByteToMessageCodec
|
||||
|
||||
object ClusterMsgCodec : ByteToMessageCodec<BungeePacket>() {
|
||||
override fun encode(ctx: ChannelHandlerContext, msg: BungeePacket, out: ByteBuf) {
|
||||
msg.encode(out)
|
||||
}
|
||||
|
||||
override fun decode(ctx: ChannelHandlerContext, `in`: ByteBuf, out: MutableList<Any>) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cc.maxmc.msm.common.network
|
||||
|
||||
import com.google.common.collect.HashBiMap
|
||||
|
||||
object NetworkRegistry {
|
||||
val parentBoundMap = HashBiMap.create<Int, BungeePacket>()
|
||||
val childBoundMap = HashBiMap.create<Int, BungeePacket>()
|
||||
|
||||
fun registerPacket(packet: BungeePacket, direction: PacketDirection) {
|
||||
if (direction == PacketDirection.ParentBound) {
|
||||
parentBoundMap
|
||||
} else {
|
||||
childBoundMap
|
||||
}.let {
|
||||
it[it.size] = packet
|
||||
}
|
||||
}
|
||||
|
||||
enum class PacketDirection {
|
||||
ParentBound,
|
||||
ChildBound;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user