sync with remote
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("com.github.johnrengelman.shadow")
|
||||
}
|
||||
|
||||
group = "cc.maxmc.msm.parent"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
implementation(project(":common"))
|
||||
@Suppress("VulnerableLibrariesLocal")
|
||||
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
relocate("kotlin", "cc.maxmc.msm.lib.kotlin")
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(tasks.shadowJar)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cc.maxmc.msm.parent
|
||||
|
||||
import cc.maxmc.msm.parent.listener.PacketListener
|
||||
import cc.maxmc.msm.parent.netty.NetManager
|
||||
import net.md_5.bungee.api.ProxyServer
|
||||
import net.md_5.bungee.api.plugin.Plugin
|
||||
|
||||
class MultiServerMan : Plugin() {
|
||||
|
||||
override fun onEnable() {
|
||||
instance = this
|
||||
ProxyServer.getInstance().pluginManager.registerListener(this, PacketListener)
|
||||
NetManager.startServer()
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
NetManager.shutdownServer()
|
||||
}
|
||||
|
||||
companion object {
|
||||
lateinit var instance: MultiServerMan
|
||||
private set
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cc.maxmc.msm.parent.listener
|
||||
|
||||
import cc.maxmc.msm.common.event.PacketReceiveEvent
|
||||
import cc.maxmc.msm.common.network.packet.CPacketDebug
|
||||
import cc.maxmc.msm.common.network.packet.PPacketDebug
|
||||
import cc.maxmc.msm.common.utils.log
|
||||
import net.md_5.bungee.api.plugin.Listener
|
||||
import net.md_5.bungee.event.EventHandler
|
||||
|
||||
object PacketListener : Listener {
|
||||
@EventHandler
|
||||
fun onPacket(evt: PacketReceiveEvent) {
|
||||
val packet = evt.packet
|
||||
if (packet !is PPacketDebug) {
|
||||
return
|
||||
}
|
||||
log("§fDEBUG | §7收到: \"${packet.content}\"")
|
||||
evt.channel.writeAndFlush(CPacketDebug("(${evt.channel.localAddress()}) - ${packet.content}"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package cc.maxmc.msm.parent.manager
|
||||
|
||||
import cc.maxmc.msm.parent.misc.ChildBungee
|
||||
|
||||
object ChildManager {
|
||||
val children = ArrayList<ChildBungee>()
|
||||
|
||||
fun registerChild(child: ChildBungee) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package cc.maxmc.msm.parent.misc
|
||||
|
||||
import io.netty.channel.Channel
|
||||
|
||||
data class ChildBungee(val channel: Channel)
|
||||
@@ -0,0 +1,32 @@
|
||||
package cc.maxmc.msm.parent.netty
|
||||
|
||||
import cc.maxmc.msm.common.network.netty.NetworkRegistry
|
||||
import cc.maxmc.msm.common.utils.log
|
||||
import cc.maxmc.msm.common.utils.pipelineInit
|
||||
import cc.maxmc.msm.parent.settings.Settings
|
||||
import io.netty.bootstrap.ServerBootstrap
|
||||
import io.netty.channel.ChannelFutureListener
|
||||
import io.netty.channel.nio.NioEventLoopGroup
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel
|
||||
|
||||
object NetManager {
|
||||
private val parentGroup = NioEventLoopGroup()
|
||||
private val childGroup = NioEventLoopGroup()
|
||||
|
||||
fun startServer() {
|
||||
ServerBootstrap()
|
||||
.channel(NioServerSocketChannel::class.java)
|
||||
.group(parentGroup, childGroup)
|
||||
.childHandler(pipelineInit(NetworkRegistry.PacketDirection.PARENT_BOUND))
|
||||
.bind(Settings.serverPort)
|
||||
.addListener(ChannelFutureListener {
|
||||
log("§a| §7集群主服务端启动成功. ${it.channel().localAddress()}")
|
||||
})
|
||||
}
|
||||
|
||||
fun shutdownServer() {
|
||||
parentGroup.shutdownGracefully().sync()
|
||||
childGroup.shutdownGracefully().sync()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cc.maxmc.msm.parent.settings
|
||||
|
||||
import cc.maxmc.msm.parent.settings.SettingsReader.config
|
||||
|
||||
object Settings {
|
||||
val name
|
||||
get() = config
|
||||
val serverPort
|
||||
get() = config.getInt("server_port", 25566)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cc.maxmc.msm.parent.settings
|
||||
|
||||
import cc.maxmc.msm.parent.MultiServerMan
|
||||
import net.md_5.bungee.api.ProxyServer
|
||||
import net.md_5.bungee.api.chat.TextComponent
|
||||
import net.md_5.bungee.config.Configuration
|
||||
import net.md_5.bungee.config.ConfigurationProvider
|
||||
import net.md_5.bungee.config.YamlConfiguration
|
||||
import kotlin.io.path.*
|
||||
|
||||
object SettingsReader {
|
||||
private val file = MultiServerMan.instance.dataFolder.toPath().resolve("settings.yml")
|
||||
val config: Configuration
|
||||
|
||||
init {
|
||||
if (!file.exists()) {
|
||||
MultiServerMan.instance.dataFolder.toPath().createDirectories()
|
||||
val stream = MultiServerMan.instance.getResourceAsStream("settings.yml")
|
||||
file.createFile()
|
||||
stream.copyTo(file.outputStream())
|
||||
ProxyServer.getInstance().console.sendMessage(TextComponent("§b| §7配置文件不存在,正在创建配置文件。"))
|
||||
}
|
||||
config = ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(file.inputStream())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
name: MultiServerMan-Parent
|
||||
main: cc.maxmc.msm.parent.MultiServerMan
|
||||
author: TONY_All
|
||||
@@ -0,0 +1,3 @@
|
||||
parent:
|
||||
address: 127.0.0.1
|
||||
port: 23333
|
||||
Reference in New Issue
Block a user