From ebf6371e4a5ebab4bcce10d80f17962347b67b5e Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 16 Mar 2023 13:35:45 +0200 Subject: [PATCH] feat(shared): add a channel and messages for generic data requests --- shared/src/server/channels.rs | 16 ++++++--- shared/src/server/messages/datarequest.rs | 41 +++++++++++++++++++++++ shared/src/server/messages/mod.rs | 8 ++++- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 shared/src/server/messages/datarequest.rs diff --git a/shared/src/server/channels.rs b/shared/src/server/channels.rs index 8c8412e..ceb7808 100644 --- a/shared/src/server/channels.rs +++ b/shared/src/server/channels.rs @@ -13,13 +13,21 @@ use naia_bevy_shared::{ #[derive(Channel)] pub struct AfterAuthChannel; +#[derive(Channel)] +pub struct DataRequestChannel; + pub struct ChannelsPlugin; impl ProtocolPlugin for ChannelsPlugin { fn build(&self, protocol: &mut Protocol) { - protocol.add_channel::( - ChannelDirection::ServerToClient, - ChannelMode::UnorderedReliable(ReliableSettings::default()), - ); + protocol + .add_channel::( + ChannelDirection::ServerToClient, + ChannelMode::UnorderedReliable(ReliableSettings::default()), + ) + .add_channel::( + ChannelDirection::Bidirectional, + ChannelMode::OrderedReliable(ReliableSettings::default()), + ); } } diff --git a/shared/src/server/messages/datarequest.rs b/shared/src/server/messages/datarequest.rs new file mode 100644 index 0000000..c62ec4a --- /dev/null +++ b/shared/src/server/messages/datarequest.rs @@ -0,0 +1,41 @@ +/* + * 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::Message; + +#[derive(Message)] +pub struct DataRequest { + pub r#type: u8, +} + +impl DataRequest { + pub fn new(r#type: u8) -> Self { + Self { r#type } + } +} + +#[derive(Message)] +pub struct DataRequestResponse { + pub r#type: u8, + pub data: String, +} + +impl DataRequestResponse { + pub fn new(r#type: u8, data: &str) -> Self { + Self { + r#type, + data: data.to_string(), + } + } +} + +#[repr(u8)] +pub enum DataRequestType { + GameAllForming = 100, + GameMyGames = 101, +} diff --git a/shared/src/server/messages/mod.rs b/shared/src/server/messages/mod.rs index 92db295..a727cc7 100644 --- a/shared/src/server/messages/mod.rs +++ b/shared/src/server/messages/mod.rs @@ -11,10 +11,16 @@ use naia_bevy_shared::{Protocol, ProtocolPlugin}; mod auth; pub use auth::{AfterAuth, Auth}; +mod datarequest; + pub struct MessagesPlugin; impl ProtocolPlugin for MessagesPlugin { fn build(&self, protocol: &mut Protocol) { - protocol.add_message::().add_message::(); + protocol + .add_message::() + .add_message::() + .add_message::() + .add_message::(); } } -- 2.44.1