Skip to content

Tokio Example? #27

Description

@timelessnesses

So I tried using rcon with tokio and looks like there's none but I figured out by myself.
For anyone who wondering what is tokio example looks like, here's example code.

use rcon;
use toml;
use std;
use tokio;

#[tokio::main]
async fn main(){
    let config: toml::Value = toml::from_str(include_str!("../config.toml")).unwrap();

    let mut server = <rcon::Connection<tokio::net::TcpStream>>::builder()
    .enable_minecraft_quirks(true)
    .connect(format!("{}:{}", config["server"]["ip"].as_str().expect("Server IP isn't specified"), config["server"]["port"].as_str().unwrap_or("25575")), config["server"]["password"].as_str().unwrap())
    .await.unwrap();

    println!("Connected to the server! ({})\nRun `exit` command to exit the program or CTRL + C!", config["server"]["ip"].as_str().unwrap());

    loop {
        println!("Summoning A Zombie ");
        let res = server.cmd("summon minecraft:zombie -775.65 26.00 -180.72 ").await;
        if res.is_err() {
            println!("Server Error Out!");
            continue
        }
        println!("Server Response: {}", res.unwrap());
    }
    println!("Bye!")
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions