summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 3dd7f39..66b2cfd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -176,6 +176,8 @@ async fn tokio_main(conf: Config) -> Result<(), Box<dyn Error>> {
// If a move is made, broadcast new board, else just send current board
async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver<MetaMove>, players: PlayerMapData, bconf: minesweeper::BoardConf) {
use minesweeper::*;
+ use flate2::{ Compression, write::DeflateEncoder };
+ use std::io::Write;
let mut game = Game::new(bconf);
let mut latest_player_name = None;
while let Some(req) = move_rx.recv().await {
@@ -192,7 +194,10 @@ async fn gameloop(mut move_rx: tokio::sync::mpsc::UnboundedReceiver<MetaMove>, p
MetaMove::Reset => { game = Game::new(bconf); },
}
use warp::ws::Message;
- let mut reply = vec![Message::binary(game.board.render())];
+ let mut board_encoder = DeflateEncoder::new(Vec::new(), Compression::default());
+ board_encoder.write_all(&game.board.render()).unwrap();
+ let compressed_board = board_encoder.finish().unwrap();
+ let mut reply = vec![Message::binary(compressed_board)];
let lpname = latest_player_name.as_ref().map(|s| s.as_str()).unwrap_or("unknown player");
match game.phase {
Phase::Win => { reply.push(Message::text(format!("win {lpname}"))); },