fix WHO replies

This commit is contained in:
Nikita Vilunov 2023-02-16 19:33:36 +01:00
parent 81ee1c1044
commit 69bccef3bf
2 changed files with 42 additions and 32 deletions

View File

@ -27,6 +27,11 @@ pub struct ServerConfig {
#[derive(Debug)]
struct RegisteredUser {
nickname: Vec<u8>,
/**
* Username is mostly unused in modern IRC.
*
* [https://stackoverflow.com/questions/31666247/what-is-the-difference-between-the-nick-username-and-real-name-in-irc-and-wha]
*/
username: Vec<u8>,
realname: Vec<u8>,
}
@ -383,19 +388,22 @@ async fn handle_incoming_message(
}
ClientMessage::Who { target } => match &target {
Recipient::Nick(nick) => {
if nick == &user.nickname {
let mut username = Vec::with_capacity(user.username.len() + 1);
// TODO handle non-existing user
let mut username = Vec::with_capacity(nick.len() + 1);
username.push(b'~');
username.extend_from_slice(user.username.as_slice());
username.extend_from_slice(nick.as_slice());
let mut host = b"user/".to_vec();
host.extend_from_slice(nick.as_slice());
ServerMessage {
tags: vec![],
sender: Some(config.server_name.as_bytes().to_vec()),
body: ServerMessageBody::N352WhoReply {
client: user.nickname.clone(),
username,
host: b"*".to_vec(), // TODO need to decide what to send as user's host
host,
server: config.server_name.as_bytes().to_vec(),
flags: AwayStatus::Here,
nickname: nick.clone(),
hops: 0,
realname: user.realname.clone(),
},
@ -415,8 +423,6 @@ async fn handle_incoming_message(
.await?;
writer.flush().await?;
}
log::warn!("WHO for other users is not implemented")
}
Recipient::Chan(_) => {
log::warn!("WHO for chans not implemented")
}

View File

@ -104,6 +104,7 @@ pub enum ServerMessageBody {
host: ByteVec,
/// Hostname of the server the user is connected to
server: ByteVec,
nickname: ByteVec,
/// Flags
flags: AwayStatus,
hops: u8,
@ -224,6 +225,7 @@ impl ServerMessageBody {
host,
server,
flags,
nickname,
hops,
realname,
} => {
@ -240,6 +242,8 @@ impl ServerMessageBody {
AwayStatus::Here => writer.write_all(b"H").await?,
AwayStatus::Gone => writer.write_all(b"G").await?,
}
writer.write_all(b" ").await?;
writer.write_all(&nickname).await?;
writer.write_all(b" :").await?;
writer.write_all(hops.to_string().as_bytes()).await?;
writer.write_all(b" ").await?;