aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/Cargo.toml1
-rw-r--r--server/client-lib/Cargo.toml1
-rw-r--r--server/client-lib/src/network/sync.rs41
-rw-r--r--server/client-lib/src/network/tokio.rs54
-rw-r--r--server/protocol/Cargo.toml1
-rw-r--r--server/protocol/src/book.rs14
-rw-r--r--server/protocol/src/lib.rs77
-rw-r--r--server/src/main.rs53
8 files changed, 101 insertions, 141 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml
index fe65952f..0698e6ab 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -25,7 +25,6 @@ reqwest = { version = "0.12.23", optional = true, default-features = false, feat
"rustls-tls-native-roots",
] }
pollster = "0.4.0"
-bincode = "2.0.1"
directories = "6.0.0"
igd = { version = "0.12.1", optional = true, features = ["aio"] }
get_if_addrs = { version = "0.5.3", optional = true }
diff --git a/server/client-lib/Cargo.toml b/server/client-lib/Cargo.toml
index b06cbf9f..9d1cb94c 100644
--- a/server/client-lib/Cargo.toml
+++ b/server/client-lib/Cargo.toml
@@ -13,7 +13,6 @@ tokio-tungstenite = { version = "0.27.0", optional = true, features = [
] }
tokio = { version = "1.47.1", features = ["net", "sync"], optional = true }
serde_json = "1.0.145"
-bincode = "2.0.1"
log = "0.4.28"
anyhow = "1.0.99"
futures-util = { version = "0.3.31", optional = true }
diff --git a/server/client-lib/src/network/sync.rs b/server/client-lib/src/network/sync.rs
index eaee72c4..4d6919c9 100644
--- a/server/client-lib/src/network/sync.rs
+++ b/server/client-lib/src/network/sync.rs
@@ -16,7 +16,7 @@
*/
use anyhow::Result;
-use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
+use hurrycurry_protocol::{PacketC, PacketS, VERSION};
use log::{debug, info, warn};
use std::{collections::VecDeque, net::TcpStream};
use tungstenite::{
@@ -104,17 +104,18 @@ impl Network {
None
}
},
- Ok(Message::Binary(packet)) => {
- match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
- Ok((packet, _)) => {
- debug!("<- {packet:?}");
- Some(packet)
- }
- Err(e) => {
- warn!("invalid bincode packet: {e:?}");
- None
- }
- }
+ Ok(Message::Binary(_packet)) => {
+ // match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
+ // Ok((packet, _)) => {
+ // debug!("<- {packet:?}");
+ // Some(packet)
+ // }
+ // Err(e) => {
+ // warn!("invalid bincode packet: {e:?}");
+ // None
+ // }
+ // }
+ None
}
Ok(_) => None,
Err(e) => {
@@ -130,14 +131,14 @@ impl Network {
for packet in self.queue_out.drain(..) {
debug!("-> {packet:?}");
- if self.use_bincode {
- self.sock.write(Message::Binary(
- bincode::encode_to_vec(&packet, BINCODE_CONFIG)?.into(),
- ))?;
- } else {
- self.sock
- .write(Message::Text(serde_json::to_string(&packet)?.into()))?;
- }
+ // if self.use_bincode {
+ // self.sock.write(Message::Binary(
+ // bincode::encode_to_vec(&packet, BINCODE_CONFIG)?.into(),
+ // ))?;
+ // } else {
+ self.sock
+ .write(Message::Text(serde_json::to_string(&packet)?.into()))?;
+ // }
}
self.sock.flush()?;
diff --git a/server/client-lib/src/network/tokio.rs b/server/client-lib/src/network/tokio.rs
index 9fce3909..d42d0fc1 100644
--- a/server/client-lib/src/network/tokio.rs
+++ b/server/client-lib/src/network/tokio.rs
@@ -20,7 +20,7 @@ use futures_util::{
stream::{SplitSink, SplitStream, StreamExt},
SinkExt, TryStreamExt,
};
-use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
+use hurrycurry_protocol::{PacketC, PacketS, VERSION};
use log::{debug, info, warn};
use std::sync::atomic::{AtomicBool, Ordering};
use tokio::{net::TcpStream, sync::RwLock};
@@ -35,7 +35,7 @@ use tungstenite::{
pub struct Network {
sock_recv: RwLock<SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>>,
sock_send: RwLock<SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>,
- use_bincode: AtomicBool,
+ use_binary: AtomicBool,
}
impl Network {
@@ -82,7 +82,7 @@ impl Network {
Ok(Self {
sock_recv: RwLock::new(sock_recv),
sock_send: RwLock::new(sock_send),
- use_bincode: false.into(),
+ use_binary: false.into(),
})
}
@@ -101,7 +101,7 @@ impl Network {
{
if *minor == VERSION.0 && *major == VERSION.1 && *supports_bincode {
info!("Binary protocol format enabled.");
- self.use_bincode.store(true, Ordering::Relaxed);
+ self.use_binary.store(true, Ordering::Relaxed);
}
}
return Ok(Some(packet));
@@ -110,16 +110,16 @@ impl Network {
warn!("invalid json packet: {e:?}");
}
},
- Some(Message::Binary(packet)) => {
- match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
- Ok((packet, _)) => {
- debug!("<- {packet:?}");
- return Ok(Some(packet));
- }
- Err(e) => {
- warn!("invalid bincode packet: {e:?}");
- }
- }
+ Some(Message::Binary(_packet)) => {
+ // match bincode::decode_from_slice(&packet, BINCODE_CONFIG) {
+ // Ok((packet, _)) => {
+ // debug!("<- {packet:?}");
+ // return Ok(Some(packet));
+ // }
+ // Err(e) => {
+ // warn!("invalid bincode packet: {e:?}");
+ // }
+ // }
}
_ => (),
};
@@ -128,19 +128,19 @@ impl Network {
pub async fn send(&self, packet: PacketS) -> anyhow::Result<()> {
debug!("-> {packet:?}");
let mut g = self.sock_send.write().await;
- if self.use_bincode.load(Ordering::Relaxed) {
- g.send(Message::Binary(
- bincode::encode_to_vec(&packet, BINCODE_CONFIG)
- .unwrap()
- .into(),
- ))
- .await?;
- } else {
- g.send(Message::Text(
- serde_json::to_string(&packet).unwrap().into(),
- ))
- .await?;
- }
+ // if self.use_binary.load(Ordering::Relaxed) {
+ // g.send(Message::Binary(
+ // bincode::encode_to_vec(&packet, BINCODE_CONFIG)
+ // .unwrap()
+ // .into(),
+ // ))
+ // .await?;
+ // } else {
+ g.send(Message::Text(
+ serde_json::to_string(&packet).unwrap().into(),
+ ))
+ .await?;
+ // }
Ok(())
}
}
diff --git a/server/protocol/Cargo.toml b/server/protocol/Cargo.toml
index 5905ecb7..5ef6df40 100644
--- a/server/protocol/Cargo.toml
+++ b/server/protocol/Cargo.toml
@@ -6,4 +6,3 @@ edition = "2021"
[dependencies]
serde = { version = "1.0.225", features = ["derive"] }
glam = { version = "0.30.5", features = ["serde"] }
-bincode = { version = "2.0.1", features = ["serde", "derive"] }
diff --git a/server/protocol/src/book.rs b/server/protocol/src/book.rs
index 02dfa425..a8ab5792 100644
--- a/server/protocol/src/book.rs
+++ b/server/protocol/src/book.rs
@@ -17,16 +17,15 @@
*/
use crate::Message;
-use bincode::{Decode, Encode};
use glam::Vec2;
use serde::{Deserialize, Serialize};
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Book {
pub pages: Vec<BookPage>,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "page_type")]
pub enum BookPage {
Cover,
@@ -43,21 +42,20 @@ pub enum BookPage {
},
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, Default)]
+#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Diagram {
pub nodes: Vec<DiagramNode>,
pub edges: Vec<DiagramEdge>,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiagramNode {
- #[bincode(with_serde)]
pub position: Vec2,
pub label: Message,
pub style: NodeStyle,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NodeStyle {
IntermediateProduct,
FinalProduct,
@@ -66,7 +64,7 @@ pub enum NodeStyle {
ProcessInstant,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiagramEdge {
pub src: usize,
pub dst: usize,
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index 146a5a92..90106317 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -15,10 +15,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use bincode::{
- config::{standard, Configuration, Limit, LittleEndian, Varint},
- Decode, Encode,
-};
use glam::{IVec2, Vec2};
use serde::{Deserialize, Deserializer, Serialize};
use std::{collections::HashSet, sync::LazyLock};
@@ -44,48 +40,35 @@ fn test_version_parse() {
let _ = *VERSION;
}
-pub const BINCODE_CONFIG: Configuration<LittleEndian, Varint, Limit<4096>> =
- standard().with_limit();
-
-#[derive(
- Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash,
-)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(transparent)]
pub struct PlayerID(#[serde(deserialize_with = "deser_i64")] pub i64);
-#[derive(
- Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash,
-)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(transparent)]
pub struct ItemIndex(#[serde(deserialize_with = "deser_usize")] pub usize);
-#[derive(
- Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash,
-)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(transparent)]
pub struct TileIndex(#[serde(deserialize_with = "deser_usize")] pub usize);
-#[derive(
- Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash,
-)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(transparent)]
pub struct RecipeIndex(#[serde(deserialize_with = "deser_usize")] pub usize);
-#[derive(
- Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, Hash,
-)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(transparent)]
pub struct DemandIndex(#[serde(deserialize_with = "deser_usize")] pub usize);
-#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(transparent)]
pub struct Hand(#[serde(deserialize_with = "deser_usize")] pub usize);
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MapMetadata {
pub name: String,
pub players: usize,
pub difficulty: i32,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Demand {
pub input: ItemIndex,
pub output: Option<ItemIndex>,
@@ -93,7 +76,7 @@ pub struct Demand {
pub points: i64,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, Default)]
+#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[rustfmt::skip]
pub struct Gamedata {
pub current_map: String,
@@ -108,7 +91,7 @@ pub struct Gamedata {
pub hand_count: usize,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PacketS {
Join {
@@ -116,10 +99,9 @@ pub enum PacketS {
character: Character,
#[serde(default = "chef_class")]
class: PlayerClass,
- #[serde(skip)] // TODO fix bincode can still set id
+ #[serde(skip)]
id: Option<PlayerID>, // used entity bots that cant receive a response
- #[serde(skip)] // TODO fix bincode aswell
- #[bincode(with_serde)]
+ #[serde(skip)]
position: Option<Vec2>, // used entity bots that spawn in different locations
},
Leave {
@@ -127,17 +109,14 @@ pub enum PacketS {
},
Movement {
player: PlayerID,
- #[bincode(with_serde)]
dir: Vec2,
boost: bool,
- #[bincode(with_serde)]
pos: Option<Vec2>,
},
Interact {
player: PlayerID,
hand: Hand,
#[serde(deserialize_with = "deser_ivec2_opt", default)]
- #[bincode(with_serde)]
pos: Option<IVec2>,
},
Communicate {
@@ -156,7 +135,6 @@ pub enum PacketS {
},
#[serde(skip)]
- #[bincode(skip)]
/// For internal use only (customers)
ReplaceHand {
player: PlayerID,
@@ -164,11 +142,9 @@ pub enum PacketS {
item: Option<ItemIndex>,
},
#[serde(skip)]
- #[bincode(skip)]
/// For internal use only (customers)
ApplyScore(Score),
#[serde(skip)]
- #[bincode(skip)]
/// For internal use only (customers)
Effect {
player: PlayerID,
@@ -176,7 +152,7 @@ pub enum PacketS {
},
}
-#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
pub struct Character {
#[serde(deserialize_with = "deser_i32", default)]
pub color: i32,
@@ -190,7 +166,7 @@ fn chef_class() -> PlayerClass {
PlayerClass::Chef
}
-#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum PlayerClass {
Chef,
@@ -204,7 +180,7 @@ impl PlayerClass {
}
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, PartialEq, Eq)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum Message {
Translation { id: String, params: Vec<Message> },
@@ -213,7 +189,7 @@ pub enum Message {
Tile(TileIndex),
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PacketC {
Version {
@@ -229,7 +205,6 @@ pub enum PacketC {
},
AddPlayer {
id: PlayerID,
- #[bincode(with_serde)]
position: Vec2,
class: PlayerClass,
character: Character,
@@ -240,10 +215,8 @@ pub enum PacketC {
},
Movement {
player: PlayerID,
- #[bincode(with_serde)]
pos: Vec2,
rot: f32,
- #[bincode(with_serde)]
dir: Vec2,
boost: bool,
},
@@ -269,7 +242,6 @@ pub enum PacketC {
warn: bool,
},
UpdateMap {
- #[bincode(with_serde)]
tile: IVec2,
kind: Option<TileIndex>,
neighbors: [Option<TileIndex>; 4],
@@ -289,7 +261,6 @@ pub enum PacketC {
error: bool,
},
ServerHint {
- #[bincode(with_serde)]
position: Option<IVec2>,
message: Option<Message>,
player: PlayerID,
@@ -320,7 +291,7 @@ pub enum PacketC {
ReplayStop,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "menu", content = "data")]
pub enum Menu {
Score(Score),
@@ -329,14 +300,14 @@ pub enum Menu {
AnnounceStart,
}
-#[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, Default)]
+#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub struct MessageTimeout {
pub remaining: f32,
pub initial: f32,
pub pinned: bool,
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, Default)]
+#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct Score {
pub time_remaining: f64,
pub stars: u8,
@@ -349,18 +320,18 @@ pub struct Score {
pub instant_recipes: usize,
}
-#[derive(Debug, Serialize, Deserialize, Encode, Decode, Clone, Default)]
+#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Scoreboard {
pub plays: usize,
pub best: Vec<ScoreboardEntry>,
}
-#[derive(Debug, Serialize, Deserialize, Encode, Decode, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ScoreboardEntry {
pub players: Vec<String>,
pub score: Score,
}
-#[derive(Debug, Clone, Serialize, Encode, Decode, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Recipe {
Passive {
@@ -385,10 +356,10 @@ pub enum Recipe {
},
}
-#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, Copy, PartialEq, Eq, Hash)]
+#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub enum ItemLocation {
- Tile(#[bincode(with_serde)] IVec2),
+ Tile(IVec2),
Player(PlayerID, Hand),
}
diff --git a/server/src/main.rs b/server/src/main.rs
index ef397c7d..c6b0d59f 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -18,7 +18,7 @@
use anyhow::{bail, Result};
use clap::Parser;
use futures_util::{SinkExt, StreamExt};
-use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
+use hurrycurry_protocol::{PacketC, PacketS, VERSION};
use hurrycurry_server::{
data::DATA_DIR,
server::{GameServerExt, Server},
@@ -26,15 +26,7 @@ use hurrycurry_server::{
};
use log::{debug, info, trace, warn, LevelFilter};
use std::{
- env::var,
- net::SocketAddr,
- path::PathBuf,
- process::exit,
- str::FromStr,
- sync::{
- atomic::{AtomicBool, Ordering},
- Arc,
- },
+ env::var, net::SocketAddr, path::PathBuf, process::exit, str::FromStr, sync::Arc,
time::Duration,
};
use tokio::{
@@ -227,8 +219,8 @@ async fn run(args: Args) -> anyhow::Result<()> {
},
);
- let supports_binary = Arc::new(AtomicBool::new(false));
- let supports_binary2 = supports_binary.clone();
+ // let supports_binary = Arc::new(AtomicBool::new(false));
+ // let supports_binary2 = supports_binary.clone();
spawn(async move {
for p in init {
@@ -260,15 +252,15 @@ async fn run(args: Args) -> anyhow::Result<()> {
info!("Client outbound sender dropped. closing connection");
break;
};
- let message = if supports_binary.load(Ordering::Relaxed) {
- Message::Binary(
- bincode::encode_to_vec(&packet, BINCODE_CONFIG)
- .unwrap()
- .into(),
- )
- } else {
- Message::Text(serde_json::to_string(&packet).unwrap().into())
- };
+ // let message = if supports_binary.load(Ordering::Relaxed) {
+ // Message::Binary(
+ // bincode::encode_to_vec(&packet, BINCODE_CONFIG)
+ // .unwrap()
+ // .into(),
+ // )
+ // } else {
+ let message = Message::Text(serde_json::to_string(&packet).unwrap().into());
+ // };
if let Err(e) = write.send(message).await {
warn!("WebSocket error: {e}");
break;
@@ -287,15 +279,16 @@ async fn run(args: Args) -> anyhow::Result<()> {
break;
}
},
- Message::Binary(packet) => {
- supports_binary2.store(true, Ordering::Relaxed);
- match bincode::decode_from_slice::<PacketS, _>(&packet, BINCODE_CONFIG) {
- Ok((p, _size)) => p,
- Err(e) => {
- warn!("Invalid binary packet: {e}");
- break;
- }
- }
+ Message::Binary(_packet) => {
+ // supports_binary2.store(true, Ordering::Relaxed);
+ // match bincode::decode_from_slice::<PacketS, _>(&packet, BINCODE_CONFIG) {
+ // Ok((p, _size)) => p,
+ // Err(e) => {
+ // warn!("Invalid binary packet: {e}");
+ // break;
+ // }
+ // }
+ continue;
}
Message::Close(_) => break,
_ => continue,