From 7a18af7d88292475f5936f0200ebe1c1bc0ad592 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 9 Oct 2019 22:45:51 -0700 Subject: [PATCH] ship init --- src/main.rs | 51 +++++++++++++++++++++++++++++++++++++++ src/ship/mod.rs | 1 + src/ship/ship.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 src/main.rs create mode 100644 src/ship/mod.rs create mode 100644 src/ship/ship.rs 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