🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-02-02 0:13:00.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-02-02 0:13:00.0 +00:00:00
commit
524a15ea38e64b60889950c2dee41b7d3f42dd5e [patch]
tree
6c38cc78dae491c128906a4415b67cfd4b3e0655
parent
44a1108518cc324a9441a63064cea6860a7e4cf6
download
524a15ea38e64b60889950c2dee41b7d3f42dd5e.tar.gz

Acknowledge client QUITs by sending an ERROR as defined in the spec



Diff

 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
+++ a/src/client.rs
@@ -129,7 +129,11 @@
        // 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 @@
            });
        }

        // 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
+++ a/src/database/mod.rs
@@ -48,6 +48,9 @@
}

/// 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)
}