diff options
author | gilles henaux <gill.henaux@gmail.com> | 2023-02-20 21:49:49 +0100 |
---|---|---|
committer | gilles henaux <gill.henaux@gmail.com> | 2023-02-20 21:49:49 +0100 |
commit | 321fb46598de84c6f4ebfa4a62cb5f11ea746eb1 (patch) | |
tree | e2384f6a4fd1937244d911237156c3b9f37a62c7 | |
parent | 5cd8de4ac805590fc183276e3114aadad35051de (diff) |
[examples] Use the new configuration methods
-rw-r--r-- | examples/breakout/breakout.rs | 3 | ||||
-rw-r--r-- | examples/breakout/client.rs | 10 | ||||
-rw-r--r-- | examples/breakout/server.rs | 20 | ||||
-rw-r--r-- | examples/chat/client.rs | 2 | ||||
-rw-r--r-- | examples/chat/server.rs | 8 |
5 files changed, 22 insertions, 21 deletions
diff --git a/examples/breakout/breakout.rs b/examples/breakout/breakout.rs index e57e2d7..31fcf01 100644 --- a/examples/breakout/breakout.rs +++ b/examples/breakout/breakout.rs @@ -1,6 +1,8 @@ //! A simplified implementation of the classic game "Breakout". //! => Original example by Bevy, modified for Bevy Quinnet to add a 2 players versus mode. +use std::net::{IpAddr, Ipv4Addr}; + use bevy::{ecs::schedule::ShouldRun, prelude::*, time::FixedTimestep}; use bevy_quinnet::{ client::QuinnetClientPlugin, @@ -13,6 +15,7 @@ mod protocol; mod server; const SERVER_HOST: &str = "127.0.0.1"; +const LOCAL_BIND_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)); const SERVER_PORT: u16 = 6000; // Defines the amount of time that should elapse between each physics step. diff --git a/examples/breakout/client.rs b/examples/breakout/client.rs index 33873d3..be4435a 100644 --- a/examples/breakout/client.rs +++ b/examples/breakout/client.rs @@ -24,7 +24,8 @@ use bevy_quinnet::{ use crate::{ protocol::{ClientMessage, PaddleInput, ServerMessage}, BrickId, CollisionEvent, CollisionSound, GameState, Score, Velocity, WallLocation, BALL_SIZE, - BALL_SPEED, BRICK_SIZE, GAP_BETWEEN_BRICKS, PADDLE_SIZE, SERVER_HOST, SERVER_PORT, TIME_STEP, + BALL_SPEED, BRICK_SIZE, GAP_BETWEEN_BRICKS, LOCAL_BIND_IP, PADDLE_SIZE, SERVER_HOST, + SERVER_PORT, TIME_STEP, }; const SCOREBOARD_FONT_SIZE: f32 = 40.0; @@ -91,14 +92,13 @@ struct WallBundle { #[bundle] sprite_bundle: SpriteBundle, } - pub(crate) fn start_connection(mut client: ResMut<Client>) { client .open_connection( - ConnectionConfiguration::new( - SERVER_HOST.to_string(), + ConnectionConfiguration::from_ips( + SERVER_HOST.parse().unwrap(), SERVER_PORT, - "0.0.0.0".to_string(), + LOCAL_BIND_IP, 0, ), CertificateVerificationMode::SkipVerification, diff --git a/examples/breakout/server.rs b/examples/breakout/server.rs index 4164f7e..f2389bd 100644 --- a/examples/breakout/server.rs +++ b/examples/breakout/server.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap}; use bevy::{ prelude::{ @@ -9,9 +9,7 @@ use bevy::{ transform::TransformBundle, }; use bevy_quinnet::{ - server::{ - certificate::CertificateRetrievalMode, ConnectionEvent, Server, ServerConfigurationData, - }, + server::{certificate::CertificateRetrievalMode, ConnectionEvent, Server, ServerConfiguration}, shared::{channel::ChannelId, ClientId}, }; @@ -19,8 +17,8 @@ use crate::{ protocol::{ClientMessage, PaddleInput, ServerMessage}, BrickId, Velocity, WallLocation, BALL_SIZE, BALL_SPEED, BOTTOM_WALL, BRICK_SIZE, GAP_BETWEEN_BRICKS, GAP_BETWEEN_BRICKS_AND_SIDES, GAP_BETWEEN_PADDLE_AND_BRICKS, - GAP_BETWEEN_PADDLE_AND_FLOOR, LEFT_WALL, PADDLE_PADDING, PADDLE_SIZE, PADDLE_SPEED, RIGHT_WALL, - SERVER_HOST, SERVER_PORT, TIME_STEP, TOP_WALL, WALL_THICKNESS, + GAP_BETWEEN_PADDLE_AND_FLOOR, LEFT_WALL, LOCAL_BIND_IP, PADDLE_PADDING, PADDLE_SIZE, + PADDLE_SPEED, RIGHT_WALL, SERVER_HOST, SERVER_PORT, TIME_STEP, TOP_WALL, WALL_THICKNESS, }; const GAP_BETWEEN_PADDLE_AND_BALL: f32 = 35.; @@ -81,12 +79,10 @@ struct WallBundle { pub(crate) fn start_listening(mut server: ResMut<Server>) { server .start_endpoint( - ServerConfigurationData::new( - SERVER_HOST.to_string(), - SERVER_PORT, - "0.0.0.0".to_string(), - ), - CertificateRetrievalMode::GenerateSelfSigned, + ServerConfiguration::from_ip(LOCAL_BIND_IP, SERVER_PORT), + CertificateRetrievalMode::GenerateSelfSigned { + server_hostname: SERVER_HOST.to_string(), + }, ) .unwrap(); } diff --git a/examples/chat/client.rs b/examples/chat/client.rs index 6cb25e4..fae4976 100644 --- a/examples/chat/client.rs +++ b/examples/chat/client.rs @@ -120,7 +120,7 @@ fn start_terminal_listener(mut commands: Commands) { fn start_connection(mut client: ResMut<Client>) { client .open_connection( - ConnectionConfiguration::new("127.0.0.1".to_string(), 6000, "0.0.0.0".to_string(), 0), + ConnectionConfiguration::from_strings("127.0.0.1:6000", "0.0.0.0:0").unwrap(), CertificateVerificationMode::SkipVerification, ) .unwrap(); diff --git a/examples/chat/server.rs b/examples/chat/server.rs index 8c89f2b..da28f88 100644 --- a/examples/chat/server.rs +++ b/examples/chat/server.rs @@ -4,7 +4,7 @@ use bevy::{app::ScheduleRunnerPlugin, log::LogPlugin, prelude::*}; use bevy_quinnet::{ server::{ certificate::CertificateRetrievalMode, ConnectionLostEvent, Endpoint, QuinnetServerPlugin, - Server, ServerConfigurationData, + Server, ServerConfiguration, }, shared::{channel::ChannelId, ClientId}, }; @@ -116,8 +116,10 @@ fn handle_disconnect(endpoint: &mut Endpoint, users: &mut ResMut<Users>, client_ fn start_listening(mut server: ResMut<Server>) { server .start_endpoint( - ServerConfigurationData::new("127.0.0.1".to_string(), 6000, "0.0.0.0".to_string()), - CertificateRetrievalMode::GenerateSelfSigned, + ServerConfiguration::from_string("0.0.0.0:6000").unwrap(), + CertificateRetrievalMode::GenerateSelfSigned { + server_hostname: "127.0.0.1".to_string(), + }, ) .unwrap(); } |