-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat): Add packet passing from Client <-> GroupServer
- Loading branch information
Showing
15 changed files
with
595 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,76 @@ | ||
use serde::de::DeserializeOwned; | ||
use serde::{Deserialize, Serialize}; | ||
use std::env::current_dir; | ||
use std::fs; | ||
use std::path::Path; | ||
use serde::{Serialize, Deserialize}; | ||
use serde::de::DeserializeOwned; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct ConfigParser<T> { | ||
data: T | ||
data: T, | ||
} | ||
|
||
impl<T> ConfigParser<T> { | ||
pub fn parse_file(file_path: &Path) -> Self | ||
where | ||
T: DeserializeOwned { | ||
let contents = match fs::read_to_string (file_path) { | ||
Ok(contents) => contents, | ||
Err(err) => panic!("Could not find config file at {:?}, error - {}", file_path, err) | ||
}; | ||
pub fn parse_file(file_path: &Path) -> Self | ||
where | ||
T: DeserializeOwned, | ||
{ | ||
println!("{:?} {:?}", current_dir(), file_path); | ||
let contents = match fs::read_to_string(file_path) { | ||
Ok(contents) => contents, | ||
Err(err) => panic!( | ||
"Could not find config file at {:?}, error - {}", | ||
file_path, err | ||
), | ||
}; | ||
|
||
let data: T = match serde_yaml::from_str(&contents) { | ||
Ok(yaml) => yaml, | ||
Err(err) => panic!("Unable to parse the YAML config, err - {}", err) | ||
}; | ||
let data: T = match serde_yaml::from_str(&contents) { | ||
Ok(yaml) => yaml, | ||
Err(err) => panic!("Unable to parse the YAML config, err - {}", err), | ||
}; | ||
|
||
let config_parser: ConfigParser<T> = ConfigParser { | ||
data | ||
}; | ||
let config_parser: ConfigParser<T> = ConfigParser { data }; | ||
|
||
config_parser | ||
} | ||
config_parser | ||
} | ||
|
||
pub fn get_data(self) -> T { | ||
self.data | ||
} | ||
pub fn get_data(self) -> T { | ||
self.data | ||
} | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::path::Path; | ||
use std::path::Path; | ||
|
||
use super::ConfigParser; | ||
use super::ConfigParser; | ||
|
||
use serde::{Serialize, Deserialize}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct ConfigStructure { | ||
name: String, | ||
id: u64 | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn it_throws_an_error_if_file_doesnt_exist() { | ||
ConfigParser::<ConfigStructure>::parse_file(Path::new("./tests/yada.yml")); | ||
} | ||
#[derive(Serialize, Deserialize)] | ||
struct ConfigStructure { | ||
name: String, | ||
id: u64, | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn it_throws_an_error_if_the_file_is_not_valid_yaml() { | ||
ConfigParser::<ConfigStructure>::parse_file(Path::new("./tests/invalid_yaml.yml")); | ||
} | ||
#[test] | ||
#[should_panic] | ||
fn it_throws_an_error_if_file_doesnt_exist() { | ||
ConfigParser::<ConfigStructure>::parse_file(Path::new("./tests/yada.yml")); | ||
} | ||
|
||
#[test] | ||
fn it_parses_a_valid_yml_file_correctly() { | ||
let contents = ConfigParser::<ConfigStructure>::parse_file(Path::new("./tests/valid_yaml.yml")); | ||
let data = contents.get_data(); | ||
|
||
assert_eq!(data.id, 5); | ||
assert_eq!(data.name, "This is the name"); | ||
} | ||
} | ||
#[test] | ||
#[should_panic] | ||
fn it_throws_an_error_if_the_file_is_not_valid_yaml() { | ||
ConfigParser::<ConfigStructure>::parse_file(Path::new("./tests/invalid_yaml.yml")); | ||
} | ||
|
||
#[test] | ||
fn it_parses_a_valid_yml_file_correctly() { | ||
let contents = | ||
ConfigParser::<ConfigStructure>::parse_file(Path::new("./tests/valid_yaml.yml")); | ||
let data = contents.get_data(); | ||
|
||
assert_eq!(data.id, 5); | ||
assert_eq!(data.name, "This is the name"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
main: | ||
name: "GateServer2" | ||
|
||
client_config: | ||
ip: "127.0.0.1" | ||
ddos_protection: true | ||
max_connections: 500 | ||
max_login_per_ip: 50 | ||
ping_duration: 180 | ||
port: 1973 | ||
wpe_protection: true | ||
wpe_version: 30 | ||
|
||
group_config: | ||
ip: "172.24.80.1" | ||
port: 1975 | ||
ping_duration: 180 | ||
|
||
game_server_config: | ||
ip: "127.0.0.1" | ||
port: 3002 | ||
ping_duration: 180 | ||
|
Oops, something went wrong.