sync with remote

This commit is contained in:
2023-03-19 12:56:58 +08:00
parent 0ee45b6179
commit 93ddf5994f
30 changed files with 201 additions and 20 deletions
+29
View File
@@ -0,0 +1,29 @@
plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow")
}
group = "cc.maxmc.msm.child"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
implementation(kotlin("stdlib"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-Beta")
implementation(project(":common"))
implementation("io.netty:netty-all:4.1.90.Final")
@Suppress("VulnerableLibrariesLocal")
implementation("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
}
tasks.shadowJar {
archiveClassifier.set(null as? String?)
relocate("kotlin", "cc.maxmc.msm.lib.kotlin")
}
tasks.build {
dependsOn(tasks.shadowJar)
}
@@ -0,0 +1,28 @@
package cc.maxmc.msm.child
import cc.maxmc.msm.child.command.Send
import cc.maxmc.msm.child.netty.NetClient
import cc.maxmc.msm.child.settings.Settings
import cc.maxmc.msm.common.network.netty.NetworkRegistry
import net.md_5.bungee.api.ProxyServer
import net.md_5.bungee.api.plugin.Plugin
class MultiServerMan : Plugin() {
init {
instance = this
}
override fun onEnable() {
ProxyServer.getInstance().pluginManager.registerCommand(this, Send)
NetworkRegistry
NetClient.start(Settings.Parent.address, Settings.Parent.port)
}
override fun onDisable() {
NetClient.shutdown()
}
companion object {
lateinit var instance: MultiServerMan
}
}
@@ -0,0 +1,27 @@
package cc.maxmc.msm.child.api
import cc.maxmc.msm.api.MultiServerManAPI
import cc.maxmc.msm.api.misc.ServerInfo
import net.md_5.bungee.api.connection.ProxiedPlayer
import java.util.UUID
import java.util.concurrent.Future
object APIImpl: MultiServerManAPI {
val apiCallCache = HashMap<UUID, Future<Any>>()
override fun getServer(type: String, players: MutableList<ProxiedPlayer>): ServerInfo {
TODO("Not yet implemented")
}
override fun informEnd(id: Int) {
TODO("Not yet implemented")
}
override fun getPlayerServer(player: ProxiedPlayer): ServerInfo {
TODO("Not yet implemented")
}
override fun containPlayer(player: ProxiedPlayer): Boolean {
TODO("Not yet implemented")
}
}
@@ -0,0 +1,16 @@
package cc.maxmc.msm.child.command
import cc.maxmc.msm.child.netty.NetClient
import cc.maxmc.msm.common.network.packet.PPacketDebug
import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.chat.TextComponent
import net.md_5.bungee.api.plugin.Command
object Send : Command("debugP") {
override fun execute(sender: CommandSender, args: Array<out String>) {
val content = args.joinToString(" ")
val packet = PPacketDebug(content)
NetClient.sendPacket(packet)
sender.sendMessage(TextComponent("Success."))
}
}
@@ -0,0 +1,37 @@
package cc.maxmc.msm.child.netty
import cc.maxmc.msm.common.network.BungeePacket
import cc.maxmc.msm.common.network.netty.NetworkRegistry
import cc.maxmc.msm.common.utils.pipelineInit
import io.netty.bootstrap.Bootstrap
import io.netty.channel.Channel
import io.netty.channel.ChannelFutureListener
import io.netty.channel.ChannelOption
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioSocketChannel
object NetClient {
private val loop = NioEventLoopGroup()
private lateinit var channel: Channel
fun start(address: String, port: Int) {
val future = Bootstrap()
.channel(NioSocketChannel::class.java)
.group(loop)
.handler(pipelineInit(NetworkRegistry.PacketDirection.CHILD_BOUND))
.option(ChannelOption.TCP_NODELAY, true)
.remoteAddress(address, port)
.connect().addListener(ChannelFutureListener {
println("§a| §7成功连接到集群的主节点. (${it.channel().remoteAddress()})")
})
channel = future.channel()
}
fun sendPacket(packet: BungeePacket) {
channel.writeAndFlush(packet)
}
fun shutdown() {
loop.shutdownGracefully().sync()
}
}
@@ -0,0 +1,15 @@
package cc.maxmc.msm.child.settings
import cc.maxmc.msm.child.settings.SettingsReader.config
object Settings {
val name
get() = config
object Parent {
val address: String
get() = config.getString("parent.address", "localhost")
val port: Int
get() = config.getInt("parent.port", 23333)
}
}
@@ -0,0 +1,25 @@
package cc.maxmc.msm.child.settings
import cc.maxmc.msm.child.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())
}
}
+3
View File
@@ -0,0 +1,3 @@
name: MultiServerMan-Child
main: cc.maxmc.msm.child.MultiServerMan
author: TONY_All
+3
View File
@@ -0,0 +1,3 @@
parent:
address: 127.0.0.1
port: 23333