+use std::{ fs::File, io::prelude::* };
+
+use ron::{ de::from_reader, ser::{ to_string_pretty, PrettyConfig } };
+use serde::{ Deserialize, Serialize };
+
+#[derive(Clone)]
+enum BlockType {
+ Empty,
+ Dirt,
+}
+
+mod consts {
+ pub const FILE_CONF: &str = "conf.ron";
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+struct Config {
+ #[serde(default = "empty_string")]
+ server_address: String,
+
+ #[serde(default = "empty_string")]
+ rcon_password: String,
+}
+
+fn empty_string() -> String { "".to_owned() }
+
+impl Config {
+ fn default() -> Self {
+ Config { server_address: String::from("127.0.0.1"), rcon_password: String::from("") }
+ }
+}
+
+fn load_config() -> Config {
+ match File::open(consts::FILE_CONF) {
+ Ok(file) => from_reader(file).unwrap_or_else(|_| panic!("Failed to open configuration file {}", consts::FILE_CONF)),
+ Err(_) => {
+ let mut file = File::create(consts::FILE_CONF) .unwrap();
+ let default_config = Config::default();
+ file.write_all(to_string_pretty(&default_config, PrettyConfig::new()).unwrap().as_bytes()).unwrap(); // We do not use 'to_writer' because it can't pretty format the output.
+ default_config
+ }
+ }
+}
+
+fn main() {
+ println!("Minecraft generator");
+
+ let config = load_config();
+
+ let m = 5;
+ let n = 5;
+
+ let mut maze = vec![vec![BlockType::Dirt; n]; m];
+
+ let conf = load_config();
+
+ let mut client = minecraft_client_rs::Client::new(format!("{}:25575", config.server_address)).unwrap();
+
+ // List of block: https://minecraft-ids.grahamedgecombe.com/
+
+ match client.authenticate(conf.rcon_password) {
+ Ok(_) => {
+ //match client.send_command("fill 233 71 -241 233 71 -241 dirt replace".to_string()) {
+ match client.send_command("fill 233 70 -241 284 70 -289 air replace".to_string()) {
+ Ok(resp) =>
+ println!("Response: {}", resp.body),
+ Err(e) => {
+ println!("Error from 'list' command: {:?}", e);
+ },
+ }
+ },
+ Err(e) => {
+ println!("Authentication error: {:?}", e);
+ },
+ };
+
+ client.close().unwrap();
+}