|
|
@ -49,12 +49,12 @@ impl MessageReceiver { |
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
enum InterserverInputAction<S, R> {
|
|
|
|
NewConnection(ServerId, async_std::sync::Sender<S>),
|
|
|
|
NewConnection(ServerId, async_std::channel::Sender<S>),
|
|
|
|
Message(ServerId, R),
|
|
|
|
Disconnect(ServerId),
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn interserver_state_loop<A, S, R>(state: Arc<Mutex<A>>, action_receiver: async_std::sync::Receiver<InterserverInputAction<S, R>>)
|
|
|
|
async fn interserver_state_loop<A, S, R>(state: Arc<Mutex<A>>, action_receiver: async_std::channel::Receiver<InterserverInputAction<S, R>>)
|
|
|
|
where
|
|
|
|
A: InterserverActor<SendMessage=S, RecvMessage=R, Error=()> + Send + 'static,
|
|
|
|
S: Serialize + Send + 'static,
|
|
|
@ -114,8 +114,8 @@ where |
|
|
|
|
|
|
|
async fn login_recv_loop<S, R>(server_id: ServerId,
|
|
|
|
socket: async_std::net::TcpStream,
|
|
|
|
state_loop_sender: async_std::sync::Sender<InterserverInputAction<S, R>>,
|
|
|
|
output_loop_sender: async_std::sync::Sender<S>)
|
|
|
|
state_loop_sender: async_std::channel::Sender<InterserverInputAction<S, R>>,
|
|
|
|
output_loop_sender: async_std::channel::Sender<S>)
|
|
|
|
where
|
|
|
|
S: Serialize + std::fmt::Debug + Send + 'static,
|
|
|
|
R: DeserializeOwned + std::fmt::Debug + Send + 'static,
|
|
|
@ -129,7 +129,7 @@ where |
|
|
|
match msg_receiver.recv().await {
|
|
|
|
Ok(msg) => {
|
|
|
|
info!("[login recv loop msg] {:?}", msg);
|
|
|
|
state_loop_sender.send(InterserverInputAction::Message(server_id, msg)).await
|
|
|
|
state_loop_sender.send(InterserverInputAction::Message(server_id, msg)).await;
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
if let MessageReceiverError::Disconnected = err {
|
|
|
@ -146,7 +146,7 @@ where |
|
|
|
|
|
|
|
async fn interserver_send_loop<S>(server_id: ServerId,
|
|
|
|
mut socket: async_std::net::TcpStream,
|
|
|
|
output_loop_receiver: async_std::sync::Receiver<S>)
|
|
|
|
output_loop_receiver: async_std::channel::Receiver<S>)
|
|
|
|
where
|
|
|
|
S: Serialize + std::fmt::Debug + Send + 'static,
|
|
|
|
{
|
|
|
@ -159,13 +159,13 @@ where |
|
|
|
if let Ok(payload) = payload {
|
|
|
|
let len_bytes = u32::to_le_bytes(payload.len() as u32);
|
|
|
|
|
|
|
|
match socket.write_all(&len_bytes).await {
|
|
|
|
Ok(_) => {},
|
|
|
|
Err(err) => warn!("send failed: {:?}", err),
|
|
|
|
if let Err(err) = socket.write_all(&len_bytes).await {
|
|
|
|
warn!("interserver send failed: {:?}", err);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
match socket.write_all(&payload.as_bytes()).await {
|
|
|
|
Ok(_) => {},
|
|
|
|
Err(err) => warn!("send failed: {:?}", err),
|
|
|
|
if let Err(err) = socket.write_all(&payload.as_bytes()).await {
|
|
|
|
warn!("intserserver send failed: {:?}", err);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
@ -185,7 +185,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara |
|
|
|
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 = 0;
|
|
|
|
|
|
|
|
let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024);
|
|
|
|
let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024);
|
|
|
|
interserver_state_loop(state.clone(), server_state_receiver).await;
|
|
|
|
|
|
|
|
loop {
|
|
|
@ -194,7 +194,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara |
|
|
|
|
|
|
|
id += 1;
|
|
|
|
let server_id = crate::common::interserver::ServerId(id);
|
|
|
|
let (client_sender, client_receiver) = async_std::sync::channel(64);
|
|
|
|
let (client_sender, client_receiver) = async_std::channel::bounded(64);
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut state = state.lock().await;
|
|
|
@ -213,7 +213,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara |
|
|
|
pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipServerState<EG>>>, ip: std::net::Ipv4Addr, port: u16) -> Pin<Box<dyn Future<Output = ()>>> {
|
|
|
|
Box::pin(async_std::task::spawn(async move {
|
|
|
|
let mut id = 0;
|
|
|
|
let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024);
|
|
|
|
let (server_state_sender, server_state_receiver) = async_std::channel::bounded(1024);
|
|
|
|
|
|
|
|
interserver_state_loop(state.clone(), server_state_receiver).await;
|
|
|
|
|
|
|
@ -230,7 +230,7 @@ pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipS |
|
|
|
id += 1;
|
|
|
|
let server_id = crate::common::interserver::ServerId(id);
|
|
|
|
info!("found loginserv: {:?} {:?}", server_id, socket);
|
|
|
|
let (client_sender, client_receiver) = async_std::sync::channel(64);
|
|
|
|
let (client_sender, client_receiver) = async_std::channel::bounded(64);
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut state = state.lock().await;
|
|
|
|