minor changes according to the comments

This commit is contained in:
JustTestingV 2023-10-02 18:58:59 +03:00
parent 82f8fc90b3
commit ffc383af3b
2 changed files with 5 additions and 4 deletions

View File

@ -147,7 +147,7 @@ async fn handle_socket(
socket_addr: &SocketAddr,
mut players: PlayerRegistry,
rooms: RoomRegistry,
storage: Storage,
mut storage: Storage,
termination: Deferred<()>, // TODO use it to stop the connection gracefully
) -> Result<()> {
log::info!("Received an XMPP connection from {socket_addr}");
@ -172,7 +172,6 @@ async fn handle_socket(
let mut xml_reader = NsReader::from_reader(BufReader::new(a));
let mut xml_writer = Writer::new(b);
let mut storage = storage.clone();
let authenticated = socket_auth(&mut xml_reader, &mut xml_writer, &mut reader_buf, &mut storage).await?;
log::debug!("User authenticated");
let mut connection = players.connect_to_player(authenticated.player_id.clone()).await;
@ -272,6 +271,8 @@ async fn socket_auth(
return Err(fail("no user found"));
}
};
// TODO return proper XML errors to the client
if stored_user.password.is_none() {
log::info!("Password not defined for user '{}'", name);
return Err(fail("password is not defined"));
@ -282,7 +283,7 @@ async fn socket_auth(
}
Ok(Authenticated {
player_id: PlayerId::from("darova")?,
player_id: PlayerId::from(name.as_str())?,
xmpp_name: Name(name.to_string().into()),
xmpp_resource: Resource(name.to_string().into()),
xmpp_muc_name: Resource(name.to_string().into()),

View File

@ -39,7 +39,7 @@ impl AuthBody {
let decoded_body = general_purpose::STANDARD.decode(input).unwrap();
let parsed_to_string = String::from_utf8(decoded_body).unwrap();
let separated_words: Vec<&str> = parsed_to_string.split("\x00").filter(|&part| !part.is_empty()).collect::<Vec<_>>().clone();
if &separated_words.len() == &2_usize {
if separated_words.len() == 2 {
Ok(AuthBody { login: separated_words[0].to_string(), password: separated_words[1].to_string() })
} else { Err(anyhow!("Incorrect auth format")) }
}