2026-09-04 15:21:22 +08:00
|
|
|
# libmc
|
2026-09-03 19:32:46 +08:00
|
|
|
|
2026-09-04 01:27:18 +08:00
|
|
|
A lightweight motd ping / rcon client library for kotlin multiplatform and java,
|
2026-09-03 19:32:46 +08:00
|
|
|
no dependencies in `jvm` target except `kotlin-stdlib`
|
|
|
|
|
|
|
|
|
|
native platforms required `ktor-network` and `kotlinx-io`
|
|
|
|
|
|
|
|
|
|
# Supported targets
|
|
|
|
|
|
|
|
|
|
- jvm 1.8
|
|
|
|
|
- mingwX64
|
|
|
|
|
- linuxArm64
|
|
|
|
|
- liunxX64
|
|
|
|
|
- iosArm64
|
|
|
|
|
- iosSimulatorArm64
|
|
|
|
|
- macosArm64
|
|
|
|
|
|
|
|
|
|
# Get started
|
|
|
|
|
|
2026-09-04 01:35:47 +08:00
|
|
|
[Use mcping module](https://repo.rtast.cn/packages/-/cn.rtast.mcping:mcping/)
|
|
|
|
|
|
|
|
|
|
[Use rconlib module](https://repo.rtast.cn/packages/-/cn.rtast.mcping:rconlib/)
|
|
|
|
|
|
2026-09-03 23:52:59 +08:00
|
|
|
|
2026-09-04 01:27:18 +08:00
|
|
|
# MC Ping
|
|
|
|
|
|
2026-09-03 22:47:27 +08:00
|
|
|
## Kotlin example
|
|
|
|
|
|
2026-09-03 19:32:46 +08:00
|
|
|
```kotlin
|
|
|
|
|
fun main() {
|
2026-09-03 22:47:27 +08:00
|
|
|
val sm = SelectorManager(Dispatchers.IO)
|
|
|
|
|
// context is not required, if not passed, default context will be used
|
|
|
|
|
// ping java server
|
|
|
|
|
val response: PingResponse =
|
2026-09-04 15:27:20 +08:00
|
|
|
mcping(host = "org.mc-complex.com", port = 25565, type = ServerType.Java, context = LibMCContext(sm))
|
2026-09-03 22:47:27 +08:00
|
|
|
println(response.content)
|
|
|
|
|
println(response.latency)
|
|
|
|
|
|
|
|
|
|
// ping bedrock
|
|
|
|
|
val response = mcping("play.wildnetwork.net", 19132, ServerType.Bedrock)
|
|
|
|
|
println(response.toBedrockResponse())
|
2026-09-03 19:32:46 +08:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-09-03 22:47:27 +08:00
|
|
|
## Java example
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
void main() {
|
|
|
|
|
// ping java server
|
|
|
|
|
String testJavaHost = "org.mc-complex.com";
|
|
|
|
|
PingResponse javaResponse = McPing.mcping(testJavaHost, 25565);
|
|
|
|
|
|
|
|
|
|
// ping bedrock server
|
|
|
|
|
String testBedrockHost = "play.wildnetwork.net";
|
|
|
|
|
PingResponse bedrockResponse = McPing.mcping(testBedrockHost, 19132, ServerType.Bedrock);
|
|
|
|
|
System.out.println(bedrockResponse.toBedrockResponse());
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> java consumers should not manually pass the context parameter
|
|
|
|
|
|
|
|
|
|
## Other resources
|
|
|
|
|
|
|
|
|
|
> An example of java ping json response can be found at [ping-response-example](example/java-ping-response.json) (Formatted),
|
|
|
|
|
> a raw response of bedrock ping response can be found at [bedrock-pinng-raw-response](example/bedrock-pinng-raw-response.txt)
|
2026-09-03 19:32:46 +08:00
|
|
|
|
2026-09-04 01:27:18 +08:00
|
|
|
|
|
|
|
|
# rcon client
|
|
|
|
|
|
|
|
|
|
```kotlin
|
|
|
|
|
fun main() {
|
|
|
|
|
val host = "127.0.0.1"
|
|
|
|
|
val port = 25575
|
|
|
|
|
val client = rconClient(host, port)
|
|
|
|
|
val authed = client.connect("123456")
|
|
|
|
|
if (authed) println(client.command("list")) else throw IllegalArgumentException("incorrect password")
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
> also supports java
|
|
|
|
|
|
|
|
|
|
```java
|
|
|
|
|
void main() {
|
|
|
|
|
String host = "127.0.0.1";
|
|
|
|
|
int port = 25575;
|
|
|
|
|
String password = "123456";
|
|
|
|
|
RCONClient rconClient = Rconlib.rconClient(host, port);
|
|
|
|
|
boolean authed = rconClient.connect(password);
|
|
|
|
|
if (authed) {
|
|
|
|
|
System.out.println(rconClient.command("list"));
|
|
|
|
|
} else {
|
|
|
|
|
throw new IllegalStateException("incorrect password");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2026-09-03 19:32:46 +08:00
|
|
|
# Open Source
|
|
|
|
|
|
|
|
|
|
Open source under [Apache-2.0](LICENSE)
|