mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
remove ViewDistance from Client::new() and fix tests
This commit is contained in:
parent
2ea5fd876b
commit
9e357dfa0c
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,6 @@ pub struct CharacterList {
|
||||
impl Client {
|
||||
pub async fn new(
|
||||
addr: ConnectionArgs,
|
||||
view_distance: Option<u32>,
|
||||
runtime: Arc<Runtime>,
|
||||
// TODO: refactor to avoid needing to use this out parameter
|
||||
mismatched_server_info: &mut Option<ServerInfo>,
|
||||
@ -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<u32> = None;
|
||||
let runtime = Arc::new(Runtime::new().unwrap());
|
||||
let runtime2 = Arc::clone(&runtime);
|
||||
let veloren_client: Result<Client, Error> = 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,
|
||||
));
|
||||
|
@ -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,
|
||||
|
@ -46,7 +46,6 @@ impl ClientInit {
|
||||
pub fn new(
|
||||
connection_args: ConnectionArgs,
|
||||
username: String,
|
||||
view_distance: Option<u32>,
|
||||
password: String,
|
||||
runtime: Option<Arc<runtime::Runtime>>,
|
||||
) -> 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,
|
||||
)
|
||||
|
@ -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<String>,
|
||||
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,
|
||||
));
|
||||
|
Loading…
Reference in New Issue
Block a user