diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-08 17:16:06 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-08 17:16:06 +0200 |
commit | 70bb8744cd742dc6c8a71ab174e4a1b058c7bec8 (patch) | |
tree | 78c5a190856f1c6281e8773a05408ede02a13947 /server/src | |
parent | a1921104e13c9cf39439ee424d54f7cece67fc5b (diff) | |
download | hurrycurry-70bb8744cd742dc6c8a71ab174e4a1b058c7bec8.tar hurrycurry-70bb8744cd742dc6c8a71ab174e4a1b058c7bec8.tar.bz2 hurrycurry-70bb8744cd742dc6c8a71ab174e4a1b058c7bec8.tar.zst |
split off protocol into its own crate
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/bin/graph.rs | 2 | ||||
-rw-r--r-- | server/src/customer/mod.rs | 7 | ||||
-rw-r--r-- | server/src/customer/movement.rs | 2 | ||||
-rw-r--r-- | server/src/customer/pathfinding.rs | 2 | ||||
-rw-r--r-- | server/src/data.rs | 2 | ||||
-rw-r--r-- | server/src/entity/conveyor.rs | 2 | ||||
-rw-r--r-- | server/src/entity/mod.rs | 3 | ||||
-rw-r--r-- | server/src/game.rs | 16 | ||||
-rw-r--r-- | server/src/interaction.rs | 2 | ||||
-rw-r--r-- | server/src/lib.rs | 1 | ||||
-rw-r--r-- | server/src/main.rs | 7 | ||||
-rw-r--r-- | server/src/protocol.rs | 154 | ||||
-rw-r--r-- | server/src/state.rs | 7 |
13 files changed, 25 insertions, 182 deletions
diff --git a/server/src/bin/graph.rs b/server/src/bin/graph.rs index ace1b676..888119aa 100644 --- a/server/src/bin/graph.rs +++ b/server/src/bin/graph.rs @@ -16,10 +16,10 @@ */ use anyhow::{anyhow, Result}; +use hurrycurry_protocol::{ItemIndex, RecipeIndex}; use hurrycurry_server::{ data::{DataIndex, Demand}, interaction::Recipe, - protocol::{ItemIndex, RecipeIndex}, }; #[tokio::main] diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index 191f9e3b..c11a1aec 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -18,14 +18,11 @@ pub mod movement; mod pathfinding; -use crate::{ - data::Gamedata, - game::Tile, - protocol::{DemandIndex, Message, PacketS, PlayerID}, -}; +use crate::{data::Gamedata, game::Tile}; use anyhow::{anyhow, Result}; use fake::{faker, Fake}; use glam::IVec2; +use hurrycurry_protocol::{DemandIndex, Message, PacketS, PlayerID}; use log::debug; use movement::MovementBase; use pathfinding::{find_path, Path}; diff --git a/server/src/customer/movement.rs b/server/src/customer/movement.rs index ca7afdbe..4da76de7 100644 --- a/server/src/customer/movement.rs +++ b/server/src/customer/movement.rs @@ -16,8 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use crate::protocol::PacketS; use glam::{IVec2, Vec2}; +use hurrycurry_protocol::PacketS; use std::collections::HashSet; const PLAYER_SIZE: f32 = 0.4; diff --git a/server/src/customer/pathfinding.rs b/server/src/customer/pathfinding.rs index 743515b9..a2623e5c 100644 --- a/server/src/customer/pathfinding.rs +++ b/server/src/customer/pathfinding.rs @@ -16,8 +16,8 @@ */ use super::movement::MovementBase; -use crate::protocol::PacketS; use glam::{IVec2, Vec2}; +use hurrycurry_protocol::PacketS; use log::debug; use std::{ cmp::Ordering, diff --git a/server/src/data.rs b/server/src/data.rs index bca7f543..fd028c94 100644 --- a/server/src/data.rs +++ b/server/src/data.rs @@ -19,10 +19,10 @@ use crate::{ entity::{construct_entity, Entity, EntityDecl}, interaction::Recipe, - protocol::{DemandIndex, ItemIndex, RecipeIndex, TileIndex}, }; use anyhow::{anyhow, bail, Result}; use glam::{IVec2, Vec2}; +use hurrycurry_protocol::{DemandIndex, ItemIndex, RecipeIndex, TileIndex}; use serde::{Deserialize, Serialize}; use std::{ collections::{HashMap, HashSet}, diff --git a/server/src/entity/conveyor.rs b/server/src/entity/conveyor.rs index 0a73b55c..f4692f6d 100644 --- a/server/src/entity/conveyor.rs +++ b/server/src/entity/conveyor.rs @@ -19,10 +19,10 @@ use super::EntityT; use crate::{ data::Gamedata, game::{interact_effect, Tile}, - protocol::{ItemLocation, PacketC}, }; use anyhow::{anyhow, Result}; use glam::IVec2; +use hurrycurry_protocol::{ItemLocation, PacketC}; use std::collections::{HashMap, VecDeque}; #[derive(Debug, Default, Clone)] diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index 5cb3ed0f..1bc558b1 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -16,10 +16,11 @@ */ pub mod conveyor; -use crate::{data::Gamedata, game::Tile, protocol::PacketC}; +use crate::{data::Gamedata, game::Tile}; use anyhow::{anyhow, Result}; use conveyor::Conveyor; use glam::IVec2; +use hurrycurry_protocol::PacketC; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, VecDeque}; diff --git a/server/src/game.rs b/server/src/game.rs index 851d485c..daf08ad3 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -20,16 +20,16 @@ use crate::{ data::Gamedata, entity::{Entity, EntityT}, interaction::{interact, tick_slot, InteractEffect, TickEffect}, - protocol::{ - ItemIndex, ItemLocation, Message, PacketC, PacketS, PlayerID, RecipeIndex, TileIndex, - }, }; use anyhow::{anyhow, bail, Result}; use glam::{IVec2, Vec2}; +use hurrycurry_protocol::{ + ClientGamedata, ItemIndex, ItemLocation, Message, PacketC, PacketS, PlayerID, RecipeIndex, + TileIndex, +}; use log::{info, warn}; use std::{ collections::{HashMap, VecDeque}, - ops::Deref, sync::Arc, time::{Duration, Instant}, }; @@ -164,7 +164,13 @@ impl Game { pub fn prime_client(&self) -> Vec<PacketC> { let mut out = Vec::new(); out.push(PacketC::Data { - data: self.data.deref().to_owned(), + data: ClientGamedata { + item_names: self.data.item_names.clone(), + tile_names: self.data.tile_names.clone(), + tile_collide: self.data.tile_collide.clone(), + tile_interact: self.data.tile_interact.clone(), + map_names: self.data.map_names.clone(), + }, }); for (&id, player) in &self.players { out.push(PacketC::AddPlayer { diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 25b96813..b3f6af8c 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -18,8 +18,8 @@ use crate::{ data::Gamedata, game::{Involvement, Item}, - protocol::{ItemIndex, TileIndex}, }; +use hurrycurry_protocol::{ItemIndex, TileIndex}; use log::info; use serde::{Deserialize, Serialize}; diff --git a/server/src/lib.rs b/server/src/lib.rs index a6d29c03..6d0d4e26 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -21,5 +21,4 @@ pub mod data; pub mod entity; pub mod game; pub mod interaction; -pub mod protocol; pub mod state; diff --git a/server/src/main.rs b/server/src/main.rs index 99834fbd..4c6bcc34 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -18,6 +18,8 @@ use anyhow::{anyhow, Result}; use clap::Parser; use futures_util::{SinkExt, StreamExt}; +use hurrycurry_protocol::{PacketC, PacketS, PlayerID}; +use hurrycurry_server::{data::DATA_DIR, state::State}; use log::{debug, info, warn, LevelFilter}; use std::{path::PathBuf, process::exit, str::FromStr, sync::Arc, time::Duration}; use tokio::{ @@ -27,11 +29,6 @@ use tokio::{ time::interval, }; use tokio_tungstenite::tungstenite::Message; -use hurrycurry_server::{ - data::DATA_DIR, - protocol::{PacketC, PacketS, PlayerID}, - state::State, -}; #[derive(Parser)] struct Args { diff --git a/server/src/protocol.rs b/server/src/protocol.rs deleted file mode 100644 index fc8abda4..00000000 --- a/server/src/protocol.rs +++ /dev/null @@ -1,154 +0,0 @@ -/* - Hurry Curry! - a game about cooking - Copyright 2024 metamuffin - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, version 3 of the License only. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>. - -*/ -use crate::data::Gamedata; -use glam::{IVec2, Vec2}; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[serde(transparent)] -pub struct PlayerID(pub i64); - -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[serde(transparent)] -pub struct ItemIndex(pub usize); -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[serde(transparent)] -pub struct TileIndex(pub usize); -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[serde(transparent)] -pub struct RecipeIndex(pub usize); -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] -#[serde(transparent)] -pub struct DemandIndex(pub usize); - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case", tag = "type")] -pub enum PacketS { - Join { - name: String, - character: i32, - }, - Leave, - Position { - pos: Vec2, - rot: f32, - boosting: bool, - }, - Interact { - pos: IVec2, - edge: bool, - }, - Collide { - player: PlayerID, - force: Vec2, - }, - Communicate { - message: Option<Message>, - persist: bool, - }, - - #[serde(skip)] - /// For internal use only - ReplaceHand { - item: Option<ItemIndex>, - }, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum Message { - Text(String), - Item(ItemIndex), - Effect(String), -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case", tag = "type")] -pub enum PacketC { - Init { - id: PlayerID, - }, - Data { - data: Gamedata, - }, - AddPlayer { - id: PlayerID, - position: Vec2, - character: i32, - name: String, - }, - RemovePlayer { - id: PlayerID, - }, - Position { - player: PlayerID, - pos: Vec2, - rot: f32, - boosting: bool, - }, - MoveItem { - from: ItemLocation, - to: ItemLocation, - }, - SetItem { - location: ItemLocation, - item: Option<ItemIndex>, - }, - SetProgress { - item: ItemLocation, - progress: Option<f32>, - warn: bool, - }, - UpdateMap { - tile: IVec2, - kind: Option<TileIndex>, - neighbors: [Option<TileIndex>; 4], - }, - Collide { - player: PlayerID, - force: Vec2, - }, - Communicate { - player: PlayerID, - message: Option<Message>, - persist: bool, - }, - ServerMessage { - text: String, - }, - Score { - points: i64, - demands_failed: usize, - demands_completed: usize, - time_remaining: Option<f32>, - }, - SetIngame { - state: bool, - lobby: bool, - }, - Error { - message: String, - }, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Copy)] -#[serde(rename_all = "snake_case")] -pub enum ItemLocation { - Tile(IVec2), - Player(PlayerID), -} diff --git a/server/src/state.rs b/server/src/state.rs index 72d3e911..5af6f181 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -17,13 +17,10 @@ */ use std::time::Duration; -use crate::{ - data::DataIndex, - game::Game, - protocol::{Message, PacketC, PacketS, PlayerID}, -}; +use crate::{data::DataIndex, game::Game}; use anyhow::{anyhow, bail, Result}; use clap::{Parser, ValueEnum}; +use hurrycurry_protocol::{Message, PacketC, PacketS, PlayerID}; use log::debug; use tokio::sync::broadcast::Sender; |