Connections are properly closed
This commit is contained in:
		| @@ -162,4 +162,11 @@ impl Client { | ||||
|     pub async fn recv_next_message(&self) -> Res<ServerMessage> { | ||||
|         Ok(self.receiver.recv()?) | ||||
|     } | ||||
|  | ||||
|     /// Close connection | ||||
|     pub async fn close_connection(&mut self) { | ||||
|         if let Err(e) = self.sink.send(Message::Close(None)).await { | ||||
|             log::debug!("Failed to close WS connection! {:?}", e); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -145,6 +145,7 @@ impl GameScreen { | ||||
|                         KeyCode::Char('q') | ||||
|                             if confirm(terminal, "Do you really want to leave game?") => | ||||
|                         { | ||||
|                             self.client.close_connection().await; | ||||
|                             return Ok(ScreenResult::Canceled); | ||||
|                         } | ||||
|  | ||||
| @@ -192,7 +193,10 @@ impl GameScreen { | ||||
|                                     .await?; | ||||
|                                 self.status = GameStatus::RematchRejected; | ||||
|                             } | ||||
|                             Buttons::QuitGame => return Ok(ScreenResult::Ok(())), | ||||
|                             Buttons::QuitGame => { | ||||
|                                 self.client.close_connection().await; | ||||
|                                 return Ok(ScreenResult::Ok(())); | ||||
|                             } | ||||
|                         }, | ||||
|  | ||||
|                         _ => {} | ||||
| @@ -249,6 +253,7 @@ impl GameScreen { | ||||
|                                     .await? | ||||
|                             } | ||||
|                             ScreenResult::Canceled => { | ||||
|                                 self.client.close_connection().await; | ||||
|                                 return Ok(ScreenResult::Canceled); | ||||
|                             } | ||||
|                         }; | ||||
|   | ||||
| @@ -72,7 +72,7 @@ impl GameStatus { | ||||
|     pub fn can_game_continue_with_bot(&self) -> bool { | ||||
|         *self != GameStatus::Finished | ||||
|             && *self != GameStatus::RematchRejected | ||||
|             && *self != GameStatus::RematchRejected | ||||
|             && *self != GameStatus::RematchRequested | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user