[backup] games from server with images

This commit is contained in:
2024-11-13 23:51:28 +01:00
parent 5d45c4ce4b
commit a6ed6e04fe
13 changed files with 214 additions and 113 deletions

View File

@ -1,5 +1,6 @@
use std::{net::SocketAddr, time::Duration};
use bytes::{Bytes, BytesMut};
use lanspread_db::db::Game;
use lanspread_proto::{Message as _, Request, Response};
use lanspread_utils::maybe_addr;
@ -69,7 +70,7 @@ pub async fn run(
ClientCommand::ListGames => Request::ListGames,
ClientCommand::GetGame(id) => Request::GetGame { id },
ClientCommand::ServerAddr(_) => Request::Invalid(
[].into(),
Bytes::new(),
"invalid control message (ServerAddr), should not happen".into(),
),
};
@ -91,24 +92,26 @@ pub async fn run(
log::error!("failed to send request to server {:?}", e);
}
let mut data: Vec<u8> = Vec::new();
let mut data = BytesMut::new();
while let Ok(Some(bytes)) = rx.receive().await {
data.extend_from_slice(&bytes);
}
log::debug!("{} bytes received from server", data.len());
log::trace!("server response (RAW): {}", String::from_utf8_lossy(&data));
let response = Response::decode(&data);
let response = Response::decode(data.freeze());
log::trace!("server response (DECODED): {response:?}");
match response {
Response::Games(games) => {
for game in &games {
log::debug!("{game}");
log::trace!("{game}");
}
if let Err(e) = tx_notify_ui.send(ClientEvent::ListGames(games)) {
log::debug!("failed to send ClientEvent::ListGames to client {e:?}");
} else {
log::info!("sent ClientEvent::ListGames to Tauri client");
}
}
Response::Game(game) => log::debug!("game received: {game:?}"),