From 53f218c58fafa70d11bc9dc2411fb7396bca1ab7 Mon Sep 17 00:00:00 2001 From: JustTestingV Date: Wed, 6 Sep 2023 18:43:07 +0000 Subject: [PATCH] [irc] send 502 if not sender tries to change mode for other users (#4) Reviewed-on: https://git.vilunov.me/lavina/lavina/pulls/4 Co-authored-by: JustTestingV Co-committed-by: JustTestingV --- src/projections/irc/mod.rs | 12 +++++++++++- src/protos/irc/server.rs | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/projections/irc/mod.rs b/src/projections/irc/mod.rs index 6c36716..fc490fd 100644 --- a/src/projections/irc/mod.rs +++ b/src/projections/irc/mod.rs @@ -528,7 +528,17 @@ async fn handle_incoming_message( .await?; writer.flush().await?; } else { - // TODO send 502 (not 401) if the user is not the sender + ServerMessage { + tags: vec![], + sender: Some(config.server_name.clone()), + body: ServerMessageBody::N502UsersDontMatch { + client: user.nickname.clone(), + message: "Cant change mode for other users".into(), + }, + } + .write_async(writer) + .await?; + writer.flush().await?; } } Recipient::Chan(_) => { diff --git a/src/protos/irc/server.rs b/src/protos/irc/server.rs index 16b5804..b2efcd4 100644 --- a/src/protos/irc/server.rs +++ b/src/protos/irc/server.rs @@ -132,6 +132,10 @@ pub enum ServerMessageBody { chan: Chan, message: Str, }, + N502UsersDontMatch { + client: Str, + message: Str, + }, } impl ServerMessageBody { @@ -301,6 +305,13 @@ impl ServerMessageBody { writer.write_all(b" :").await?; writer.write_all(message.as_bytes()).await?; } + ServerMessageBody::N502UsersDontMatch { client, message } => { + writer.write_all(b"502 ").await?; + writer.write_all(client.as_bytes()).await?; + writer.write_all(b" ").await?; + writer.write_all(b" :").await?; + writer.write_all(message.as_bytes()).await?; + } } Ok(()) }