Browse Source

adding patch server config (#29)

pbs
andy 5 years ago
committed by Gogs
parent
commit
a3e90516d7
  1. 2
      Cargo.toml
  2. 5
      patch.ron
  3. 7
      src/main.rs
  4. 28
      src/patch/patch.rs
  5. 16
      src/patch_main.rs

2
Cargo.toml

@ -26,4 +26,6 @@ crc = "^1.0.0"
bcrypt = "0.4"
threadpool = "1.0"
chrono = "*"
serde = "*"
ron = "*"

5
patch.ron

@ -0,0 +1,5 @@
(
path: "patchfiles",
ip: "127.0.0.1",
port: 11000,
)

7
src/main.rs

@ -10,7 +10,7 @@ mod ship;
use std::thread;
use std::time::SystemTime;
use patch::patch::{PatchServerState, generate_patch_tree};
use patch::patch::{PatchServerState, generate_patch_tree, load_config};
use login::login::LoginServerState;
use login::character::CharacterServerState;
use ship::ship::ShipServerState;
@ -46,9 +46,10 @@ fn main() {
let patch_thread = thread::spawn(|| {
println!("[patch] starting server");
let (patch_file_tree, patch_file_lookup) = generate_patch_tree("patchfiles/");
let patch_config = load_config();
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);
common::mainloop::mainloop(patch_state, patch::patch::PATCH_PORT);
common::mainloop::mainloop(patch_state, patch_config.port);
});
let thread_entity_gateway = entity_gateway.clone();
let auth_thread = thread::spawn(|| {

28
src/patch/patch.rs

@ -8,12 +8,12 @@ use crc::{crc32, Hasher32};
use libpso::{PacketParseError, PSOPacket};
use libpso::packet::patch::*;
use libpso::crypto::pc::PSOPCCipher;
use ron::de::from_str;
use serde::Deserialize;
use crate::common::network::{PacketNetworkError};
use crate::common::serverstate::{RecvServerPacket, SendServerPacket, ServerState, OnConnect, ClientId};
pub const PATCH_PORT: u16 = 11000;
#[derive(Debug)]
pub enum PatchError {
PacketNetworkError(PacketNetworkError),
@ -371,3 +371,27 @@ impl Iterator for SendFileIterator {
}
}
#[derive(Debug, Deserialize)]
pub struct PatchConfig {
pub path: String,
pub ip: String,
pub port: u16,
}
pub fn load_config() -> PatchConfig {
let ini_file = match fs::File::open(std::path::Path::new("patch.ron")) {
Err(err) => panic!("Failed to open patch.ron config file. \n{}", err),
Ok(ini_file) => ini_file,
};
let mut s = String::new();
if let Err(err) = (&ini_file).read_to_string(&mut s) {
panic!("Failed to read patch.ron config file. \n{}", err);
}
let config: PatchConfig = match from_str(s.as_str()) {
Ok(config) => config,
Err(err) => panic!("Failed to load values from patch.ron \n{}",err),
};
config
}

16
src/patch_main.rs

@ -2,17 +2,21 @@
mod common;
mod patch;
use crate::patch::patch::{PatchServerState, PatchTreeIterItem, generate_patch_tree, PATCH_PORT};
use crate::patch::patch::{PatchServerState, PatchTreeIterItem, generate_patch_tree, load_config};
fn main() {
println!("[patch] starting server");
if let Err(_) = std::fs::read_dir("patchfiles/") {
if let Err(_) = std::fs::create_dir("patchfiles/") {
panic!("Could not create patchfiles directory!");
let patch_config = load_config();
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());
if let Err(err) = std::fs::create_dir(patch_config.path.as_str()) {
panic!("Failed to create patch directory! \n{}", err);
}
}
let (patch_file_tree, patch_file_lookup) = generate_patch_tree("patchfiles/");
let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str());
println!("[patch] files to patch:");
let mut indent = 0;
for item in patch_file_tree.flatten() {
@ -33,7 +37,7 @@ fn main() {
}
let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup);
common::mainloop::mainloop(patch_state, PATCH_PORT);
common::mainloop::mainloop(patch_state, patch_config.port);
println!("[patch] exiting...");
}
Loading…
Cancel
Save