aboutsummaryrefslogtreecommitdiff
path: root/server/protocol/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/protocol/src')
-rw-r--r--server/protocol/src/helpers.rs101
-rw-r--r--server/protocol/src/lib.rs76
2 files changed, 110 insertions, 67 deletions
diff --git a/server/protocol/src/helpers.rs b/server/protocol/src/helpers.rs
index 31e68d02..90dfd6ff 100644
--- a/server/protocol/src/helpers.rs
+++ b/server/protocol/src/helpers.rs
@@ -15,8 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use crate::{Gamedata, Hand, ItemIndex, ItemLocation, PlayerID, Recipe, RecipeIndex, TileIndex};
-use std::fmt::Display;
+use crate::{Gamedata, ItemIndex, Recipe, RecipeIndex, TileIndex};
impl Gamedata {
pub fn tile_name(&self, index: TileIndex) -> &str {
@@ -102,37 +101,89 @@ impl Recipe {
}
}
-impl Display for ItemLocation {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- match self {
- ItemLocation::Tile(pos) => write!(f, "tile({}, {})", pos.x, pos.y),
- ItemLocation::Player(player, hand) => write!(f, "{player}-{hand}"),
+mod display {
+ use crate::*;
+ use std::fmt::Display;
+
+ impl Display for ItemLocation {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ ItemLocation::Tile(pos) => write!(f, "tile({}, {})", pos.x, pos.y),
+ ItemLocation::Player(player, hand) => write!(f, "{player}-{hand}"),
+ }
+ }
+ }
+ impl Display for Hand {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "hand#{}", self.0)
+ }
+ }
+ impl Display for PlayerID {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "player#{}", self.0)
+ }
+ }
+ impl Display for TileIndex {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "tile#{}", self.0)
+ }
+ }
+ impl Display for ItemIndex {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "item#{}", self.0)
+ }
+ }
+ impl Display for RecipeIndex {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "recipe#{}", self.0)
}
}
}
-impl Display for Hand {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "hand#{}", self.0)
+mod enum_is {
+ use crate::*;
+
+ impl PlayerClass {
+ pub fn is_cheflike(&self) -> bool {
+ matches!(self, Self::Bot | Self::Chef)
+ }
}
-}
-impl Display for PlayerID {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "player#{}", self.0)
+
+ impl ItemLocation {
+ pub fn is_tile(&self) -> bool {
+ matches!(self, Self::Tile(..))
+ }
+ pub fn is_player(&self) -> bool {
+ matches!(self, Self::Player(..))
+ }
}
}
-impl Display for TileIndex {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "tile#{}", self.0)
+
+pub mod deser {
+ use crate::*;
+ use serde::Deserializer;
+ use std::collections::BTreeMap;
+
+ pub(crate) fn deser_i64<'de, D: Deserializer<'de>>(deserializer: D) -> Result<i64, D::Error> {
+ let x = f64::deserialize(deserializer)?;
+ Ok(x.trunc() as i64)
}
-}
-impl Display for ItemIndex {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "item#{}", self.0)
+ pub(crate) fn deser_i32<'de, D: Deserializer<'de>>(deserializer: D) -> Result<i32, D::Error> {
+ let x = f64::deserialize(deserializer)?;
+ Ok(x.trunc() as i32)
}
-}
-impl Display for RecipeIndex {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "recipe#{}", self.0)
+ pub(crate) fn deser_usize<'de, D: Deserializer<'de>>(
+ deserializer: D,
+ ) -> Result<usize, D::Error> {
+ let x = f64::deserialize(deserializer)?;
+ Ok(x.trunc() as usize)
+ }
+ pub(crate) fn deser_tile_index_map<'de, D: Deserializer<'de>>(
+ deserializer: D,
+ ) -> Result<BTreeMap<TileIndex, HashSet<ItemIndex>>, D::Error> {
+ let x = BTreeMap::<String, HashSet<ItemIndex>>::deserialize(deserializer)?;
+ Ok(x.into_iter()
+ .map(|(k, v)| (TileIndex(k.parse().ok().unwrap_or_default()), v))
+ .collect())
}
}
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index 2be37730..a89d9c30 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -15,8 +15,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::book::Book;
use glam::{IVec2, Vec2};
-use serde::{Deserialize, Deserializer, Serialize};
+use helpers::deser::*;
+use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, BTreeSet, HashSet},
sync::LazyLock,
@@ -24,8 +26,6 @@ use std::{
pub use glam;
-use crate::book::Book;
-
pub mod book;
pub mod helpers;
pub mod movement;
@@ -94,8 +94,18 @@ pub struct Gamedata {
pub recipes: Vec<Recipe>,
pub demands: Vec<Demand>,
pub hand_count: usize,
+ pub flags: GamedataFlags,
+}
+
+#[rustfmt::skip]
+#[derive(Debug, Clone, Default, Serialize, Deserialize)]
+pub struct GamedataFlags {
+ #[serde(default)] pub disable_unknown_orders: bool,
}
+fn chef_class() -> PlayerClass {
+ PlayerClass::Chef
+}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum PacketS {
@@ -139,22 +149,28 @@ pub enum PacketS {
dt: f64,
},
- #[serde(skip)]
/// For internal use only (customers)
+ #[serde(skip)]
ReplaceHand {
player: PlayerID,
hand: Hand,
item: Option<ItemIndex>,
},
- #[serde(skip)]
+
/// For internal use only (customers)
- ApplyScore(Score),
#[serde(skip)]
+ ApplyScore(Score),
+
/// For internal use only (customers)
+ #[serde(skip)]
Effect {
player: PlayerID,
name: String,
},
+
+ /// Used internally and only used when built with debug_events
+ #[serde(skip)]
+ Debug(DebugEvent),
}
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
@@ -167,10 +183,6 @@ pub struct Character {
pub headwear: i32,
}
-fn chef_class() -> PlayerClass {
- PlayerClass::Chef
-}
-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum PlayerClass {
@@ -179,11 +191,6 @@ pub enum PlayerClass {
Customer,
Tram,
}
-impl PlayerClass {
- pub fn is_cheflike(&self) -> bool {
- matches!(self, Self::Bot | Self::Chef)
- }
-}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
@@ -294,6 +301,9 @@ pub enum PacketC {
/// For use in replay sessions only
ReplayStart,
ReplayStop,
+
+ /// Only used when built with debug_events
+ Debug(DebugEvent),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -369,32 +379,14 @@ pub enum ItemLocation {
Player(PlayerID, Hand),
}
-impl ItemLocation {
- pub fn is_tile(&self) -> bool {
- matches!(self, Self::Tile(..))
- }
- pub fn is_player(&self) -> bool {
- matches!(self, Self::Player(..))
- }
-}
-
-fn deser_i64<'de, D: Deserializer<'de>>(deserializer: D) -> Result<i64, D::Error> {
- let x = f64::deserialize(deserializer)?;
- Ok(x.trunc() as i64)
-}
-fn deser_i32<'de, D: Deserializer<'de>>(deserializer: D) -> Result<i32, D::Error> {
- let x = f64::deserialize(deserializer)?;
- Ok(x.trunc() as i32)
-}
-fn deser_usize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<usize, D::Error> {
- let x = f64::deserialize(deserializer)?;
- Ok(x.trunc() as usize)
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct DebugEvent {
+ key: String,
+ display: Vec<DebugEventDisplay>,
+ timeout: Option<f32>,
}
-fn deser_tile_index_map<'de, D: Deserializer<'de>>(
- deserializer: D,
-) -> Result<BTreeMap<TileIndex, HashSet<ItemIndex>>, D::Error> {
- let x = BTreeMap::<String, HashSet<ItemIndex>>::deserialize(deserializer)?;
- Ok(x.into_iter()
- .map(|(k, v)| (TileIndex(k.parse().ok().unwrap_or_default()), v))
- .collect())
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub enum DebugEventDisplay {
+ Path(Vec<Vec2>),
+ Label(Vec2, String),
}