From 524a15ea38e64b60889950c2dee41b7d3f42dd5e Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Thu, 2 Feb 2023 00:13:00 +0000 Subject: [PATCH] Acknowledge client QUITs by sending an ERROR as defined in the spec --- src/client.rs | 33 +++++++++++++++------------------ src/database/mod.rs | 5 ++++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/client.rs b/src/client.rs index 656e4ce..540390c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -129,7 +129,11 @@ impl Actor for Client { // inform the server that the user is leaving the server self.server.do_send(ServerDisconnect { client: ctx.address(), - message: message.clone(), + message: if self.graceful_shutdown { + Some(format!("Quit: {}", message.as_deref().unwrap_or(""))) + } else { + message.clone() + }, span: Span::current(), }); @@ -142,23 +146,16 @@ impl Actor for Client { }); } - // send the shutdown message to the client before we terminate the connection on - // return of this function - if self.graceful_shutdown { - self.writer.write(Message { - tags: None, - prefix: Some(self.connection.to_nick()), - command: Command::QUIT(message), - }); - } else { - let message = message.unwrap_or_else(|| "Ungraceful shutdown".to_string()); - - self.writer.write(Message { - tags: None, - prefix: None, - command: Command::ERROR(message), - }); - } + // acknowledge the client's quit message by sending an ERROR + self.writer.write(Message { + tags: None, + prefix: None, + command: Command::ERROR(if self.graceful_shutdown { + String::new() + } else { + message.unwrap_or_else(|| "Ungraceful shutdown".to_string()) + }), + }); } } diff --git a/src/database/mod.rs b/src/database/mod.rs index b830103..268e17e 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -48,6 +48,9 @@ pub async fn reserve_nick( } /// Compares a password to a hash stored in the database. -pub fn verify_password(password: &[u8], hash: &PasswordHash<'_>) -> argon2::password_hash::Result<()> { +pub fn verify_password( + password: &[u8], + hash: &PasswordHash<'_>, +) -> argon2::password_hash::Result<()> { Argon2::default().verify_password(password, hash) } -- libgit2 1.7.2