Refactor config servers first read to fix docker deploy

This commit is contained in:
Guillermo Roche 2023-06-03 13:20:56 +02:00
parent 8b1b64bd87
commit 0be47b8b88
3 changed files with 42 additions and 20 deletions

View File

@ -7,4 +7,5 @@ COPY src /opt/mrproxy/src
COPY config/* /etc/mrproxy COPY config/* /etc/mrproxy
WORKDIR /opt/mrproxy WORKDIR /opt/mrproxy
RUN apk add cargo RUN apk add cargo
RUN cargo run --release RUN cargo build --release
CMD /opt/mrproxy/target/release/minecraft_proxy

View File

@ -5,4 +5,4 @@ conf:
sock_type: 'TCP' sock_type: 'TCP'
#path: '/home/roche/portmrproxy' #path: '/home/roche/portmrproxy'
port: '25564' port: '25564'
ip: '127.0.0.1' ip: '0.0.0.0'

View File

@ -50,27 +50,48 @@ pub struct Config{
conf: ConfServer, conf: ConfServer,
} }
pub fn generate_conf_from_file() -> ConfFile{
match File::open(&FILE_CONF) {
Ok(mut f) => {
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
match serde_yaml::from_str(&s) {
Ok(result) => result,
Err(e) => {error!("Config file malformed: {}",e); panic!("{}", e);},
}
}
Err(e) => {error!("Error open config file: {}",e); panic!("{}",e)}
}
}
pub fn generate_slist_from_file() -> Vec<ServerData>{
match File::open(&FILE_SERVERS){
Ok(mut f) => {
let mut s = String::new();
f.read_to_string(&mut s).unwrap();
match serde_yaml::from_str(&s) {
Ok(result) => result,
Err(e) => {
warn!("IPs list file malformed; creating new one\nerror: {}",e);
Vec::new()
},
}
}
Err(e) => {
warn!("IPs list file can't be open; creating new one \nerror: {}",e);
Vec::new()
},
}
}
impl Config { impl Config {
pub fn new() -> Self { pub fn new() -> Self {
let mut conf_file = File::open(&FILE_CONF).unwrap(); let yaml_conf = generate_conf_from_file();
let mut servers_file = File::open(&FILE_SERVERS).unwrap();
let mut s1 = String::new();
let mut s2 = String::new();
conf_file.read_to_string(&mut s1).unwrap();
servers_file.read_to_string(&mut s2).unwrap();
let yam_conf:ConfFile = match serde_yaml::from_str(&s1) {
Ok(result) => result,
Err(e) => {error!("Config file malformed: {}",e); panic!("{}", e);},
};
let yam_ser: Vec<ServerData> = match serde_yaml::from_str(&s2) {
Ok(result) => result,
Err(e) => {warn!("IPs list file malformed; creating new one"); Vec::new()},
};
Self{ Self{
l_servers: Self::get_servers(&yam_ser), l_servers: Self::get_servers(&generate_slist_from_file()),
port: yam_conf.port, port: yaml_conf.port,
ip: yam_conf.ip, ip: yaml_conf.ip,
conf: yam_conf.conf, conf: yaml_conf.conf,
} }
} }