diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..68d5265 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,51 @@ +#![feature(const_generics)] + + +mod common; +mod entity; +mod patch; +mod login; +mod ship; + +use std::thread; + +use patch::patch::{PatchServerState, generate_patch_tree}; +use login::login::LoginServerState; +use login::character::CharacterServerState; +use ship::ship::ShipServerState; + +use entity::gateway::{EntityGateway, InMemoryGateway}; + +fn main() { + let entity_gateway = InMemoryGateway::new(); + + let patch_thread = thread::spawn(|| { + println!("[patch] starting server"); + let (patch_file_tree, patch_file_lookup) = generate_patch_tree("patchfiles/"); + let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup); + common::mainloop::mainloop(patch_state, patch::patch::PATCH_PORT); + }); + let thread_entity_gateway = entity_gateway.clone(); + let auth_thread = thread::spawn(|| { + println!("[auth] starting server"); + let auth_state = LoginServerState::new(thread_entity_gateway); + common::mainloop::mainloop(auth_state, login::login::LOGIN_PORT); + }); + let thread_entity_gateway = entity_gateway.clone(); + let char_thread = thread::spawn(|| { + println!("[character] starting server"); + let char_state = CharacterServerState::new(thread_entity_gateway); + common::mainloop::mainloop(char_state, login::character::CHARACTER_PORT); + }); + let thread_entity_gateway = entity_gateway.clone(); + let ship_thread = thread::spawn(|| { + println!("[ship] starting server"); + let ship_state = ShipServerState::new(thread_entity_gateway); + common::mainloop::mainloop(ship_state, ship::ship::SHIP_PORT); + }); + + patch_thread.join().unwrap(); + auth_thread.join().unwrap(); + char_thread.join().unwrap(); + ship_thread.join().unwrap(); +} diff --git a/src/ship/mod.rs b/src/ship/mod.rs new file mode 100644 index 0000000..3df90d6 --- /dev/null +++ b/src/ship/mod.rs @@ -0,0 +1 @@ +pub mod ship; \ No newline at end of file diff --git a/src/ship/ship.rs b/src/ship/ship.rs new file mode 100644 index 0000000..b1d813f --- /dev/null +++ b/src/ship/ship.rs @@ -0,0 +1,63 @@ +use libpso::PacketParseError; + +use crate::common::serverstate::{SendServerPacket, RecvServerPacket, ServerState, OnConnect, ClientId}; +use crate::entity::gateway::EntityGateway; + +pub const SHIP_PORT: u16 = 12345; + +#[derive(Debug)] +pub enum ShipError { + +} + +#[derive(Debug)] +pub enum RecvShipPacket { + +} + +impl RecvServerPacket for RecvShipPacket { + fn from_bytes(data: &[u8]) -> Result { + Err(PacketParseError::WrongPacketForServerType) + } +} + +#[derive(Debug)] +pub enum SendShipPacket { + + +} + +impl SendServerPacket for SendShipPacket { + fn as_bytes(&self) -> Vec { + Vec::new() + } +} + + +pub struct ShipServerState { + entity_gateway: EG, +} + +impl ShipServerState { + pub fn new(entity_gateway: EG) -> ShipServerState { + ShipServerState { + entity_gateway: entity_gateway + } + } +} + + +impl ServerState for ShipServerState { + type SendPacket = SendShipPacket; + type RecvPacket = RecvShipPacket; + type PacketError = ShipError; + + fn on_connect(&mut self, id: ClientId) -> Vec> { + Vec::new() + } + + fn handle(&mut self, id: ClientId, pkt: &RecvShipPacket) + -> Result>, ShipError> { + Ok(Box::new(Vec::new().into_iter())) + } +} \ No newline at end of file