From 9e357dfa0cd45c85f74129a9a03516b87c680280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Fri, 7 May 2021 15:00:24 +0200 Subject: [PATCH] remove ViewDistance from Client::new() and fix tests --- client/src/addr.rs | 94 ++++++++------------------ client/src/lib.rs | 17 ++--- voxygen/src/menu/char_selection/mod.rs | 4 ++ voxygen/src/menu/main/client_init.rs | 2 - voxygen/src/menu/main/mod.rs | 4 -- 5 files changed, 38 insertions(+), 83 deletions(-) diff --git a/client/src/addr.rs b/client/src/addr.rs index 6002ce4a4c..539c294006 100644 --- a/client/src/addr.rs +++ b/client/src/addr.rs @@ -61,7 +61,7 @@ where let mut participant = None; for addr in resolve(&address, prefer_ipv6) .await - .map_err(|e| Error::HostnameLookupFailed(e))? + .map_err(Error::HostnameLookupFailed)? { match network.connect(f(addr)).await { Ok(p) => { @@ -87,85 +87,47 @@ mod tests { #[tokio::test] async fn resolve_localhost() { - let args = ConnectionArgs::resolve("localhost", false) - .await - .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert!(args.len() == 1 || args.len() == 2); - assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); - assert_eq!(args[0].port(), 14004); - } else { - panic!("wrong resolution"); - } + let args = resolve("localhost", false).await.expect("resolve failed"); + assert!(args.len() == 1 || args.len() == 2); + assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); + assert_eq!(args[0].port(), 14004); - let args = ConnectionArgs::resolve("localhost:666", false) + let args = resolve("localhost:666", false) .await .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert!(args.len() == 1 || args.len() == 2); - assert_eq!(args[0].port(), 666); - } else { - panic!("wrong resolution"); - } + assert!(args.len() == 1 || args.len() == 2); + assert_eq!(args[0].port(), 666); } #[tokio::test] async fn resolve_ipv6() { - let args = ConnectionArgs::resolve("localhost", true) - .await - .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert!(args.len() == 1 || args.len() == 2); - assert_eq!(args[0].ip(), Ipv6Addr::LOCALHOST); - assert_eq!(args[0].port(), 14004); - } else { - panic!("wrong resolution"); - } + let args = resolve("localhost", true).await.expect("resolve failed"); + assert!(args.len() == 1 || args.len() == 2); + assert_eq!(args[0].ip(), Ipv6Addr::LOCALHOST); + assert_eq!(args[0].port(), 14004); } #[tokio::test] - async fn resolve() { - let args = ConnectionArgs::resolve("google.com", false) - .await - .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert!(args.len() == 1 || args.len() == 2); - assert_eq!(args[0].port(), 14004); - } else { - panic!("wrong resolution"); - } + async fn tresolve() { + let args = resolve("google.com", false).await.expect("resolve failed"); + assert!(args.len() == 1 || args.len() == 2); + assert_eq!(args[0].port(), 14004); - let args = ConnectionArgs::resolve("127.0.0.1", false) - .await - .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert_eq!(args.len(), 1); - assert_eq!(args[0].port(), 14004); - assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); - } else { - panic!("wrong resolution"); - } + let args = resolve("127.0.0.1", false).await.expect("resolve failed"); + assert_eq!(args.len(), 1); + assert_eq!(args[0].port(), 14004); + assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); - let args = ConnectionArgs::resolve("55.66.77.88", false) - .await - .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert_eq!(args.len(), 1); - assert_eq!(args[0].port(), 14004); - assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::new(55, 66, 77, 88))); - } else { - panic!("wrong resolution"); - } + let args = resolve("55.66.77.88", false).await.expect("resolve failed"); + assert_eq!(args.len(), 1); + assert_eq!(args[0].port(), 14004); + assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::new(55, 66, 77, 88))); - let args = ConnectionArgs::resolve("127.0.0.1:776", false) + let args = resolve("127.0.0.1:776", false) .await .expect("resolve failed"); - if let ConnectionArgs::IpAndPort(args) = args { - assert_eq!(args.len(), 1); - assert_eq!(args[0].port(), 776); - assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); - } else { - panic!("wrong resolution"); - } + assert_eq!(args.len(), 1); + assert_eq!(args[0].port(), 776); + assert_eq!(args[0].ip(), IpAddr::V4(Ipv4Addr::LOCALHOST)); } } diff --git a/client/src/lib.rs b/client/src/lib.rs index aaf0a342b9..76ae3151e9 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -205,7 +205,6 @@ pub struct CharacterList { impl Client { pub async fn new( addr: ConnectionArgs, - view_distance: Option, runtime: Arc, // TODO: refactor to avoid needing to use this out parameter mismatched_server_info: &mut Option, @@ -216,9 +215,7 @@ impl Client { ConnectionArgs::Tcp { hostname, prefer_ipv6, - } => { - addr::try_connect(&network, &hostname, prefer_ipv6, |a| ConnectAddr::Tcp(a)).await? - }, + } => addr::try_connect(&network, &hostname, prefer_ipv6, ConnectAddr::Tcp).await?, ConnectionArgs::Quic { hostname, prefer_ipv6, @@ -696,7 +693,7 @@ impl Client { tick: 0, state, - view_distance, + view_distance: None, loaded_distance: 0.0, pending_chunks: HashMap::new(), @@ -2439,7 +2436,6 @@ impl Drop for Client { #[cfg(test)] mod tests { use super::*; - use std::net::SocketAddr; #[test] /// THIS TEST VERIFIES THE CONSTANT API. @@ -2449,17 +2445,16 @@ mod tests { /// CONTACT @Core Developer BEFORE MERGING CHANGES TO THIS TEST fn constant_api_test() { use common::clock::Clock; - use std::net::{IpAddr, Ipv4Addr}; const SPT: f64 = 1.0 / 60.0; - let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 9000); - let view_distance: Option = None; let runtime = Arc::new(Runtime::new().unwrap()); let runtime2 = Arc::clone(&runtime); let veloren_client: Result = runtime.block_on(Client::new( - ConnectionArgs::IpAndPort(vec![socket]), - view_distance, + ConnectionArgs::Tcp { + hostname: "127.0.0.1:9000".to_owned(), + prefer_ipv6: false, + }, runtime2, &mut None, )); diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index a7825976a7..007914cb4d 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -116,6 +116,10 @@ impl PlayState for CharSelectionState { }, ui::Event::Play(character_id) => { self.client.borrow_mut().request_character(character_id); + //Send our ViewDistance + self.client + .borrow_mut() + .set_view_distance(global_state.settings.graphics.view_distance); return PlayStateResult::Switch(Box::new(SessionState::new( global_state, diff --git a/voxygen/src/menu/main/client_init.rs b/voxygen/src/menu/main/client_init.rs index 707b708c59..622633660c 100644 --- a/voxygen/src/menu/main/client_init.rs +++ b/voxygen/src/menu/main/client_init.rs @@ -46,7 +46,6 @@ impl ClientInit { pub fn new( connection_args: ConnectionArgs, username: String, - view_distance: Option, password: String, runtime: Option>, ) -> Self { @@ -92,7 +91,6 @@ impl ClientInit { let mut mismatched_server_info = None; match Client::new( connection_args.clone(), - view_distance, Arc::clone(&runtime2), &mut mismatched_server_info, ) diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index e682e5348b..d03c45167b 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -70,7 +70,6 @@ impl PlayState for MainMenuState { Ok(Ok(runtime)) => { // Attempt login after the server is finished initializing attempt_login( - &mut global_state.settings, &mut global_state.info_message, "singleplayer".to_owned(), "".to_owned(), @@ -177,7 +176,6 @@ impl PlayState for MainMenuState { } }; attempt_login( - &mut global_state.settings, &mut global_state.info_message, username, password, @@ -352,7 +350,6 @@ fn get_client_msg_error(e: client_init::Error, localized_strings: &LocalizationH } fn attempt_login( - settings: &mut Settings, info_message: &mut Option, username: String, password: String, @@ -370,7 +367,6 @@ fn attempt_login( *client_init = Some(ClientInit::new( connection_args, username, - Some(settings.graphics.view_distance), password, runtime, ));