sync with remote

This commit is contained in:
TONY_All 2023-03-19 12:56:58 +08:00
parent 0ee45b6179
commit 93ddf5994f
30 changed files with 201 additions and 20 deletions

View File

@ -38,8 +38,8 @@
- Int类型的对局id - Int类型的对局id
- 参数列表: - 参数列表:
- `(List<Player> players)` - `List<Player> players`
- - `String type`
### `func informEnd()` ### `func informEnd()`
@ -48,7 +48,7 @@
- 返回值:无 - 返回值:无
- 参数列表: - 参数列表:
- `(int id)` - `int id`
### `func getPlayerServer()` ### `func getPlayerServer()`
@ -59,7 +59,7 @@
- Int 类型的对局id未在对局中返回-1 - Int 类型的对局id未在对局中返回-1
- 参数列表: - 参数列表:
- `(Player player)` - `Player player`
### `func containPlayer()` ### `func containPlayer()`
@ -67,15 +67,15 @@
- 返回值: - 返回值:
- bool - bool
- 参数列表: - 参数列表:
- `(Player player)` - `Player player`
## 数据库结构 ## 数据库结构
- `match` - `match`
| id(int) | start(datetime) | end(datetime) | players(text) | | id(int) | start(datetime) | end(datetime) | players(text) | type(varchar) |
| ------- | --------------- | ------------- | ------------------------------------ | | ------- | --------------- | ------------- | ------------------------------------ | ------------- |
| 1 | 1678554776 | 1678554784 | TONY_All,Sanseyooyea,PlayerA,PlayerB | | 1 | 1678554776 | 1678554784 | TONY_All,Sanseyooyea,PlayerA,PlayerB | bedwars |
## API 使用 ## API 使用
依赖: 依赖:

View File

@ -13,4 +13,12 @@ dependencies {
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))
@Suppress("VulnerableLibrariesLocal") @Suppress("VulnerableLibrariesLocal")
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT") compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
}
publishing {
publications {
val release by getting(MavenPublication::class) {
artifact(tasks.jar)
}
}
} }

View File

@ -2,17 +2,20 @@ package cc.maxmc.msm.api;
import cc.maxmc.msm.api.misc.ServerInfo; import cc.maxmc.msm.api.misc.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
@SuppressWarnings("unused") // API @SuppressWarnings("unused") // API
public interface MultiServerManAPI { public interface MultiServerManAPI {
ServerInfo getServer(String type, List<ProxiedPlayer> players); @NotNull
ServerInfo getServer(@NotNull String type, @NotNull List<ProxiedPlayer> players);
void informEnd(int id); void informEnd(int id);
ServerInfo getPlayerServer(ProxiedPlayer player); @NotNull
ServerInfo getPlayerServer(@NotNull ProxiedPlayer player);
Boolean containPlayer(ProxiedPlayer player); Boolean containPlayer(@NotNull ProxiedPlayer player);
} }

View File

@ -0,0 +1,8 @@
package cc.maxmc.msm.api.misc
enum class EnumAPI {
GET_SERVER,
INFORM_END,
GET_PLAYER_SERVER,
CONTAIN_PLAYER;
}

View File

@ -9,6 +9,11 @@ public class ServerInfo {
private final HostAndPort server; private final HostAndPort server;
private final int id; private final int id;
public ServerInfo() {
server = HostAndPort.fromString("127.0.0.1");
id = -1;
}
public ServerInfo(@Nullable HostAndPort server, int id) { public ServerInfo(@Nullable HostAndPort server, int id) {
this.server = server; this.server = server;
this.id = id; this.id = id;

View File

@ -1,2 +1,31 @@
plugins {
`maven-publish`
}
group = "cc.maxmc.msm" 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)
}
}
}
}

View File

@ -12,7 +12,7 @@ repositories {
dependencies { dependencies {
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))
implementation(project(":api")) implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-Beta")
implementation(project(":common")) implementation(project(":common"))
implementation("io.netty:netty-all:4.1.90.Final") implementation("io.netty:netty-all:4.1.90.Final")
@Suppress("VulnerableLibrariesLocal") @Suppress("VulnerableLibrariesLocal")
@ -20,6 +20,7 @@ dependencies {
} }
tasks.shadowJar { tasks.shadowJar {
archiveClassifier.set(null as? String?)
relocate("kotlin", "cc.maxmc.msm.lib.kotlin") relocate("kotlin", "cc.maxmc.msm.lib.kotlin")
} }

View File

@ -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")
}
}

View File

@ -12,8 +12,7 @@ import io.netty.channel.socket.nio.NioSocketChannel
object NetClient { object NetClient {
private val loop = NioEventLoopGroup() private val loop = NioEventLoopGroup()
lateinit var channel: Channel private lateinit var channel: Channel
private set
fun start(address: String, port: Int) { fun start(address: String, port: Int) {
val future = Bootstrap() val future = Bootstrap()

View File

@ -11,6 +11,7 @@ repositories {
} }
dependencies { dependencies {
api(project(":api"))
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))
@Suppress("VulnerableLibrariesLocal") @Suppress("VulnerableLibrariesLocal")
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT") compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")

View File

@ -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)
}
}
}

View File

@ -5,9 +5,8 @@ import cc.maxmc.msm.common.utils.debug
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
data class PPacketDebug( data class PPacketDebug(
var content: String var content: String = ""
) : BungeePacket() { ) : BungeePacket() {
constructor() : this("")
override fun encode(buf: ByteBuf) { override fun encode(buf: ByteBuf) {
debug("start packet encode") debug("start packet encode")

View File

@ -1,11 +1,15 @@
package cc.maxmc.msm.common.utils 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.ClusterPacketHandler
import cc.maxmc.msm.common.network.netty.ClusterMsgCodec import cc.maxmc.msm.common.network.netty.ClusterMsgCodec
import cc.maxmc.msm.common.network.netty.NetworkRegistry 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.Channel
import io.netty.channel.ChannelInitializer import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel 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.Varint21FrameDecoder
import net.md_5.bungee.protocol.Varint21LengthFieldPrepender 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("frame_prepender", Varint21LengthFieldPrepender())
pipeline().addLast("codec", ClusterMsgCodec(direction)) pipeline().addLast("codec", ClusterMsgCodec(direction))
pipeline().addLast("packet_handler", ClusterPacketHandler) 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
)
} }

View File

@ -12,7 +12,6 @@ repositories {
dependencies { dependencies {
implementation(kotlin("stdlib")) implementation(kotlin("stdlib"))
implementation(project(":api"))
implementation(project(":common")) implementation(project(":common"))
@Suppress("VulnerableLibrariesLocal") @Suppress("VulnerableLibrariesLocal")
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT") compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")

View File

@ -5,5 +5,6 @@ plugins {
rootProject.name = "MultiServerMan" rootProject.name = "MultiServerMan"
include("common", "parent-side", "child-side") val subProjects = listOf("api", "common", "parent", "child")
include("api")
include(subProjects)