[irc] send 502 if not sender tries to change mode for other users (#4)

Reviewed-on: lavina/lavina#4
Co-authored-by: JustTestingV <JustTestingV@gmail.com>
Co-committed-by: JustTestingV <JustTestingV@gmail.com>
This commit is contained in:
JustTestingV 2023-09-06 18:43:07 +00:00 committed by Nikita Vilunov
parent 377d9c32d2
commit 53f218c58f
2 changed files with 22 additions and 1 deletions

View File

@ -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(_) => {

View File

@ -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(())
}