From f95462c1f78a1efe2a77aba31952a9b7887b5af3 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 23 Feb 2023 13:14:51 +0200 Subject: [PATCH] feat(shared): setup server protocol configuration --- shared/src/lib.rs | 15 +-------------- shared/src/server/channels.rs | 15 +++++++++++++++ shared/src/server/messages/mod.rs | 15 +++++++++++++++ shared/src/server/mod.rs | 12 ++++++++++++ shared/src/server/protocol.rs | 25 +++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 shared/src/server/channels.rs create mode 100644 shared/src/server/messages/mod.rs create mode 100644 shared/src/server/mod.rs create mode 100644 shared/src/server/protocol.rs diff --git a/shared/src/lib.rs b/shared/src/lib.rs index b8d01de..668d51f 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -6,17 +6,4 @@ * See LICENSE for licensing information. */ -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +pub mod server; diff --git a/shared/src/server/channels.rs b/shared/src/server/channels.rs new file mode 100644 index 0000000..c223252 --- /dev/null +++ b/shared/src/server/channels.rs @@ -0,0 +1,15 @@ +/* + * This file is part of laurelin/shared + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use naia_bevy_shared::{Protocol, ProtocolPlugin}; + +pub struct ChannelsPlugin; + +impl ProtocolPlugin for ChannelsPlugin { + fn build(&self, protocol: &mut Protocol) {} +} diff --git a/shared/src/server/messages/mod.rs b/shared/src/server/messages/mod.rs new file mode 100644 index 0000000..73d7061 --- /dev/null +++ b/shared/src/server/messages/mod.rs @@ -0,0 +1,15 @@ +/* + * This file is part of laurelin/shared + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use naia_bevy_shared::{Protocol, ProtocolPlugin}; + +pub struct MessagesPlugin; + +impl ProtocolPlugin for MessagesPlugin { + fn build(&self, protocol: &mut Protocol) {} +} diff --git a/shared/src/server/mod.rs b/shared/src/server/mod.rs new file mode 100644 index 0000000..1b20941 --- /dev/null +++ b/shared/src/server/mod.rs @@ -0,0 +1,12 @@ +/* + * This file is part of laurelin/shared + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +pub mod channels; +pub mod messages; + +pub mod protocol; diff --git a/shared/src/server/protocol.rs b/shared/src/server/protocol.rs new file mode 100644 index 0000000..8723ada --- /dev/null +++ b/shared/src/server/protocol.rs @@ -0,0 +1,25 @@ +/* + * This file is part of laurelin/shared + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use std::time::Duration; + +use naia_bevy_shared::{LinkConditionerConfig, Protocol}; + +use super::{channels::ChannelsPlugin, messages::MessagesPlugin}; + +pub fn protocol() -> Protocol { + Protocol::builder() + // configuration + .tick_interval(Duration::from_millis(25)) + .link_condition(LinkConditionerConfig::average_condition()) + // channels + .add_plugin(ChannelsPlugin) + // messages + .add_plugin(MessagesPlugin) + .build() +} -- 2.44.1