2 个版本
0.1.3 | 2022年8月2日 |
---|---|
0.1.0 | 2021年3月20日 |
308 在 游戏
每月 25 次下载
在 rconcli 中使用
20KB
278 行
minecraft-client-rs
Minecraft RCON 协议客户端。
库使用
// Create a new client and connect to the server.
let mut client = Client::new("127.0.0.1:25575".to_string()).unwrap();
// Send some commands.
match client.authenticate("password".to_string()) {
Ok(_) => { },
Err(e) => { /* handle authentication error */ },
}
match client.send_command("seed".to_string()) {
Ok(resp) => { println!("{}", resp.body); }, // "Seed: [1871644822592853811]"
Err(e) => { /* handle error */ },
}
// Disconnect cleanly when finished.
client.close().unwrap();
Shell 工具
如果您在寻找工具而不是库,请尝试 shell 命令
# Single command mode
$ cargo run -F cli -- -h 127.0.0.1:25575 -p minecraft seed
Seed: [5454567064266725003]
# Interactive mode
$ cargo run -F cli -- -h 127.0.0.1:25575 -p minecraft -i
Starting RCON shell. Use 'exit', 'quit', or Ctrl-C to exit.
> list
There are 0 of a max of 20 players online:
> seed
Seed: [5454567064266725003]
限制
超过 4KB 的响应体将被截断。
启动服务器进行测试
$ docker pull itzg/minecraft-server
$ docker run --name=minecraft-server -p 25575:25575 -d -e EULA=TRUE itzg/minecraft-server
运行测试
要运行单元测试
$ cargo test --lib
在 Docker 中启动测试服务器后运行集成测试
$ cargo test
参考
依赖
~0–1MB
~17K SLoC