This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use send only and readonly protocols
- Loading branch information
Showing
3 changed files
with
22 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
use bevy::{log::LogPlugin, prelude::*}; | ||
use bevy_rtc::prelude::*; | ||
use protocol::PingPayload; | ||
use protocol::{PingPayload, PongPayload}; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(MinimalPlugins) | ||
.add_plugins(LogPlugin::default()) | ||
.add_plugins(RtcServerPlugin { port: 3536 }) | ||
.add_server_rw_protocol::<PingPayload>(1) | ||
.add_systems(Update, |mut server: RtcServer<PingPayload>| { | ||
for (peer_id, packet) in server.read() { | ||
if let PingPayload::Ping = packet { | ||
.add_server_ro_protocol::<PingPayload>(1) | ||
.add_server_wo_protocol::<PongPayload>() | ||
.add_systems( | ||
Update, | ||
|mut reader: RtcServer<PingPayload>, mut writer: RtcServer<PongPayload>| { | ||
for (peer_id, _ping) in reader.read() { | ||
info!("Received ping! Sending pong..."); | ||
server.reliable_to_peer(peer_id, PingPayload::Pong); | ||
writer.reliable_to_peer(peer_id, PongPayload); | ||
} | ||
} | ||
}) | ||
}, | ||
) | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters