[−][src]Crate serbo
Allows for simple control, and input / output of minecraft servers.
Examples
use serbo; use std::error::Error; use std::io; fn main() -> Result<(), Box<dyn Error>> { let mut manager = serbo::Manager::new("servers", "versions","fabric-server-launch.jar"); let port = 25565; let id = "1"; loop { let reader = io::stdin(); let mut buf = String::new(); println!("Enter your command."); reader.read_line(&mut buf)?; match buf.trim() { "delete" => { match manager.delete(id){ Ok(_) => println!("Server deleted."), Err(e) => println!("{}",e) } } "change_version" => { let mut send_buf = String::new(); println!("Enter the version to change to."); reader.read_line(&mut send_buf)?; //Remove the newline from read_line send_buf = send_buf[..send_buf.chars().count() - 1].to_string(); manager.change_version(id, &send_buf)?; } "create" => match manager.create(id, "1.16.1-fabric") { Ok(_) => println!("Server Created"), Err(e) => println!("{}", e), }, "stop" => { //Stops the server println!("Server stopping."); manager.stop(id)?; break Ok(()); } "start" => { //Starts the server println!("Server starting."); match manager.start(id, port) { Err(e) => println!("{}", e), Ok(_) => println!("Server started!"), }; } "send" => { //Prompts for a command to send to the server let instance = manager.get(id); match instance { Some(i) => { let mut send_buf = String::new(); println!("Enter the command to send to the server."); reader.read_line(&mut send_buf)?; //Remove the newline from read_line send_buf = send_buf[..send_buf.chars().count() - 1].to_string(); i.send(send_buf)?; } None => println!("Server offline."), } } "get" => { //Gets the last 5 stdout lines let instance: &serbo::Instance = manager.get(id).unwrap(); let vec = instance.get(0); let length = vec.len(); //Create a vec from the last 5 lines let trimmed_vec; if length >= 5 { trimmed_vec = Vec::from(&vec[length - 5..]); } else { trimmed_vec = Vec::from(vec); } for line in trimmed_vec { println!("{}", line); } } _ => { println!("Unrecognized command"); } } } }
Structs
Instance | Represents a currently online server. Created by calling start from a Manager |
Manager | Controls the creation and deleting of servers, and whether they are currently active. |
Enums
Error |