90% there

This commit is contained in:
telastrus 2019-08-08 11:23:58 -04:00
parent 6d94d43021
commit f2ed2870c6
4 changed files with 25 additions and 6 deletions

View File

@ -48,7 +48,7 @@ fn main() {
println!("Players online: {:?}", client.get_players());
client.register(comp::Player::new(username, None), password);
client.register(comp::Player::new(username, None), password).unwrap();
let (tx, rx) = mpsc::channel();
thread::spawn(move || loop {

View File

@ -8,7 +8,7 @@ pub use specs::{join::Join, saveload::Marker, Entity as EcsEntity, ReadStorage};
use common::{
comp,
msg::{ClientMsg, ClientState, ServerError, ServerInfo, ServerMsg},
msg::{ClientMsg, ClientState, ServerError, ServerInfo, ServerMsg, RequestStateError},
net::PostBox,
state::{State, Uid},
terrain::{block::Block, chonk::ChonkMetrics, TerrainChunk, TerrainChunkSize},
@ -134,11 +134,23 @@ impl Client {
/// Request a state transition to `ClientState::Registered`.
pub fn register(&mut self, player: comp::Player, password: String) -> Result<(), Error> {
self.postbox.send_message(ClientMsg::Register { player, password });
/*match self.postbox.next_message() {
loop {
match self.postbox.next_message() {
Some(ServerMsg::StateAnswer(Err((RequestStateError::Denied, _)))) => {
println!("Got a bad");
break Err(Error::InvalidAuth)
},
Some(ServerMsg::StateAnswer(Ok(ClientState::Registered))) => {
println!("Got a good");
break Ok(())
}
Some(x) => {
println!("Got unusual message: {:?}", x);
}
None => { println!("Got nothing?"); },
}
}
self.client_state = ClientState::Pending;*/
Err(Error::InvalidAuth)
}
/// Request a state transition to `ClientState::Character`.

View File

@ -530,11 +530,16 @@ impl Server {
// Valid player
ClientMsg::Register { player, password } if player.is_valid() => {
if let Some(pass) = accounts.get(&player.alias) {
println!("Verifying {} with {} against {}",
player.alias, password, pass);
if pass != &password {
client.error_state(RequestStateError::Denied);
break;
}
} else {
println!("Adding user {} with password {}",
player.alias, password);
accounts.insert(player.alias.clone(), password);
}
println!("{:?}", accounts);
@ -545,6 +550,7 @@ impl Server {
// Use RequestState instead (No need to send `player` again).
_ => client.error_state(RequestStateError::Impossible),
}
//client.allow_state(ClientState::Registered);
}
// Invalid player
ClientMsg::Register { .. } => {

View File

@ -64,6 +64,7 @@ impl ClientInit {
}
_ => {}
}
println!("Auth success");
let _ = tx.send(Ok(client));
#[cfg(feature = "discord")]