forked from lavina/lavina
fix WHO replies
This commit is contained in:
parent
81ee1c1044
commit
69bccef3bf
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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?;
|
||||
|
|
Loading…
Reference in New Issue