diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-03-30 10:08:34 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-03-30 10:08:34 +0200 |
| commit | 1fe3a3aad1dc346697b8815d2dba15f9e9e3265e (patch) | |
| tree | 4516c1eee220caf1dafaff673959b8d7571c460c /mumd/src/network | |
| parent | 6e71b1fee95e5f320bbc27e4148ff48e0d390073 (diff) | |
| download | mum-1fe3a3aad1dc346697b8815d2dba15f9e9e3265e.tar.gz | |
handle faulty tcp stream
Diffstat (limited to 'mumd/src/network')
| -rw-r--r-- | mumd/src/network/tcp.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index 29749f1..a1b4597 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -252,8 +252,21 @@ async fn listen( let mut crypt_state_sender = Some(crypt_state_sender); loop { - let packet = stream.next().await.unwrap(); - match packet.unwrap() { + let packet = match stream.next().await { + Some(Ok(packet)) => packet, + Some(Err(e)) => { + error!("TCP error: {:?}", e); + continue; //TODO Break here? Maybe look at the error and handle it + } + None => { + // We end up here if the login was rejected. We probably want + // to exit before that. + warn!("TCP stream gone"); + state.lock().await.broadcast_phase(StatePhase::Disconnected); + break; + } + }; + match packet { ControlPacket::TextMessage(msg) => { info!( "Got message from user with session ID {}: {}", |
