Browse Source

issue 49 add patch server motd

pbs
andy 5 years ago
parent
commit
619afad8d5
  1. 7
      src/main.rs
  2. 15
      src/patch/patch.rs
  3. 5
      src/patch_main.rs

7
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();

15
src/patch/patch.rs

@ -140,14 +140,16 @@ pub struct PatchServerState {
patch_file_tree: PatchFileTree,
patch_file_lookup: HashMap<u32, PatchFile>,
patch_file_info: Vec<FileInfoReply>,
patch_motd: String,
}
impl PatchServerState {
pub fn new(patch_file_tree: PatchFileTree, patch_file_lookup: HashMap<u32, PatchFile>) -> PatchServerState {
pub fn new(patch_file_tree: PatchFileTree, patch_file_lookup: HashMap<u32, PatchFile>, 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
}

5
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...");

Loading…
Cancel
Save