sync with remote
This commit is contained in:
parent
0ee45b6179
commit
93ddf5994f
16
README.md
16
README.md
|
|
@ -38,8 +38,8 @@
|
|||
- Int类型的对局id
|
||||
|
||||
- 参数列表:
|
||||
- `(List<Player> players)`
|
||||
-
|
||||
- `List<Player> players`
|
||||
- `String type`
|
||||
|
||||
### `func informEnd()`
|
||||
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
- 返回值:无
|
||||
|
||||
- 参数列表:
|
||||
- `(int id)`
|
||||
- `int id`
|
||||
|
||||
### `func getPlayerServer()`
|
||||
|
||||
|
|
@ -59,7 +59,7 @@
|
|||
- Int 类型的对局id,未在对局中返回-1
|
||||
|
||||
- 参数列表:
|
||||
- `(Player player)`
|
||||
- `Player player`
|
||||
|
||||
### `func containPlayer()`
|
||||
|
||||
|
|
@ -67,15 +67,15 @@
|
|||
- 返回值:
|
||||
- bool
|
||||
- 参数列表:
|
||||
- `(Player player)`
|
||||
- `Player player`
|
||||
|
||||
## 数据库结构
|
||||
|
||||
- `match`
|
||||
|
||||
| id(int) | start(datetime) | end(datetime) | players(text) |
|
||||
| ------- | --------------- | ------------- | ------------------------------------ |
|
||||
| 1 | 1678554776 | 1678554784 | TONY_All,Sanseyooyea,PlayerA,PlayerB |
|
||||
| id(int) | start(datetime) | end(datetime) | players(text) | type(varchar) |
|
||||
| ------- | --------------- | ------------- | ------------------------------------ | ------------- |
|
||||
| 1 | 1678554776 | 1678554784 | TONY_All,Sanseyooyea,PlayerA,PlayerB | bedwars |
|
||||
## API 使用
|
||||
|
||||
依赖:
|
||||
|
|
|
|||
|
|
@ -13,4 +13,12 @@ dependencies {
|
|||
implementation(kotlin("stdlib"))
|
||||
@Suppress("VulnerableLibrariesLocal")
|
||||
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
val release by getting(MavenPublication::class) {
|
||||
artifact(tasks.jar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,17 +2,20 @@ package cc.maxmc.msm.api;
|
|||
|
||||
import cc.maxmc.msm.api.misc.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused") // API
|
||||
public interface MultiServerManAPI {
|
||||
ServerInfo getServer(String type, List<ProxiedPlayer> players);
|
||||
@NotNull
|
||||
ServerInfo getServer(@NotNull String type, @NotNull List<ProxiedPlayer> players);
|
||||
|
||||
void informEnd(int id);
|
||||
|
||||
ServerInfo getPlayerServer(ProxiedPlayer player);
|
||||
@NotNull
|
||||
ServerInfo getPlayerServer(@NotNull ProxiedPlayer player);
|
||||
|
||||
Boolean containPlayer(ProxiedPlayer player);
|
||||
Boolean containPlayer(@NotNull ProxiedPlayer player);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package cc.maxmc.msm.api.misc
|
||||
|
||||
enum class EnumAPI {
|
||||
GET_SERVER,
|
||||
INFORM_END,
|
||||
GET_PLAYER_SERVER,
|
||||
CONTAIN_PLAYER;
|
||||
}
|
||||
|
|
@ -9,6 +9,11 @@ public class ServerInfo {
|
|||
private final HostAndPort server;
|
||||
private final int id;
|
||||
|
||||
public ServerInfo() {
|
||||
server = HostAndPort.fromString("127.0.0.1");
|
||||
id = -1;
|
||||
}
|
||||
|
||||
public ServerInfo(@Nullable HostAndPort server, int id) {
|
||||
this.server = server;
|
||||
this.id = id;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,31 @@
|
|||
plugins {
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
group = "cc.maxmc.msm"
|
||||
version = "1.0-SNAPSHOT"
|
||||
version = "1.0"
|
||||
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "maven-publish")
|
||||
if (name == "common") {
|
||||
return@subprojects
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven("https://repo.vip.maxmc.cc:30443/releases") {
|
||||
name = "mrepo"
|
||||
credentials(PasswordCredentials::class)
|
||||
}
|
||||
}
|
||||
|
||||
publications {
|
||||
create<MavenPublication>("release") {
|
||||
version = rootProject.version.toString()
|
||||
artifactId = "${rootProject.name}-${project.name}"
|
||||
println(project.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
implementation(project(":api"))
|
||||
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")
|
||||
|
|
@ -20,6 +20,7 @@ dependencies {
|
|||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
archiveClassifier.set(null as? String?)
|
||||
relocate("kotlin", "cc.maxmc.msm.lib.kotlin")
|
||||
}
|
||||
|
||||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
@ -12,8 +12,7 @@ import io.netty.channel.socket.nio.NioSocketChannel
|
|||
|
||||
object NetClient {
|
||||
private val loop = NioEventLoopGroup()
|
||||
lateinit var channel: Channel
|
||||
private set
|
||||
private lateinit var channel: Channel
|
||||
|
||||
fun start(address: String, port: Int) {
|
||||
val future = Bootstrap()
|
||||
|
|
@ -11,6 +11,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":api"))
|
||||
implementation(kotlin("stdlib"))
|
||||
@Suppress("VulnerableLibrariesLocal")
|
||||
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
package cc.maxmc.msm.common.network.packet
|
||||
|
||||
import cc.maxmc.msm.api.misc.EnumAPI
|
||||
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 PPacketAPICall(
|
||||
var api: EnumAPI = EnumAPI.GET_SERVER,
|
||||
var uid: UUID = UUID.randomUUID()
|
||||
) : BungeePacket() {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
DefinedPacket.writeVarInt(api.ordinal, buf)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
api = EnumAPI.values()[buf.readByte().toInt()]
|
||||
}
|
||||
|
||||
class PPacketCallGetServer(
|
||||
var type: String = "",
|
||||
var players: List<String> = emptyList()
|
||||
) : PPacketAPICall() {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
DefinedPacket.writeString(type, buf)
|
||||
DefinedPacket.writeStringArray(players, buf)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
type = DefinedPacket.readString(buf)
|
||||
players = DefinedPacket.readStringArray(buf)
|
||||
}
|
||||
}
|
||||
|
||||
class PPacketCallInformEnd(
|
||||
var matchID: Int = -1
|
||||
) : PPacketAPICall() {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
DefinedPacket.writeVarInt(matchID, buf)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
matchID = DefinedPacket.readVarInt(buf)
|
||||
}
|
||||
}
|
||||
|
||||
class PPacketCallGetPlayerServer(
|
||||
var serverInfo: ServerInfo = ServerInfo()
|
||||
) : PPacketAPICall() {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
buf.writeServerInfo(serverInfo)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
serverInfo = buf.readServerInfo()
|
||||
}
|
||||
}
|
||||
|
||||
class PPacketCallContainPlayer(
|
||||
var player: String = ""
|
||||
) : PPacketAPICall() {
|
||||
override fun encode(buf: ByteBuf) {
|
||||
super.encode(buf)
|
||||
DefinedPacket.writeString(player, buf)
|
||||
}
|
||||
|
||||
override fun decode(buf: ByteBuf) {
|
||||
super.decode(buf)
|
||||
player = DefinedPacket.readString(buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -5,9 +5,8 @@ import cc.maxmc.msm.common.utils.debug
|
|||
import io.netty.buffer.ByteBuf
|
||||
|
||||
data class PPacketDebug(
|
||||
var content: String
|
||||
var content: String = ""
|
||||
) : BungeePacket() {
|
||||
constructor() : this("")
|
||||
|
||||
override fun encode(buf: ByteBuf) {
|
||||
debug("start packet encode")
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package cc.maxmc.msm.common.utils
|
||||
|
||||
import cc.maxmc.msm.api.misc.ServerInfo
|
||||
import cc.maxmc.msm.common.network.ClusterPacketHandler
|
||||
import cc.maxmc.msm.common.network.netty.ClusterMsgCodec
|
||||
import cc.maxmc.msm.common.network.netty.NetworkRegistry
|
||||
import com.google.common.net.HostAndPort
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.channel.Channel
|
||||
import io.netty.channel.ChannelInitializer
|
||||
import io.netty.channel.socket.SocketChannel
|
||||
import net.md_5.bungee.protocol.DefinedPacket
|
||||
import net.md_5.bungee.protocol.Varint21FrameDecoder
|
||||
import net.md_5.bungee.protocol.Varint21LengthFieldPrepender
|
||||
|
||||
|
|
@ -20,5 +24,18 @@ fun pipelineInit(direction: NetworkRegistry.PacketDirection) = channelInit<Socke
|
|||
pipeline().addLast("frame_prepender", Varint21LengthFieldPrepender())
|
||||
pipeline().addLast("codec", ClusterMsgCodec(direction))
|
||||
pipeline().addLast("packet_handler", ClusterPacketHandler)
|
||||
}
|
||||
|
||||
fun ByteBuf.writeServerInfo(info: ServerInfo) {
|
||||
DefinedPacket.writeString(info.server.toString(), this)
|
||||
DefinedPacket.writeVarInt(info.id, this)
|
||||
}
|
||||
|
||||
fun ByteBuf.readServerInfo(): ServerInfo {
|
||||
val hap = DefinedPacket.readString(this)
|
||||
val id = DefinedPacket.readVarInt(this)
|
||||
return ServerInfo(
|
||||
HostAndPort.fromString(hap),
|
||||
id
|
||||
)
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
implementation(project(":api"))
|
||||
implementation(project(":common"))
|
||||
@Suppress("VulnerableLibrariesLocal")
|
||||
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
|
||||
|
|
@ -5,5 +5,6 @@ plugins {
|
|||
|
||||
rootProject.name = "MultiServerMan"
|
||||
|
||||
include("common", "parent-side", "child-side")
|
||||
include("api")
|
||||
val subProjects = listOf("api", "common", "parent", "child")
|
||||
|
||||
include(subProjects)
|
||||
Loading…
Reference in New Issue