forked from lavina/lavina
return user's mode to themselves
This commit is contained in:
parent
63f31aa42f
commit
204126b9fb
|
@ -446,6 +446,27 @@ async fn handle_incoming_message(
|
||||||
log::warn!("Local chans not supported");
|
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 => {
|
cmd => {
|
||||||
log::warn!("Not implemented handler for client command: {cmd:?}");
|
log::warn!("Not implemented handler for client command: {cmd:?}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@ pub enum ClientMessage {
|
||||||
/// JOIN <chan>
|
/// JOIN <chan>
|
||||||
Join(Chan),
|
Join(Chan),
|
||||||
/// MODE <target>
|
/// MODE <target>
|
||||||
Mode(Chan), // TODO support not only chan
|
Mode {
|
||||||
|
target: Recipient,
|
||||||
|
},
|
||||||
/// WHO <target>
|
/// WHO <target>
|
||||||
Who {
|
Who {
|
||||||
target: Recipient, // aka mask
|
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> {
|
fn client_message_mode(input: &[u8]) -> IResult<&[u8], ClientMessage> {
|
||||||
let (input, _) = tag("MODE ")(input)?;
|
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> {
|
fn client_message_who(input: &[u8]) -> IResult<&[u8], ClientMessage> {
|
||||||
|
|
|
@ -83,6 +83,11 @@ pub enum ServerMessageBody {
|
||||||
client: ByteVec,
|
client: ByteVec,
|
||||||
params: ByteVec, // TODO make this a datatype
|
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.
|
/// Final reply to a client's [Who](crate::protos::irc::client::ClientMessage::Who) request.
|
||||||
N315EndOfWho {
|
N315EndOfWho {
|
||||||
client: ByteVec,
|
client: ByteVec,
|
||||||
|
@ -188,7 +193,7 @@ impl ServerMessageBody {
|
||||||
writer.write_all(b" ").await?;
|
writer.write_all(b" ").await?;
|
||||||
writer.write_all(&softname).await?;
|
writer.write_all(&softname).await?;
|
||||||
writer
|
writer
|
||||||
.write_all(b" DGMQRSZagiloswz CFILPQbcefgijklmnopqrstvz bkloveqjfI")
|
.write_all(b" r CFILPQbcefgijklmnopqrstvz")
|
||||||
.await?;
|
.await?;
|
||||||
// TODO remove hardcoded modes
|
// TODO remove hardcoded modes
|
||||||
}
|
}
|
||||||
|
@ -199,6 +204,12 @@ impl ServerMessageBody {
|
||||||
writer.write_all(¶ms).await?;
|
writer.write_all(¶ms).await?;
|
||||||
writer.write_all(b" :are supported by this server").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 } => {
|
ServerMessageBody::N315EndOfWho { client, mask, msg } => {
|
||||||
writer.write_all(b"315 ").await?;
|
writer.write_all(b"315 ").await?;
|
||||||
writer.write_all(&client).await?;
|
writer.write_all(&client).await?;
|
||||||
|
|
Loading…
Reference in New Issue