diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/Cargo.toml | 2 | ||||
-rw-r--r-- | server/examples/client.rs | 2 | ||||
-rw-r--r-- | server/protocol/Cargo.toml | 9 | ||||
-rw-r--r-- | server/protocol/src/lib.rs (renamed from server/src/protocol.rs) | 14 | ||||
-rw-r--r-- | server/replaytool/Cargo.toml | 7 | ||||
-rw-r--r-- | server/replaytool/src/main.rs | 3 | ||||
-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/state.rs | 7 |
18 files changed, 59 insertions, 31 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml index 6b9037ac..e8cb0ed9 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -20,3 +20,5 @@ shlex = "1.3.0" clap = { version = "4.5.8", features = ["derive"] } fake = "2.9.2" pollster = "0.3.0" + +hurrycurry-protocol = { path = "protocol" } diff --git a/server/examples/client.rs b/server/examples/client.rs index 487c9738..80ba8ffa 100644 --- a/server/examples/client.rs +++ b/server/examples/client.rs @@ -22,7 +22,7 @@ use std::{ }; use glam::Vec2; -use hurrycurry_server::protocol::{PacketC, PacketS}; +use hurrycurry_protocol::{PacketC, PacketS}; fn main() { let mut sock = TcpStream::connect("127.0.0.1:27031").unwrap(); diff --git a/server/protocol/Cargo.toml b/server/protocol/Cargo.toml new file mode 100644 index 00000000..8fc63121 --- /dev/null +++ b/server/protocol/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "hurrycurry-protocol" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.204", features = ["derive"] } +glam = { version = "0.28.0", features = ["serde"] } + diff --git a/server/src/protocol.rs b/server/protocol/src/lib.rs index fc8abda4..0342049c 100644 --- a/server/src/protocol.rs +++ b/server/protocol/src/lib.rs @@ -15,9 +15,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use crate::data::Gamedata; use glam::{IVec2, Vec2}; use serde::{Deserialize, Serialize}; +use std::collections::HashSet; #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[serde(transparent)] @@ -36,6 +36,16 @@ pub struct RecipeIndex(pub usize); #[serde(transparent)] pub struct DemandIndex(pub usize); +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +#[rustfmt::skip] +pub struct ClientGamedata { + pub item_names: Vec<String>, + pub tile_names: Vec<String>, + pub tile_collide: Vec<bool>, + pub tile_interact: Vec<bool>, + pub map_names: HashSet<String>, +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case", tag = "type")] pub enum PacketS { @@ -84,7 +94,7 @@ pub enum PacketC { id: PlayerID, }, Data { - data: Gamedata, + data: ClientGamedata, }, AddPlayer { id: PlayerID, diff --git a/server/replaytool/Cargo.toml b/server/replaytool/Cargo.toml new file mode 100644 index 00000000..6983781d --- /dev/null +++ b/server/replaytool/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hurrycurry-replaytool" +version = "0.1.0" +edition = "2021" + +[dependencies] +hurrycurry-protocol = { path = "../protocol" } diff --git a/server/replaytool/src/main.rs b/server/replaytool/src/main.rs new file mode 100644 index 00000000..58dfaaa8 --- /dev/null +++ b/server/replaytool/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + +} 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/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; |