First commit: test to fill some area master
authorGreg Burri <greg.burri@gmail.com>
Sat, 11 Feb 2023 16:38:52 +0000 (17:38 +0100)
committerGreg Burri <greg.burri@gmail.com>
Sat, 11 Feb 2023 16:38:52 +0000 (17:38 +0100)
.gitignore [new file with mode: 0644]
Cargo.lock [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..6300790
--- /dev/null
@@ -0,0 +1,2 @@
+/target
+conf.ron
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644 (file)
index 0000000..5f8015d
--- /dev/null
@@ -0,0 +1,112 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "base64"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
+
+[[package]]
+name = "bitflags"
+version = "1.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
+
+[[package]]
+name = "either"
+version = "1.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
+
+[[package]]
+name = "itertools"
+version = "0.10.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
+dependencies = [
+ "either",
+]
+
+[[package]]
+name = "minecraft-client-rs"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c9d7111eb75f0736910124bb828b5555e7b1be8a81fce42f90cb5711fada9fb0"
+
+[[package]]
+name = "minecraft_maze"
+version = "0.1.0"
+dependencies = [
+ "itertools",
+ "minecraft-client-rs",
+ "ron",
+ "serde",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.51"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "ron"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff"
+dependencies = [
+ "base64",
+ "bitflags",
+ "serde",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.152"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.152"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.107"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..8fe2491
--- /dev/null
@@ -0,0 +1,11 @@
+[package]
+name = "minecraft_maze"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
+
+minecraft-client-rs = "0.1"
+serde = { version = "1.0", features = ["derive"] }
+ron = "0.8" # Rust object notation, to load configuration files.
+itertools = "0.10"
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..7f89cfc
--- /dev/null
@@ -0,0 +1,78 @@
+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();
+}