mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
laying the groundwork
This commit is contained in:
@ -7,6 +7,7 @@ pub enum Error {
|
|||||||
ServerTimeout,
|
ServerTimeout,
|
||||||
ServerShutdown,
|
ServerShutdown,
|
||||||
TooManyPlayers,
|
TooManyPlayers,
|
||||||
|
InvalidAuth,
|
||||||
//TODO: InvalidAlias,
|
//TODO: InvalidAlias,
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ pub enum Error {
|
|||||||
NoAddress,
|
NoAddress,
|
||||||
// Parsing/host name resolution successful but could not connect.
|
// Parsing/host name resolution successful but could not connect.
|
||||||
ConnectionFailed(ClientError),
|
ConnectionFailed(ClientError),
|
||||||
|
InvalidAuth,
|
||||||
ClientCrashed,
|
ClientCrashed,
|
||||||
ServerIsFull,
|
ServerIsFull,
|
||||||
}
|
}
|
||||||
@ -81,6 +82,9 @@ impl ClientInit {
|
|||||||
last_err = Some(Error::ServerIsFull);
|
last_err = Some(Error::ServerIsFull);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
ClientError::InvalidAuth => {
|
||||||
|
last_err = Some(Error::InvalidAuth);
|
||||||
|
}
|
||||||
// TODO: Handle errors?
|
// TODO: Handle errors?
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"Unexpected non-network error when creating client: {:?}",
|
"Unexpected non-network error when creating client: {:?}",
|
||||||
|
@ -64,6 +64,7 @@ impl PlayState for MainMenuState {
|
|||||||
self.main_menu_ui.login_error(
|
self.main_menu_ui.login_error(
|
||||||
match err {
|
match err {
|
||||||
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
InitError::BadAddress(_) | InitError::NoAddress => "Server not found",
|
||||||
|
InitError::InvalidAuth => "Invalid username or password",
|
||||||
InitError::ServerIsFull => "Server is Full!",
|
InitError::ServerIsFull => "Server is Full!",
|
||||||
InitError::ConnectionFailed(_) => "Connection failed",
|
InitError::ConnectionFailed(_) => "Connection failed",
|
||||||
InitError::ClientCrashed => "Client crashed",
|
InitError::ClientCrashed => "Client crashed",
|
||||||
@ -82,10 +83,12 @@ impl PlayState for MainMenuState {
|
|||||||
match event {
|
match event {
|
||||||
MainMenuEvent::LoginAttempt {
|
MainMenuEvent::LoginAttempt {
|
||||||
username,
|
username,
|
||||||
|
password,
|
||||||
server_address,
|
server_address,
|
||||||
} => {
|
} => {
|
||||||
let mut net_settings = &mut global_state.settings.networking;
|
let mut net_settings = &mut global_state.settings.networking;
|
||||||
net_settings.username = username.clone();
|
net_settings.username = username.clone();
|
||||||
|
net_settings.password = password.clone();
|
||||||
if !net_settings.servers.contains(&server_address) {
|
if !net_settings.servers.contains(&server_address) {
|
||||||
net_settings.servers.push(server_address.clone());
|
net_settings.servers.push(server_address.clone());
|
||||||
}
|
}
|
||||||
@ -107,7 +110,7 @@ impl PlayState for MainMenuState {
|
|||||||
)));
|
)));
|
||||||
} else {
|
} else {
|
||||||
self.main_menu_ui
|
self.main_menu_ui
|
||||||
.login_error("Invalid username".to_string());
|
.login_error("Invalid username or password".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainMenuEvent::StartSingleplayer => {
|
MainMenuEvent::StartSingleplayer => {
|
||||||
|
@ -38,10 +38,14 @@ widget_ids! {
|
|||||||
username_text,
|
username_text,
|
||||||
username_bg,
|
username_bg,
|
||||||
username_field,
|
username_field,
|
||||||
|
password_text,
|
||||||
|
password_bg,
|
||||||
|
password_field,
|
||||||
singleplayer_button,
|
singleplayer_button,
|
||||||
singleplayer_text,
|
singleplayer_text,
|
||||||
usrnm_bg,
|
usrnm_bg,
|
||||||
srvr_bg,
|
srvr_bg,
|
||||||
|
passwd_bg,
|
||||||
// Server list
|
// Server list
|
||||||
servers_button,
|
servers_button,
|
||||||
servers_frame,
|
servers_frame,
|
||||||
@ -87,6 +91,7 @@ font_ids! {
|
|||||||
pub enum Event {
|
pub enum Event {
|
||||||
LoginAttempt {
|
LoginAttempt {
|
||||||
username: String,
|
username: String,
|
||||||
|
password: String,
|
||||||
server_address: String,
|
server_address: String,
|
||||||
},
|
},
|
||||||
StartSingleplayer,
|
StartSingleplayer,
|
||||||
@ -101,6 +106,7 @@ pub struct MainMenuUi {
|
|||||||
imgs: Imgs,
|
imgs: Imgs,
|
||||||
fonts: Fonts,
|
fonts: Fonts,
|
||||||
username: String,
|
username: String,
|
||||||
|
password: String,
|
||||||
server_address: String,
|
server_address: String,
|
||||||
login_error: Option<String>,
|
login_error: Option<String>,
|
||||||
connecting: Option<std::time::Instant>,
|
connecting: Option<std::time::Instant>,
|
||||||
@ -129,6 +135,7 @@ impl MainMenuUi {
|
|||||||
imgs,
|
imgs,
|
||||||
fonts,
|
fonts,
|
||||||
username: networking.username.clone(),
|
username: networking.username.clone(),
|
||||||
|
password: "".to_owned(),
|
||||||
server_address: networking.servers[networking.default_server].clone(),
|
server_address: networking.servers[networking.default_server].clone(),
|
||||||
login_error: None,
|
login_error: None,
|
||||||
connecting: None,
|
connecting: None,
|
||||||
@ -227,6 +234,7 @@ impl MainMenuUi {
|
|||||||
self.connecting = Some(std::time::Instant::now());
|
self.connecting = Some(std::time::Instant::now());
|
||||||
events.push(Event::LoginAttempt {
|
events.push(Event::LoginAttempt {
|
||||||
username: self.username.clone(),
|
username: self.username.clone(),
|
||||||
|
password: self.password.clone(),
|
||||||
server_address: self.server_address.clone(),
|
server_address: self.server_address.clone(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -240,6 +248,7 @@ impl MainMenuUi {
|
|||||||
events.push(Event::StartSingleplayer);
|
events.push(Event::StartSingleplayer);
|
||||||
events.push(Event::LoginAttempt {
|
events.push(Event::LoginAttempt {
|
||||||
username: "singleplayer".to_string(),
|
username: "singleplayer".to_string(),
|
||||||
|
password: String::default(),
|
||||||
server_address: "localhost".to_string(),
|
server_address: "localhost".to_string(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -274,6 +283,35 @@ impl MainMenuUi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Password
|
||||||
|
Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97))
|
||||||
|
.down_from(self.ids.usrnm_bg, 30.0)
|
||||||
|
.set(self.ids.passwd_bg, ui_widgets);
|
||||||
|
Image::new(self.imgs.input_bg)
|
||||||
|
.w_h(337.0, 67.0)
|
||||||
|
.middle_of(self.ids.passwd_bg)
|
||||||
|
.set(self.ids.password_bg, ui_widgets);
|
||||||
|
for event in TextBox::new(&self.password)
|
||||||
|
.w_h(290.0, 30.0)
|
||||||
|
.mid_bottom_with_margin_on(self.ids.password_bg, 44.0 / 2.0)
|
||||||
|
.font_size(22)
|
||||||
|
.font_id(self.fonts.opensans)
|
||||||
|
.text_color(TEXT_COLOR)
|
||||||
|
// transparent background
|
||||||
|
.color(TRANSPARENT)
|
||||||
|
.border_color(TRANSPARENT)
|
||||||
|
.set(self.ids.password_field, ui_widgets)
|
||||||
|
{
|
||||||
|
match event {
|
||||||
|
TextBoxEvent::Update(password) => {
|
||||||
|
// Note: TextBox limits the input string length to what fits in it
|
||||||
|
self.password = password;
|
||||||
|
}
|
||||||
|
TextBoxEvent::Enter => {
|
||||||
|
login!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Login error
|
// Login error
|
||||||
if let Some(msg) = &self.login_error {
|
if let Some(msg) = &self.login_error {
|
||||||
let text = Text::new(&msg)
|
let text = Text::new(&msg)
|
||||||
@ -369,7 +407,7 @@ impl MainMenuUi {
|
|||||||
}
|
}
|
||||||
// Server address
|
// Server address
|
||||||
Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97))
|
Rectangle::fill_with([320.0, 50.0], color::rgba(0.0, 0.0, 0.0, 0.97))
|
||||||
.down_from(self.ids.usrnm_bg, 30.0)
|
.down_from(self.ids.passwd_bg, 30.0)
|
||||||
.set(self.ids.srvr_bg, ui_widgets);
|
.set(self.ids.srvr_bg, ui_widgets);
|
||||||
Image::new(self.imgs.input_bg)
|
Image::new(self.imgs.input_bg)
|
||||||
.w_h(337.0, 67.0)
|
.w_h(337.0, 67.0)
|
||||||
|
@ -100,6 +100,7 @@ impl Default for GameplaySettings {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct NetworkingSettings {
|
pub struct NetworkingSettings {
|
||||||
pub username: String,
|
pub username: String,
|
||||||
|
pub password: String,
|
||||||
pub servers: Vec<String>,
|
pub servers: Vec<String>,
|
||||||
pub default_server: usize,
|
pub default_server: usize,
|
||||||
}
|
}
|
||||||
@ -108,6 +109,7 @@ impl Default for NetworkingSettings {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
username: "Username".to_string(),
|
username: "Username".to_string(),
|
||||||
|
password: String::default(),
|
||||||
servers: vec!["server.veloren.net".to_string()],
|
servers: vec!["server.veloren.net".to_string()],
|
||||||
default_server: 0,
|
default_server: 0,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user