forked from lavina/lavina
1
0
Fork 0

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)] #[derive(Debug)]
struct RegisteredUser { struct RegisteredUser {
nickname: Vec<u8>, 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>, username: Vec<u8>,
realname: Vec<u8>, realname: Vec<u8>,
} }
@ -383,19 +388,22 @@ async fn handle_incoming_message(
} }
ClientMessage::Who { target } => match &target { ClientMessage::Who { target } => match &target {
Recipient::Nick(nick) => { Recipient::Nick(nick) => {
if nick == &user.nickname { // TODO handle non-existing user
let mut username = Vec::with_capacity(user.username.len() + 1); let mut username = Vec::with_capacity(nick.len() + 1);
username.push(b'~'); 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 { ServerMessage {
tags: vec![], tags: vec![],
sender: Some(config.server_name.as_bytes().to_vec()), sender: Some(config.server_name.as_bytes().to_vec()),
body: ServerMessageBody::N352WhoReply { body: ServerMessageBody::N352WhoReply {
client: user.nickname.clone(), client: user.nickname.clone(),
username, 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(), server: config.server_name.as_bytes().to_vec(),
flags: AwayStatus::Here, flags: AwayStatus::Here,
nickname: nick.clone(),
hops: 0, hops: 0,
realname: user.realname.clone(), realname: user.realname.clone(),
}, },
@ -415,8 +423,6 @@ async fn handle_incoming_message(
.await?; .await?;
writer.flush().await?; writer.flush().await?;
} }
log::warn!("WHO for other users is not implemented")
}
Recipient::Chan(_) => { Recipient::Chan(_) => {
log::warn!("WHO for chans not implemented") log::warn!("WHO for chans not implemented")
} }

View File

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