Skip to content

Commit

Permalink
msrv 1.80
Browse files Browse the repository at this point in the history
  • Loading branch information
aecsocket committed Jul 30, 2024
1 parent e05fac7 commit e8acf78
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
keywords = ["gamedev", "network", "bevy"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/aecsocket/aeronet"
rust-version = "1.79.0"
rust-version = "1.80.0"
version = "0.6.0"

[workspace.lints.rust]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ cargo install wasm-server-runner
cargo run --bin move_box_client --target wasm32-unknown-unknown
```

And connect to `http://[::1]:25565`
And connect to `http://[::1]:25565`.

See the [examples](./examples) folder for the source code.

# Transport

Expand Down
3 changes: 1 addition & 2 deletions crates/aeronet_proto/src/session/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ impl Session {
*packets_acked = packets_acked.saturating_add(1);
let packet_rtt = now - packet.flushed_at;
rtt.update(packet_rtt);
// TODO Rust 1.80: Box::into_iter - https://github.com/rust-lang/rust/issues/59878
packet.frags.into_vec().into_iter()
Box::into_iter(packet.frags)
})
.filter_map(|frag_path| {
// for each of those fragments, we'll mark that fragment as acked
Expand Down
5 changes: 4 additions & 1 deletion crates/aeronet_replicon/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ impl<T: ServerTransport + Resource> RepliconServerPlugin<T> {
});

let Some((_, client_id)) = client_keys.id_map.remove_by_left(&client_key) else {
warn!("Disconnected client {client_key:?} which does not have a client ID");
// this may happen if the client started connecting,
// but disconnected before fully connecting,
// leaving behind no replicon client ID
debug!("Disconnected client {client_key:?} which does not have a client ID");
return;
};
debug!("Removed {client_key:?} associated with {client_id:?}");
Expand Down
4 changes: 2 additions & 2 deletions examples/move_box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cargo run --bin move_box_client --target wasm32-unknown-unknown

If you have problems running the client in Firefox (especially LibreWolf), check:
- `privacy.resistFingerprinting` is disabled, or Enhanced Tracking Protection is disabled for the
website (see winit #3345)
website (see [winit #3345](https://github.com/rust-windowing/winit/issues/3345))
- `webgl.disabled` is set to `false`, so that Bevy can use the GPU
- todo: current bug in `xwt_web_sys`: something to do with ReadableStream.getReader with BYOB

Expand All @@ -47,7 +47,7 @@ which your client (native or browser) will treat as invalid. To get around this,
provide SHA-256 digest of the certificate's DER as a base 64 string.

When starting the server, it outputs the *certificate hash* as a base 64 string (it also outputs the
*SPKI fingerprint*, which is different and is not necessary here). Copy this string and enter it
*SPKI fingerprint*, which is different and is not necessary h)ere). Copy this string and enter it
into the "certificate hash" field of the client before connecting. The client will then ignore
certificate validation errors for this specific certificate, and allow a connection to be
established.
Expand Down
6 changes: 6 additions & 0 deletions examples/move_box/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bevy::prelude::*;
use bevy_replicon::prelude::*;
use serde::{Deserialize, Serialize};

/// How many units a player may move in a single second.
const MOVE_SPEED: f32 = 2500.0;

/// Sets up replication and basic game systems.
Expand All @@ -13,6 +14,8 @@ pub struct MoveBoxPlugin;

impl Plugin for MoveBoxPlugin {
fn build(&self, app: &mut App) {
// use the convenience resource WebTransportRuntime for spawning tasks
// platform-independently (native using tokio, or WASM using wasm-bindgen-futures)
app.init_resource::<WebTransportRuntime>()
.add_plugins(RepliconPlugins.build().set(ServerPlugin {
tick_policy: TickPolicy::MaxTickRate(128),
Expand Down Expand Up @@ -53,6 +56,9 @@ fn apply_movement(
{
for (player, mut position) in &mut players {
if *client_id == player.0 {
// make sure to normalize on the server side;
// since we're accepting arbitrary client input,
// we have to do input validation on the server side
**position += delta.normalize_or_zero() * time.delta_seconds() * MOVE_SPEED;
}
}
Expand Down
9 changes: 9 additions & 0 deletions examples/move_box_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy_replicon::prelude::RepliconChannels;
use move_box::{MoveBoxPlugin, PlayerColor, PlayerMove, PlayerPosition};

/// State of the [`egui`] interface used for connecting and disconnecting.
#[derive(Debug, Default, Resource)]
struct UiState {
/// HTTPS URL of the server to connect to.
target: String,
/// Optional hash of a certificate that we want to ignore validation for.
///
/// See the readme for why this is necessary.
cert_hash: String,
}

/// One-shot system for connecting to a remote server.
///
/// Accepts a tuple of `(target, cert_hash)`.
#[derive(Debug, Clone, Copy, Deref, Resource)]
struct ConnectToRemote(SystemId<(String, String)>);

Expand Down Expand Up @@ -67,6 +75,7 @@ fn connect_to_remote(
runtime: Res<WebTransportRuntime>,
) {
let net_config = net_config(spki_hash);
// since we're using replicon, we map each replicon channel to a lane, 1 to 1
let session_config = SessionConfig::default()
.with_send_lanes(channels.client_channels())
.with_recv_lanes(channels.server_channels());
Expand Down
4 changes: 2 additions & 2 deletions examples/move_box_server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use aeronet_webtransport::{
cert,
proto::session::SessionConfig,
runtime::WebTransportRuntime,
server::{ConnectionResponse, WebTransportServer},
server::{ConnectionResponse, ServerConfig, WebTransportServer},
shared::RawRtt,
wtransport,
};
Expand Down Expand Up @@ -77,7 +77,7 @@ fn open_server(
info!(" {cert_hash}");
info!("************************");

let net_config = wtransport::ServerConfig::builder()
let net_config = ServerConfig::builder()
.with_bind_default(args.port)
.with_identity(&identity)
.keep_alive_interval(Some(Duration::from_secs(1)))
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8acf78

Please sign in to comment.