auth done, no popup yet

This commit is contained in:
telastrus 2019-08-08 12:01:15 -04:00
parent f2ed2870c6
commit de2082469d
3 changed files with 12 additions and 6 deletions

View File

@ -132,9 +132,10 @@ impl Client {
} }
/// Request a state transition to `ClientState::Registered`. /// Request a state transition to `ClientState::Registered`.
pub fn register(&mut self, player: comp::Player, password: String) -> Result<(), Error> { pub fn register(&mut self, player: comp::Player, password: String) /*-> Result<(), Error>*/ {
self.postbox.send_message(ClientMsg::Register { player, password }); self.postbox.send_message(ClientMsg::Register { player, password });
loop { self.client_state = ClientState::Pending;
/*loop {
match self.postbox.next_message() { match self.postbox.next_message() {
Some(ServerMsg::StateAnswer(Err((RequestStateError::Denied, _)))) => { Some(ServerMsg::StateAnswer(Err((RequestStateError::Denied, _)))) => {
println!("Got a bad"); println!("Got a bad");
@ -150,7 +151,7 @@ impl Client {
None => { println!("Got nothing?"); }, None => { println!("Got nothing?"); },
} }
} }*/
} }
/// Request a state transition to `ClientState::Character`. /// Request a state transition to `ClientState::Character`.
@ -470,6 +471,10 @@ impl Client {
self.client_state = state; self.client_state = state;
} }
ServerMsg::StateAnswer(Err((error, state))) => { ServerMsg::StateAnswer(Err((error, state))) => {
if error == RequestStateError::Denied {
warn!("Connection denied!");
return Err(Error::InvalidAuth);
}
warn!( warn!(
"StateAnswer: {:?}. Server thinks client is in state {:?}.", "StateAnswer: {:?}. Server thinks client is in state {:?}.",
error, state error, state

View File

@ -7,7 +7,7 @@ use crate::{
use fxhash::FxHashMap; use fxhash::FxHashMap;
use vek::*; use vek::*;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum RequestStateError { pub enum RequestStateError {
Denied, Denied,
Already, Already,

View File

@ -57,14 +57,15 @@ impl ClientInit {
for socket_addr in first_addrs.into_iter().chain(second_addrs) { for socket_addr in first_addrs.into_iter().chain(second_addrs) {
match Client::new(socket_addr, player.view_distance) { match Client::new(socket_addr, player.view_distance) {
Ok(mut client) => { Ok(mut client) => {
match client.register(player, password) { /*match client.register(player, password) {
Err(ClientError::InvalidAuth) => { Err(ClientError::InvalidAuth) => {
last_err = Some(Error::InvalidAuth); last_err = Some(Error::InvalidAuth);
break; break;
} }
_ => {} _ => {}
} }
println!("Auth success"); println!("Auth success");*/
client.register(player, password);
let _ = tx.send(Ok(client)); let _ = tx.send(Ok(client));
#[cfg(feature = "discord")] #[cfg(feature = "discord")]