diff --git a/Cargo.lock b/Cargo.lock index a45099d..208de23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,34 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -12,9 +40,91 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" name = "minecraft_proxy" version = "0.1.0" dependencies = [ + "serde", + "serde_yaml", "yaml-rust", ] +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "serde" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_yaml" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d232d893b10de3eb7258ff01974d6ee20663d8e833263c99409d4b13a0209da" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/Cargo.toml b/Cargo.toml index bc223a7..05df746 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -yaml-rust = "*" \ No newline at end of file +yaml-rust = "*" +serde = { version = "*", features = ["derive"] } +serde_yaml = "*" \ No newline at end of file diff --git a/src/conf/mod.rs b/src/conf/mod.rs index 3a89a75..0081617 100644 --- a/src/conf/mod.rs +++ b/src/conf/mod.rs @@ -1,4 +1,5 @@ use yaml_rust::yaml; +use serde::{Serialize, Deserialize}; use std::fs::File; use std::str::FromStr; use std::io::prelude::*; diff --git a/src/conf/server_conf.rs b/src/conf/server_conf.rs index 9549535..055101f 100644 --- a/src/conf/server_conf.rs +++ b/src/conf/server_conf.rs @@ -1,34 +1,36 @@ use std::net::{TcpListener, TcpStream}; +use std::os::unix::net::{UnixListener, UnixStream}; use std::io::prelude::*; use crate::conf; use std::sync::{Arc, RwLock}; pub fn server_conf(conf: Arc>){ - let listener = TcpListener::bind(String::from("0.0.0.0:") + - conf.read().unwrap().get_port_conf()).unwrap(); + let listener = UnixListener::bind("mineproxy").unwrap(); for stream in listener.incoming() { match stream{ - Ok(s) => process_reques(s), + Ok(s) => process_reques(s, conf.clone()), Err(_e) => println!("{}",_e), } } } -fn process_reques(mut stream: TcpStream) { +fn process_reques(mut stream: UnixStream, conf: Arc>) { let mut buf: [u8; 256] = [1; 256]; match stream.read(&mut buf){ - Ok(len) => check_state(&mut buf, len), - Err(e) => println!("pos no {}", e), + Ok(len) => check_state(&mut buf, len, conf), + Err(e) => println!("Fatal: {}", e), } } -fn check_state(buf: &mut [u8; 256], len: usize) { - let var = String::from_utf8(buf[0 .. len-2].to_vec()).unwrap(); +fn check_state(buf: &mut [u8; 256], len: usize, conf: Arc>) { + let var = String::from_utf8(buf[0 .. len].to_vec()).unwrap(); match var.as_str(){ - "some" => println!("entra"), - _=> println!("pos no {}", var), + "add" => println!("entra"), + "dell" => println!("del"), + "mod" => println!("mod"), + _=> println!("no recognice option: {}", var), } }