[code][fix] improvements for LAN 202503
- more robust client <-> server connection - new client event: DownloadGameFilesFailed - 3 seconds to reconnect - retry forever if server is gone and never lose a UI request - code cleanup here and there (mostly server)
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
use bytes::Bytes;
|
||||
use lanspread_db::db::{Game, GameFileDescription};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::error;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum Request {
|
||||
@ -15,8 +14,11 @@ pub enum Request {
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum Response {
|
||||
Pong,
|
||||
Games(Vec<Game>),
|
||||
GetGame(Vec<GameFileDescription>),
|
||||
ListGames(Vec<Game>),
|
||||
GetGame {
|
||||
id: String,
|
||||
file_descriptions: Vec<GameFileDescription>,
|
||||
},
|
||||
GameNotFound(String),
|
||||
InvalidRequest(Bytes, String),
|
||||
EncodingError(String),
|
||||
@ -35,11 +37,7 @@ impl Message for Request {
|
||||
match serde_json::from_slice(&bytes) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"got invalid request from client (error: {}): {}",
|
||||
e,
|
||||
String::from_utf8_lossy(&bytes)
|
||||
);
|
||||
tracing::error!(?e, "Request decoding error");
|
||||
Request::Invalid(bytes, e.to_string())
|
||||
}
|
||||
}
|
||||
@ -49,7 +47,7 @@ impl Message for Request {
|
||||
match serde_json::to_vec(self) {
|
||||
Ok(s) => Bytes::from(s),
|
||||
Err(e) => {
|
||||
error!(?e, "Request encoding error");
|
||||
tracing::error!(?e, "Request encoding error");
|
||||
Bytes::from(format!(r#"{{"error": "encoding error: {e}"}}"#))
|
||||
}
|
||||
}
|
||||
@ -61,7 +59,10 @@ impl Message for Response {
|
||||
fn decode(bytes: Bytes) -> Self {
|
||||
match serde_json::from_slice(&bytes) {
|
||||
Ok(t) => t,
|
||||
Err(e) => Response::DecodingError(bytes, e.to_string()),
|
||||
Err(e) => {
|
||||
tracing::error!(?e, "Response decoding error");
|
||||
Response::DecodingError(bytes, e.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +70,7 @@ impl Message for Response {
|
||||
match serde_json::to_vec(self) {
|
||||
Ok(s) => Bytes::from(s),
|
||||
Err(e) => {
|
||||
error!(?e, "Response encoding error");
|
||||
tracing::error!(?e, "Response encoding error");
|
||||
Bytes::from(format!(r#"{{"error": "encoding error: {e}"}}"#))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user