jake
5 years ago
3 changed files with 115 additions and 0 deletions
@ -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();
|
|||
}
|
@ -0,0 +1 @@ |
|||
pub mod ship;
|
@ -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<RecvShipPacket, PacketParseError> {
|
|||
Err(PacketParseError::WrongPacketForServerType)
|
|||
}
|
|||
}
|
|||
|
|||
#[derive(Debug)]
|
|||
pub enum SendShipPacket {
|
|||
|
|||
|
|||
}
|
|||
|
|||
impl SendServerPacket for SendShipPacket {
|
|||
fn as_bytes(&self) -> Vec<u8> {
|
|||
Vec::new()
|
|||
}
|
|||
}
|
|||
|
|||
|
|||
pub struct ShipServerState<EG: EntityGateway> {
|
|||
entity_gateway: EG,
|
|||
}
|
|||
|
|||
impl<EG: EntityGateway> ShipServerState<EG> {
|
|||
pub fn new(entity_gateway: EG) -> ShipServerState<EG> {
|
|||
ShipServerState {
|
|||
entity_gateway: entity_gateway
|
|||
}
|
|||
}
|
|||
}
|
|||
|
|||
|
|||
impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
|||
type SendPacket = SendShipPacket;
|
|||
type RecvPacket = RecvShipPacket;
|
|||
type PacketError = ShipError;
|
|||
|
|||
fn on_connect(&mut self, id: ClientId) -> Vec<OnConnect<Self::SendPacket>> {
|
|||
Vec::new()
|
|||
}
|
|||
|
|||
fn handle(&mut self, id: ClientId, pkt: &RecvShipPacket)
|
|||
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)>>, ShipError> {
|
|||
Ok(Box::new(Vec::new().into_iter()))
|
|||
}
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue