Browse Source

if any of these sends fail the program should panic so unwrap is fine

pull/42/head
jake 4 years ago
parent
commit
60f04597d1
  1. 16
      src/common/mainloop/client.rs
  2. 16
      src/common/mainloop/interserver.rs
  3. 2
      src/login/login.rs

16
src/common/mainloop/client.rs

@ -149,7 +149,7 @@ where
R: RecvServerPacket + std::fmt::Debug + Send + 'static,
{
async_std::task::spawn(async move {
server_sender.send(ClientAction::NewClient(client_id, client_sender)).await;
server_sender.send(ClientAction::NewClient(client_id, client_sender)).await.unwrap();
let mut pkt_receiver = PacketReceiver::new(socket, cipher);
loop {
@ -157,14 +157,14 @@ where
Ok(pkts) => {
for pkt in pkts {
trace!("[recv from {:?}] {:?}", client_id, pkt);
server_sender.send(ClientAction::Packet(client_id, pkt)).await;
server_sender.send(ClientAction::Packet(client_id, pkt)).await.unwrap();
}
},
Err(err) => {
match err {
NetworkError::ClientDisconnected => {
trace!("[client disconnected] {:?}", client_id);
server_sender.send(ClientAction::Disconnect(client_id)).await;
server_sender.send(ClientAction::Disconnect(client_id)).await.unwrap();
break;
}
_ => {
@ -229,10 +229,10 @@ fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
for action in actions {
match action {
OnConnect::Cipher((inc, outc)) => {
sender.send(ServerStateAction::Cipher(inc, outc)).await;
sender.send(ServerStateAction::Cipher(inc, outc)).await.unwrap();
},
OnConnect::Packet(pkt) => {
sender.send(ServerStateAction::Packet(pkt)).await;
sender.send(ServerStateAction::Packet(pkt)).await.unwrap();
}
}
}
@ -249,7 +249,7 @@ fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
Ok(pkts) => {
for (client_id, pkt) in pkts {
if let Some(client) = clients.get_mut(&client_id) {
client.send(ServerStateAction::Packet(pkt)).await;
client.send(ServerStateAction::Packet(pkt)).await.unwrap();
}
}
},
@ -264,12 +264,12 @@ fn state_client_loop<STATE, S, R, E>(state: Arc<Mutex<STATE>>,
Ok(pkts) => {
for (client_id, pkt) in pkts {
if let Some(client) = clients.get_mut(&client_id) {
client.send(ServerStateAction::Packet(pkt)).await;
client.send(ServerStateAction::Packet(pkt)).await.unwrap();
}
}
if let Some(client) = clients.get_mut(&client_id) {
client.send(ServerStateAction::Disconnect).await;
client.send(ServerStateAction::Disconnect).await.unwrap();
}
}
Err(err) => {

16
src/common/mainloop/interserver.rs

@ -79,7 +79,7 @@ where
ships.insert(server_id, ship_action_sender);
for (server, action) in state.on_connect(server_id).await {
if let Some(sender) = ships.get_mut(&server) {
sender.send(action).await;
sender.send(action).await.unwrap();
}
}
},
@ -89,7 +89,7 @@ where
Ok(actions) => {
for (server, action) in actions{
if let Some(sender) = ships.get_mut(&server) {
sender.send(action).await;
sender.send(action).await.unwrap();
}
}
},
@ -103,7 +103,7 @@ where
ships.remove(&server_id);
for (server, action) in actions {
if let Some(sender) = ships.get_mut(&server) {
sender.send(action).await;
sender.send(action).await.unwrap();
}
}
}
@ -121,7 +121,7 @@ where
R: DeserializeOwned + std::fmt::Debug + Send + 'static,
{
async_std::task::spawn(async move {
state_loop_sender.send(InterserverInputAction::NewConnection(server_id, output_loop_sender)).await;
state_loop_sender.send(InterserverInputAction::NewConnection(server_id, output_loop_sender)).await.unwrap();
let mut msg_receiver = MessageReceiver::new(socket);
loop {
@ -129,12 +129,12 @@ 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.unwrap();
},
Err(err) => {
if let MessageReceiverError::Disconnected = err {
info!("[login recv loop disconnect] {:?}", server_id);
state_loop_sender.send(InterserverInputAction::Disconnect(server_id)).await;
state_loop_sender.send(InterserverInputAction::Disconnect(server_id)).await.unwrap();
break;
}
info!("[login recv loop err] {:?}", err);
@ -200,7 +200,7 @@ pub fn login_listen_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<Chara
let mut state = state.lock().await;
let local_sender = client_sender.clone();
state.set_sender(server_id, Box::new(move |message| {
async_std::task::block_on(local_sender.send(message));
async_std::task::block_on(local_sender.send(message)).unwrap();
}))
}
@ -236,7 +236,7 @@ pub fn ship_connect_mainloop<EG: EntityGateway + 'static>(state: Arc<Mutex<ShipS
let mut state = state.lock().await;
let local_sender = client_sender.clone();
state.set_sender(Box::new(move |message| {
async_std::task::block_on(local_sender.send(message));
async_std::task::block_on(local_sender.send(message)).unwrap();
}))
}

2
src/login/login.rs

@ -164,7 +164,7 @@ impl<EG: EntityGateway> ServerState for LoginServerState<EG> {
if let Some(username) = self.clients.remove(&id) {
if let Ok(mut user) = self.entity_gateway.get_user_by_name(username).await {
user.at_login = false;
self.entity_gateway.save_user(&user).await;
self.entity_gateway.save_user(&user).await?;
}
}
Ok(Vec::new())

Loading…
Cancel
Save