🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-01-09 20:23:29.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-01-09 20:30:48.0 +00:00:00
commit
27570a6c6019beed4c9f8465ff01bad9320b79fe [patch]
tree
b180b9a7be2bfcd1c698801642336562891bab18
parent
a9a679f17febb8c9b3b3ae05a73e4888bb018916
download
27570a6c6019beed4c9f8465ff01bad9320b79fe.tar.gz

Set user's hostname to their IP address



Diff

 src/client.rs     |  4 +++-
 src/connection.rs | 13 ++++++++++++-
 src/main.rs       |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/client.rs b/src/client.rs
index 7639e55..d8aaf32 100644
--- a/src/client.rs
+++ a/src/client.rs
@@ -66,7 +66,7 @@
        ctx.run_interval(Duration::from_secs(30), |this, ctx| {
            let _span = info_span!(parent: &this.span, "ping").entered();

            if Instant::now().duration_since(this.last_active) > Duration::from_secs(120) {
            if Instant::now().duration_since(this.last_active) >= Duration::from_secs(120) {
                this.server_leave_reason = Some("Ping timeout: 120 seconds".to_string());
                ctx.stop();
            }
@@ -78,6 +78,8 @@
            });
        });

        // join the user to all the channels they were previously in before disconnecting from
        // the server
        ctx.spawn(
            self.persistence
                .send(FetchUserChannels {
diff --git a/src/connection.rs b/src/connection.rs
index 07d8bf9..4c6b339 100644
--- a/src/connection.rs
+++ a/src/connection.rs
@@ -1,5 +1,6 @@
use std::{
    io::{Error, ErrorKind},
    net::SocketAddr,
    str::FromStr,
};

@@ -30,6 +31,7 @@

#[derive(Default)]
pub struct ConnectionRequest {
    host: Option<SocketAddr>,
    nick: Option<String>,
    user: Option<String>,
    mode: Option<String>,
@@ -38,6 +40,7 @@

#[derive(Clone)]
pub struct InitiatedConnection {
    pub host: SocketAddr,
    pub nick: String,
    pub user: String,
    pub mode: String,
@@ -51,7 +54,7 @@
        Prefix::Nickname(
            self.nick.to_string(),
            self.user.to_string(),
            "my-host".to_string(),
            self.host.ip().to_string(),
        )
    }
}
@@ -61,6 +64,7 @@

    fn try_from(value: ConnectionRequest) -> Result<Self, Self::Error> {
        let ConnectionRequest {
            host: Some(host),
            nick: Some(nick),
            user: Some(user),
            mode: Some(mode),
@@ -70,6 +74,7 @@
        };

        Ok(Self {
            host,
            nick,
            user,
            mode,
@@ -85,9 +90,13 @@
pub async fn negotiate_client_connection(
    s: &mut MessageStream,
    write: &mut tokio_util::codec::FramedWrite<WriteHalf<TcpStream>, IrcCodec>,
    host: SocketAddr,
    database: sqlx::Pool<sqlx::Any>,
) -> Result<Option<InitiatedConnection>, ProtocolError> {
    let mut request = ConnectionRequest::default();
    let mut request = ConnectionRequest {
        host: Some(host),
        ..ConnectionRequest::default()
    };

    let mut capabilities_requested = false;

diff --git a/src/main.rs b/src/main.rs
index faaad24..6bd8a3f 100644
--- a/src/main.rs
+++ a/src/main.rs
@@ -147,7 +147,7 @@

            // ensure we have all the details required to actually connect the client to the server
            // (ie. we have a nick, user, etc)
            let Some(connection) = connection::negotiate_client_connection(&mut read, &mut write, database).await.unwrap() else {
            let Some(connection) = connection::negotiate_client_connection(&mut read, &mut write, addr, database).await.unwrap() else {
                error!("Failed to fully handshake with client, dropping connection");
                return;
            };