|
@ -49,12 +49,12 @@ impl MessageReceiver { |
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
#[derive(Debug)]
|
|
|
enum InterserverInputAction<S, R> {
|
|
|
enum InterserverInputAction<S, R> {
|
|
|
NewConnection(ServerId, async_std::sync::Sender<S>),
|
|
|
|
|
|
|
|
|
NewConnection(ServerId, async_std::channel::Sender<S>),
|
|
|
Message(ServerId, R),
|
|
|
Message(ServerId, R),
|
|
|
Disconnect(ServerId),
|
|
|
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
|
|
|
where
|
|
|
A: InterserverActor<SendMessage=S, RecvMessage=R, Error=()> + Send + 'static,
|
|
|
A: InterserverActor<SendMessage=S, RecvMessage=R, Error=()> + Send + 'static,
|
|
|
S: Serialize + Send + 'static,
|
|
|
S: Serialize + Send + 'static,
|
|
@ -114,8 +114,8 @@ where |
|
|
|
|
|
|
|
|
async fn login_recv_loop<S, R>(server_id: ServerId,
|
|
|
async fn login_recv_loop<S, R>(server_id: ServerId,
|
|
|
socket: async_std::net::TcpStream,
|
|
|
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
|
|
|
where
|
|
|
S: Serialize + std::fmt::Debug + Send + 'static,
|
|
|
S: Serialize + std::fmt::Debug + Send + 'static,
|
|
|
R: DeserializeOwned + std::fmt::Debug + Send + 'static,
|
|
|
R: DeserializeOwned + std::fmt::Debug + Send + 'static,
|
|
@ -129,7 +129,7 @@ where |
|
|
match msg_receiver.recv().await {
|
|
|
match msg_receiver.recv().await {
|
|
|
Ok(msg) => {
|
|
|
Ok(msg) => {
|
|
|
info!("[login recv loop msg] {:?}", 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) => {
|
|
|
Err(err) => {
|
|
|
if let MessageReceiverError::Disconnected = err {
|
|
|
if let MessageReceiverError::Disconnected = err {
|
|
@ -146,7 +146,7 @@ where |
|
|
|
|
|
|
|
|
async fn interserver_send_loop<S>(server_id: ServerId,
|
|
|
async fn interserver_send_loop<S>(server_id: ServerId,
|
|
|
mut socket: async_std::net::TcpStream,
|
|
|
mut socket: async_std::net::TcpStream,
|
|
|
output_loop_receiver: async_std::sync::Receiver<S>)
|
|
|
|
|
|
|
|
|
output_loop_receiver: async_std::channel::Receiver<S>)
|
|
|
where
|
|
|
where
|
|
|
S: Serialize + std::fmt::Debug + Send + 'static,
|
|
|
S: Serialize + std::fmt::Debug + Send + 'static,
|
|
|
{
|
|
|
{
|
|
@ -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 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 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;
|
|
|
interserver_state_loop(state.clone(), server_state_receiver).await;
|
|
|
|
|
|
|
|
|
loop {
|
|
|
loop {
|
|
@ -194,7 +194,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara |
|
|
|
|
|
|
|
|
id += 1;
|
|
|
id += 1;
|
|
|
let server_id = crate::common::interserver::ServerId(id);
|
|
|
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;
|
|
|
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 = ()>>> {
|
|
|
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 {
|
|
|
Box::pin(async_std::task::spawn(async move {
|
|
|
let mut id = 0;
|
|
|
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;
|
|
|
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;
|
|
|
id += 1;
|
|
|
let server_id = crate::common::interserver::ServerId(id);
|
|
|
let server_id = crate::common::interserver::ServerId(id);
|
|
|
info!("found loginserv: {:?} {:?}", server_id, socket);
|
|
|
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;
|
|
|
let mut state = state.lock().await;
|
|
|