From 204126b9fba8d3384a868b76197e96953303ad5c Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Thu, 16 Feb 2023 20:37:17 +0100 Subject: [PATCH] return user's mode to themselves --- src/projections/irc/mod.rs | 21 +++++++++++++++++++++ src/protos/irc/client.rs | 8 +++++--- src/protos/irc/server.rs | 13 ++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/projections/irc/mod.rs b/src/projections/irc/mod.rs index bf5bac3..bcb699a 100644 --- a/src/projections/irc/mod.rs +++ b/src/projections/irc/mod.rs @@ -446,6 +446,27 @@ async fn handle_incoming_message( log::warn!("Local chans not supported"); } }, + ClientMessage::Mode { target } => { + match target { + Recipient::Nick(nickname) => { + if nickname == user.nickname { + ServerMessage { + tags: vec![], + sender: Some(config.server_name.as_bytes().to_vec()), + body: ServerMessageBody::N221UserModeIs { client: user.nickname.clone(), modes: b"+r".to_vec() }, + } + .write_async(writer) + .await?; + writer.flush().await?; + } else { + // TODO send 502 (not 401) if the user is not the sender + } + }, + Recipient::Chan(_) => { + // TODO handle chan mode handling + }, + } + }, cmd => { log::warn!("Not implemented handler for client command: {cmd:?}"); } diff --git a/src/protos/irc/client.rs b/src/protos/irc/client.rs index 6955b98..057fee8 100644 --- a/src/protos/irc/client.rs +++ b/src/protos/irc/client.rs @@ -27,7 +27,9 @@ pub enum ClientMessage { /// JOIN Join(Chan), /// MODE - Mode(Chan), // TODO support not only chan + Mode { + target: Recipient, + }, /// WHO Who { target: Recipient, // aka mask @@ -139,9 +141,9 @@ fn client_message_join(input: &[u8]) -> IResult<&[u8], ClientMessage> { fn client_message_mode(input: &[u8]) -> IResult<&[u8], ClientMessage> { let (input, _) = tag("MODE ")(input)?; - let (input, chan) = chan(input)?; + let (input, target) = recipient(input)?; - Ok((input, ClientMessage::Mode(chan))) + Ok((input, ClientMessage::Mode { target } )) } fn client_message_who(input: &[u8]) -> IResult<&[u8], ClientMessage> { diff --git a/src/protos/irc/server.rs b/src/protos/irc/server.rs index f4c390d..e449d69 100644 --- a/src/protos/irc/server.rs +++ b/src/protos/irc/server.rs @@ -83,6 +83,11 @@ pub enum ServerMessageBody { client: ByteVec, params: ByteVec, // TODO make this a datatype }, + /// Reply to a client's [Mode](crate::protos::irc::client::ClientMessage::Mode) request. + N221UserModeIs { + client: ByteVec, + modes: ByteVec, + }, /// Final reply to a client's [Who](crate::protos::irc::client::ClientMessage::Who) request. N315EndOfWho { client: ByteVec, @@ -188,7 +193,7 @@ impl ServerMessageBody { writer.write_all(b" ").await?; writer.write_all(&softname).await?; writer - .write_all(b" DGMQRSZagiloswz CFILPQbcefgijklmnopqrstvz bkloveqjfI") + .write_all(b" r CFILPQbcefgijklmnopqrstvz") .await?; // TODO remove hardcoded modes } @@ -199,6 +204,12 @@ impl ServerMessageBody { writer.write_all(¶ms).await?; writer.write_all(b" :are supported by this server").await?; } + ServerMessageBody::N221UserModeIs { client, modes } => { + writer.write_all(b"221 ").await?; + writer.write_all(&client).await?; + writer.write_all(b" ").await?; + writer.write_all(&modes).await?; + }, ServerMessageBody::N315EndOfWho { client, mask, msg } => { writer.write_all(b"315 ").await?; writer.write_all(&client).await?;