Skip to content

NearlyHeadlessJack/rcon2mc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | 简体中文

rcon2mc

Crates.io License Crates.io Version docs.rs GitHub Actions Workflow Status

rcon2mc is a Minecraft RCON protocol client library in Rust, used for executing commands remotely on a Java Edition Minecraft server.

Additionally, rcon2mc includes built-in wrappers for some Minecraft commands, allowing you to directly call these methods to execute commands.


Usage

Direct Usage rcon.send

(Compatible with all Minecraft versions from1.9 to 26.1)

use rcon2mc::rcon_client::RconClient;

fn main(){
    let mut rcon = RconClient::builder()
        .host("127.0.0.1".to_string())
        .port(25575)
        .password("password".to_string())
        .build().expect("Failed to connect to server");
    let feedback = rcon.send("give @a minecraft:diamond 1".to_string()).expect("Failed to send command");
    
}

Using Wrapper Commands for Handling Result

Tested on 1.12.2, 1.16.5, 1.20.1, 1.21.11, and 26.1

use rcon2mc::rcon_client::RconClient;
use rcon2mc::rcon_client::{TargetStatus, TargetStatusSuccess};

fn main(){
    let mut rcon = RconClient::builder()
        .host("127.0.0.1".to_string())
        .port(25575)
        .password("password".to_string())
        .build().expect("Failed to connect to server");
    let feedback = rcon.command().give("player114514", "minecraft:diamond_sword", 1);
    match feedback {
        // Player exists and command executed successfully
        Ok(TargetStatus::Success(TargetStatusSuccess::Success))=>{},
        // Player does not exist
        Ok(TargetStatus::NotFound)=>{},
        Err(e)=>{
            println!("{}", e);
        },
        _=>{},
    }
    
}

For specific built-in wrapper commands, please refer to the documentation.

Testings for built-in Commands in Different Versions

TBD: Not tested yet
Y: Tested Successfully
-: Will not be tested

None-player test cases are testing commands executing when target is offline or commands that don't require a target.
Player-online test cases are testing commands executing when target is online.

Test cases for built-in command
command argument Test cases for none-player server
version
1.12.2 1.16.5 1.20.1 1.21.11 26.1
ban player: &str,reason: Option<&str>, y y y y y
ban_ip ip: &str,reason: Option<&str>, y y y y y
banlist - TBD TBD TBD TBD TBD
deop player: &str y y y y y
difficulty difficulty_name: &str y y y y y
gamemode mode: &str,target: Option<&str>, y y y y y
gamerule gamerule_name: &str,value: &str, - - - - -
give target: &str,item: &str,count: i32, y y y y y
kick player: &str,reason: Option<&str>, y y y y y
kill target: &str y y y y y
list - y y y y y
list_uuid - y y y y y
msg target: &str, message: &str, y y y y y
op player: &str y y y y y
pardon player: &str y y y y y
pardon_ip ip: &str y y y y y
save save_type: &str y y y y y
say message: &str y y y y y
stop - y y y y y
tell target: &str,message: &str, y y y y y
title target: &str,title_type: &str,title_msg: &str, y y y y y
tp target: &str,x: f64,y: f64,z: f64, y y y y y
transfer hostname: &str,port: &str,target: &str, - - - y y
w target: &str,message: &str, y y y y y
weather weather_name: &str y y y y y
whitelist - TBD TBD TBD TBD TBD
whitelist_add player: &str y y y y y
whitelist_remove player: &str, y y y y y
command argument Test cases for players-online server
version
1.12.2 1.16.5 1.20.1 1.21.11 26.1
ban player: &str,reason: Option<&str>, - - - - -
ban_ip ip: &str,reason: Option<&str>, - - - - -
banlist - - - - - -
deop player: &str - - - - -
difficulty difficulty_name: &str - - - - -
gamemode mode: &str,target: Option<&str>, y y y TBD TBD
gamerule gamerule_name: &str,value: &str, - - - - -
give target: &str,item: &str,count: i32, y y y TBD TBD
kick player: &str,reason: Option<&str>, TBD TBD TBD TBD TBD
kill target: &str y y y TBD TBD
list - y y y TBD TBD
list_uuid - y y y TBD TBD
msg target: &str, message: &str, y y y TBD TBD
op player: &str - - - - -
pardon player: &str - - - - -
pardon_ip ip: &str - - - - -
save save_type: &str - - - - -
say message: &str y y y TBD TBD
stop - TBD TBD TBD TBD TBD
tell target: &str,message: &str, y y y TBD TBD
title target: &str,title_type: &str,title_msg: &str, y y y TBD TBD
tp target: &str,x: f64,y: f64,z: f64, y y y TBD TBD
transfer hostname: &str,port: &str,target: &str, - - - TBD TBD
w target: &str,message: &str, y y y TBD TBD
weather weather_name: &str - - - - -
whitelist - - - - - -
whitelist_add player: &str - - - - -
whitelist_remove player: &str, - - - - -

License

This project is licensed under the MIT License.

About

A RCON client lib for Minecraft server

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages