summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstale <redkugelblitzin@gmail.com>2022-05-29 23:56:03 -0300
committerstale <redkugelblitzin@gmail.com>2022-05-29 23:56:03 -0300
commitb1fd887402e4577cbb630fc6517cf9cd6e0d7c8f (patch)
tree7018603244d38a361f86aa0b1a6ea11ea39f27c6 /src
parentc896f3a5f9b2e3f7f03ad1871b6566f098c0e295 (diff)
compression! also bumped edition
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}"))); },