forked from lavina/lavina
minor changes according to the comments
This commit is contained in:
parent
82f8fc90b3
commit
ffc383af3b
|
@ -147,7 +147,7 @@ async fn handle_socket(
|
||||||
socket_addr: &SocketAddr,
|
socket_addr: &SocketAddr,
|
||||||
mut players: PlayerRegistry,
|
mut players: PlayerRegistry,
|
||||||
rooms: RoomRegistry,
|
rooms: RoomRegistry,
|
||||||
storage: Storage,
|
mut storage: Storage,
|
||||||
termination: Deferred<()>, // TODO use it to stop the connection gracefully
|
termination: Deferred<()>, // TODO use it to stop the connection gracefully
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
log::info!("Received an XMPP connection from {socket_addr}");
|
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_reader = NsReader::from_reader(BufReader::new(a));
|
||||||
let mut xml_writer = Writer::new(b);
|
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?;
|
let authenticated = socket_auth(&mut xml_reader, &mut xml_writer, &mut reader_buf, &mut storage).await?;
|
||||||
log::debug!("User authenticated");
|
log::debug!("User authenticated");
|
||||||
let mut connection = players.connect_to_player(authenticated.player_id.clone()).await;
|
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"));
|
return Err(fail("no user found"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// TODO return proper XML errors to the client
|
||||||
|
|
||||||
if stored_user.password.is_none() {
|
if stored_user.password.is_none() {
|
||||||
log::info!("Password not defined for user '{}'", name);
|
log::info!("Password not defined for user '{}'", name);
|
||||||
return Err(fail("password is not defined"));
|
return Err(fail("password is not defined"));
|
||||||
|
@ -282,7 +283,7 @@ async fn socket_auth(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Authenticated {
|
Ok(Authenticated {
|
||||||
player_id: PlayerId::from("darova")?,
|
player_id: PlayerId::from(name.as_str())?,
|
||||||
xmpp_name: Name(name.to_string().into()),
|
xmpp_name: Name(name.to_string().into()),
|
||||||
xmpp_resource: Resource(name.to_string().into()),
|
xmpp_resource: Resource(name.to_string().into()),
|
||||||
xmpp_muc_name: Resource(name.to_string().into()),
|
xmpp_muc_name: Resource(name.to_string().into()),
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl AuthBody {
|
||||||
let decoded_body = general_purpose::STANDARD.decode(input).unwrap();
|
let decoded_body = general_purpose::STANDARD.decode(input).unwrap();
|
||||||
let parsed_to_string = String::from_utf8(decoded_body).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();
|
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() })
|
Ok(AuthBody { login: separated_words[0].to_string(), password: separated_words[1].to_string() })
|
||||||
} else { Err(anyhow!("Incorrect auth format")) }
|
} else { Err(anyhow!("Incorrect auth format")) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue