diff --git a/src/common/interserver.rs b/src/common/interserver.rs index 2f1c494..f1110f8 100644 --- a/src/common/interserver.rs +++ b/src/common/interserver.rs @@ -11,7 +11,6 @@ pub struct AuthToken(pub String); #[derive(Debug, Serialize, Deserialize)] pub struct Ship { pub name: String, - //pub ip: String, pub ip: Ipv4Addr, pub port: u16, pub block_count: u32, @@ -43,11 +42,6 @@ pub enum ShipMessage { } - - - - - #[async_trait::async_trait] pub trait InterserverActor { type SendMessage: Serialize; diff --git a/src/common/mainloop/client.rs b/src/common/mainloop/client.rs index 7f037cd..ed32e73 100644 --- a/src/common/mainloop/client.rs +++ b/src/common/mainloop/client.rs @@ -1,11 +1,9 @@ use std::pin::Pin; -use futures::future::{Future, join_all}; +use futures::future::Future; use log::{trace, info, warn}; use async_std::sync::{Arc, Mutex}; use async_std::io::prelude::{ReadExt, WriteExt}; use std::collections::HashMap; -use serde::{Serialize, Deserialize}; -use serde::de::DeserializeOwned; use libpso::crypto::{PSOCipher, NullCipher, CipherError}; use libpso::PacketParseError; @@ -268,46 +266,6 @@ where }); } - -pub async fn simple_mainloop(state: STATE, port: u16) where - STATE: ServerState + Send + 'static, - S: SendServerPacket + std::fmt::Debug + Send + Sync + 'static, - R: RecvServerPacket + std::fmt::Debug + Send + Sync + 'static, - E: std::fmt::Debug + Send, -{ - - let listener = async_std::task::spawn(async move { - let listener = async_std::net::TcpListener::bind(&std::net::SocketAddr::from((std::net::Ipv4Addr::new(0,0,0,0), port))).await.unwrap(); - let mut id = 1; - - let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024); - - server_state_loop(state, server_state_receiver).await; - - loop { - let (sock, addr) = listener.accept().await.unwrap(); - let client_id = crate::common::serverstate::ClientId(id); - id += 1; - - info!("new client {:?} {:?} {:?}", client_id, sock, addr); - - let (client_sender, client_receiver) = async_std::sync::channel(64); - let socket = Arc::new(sock); - let cipher_in: Arc>> = Arc::new(Mutex::new(Box::new(NullCipher {}))); - let cipher_out: Arc>> = Arc::new(Mutex::new(Box::new(NullCipher {}))); - - client_recv_loop(client_id, socket.clone(), cipher_in.clone(), server_state_sender.clone(), client_sender).await; - client_send_loop(client_id, socket.clone(), cipher_in.clone(), cipher_out.clone(), client_receiver).await; - } - }); - - listener.await -} - -//////////////////////////////////////////////////////////// - - - async fn state_client_loop(state: Arc>, server_state_receiver: async_std::sync::Receiver, R>>) where STATE: ServerState + Send + 'static, diff --git a/src/common/mainloop/interserver.rs b/src/common/mainloop/interserver.rs index fbc0a47..059e27e 100644 --- a/src/common/mainloop/interserver.rs +++ b/src/common/mainloop/interserver.rs @@ -1,28 +1,24 @@ use std::time::Duration; use std::pin::Pin; -use futures::future::{Future, join_all, FutureExt}; -use log::{trace, info, warn}; +use futures::future::Future; +use log::{info, warn}; use async_std::sync::{Arc, Mutex}; use async_std::io::prelude::{ReadExt, WriteExt}; use std::collections::HashMap; -use serde::{Serialize, Deserialize}; +use serde::Serialize; use serde::de::DeserializeOwned; -use crate::common::serverstate::{RecvServerPacket, SendServerPacket, ServerState, OnConnect}; -use crate::common::interserver::{ServerId, InterserverActor, LoginMessage, ShipMessage}; -use crate::common::mainloop::client::client_accept_mainloop; -pub use crate::common::mainloop::client::NetworkError; +use crate::common::interserver::{ServerId, InterserverActor}; -use crate::patch::patch::PatchServerState; use crate::login::character::CharacterServerState; use crate::ship::ship::ShipServerState; use crate::entity::gateway::entitygateway::EntityGateway; #[derive(Debug)] enum MessageReceiverError { - InvalidSize, + //InvalidSize, InvalidPayload, - NetworkError(std::io::Error), + //NetworkError(std::io::Error), Disconnected, } @@ -41,20 +37,16 @@ impl MessageReceiver { let mut size_buf = [0u8; 4]; self.socket.read_exact(&mut size_buf).await.map_err(|_| MessageReceiverError::Disconnected)?; let size = u32::from_le_bytes(size_buf) as usize; - info!("expected len: {:?}", size); let mut payload = vec![0u8; size]; self.socket.read_exact(&mut payload).await.map_err(|err| MessageReceiverError::Disconnected)?; let payload = String::from_utf8(payload).map_err(|_| MessageReceiverError::InvalidPayload)?; - info!("payload: {:?}", payload); let msg = serde_json::from_str(&payload).map_err(|_| MessageReceiverError::InvalidPayload)?; - info!("msg: {:?}", msg); Ok(msg) } } - #[derive(Debug)] enum InterserverInputAction { NewConnection(ServerId, async_std::sync::Sender), @@ -62,10 +54,6 @@ enum InterserverInputAction { Disconnect(ServerId), } -/*struct LoginOutputAction { - Message -}*/ - async fn interserver_state_loop(state: Arc>, action_receiver: async_std::sync::Receiver>) where A: InterserverActor + Send + 'static, @@ -211,17 +199,12 @@ pub fn ship_connect_mainloop(state: Arc Ship { - Ship { - flags: 0, - name: name.to_owned(), - ip: ip, - port: port, - } - } -}*/ - pub struct CharacterServerState { entity_gateway: EG, param_header: ParamDataHeader, @@ -194,8 +174,6 @@ pub struct CharacterServerState { async fn new_character(entity_gateway: &mut EG, user: &UserAccountEntity, preview: &CharacterPreview) { - //let mut character = entity_gateway.new_character_by_user(&user); - //new_character_from_preview(&mut char, preview); let mut character = new_character_from_preview(user, preview); match character.char_class { CharacterClass::FOmar | CharacterClass::FOmarl| CharacterClass::FOnewm | CharacterClass::FOnewearl => character.techs.set_tech(Technique::Foie, TechLevel(1)), @@ -291,15 +269,10 @@ async fn new_character(entity_gateway: &mut EG, user: &UserAc } - impl CharacterServerState { pub fn new(entity_gateway: EG) -> CharacterServerState { let (param_header, param_data) = generate_param_data("data/param/"); - /*let ships = vec![Ship::new("Sona-Nyl", [127,0,0,1], 23423), - Ship::new("Dylath-Leen", [127,0,0,1], 23424), - Ship::new("Thalarion", [127,0,0,1], 23425), - ];*/ CharacterServerState { entity_gateway: entity_gateway, param_header: param_header, @@ -581,7 +554,7 @@ impl InterserverActor for CharacterServerState { async fn action(&mut self, id: ServerId, msg: Self::RecvMessage) -> Result, Self::Error> { match msg { - ShipMessage::Authenticate(auth_token) => {}, + ShipMessage::Authenticate(_auth_token) => {}, ShipMessage::NewShip(new_ship) => { self.ships.insert(id, new_ship); },