M shared/src/server/channels.rs => shared/src/server/channels.rs +12 -4
@@ 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::<AfterAuthChannel>(
- ChannelDirection::ServerToClient,
- ChannelMode::UnorderedReliable(ReliableSettings::default()),
- );
+ protocol
+ .add_channel::<AfterAuthChannel>(
+ ChannelDirection::ServerToClient,
+ ChannelMode::UnorderedReliable(ReliableSettings::default()),
+ )
+ .add_channel::<DataRequestChannel>(
+ ChannelDirection::Bidirectional,
+ ChannelMode::OrderedReliable(ReliableSettings::default()),
+ );
}
}
A shared/src/server/messages/datarequest.rs => shared/src/server/messages/datarequest.rs +41 -0
@@ 0,0 1,41 @@
+/*
+ * This file is part of laurelin/shared
+ * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
+ *
+ * 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,
+}
M shared/src/server/messages/mod.rs => shared/src/server/messages/mod.rs +7 -1
@@ 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::<Auth>().add_message::<AfterAuth>();
+ protocol
+ .add_message::<Auth>()
+ .add_message::<AfterAuth>()
+ .add_message::<datarequest::DataRequest>()
+ .add_message::<datarequest::DataRequestResponse>();
}
}