From 619afad8d55c4b138085dca5f81422214fdae438 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 22 Dec 2019 20:43:18 -0400 Subject: [PATCH 1/3] issue 49 add patch server motd --- src/main.rs | 7 ++++--- src/patch/patch.rs | 15 +++++++++++++-- src/patch_main.rs | 5 +++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index bae329e..37c6eed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use std::thread; use std::time::SystemTime; use log::{info}; -use patch::patch::{PatchServerState, generate_patch_tree, load_config}; +use patch::patch::{PatchServerState, generate_patch_tree, load_config, load_motd}; use login::login::LoginServerState; use login::character::CharacterServerState; use ship::ship::ShipServerState; @@ -47,7 +47,7 @@ fn setup_logger() { .chain(std::io::stdout()); let fileout = fern::Dispatch::new() .level(log::LevelFilter::Trace) - .chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d %H:%M:%S"))).unwrap()); + .chain(fern::log_file(format!("elseware-{}.log", chrono::Local::now().format("%Y-%m-%d_%H:%M:%S"))).unwrap()); fern::Dispatch::new() .chain(stdio) .chain(fileout) @@ -83,8 +83,9 @@ fn main() { let patch_thread = thread::spawn(|| { info!("[patch] starting server"); let patch_config = load_config(); + let patch_motd = load_motd(); let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str()); - let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup); + let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd); common::mainloop::mainloop(patch_state, patch_config.port); }); let thread_entity_gateway = entity_gateway.clone(); diff --git a/src/patch/patch.rs b/src/patch/patch.rs index 7faf2d7..2fae5b0 100644 --- a/src/patch/patch.rs +++ b/src/patch/patch.rs @@ -140,14 +140,16 @@ pub struct PatchServerState { patch_file_tree: PatchFileTree, patch_file_lookup: HashMap, patch_file_info: Vec, + patch_motd: String, } impl PatchServerState { - pub fn new(patch_file_tree: PatchFileTree, patch_file_lookup: HashMap) -> PatchServerState { + pub fn new(patch_file_tree: PatchFileTree, patch_file_lookup: HashMap, patch_motd: String) -> PatchServerState { PatchServerState { patch_file_tree: patch_file_tree, patch_file_lookup: patch_file_lookup, patch_file_info: Vec::new(), + patch_motd: patch_motd, } } } @@ -174,7 +176,7 @@ impl ServerState for PatchServerState { Box::new(vec![SendPatchPacket::RequestLogin(RequestLogin {})].into_iter().map(move |pkt| (id, pkt))) }, RecvPatchPacket::LoginReply(_pkt) => { - let mut p = vec![SendPatchPacket::Message(Message::new("hello player".to_string()))]; + let mut p = vec![SendPatchPacket::Message(Message::new(self.patch_motd.to_string()))]; p.append(&mut get_file_list_packets(&self.patch_file_tree)); p.push(SendPatchPacket::PatchEndList(PatchEndList {})); Box::new(p.into_iter().map(move |pkt| (id, pkt))) @@ -395,3 +397,12 @@ pub fn load_config() -> PatchConfig { }; config } + +pub fn load_motd() -> String { + let mut motd: String = "Welcome to Elseware!".to_string(); + + if let Ok(m) = fs::read_to_string("patch.motd") { + motd = m.clone(); + } + motd +} \ No newline at end of file diff --git a/src/patch_main.rs b/src/patch_main.rs index bf834d6..271e8fa 100644 --- a/src/patch_main.rs +++ b/src/patch_main.rs @@ -2,12 +2,13 @@ mod common; mod patch; -use crate::patch::patch::{PatchServerState, PatchTreeIterItem, generate_patch_tree, load_config}; +use crate::patch::patch::{PatchServerState, PatchTreeIterItem, generate_patch_tree, load_config, load_motd}; fn main() { println!("[patch] starting server"); let patch_config = load_config(); + let patch_motd: String = load_motd(); if let Err(_) = std::fs::read_dir(patch_config.path.as_str()) { println!("Patch directory {} does not exist. Attempting to create it...", patch_config.path.as_str()); @@ -36,7 +37,7 @@ fn main() { } } - let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup); + let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd); common::mainloop::mainloop(patch_state, patch_config.port); println!("[patch] exiting..."); From 089defeee520151c0bd94b3372992d773a5a37ae Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 22 Dec 2019 20:48:02 -0400 Subject: [PATCH 2/3] adding example motd file --- patch.motd | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 patch.motd diff --git a/patch.motd b/patch.motd new file mode 100644 index 0000000..0a0a769 --- /dev/null +++ b/patch.motd @@ -0,0 +1,3 @@ +At the end of the day, I'm the administrator here so what I say goes. +If you don't like it, go elsewhere, +thanks. From 114061c4423cb4d04f2c1ed7f8af9cba54cd4567 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 22 Dec 2019 20:58:58 -0400 Subject: [PATCH 3/3] fix motd ownership --- src/patch/patch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patch/patch.rs b/src/patch/patch.rs index 2fae5b0..dcca2be 100644 --- a/src/patch/patch.rs +++ b/src/patch/patch.rs @@ -176,7 +176,7 @@ impl ServerState for PatchServerState { Box::new(vec![SendPatchPacket::RequestLogin(RequestLogin {})].into_iter().map(move |pkt| (id, pkt))) }, RecvPatchPacket::LoginReply(_pkt) => { - let mut p = vec![SendPatchPacket::Message(Message::new(self.patch_motd.to_string()))]; + let mut p = vec![SendPatchPacket::Message(Message::new(self.patch_motd.clone()))]; p.append(&mut get_file_list_packets(&self.patch_file_tree)); p.push(SendPatchPacket::PatchEndList(PatchEndList {})); Box::new(p.into_iter().map(move |pkt| (id, pkt)))