From 1f58b87e878846ff2803cf41a8514438f0126f87 Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Wed, 16 Aug 2023 12:57:50 +0200 Subject: [PATCH] WIP --- Cargo.lock | 9 +++++++++ Cargo.toml | 1 + crates/connector/Cargo.toml | 1 + crates/connector/src/game/ereceiver.rs | 3 ++- crates/connector/src/game/greceiver.rs | 3 ++- crates/connector/src/game/preceiver.rs | 3 ++- crates/connector/src/game/state.rs | 3 ++- crates/connector/src/server.rs | 6 ++---- crates/connector/tests/commands.rs | 6 ++---- crates/messages/Cargo.toml | 15 +++++++++++++++ crates/messages/src/lib.rs | 4 ++++ crates/{net => messages}/src/messages.rs | 0 crates/multiplayer/Cargo.toml | 1 + crates/multiplayer/src/game.rs | 2 +- crates/multiplayer/src/messages.rs | 3 ++- crates/multiplayer/src/stats.rs | 2 +- crates/net/src/lib.rs | 2 -- 17 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 crates/messages/Cargo.toml create mode 100644 crates/messages/src/lib.rs rename crates/{net => messages}/src/messages.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index e1364f87..dab6f2cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2255,6 +2255,7 @@ dependencies = [ "assert_cmd", "async-std", "bincode", + "de_messages", "de_net", "futures", "nix 0.26.2", @@ -2503,6 +2504,13 @@ dependencies = [ "thiserror", ] +[[package]] +name = "de_messages" +version = "0.1.0-dev" +dependencies = [ + "bincode", +] + [[package]] name = "de_movement" version = "0.1.0-dev" @@ -2528,6 +2536,7 @@ dependencies = [ "bincode", "de_core", "de_gui", + "de_messages", "de_net", "futures-lite", "iyes_progress", diff --git a/Cargo.toml b/Cargo.toml index 9c8f9d6a..624768b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,6 +93,7 @@ de_lobby_model = { path = "crates/lobby_model", version = "0.1.0-dev" } de_log = { path = "crates/log", version = "0.1.0-dev" } de_map = { path = "crates/map", version = "0.1.0-dev" } de_menu = { path = "crates/menu", version = "0.1.0-dev" } +de_messages = { path = "crates/messages", version = "0.1.0-dev" } de_movement = { path = "crates/movement", version = "0.1.0-dev" } de_multiplayer = { path = "crates/multiplayer", version = "0.1.0-dev" } de_net = { path = "crates/net", version = "0.1.0-dev" } diff --git a/crates/connector/Cargo.toml b/crates/connector/Cargo.toml index 8b1396d0..6425044d 100644 --- a/crates/connector/Cargo.toml +++ b/crates/connector/Cargo.toml @@ -19,6 +19,7 @@ name = "de_connector" [dependencies] # DE +de_messages.workspace = true de_net.workspace = true # Other diff --git a/crates/connector/src/game/ereceiver.rs b/crates/connector/src/game/ereceiver.rs index e629e579..5a608e03 100644 --- a/crates/connector/src/game/ereceiver.rs +++ b/crates/connector/src/game/ereceiver.rs @@ -1,7 +1,8 @@ use std::time::Duration; use async_std::{channel::Sender, future::timeout}; -use de_net::{ConnErrorReceiver, ToGame}; +use de_messages::ToGame; +use de_net::ConnErrorReceiver; use tracing::{error, info, warn}; use super::greceiver::ToGameMessage; diff --git a/crates/connector/src/game/greceiver.rs b/crates/connector/src/game/greceiver.rs index 1061fac8..6fa49456 100644 --- a/crates/connector/src/game/greceiver.rs +++ b/crates/connector/src/game/greceiver.rs @@ -4,7 +4,8 @@ use async_std::{ channel::{Receiver, Sender}, task, }; -use de_net::{FromGame, JoinError, OutPackage, Peers, Readiness, Targets, ToGame}; +use de_messages::{FromGame, JoinError, Readiness, ToGame}; +use de_net::{OutPackage, Peers, Targets}; use tracing::{error, info, warn}; use super::state::{GameState, JoinError as JoinErrorInner}; diff --git a/crates/connector/src/game/preceiver.rs b/crates/connector/src/game/preceiver.rs index 43e220cc..62adf99f 100644 --- a/crates/connector/src/game/preceiver.rs +++ b/crates/connector/src/game/preceiver.rs @@ -1,7 +1,8 @@ use std::net::SocketAddr; use async_std::channel::Receiver; -use de_net::{FromGame, OutPackage, PackageSender, Peers}; +use de_messages::FromGame; +use de_net::{OutPackage, PackageSender, Peers}; use tracing::{error, info, warn}; use super::state::GameState; diff --git a/crates/connector/src/game/state.rs b/crates/connector/src/game/state.rs index 1415aec3..dd063f1e 100644 --- a/crates/connector/src/game/state.rs +++ b/crates/connector/src/game/state.rs @@ -2,7 +2,8 @@ use std::{collections::hash_map::Entry, net::SocketAddr}; use ahash::AHashMap; use async_std::sync::{Arc, RwLock}; -use de_net::{Readiness, Targets}; +use de_messages::Readiness; +use de_net::Targets; use thiserror::Error; #[derive(Clone)] diff --git a/crates/connector/src/server.rs b/crates/connector/src/server.rs index 88cff184..360d9224 100644 --- a/crates/connector/src/server.rs +++ b/crates/connector/src/server.rs @@ -2,10 +2,8 @@ use std::net::SocketAddr; use anyhow::Context; use async_std::task; -use de_net::{ - self, FromServer, GameOpenError, MessageDecoder, OutPackage, PackageReceiver, PackageSender, - Peers, Socket, ToServer, -}; +use de_messages::{FromServer, GameOpenError, ToServer}; +use de_net::{self, MessageDecoder, OutPackage, PackageReceiver, PackageSender, Peers, Socket}; use tracing::{error, info, warn}; use crate::{clients::Clients, game}; diff --git a/crates/connector/tests/commands.rs b/crates/connector/tests/commands.rs index 7abffc20..d00d52a2 100644 --- a/crates/connector/tests/commands.rs +++ b/crates/connector/tests/commands.rs @@ -4,10 +4,8 @@ use std::{ }; use async_std::{future::timeout, task}; -use de_net::{ - self, ConnErrorReceiver, FromGame, FromServer, JoinError, OutPackage, PackageReceiver, - PackageSender, Peers, Readiness, Socket, ToGame, ToServer, -}; +use de_messages::{FromGame, FromServer, JoinError, Readiness, ToGame, ToServer}; +use de_net::{self, ConnErrorReceiver, OutPackage, PackageReceiver, PackageSender, Peers, Socket}; use ntest::timeout; use crate::common::{spawn_and_wait, term_and_wait}; diff --git a/crates/messages/Cargo.toml b/crates/messages/Cargo.toml new file mode 100644 index 00000000..e0e8d913 --- /dev/null +++ b/crates/messages/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "de_messages" +description = "Digital Extinction multiplayer message protocol." + +version.workspace = true +edition.workspace = true +authors.workspace = true +repository.workspace = true +keywords.workspace = true +homepage.workspace = true +license.workspace = true +categories.workspace = true + +[dependencies] +bincode.workspace = true diff --git a/crates/messages/src/lib.rs b/crates/messages/src/lib.rs new file mode 100644 index 00000000..47af8fce --- /dev/null +++ b/crates/messages/src/lib.rs @@ -0,0 +1,4 @@ +pub use messages::{FromGame, FromServer, GameOpenError, JoinError, Readiness, ToGame, ToServer}; + +// TODO split +mod messages; diff --git a/crates/net/src/messages.rs b/crates/messages/src/messages.rs similarity index 100% rename from crates/net/src/messages.rs rename to crates/messages/src/messages.rs diff --git a/crates/multiplayer/Cargo.toml b/crates/multiplayer/Cargo.toml index 3f028b00..d38f50b9 100644 --- a/crates/multiplayer/Cargo.toml +++ b/crates/multiplayer/Cargo.toml @@ -15,6 +15,7 @@ categories.workspace = true # DE de_core.workspace = true de_gui.workspace = true +de_messages.workspace = true de_net.workspace = true # Other diff --git a/crates/multiplayer/src/game.rs b/crates/multiplayer/src/game.rs index 0208c6f4..ebee85cd 100644 --- a/crates/multiplayer/src/game.rs +++ b/crates/multiplayer/src/game.rs @@ -2,7 +2,7 @@ use std::net::SocketAddr; use bevy::prelude::*; use de_core::{player::Player, schedule::PreMovement}; -use de_net::{FromGame, FromServer, GameOpenError, JoinError, ToGame, ToServer}; +use de_messages::{FromGame, FromServer, GameOpenError, JoinError, ToGame, ToServer}; use crate::{ config::ConnectionType, diff --git a/crates/multiplayer/src/messages.rs b/crates/multiplayer/src/messages.rs index a3e6682c..99577646 100644 --- a/crates/multiplayer/src/messages.rs +++ b/crates/multiplayer/src/messages.rs @@ -2,7 +2,8 @@ use std::{net::SocketAddr, time::Instant}; use bevy::prelude::*; use de_core::schedule::PreMovement; -use de_net::{FromGame, FromServer, InPackage, PackageBuilder, Peers, ToGame, ToServer}; +use de_messages::{FromGame, FromServer, ToGame, ToServer}; +use de_net::{InPackage, PackageBuilder, Peers}; use crate::{ config::ConnectionType, diff --git a/crates/multiplayer/src/stats.rs b/crates/multiplayer/src/stats.rs index 81a00b57..afd5821e 100644 --- a/crates/multiplayer/src/stats.rs +++ b/crates/multiplayer/src/stats.rs @@ -5,7 +5,7 @@ use std::{ use bevy::prelude::*; use de_core::schedule::PreMovement; -use de_net::{FromGame, ToGame}; +use de_messages::{FromGame, ToGame}; use tracing::{debug, info, trace}; use crate::{ diff --git a/crates/net/src/lib.rs b/crates/net/src/lib.rs index a9172589..66e9ac10 100644 --- a/crates/net/src/lib.rs +++ b/crates/net/src/lib.rs @@ -1,5 +1,4 @@ pub use header::Peers; -pub use messages::{FromGame, FromServer, GameOpenError, JoinError, Readiness, ToGame, ToServer}; pub use protocol::{Targets, MAX_PACKAGE_SIZE}; pub use socket::{RecvError, SendError, Socket, MAX_DATAGRAM_SIZE}; pub use tasks::{ @@ -9,7 +8,6 @@ pub use tasks::{ mod connection; mod header; -mod messages; mod protocol; mod socket; mod tasks;