start reading future conf conexion

This commit is contained in:
2022-10-08 12:57:59 +02:00
parent 038faae0e4
commit bb6c062be4
6 changed files with 147 additions and 66 deletions

View File

@@ -3,27 +3,48 @@ use std::fs::File;
use std::str::FromStr;
use std::io::prelude::*;
use std::collections::HashMap;
pub mod server_conf;
static FILE: &str = "mrprox.conf";
pub struct Servers{
pub struct Config{
l_servers : HashMap<String, String>,
file: Vec<yaml::Yaml>,
port: String,
port_conf: String,
}
impl Servers {
impl Config {
pub fn new() -> Self {
let mut file = File::open(&FILE).unwrap();
let mut s = String::new();
file.read_to_string(&mut s).unwrap();
let yam = yaml::YamlLoader::load_from_str(&s).unwrap();
Self{
l_servers: Self::get_servers(),
l_servers: Self::get_servers(&yam),
port: Self::get_port_f(&yam),
port_conf: Self::get_conf_port_f(&yam),
file: yam,
}
}
fn get_servers() -> HashMap<String, String> {
let mut f = File::open(&FILE).unwrap();
let mut s = String::new();
fn get_port_f(file: &Vec<yaml::Yaml>) -> String {
match file[0]["port"].as_str() {
Some(h) => String::from(h),
_ => String::from("25565"),
}
}
fn get_conf_port_f(file: &Vec<yaml::Yaml>) -> String {
match file[0]["port_conf"].as_str() {
Some(h) => String::from(h),
_ => String::from("25565"),
}
}
fn get_servers(file: &Vec<yaml::Yaml>) -> HashMap<String, String> {
let mut ret = HashMap::new();
f.read_to_string(&mut s).unwrap();
let docs = yaml::YamlLoader::load_from_str(&s).unwrap();
let docs2 = match &docs[0]["servers"] {
let docs2 = match file[0]["servers"] {
yaml::Yaml::Hash(ref h) => h,
_ => return ret,
};
@@ -57,4 +78,12 @@ impl Servers {
return None;
}
}
pub fn get_port(&self) -> &String{
&self.port
}
pub fn get_port_conf(&self) -> &String{
&self.port_conf
}
}