diff --git a/src/core/player.rs b/src/core/player.rs index cb3d319..3457a88 100644 --- a/src/core/player.rs +++ b/src/core/player.rs @@ -27,7 +27,7 @@ use crate::{ /// Opaque player identifier. Cannot contain spaces, must be shorter than 32. #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)] -pub struct PlayerId(pub Str); +pub struct PlayerId(Str); impl PlayerId { pub fn from(str: impl Into) -> Result { let bytes = str.into(); @@ -46,22 +46,6 @@ impl PlayerId { self.0 } } -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Prefix(pub Str); - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct PrefixedNick { - pub prefix: Prefix, - pub nick: PlayerId, -} -impl PrefixedNick { - pub fn fromPlayerId(id: PlayerId) -> Result { - Ok(PrefixedNick { prefix: Prefix(Str::from("")), nick: id } ) - } - pub fn fromStr(nick: Str) -> Result { - Ok(PrefixedNick { prefix: Prefix(Str::from("")), nick: PlayerId(nick) } ) - } -} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ConnectionId(pub AnonKey); diff --git a/src/projections/irc/mod.rs b/src/projections/irc/mod.rs index 37fcd42..4c6808a 100644 --- a/src/projections/irc/mod.rs +++ b/src/projections/irc/mod.rs @@ -18,6 +18,7 @@ use crate::prelude::*; use crate::protos::irc::client::{client_message, ClientMessage}; use crate::protos::irc::server::{AwayStatus, ServerMessage, ServerMessageBody}; use crate::protos::irc::{Chan, Recipient}; +use crate::protos::irc::user::PrefixedNick; use crate::util::Terminator; #[cfg(test)] diff --git a/src/protos/irc/mod.rs b/src/protos/irc/mod.rs index 4d65efd..0997a79 100644 --- a/src/protos/irc/mod.rs +++ b/src/protos/irc/mod.rs @@ -1,6 +1,7 @@ //! Client-to-Server IRC protocol. pub mod client; pub mod server; +pub mod user; use std::io::Result; use crate::prelude::Str; diff --git a/src/protos/irc/server.rs b/src/protos/irc/server.rs index 47ca9ac..990941e 100644 --- a/src/protos/irc/server.rs +++ b/src/protos/irc/server.rs @@ -3,7 +3,7 @@ use tokio::io::AsyncWrite; use tokio::io::AsyncWriteExt; use super::*; -use crate::core::player::PrefixedNick; +use crate::protos::irc::user::PrefixedNick; /// Server-to-client message. #[derive(Clone, Debug, PartialEq, Eq)] @@ -284,17 +284,16 @@ impl ServerMessageBody { let mut membersTail: Vec = members.tail.clone(); membersTail.insert(0, members.clone().head); - let membersStr: Vec = membersTail.iter().map(| prefixedNick| { - let pref: String = prefixedNick.prefix.0.clone().to_string(); - let nick: String = prefixedNick.nick.0.clone().to_string(); - pref + &nick - }).collect(); writer.write_all(b"353 ").await?; writer.write_all(client.as_bytes()).await?; writer.write_all(b" = ").await?; chan.write_async(writer).await?; writer.write_all(b" :").await?; - writer.write_all(membersStr.join(", ").as_bytes()).await?; + for member in members { + writer.write_all(member.prefix.to_string().as_bytes()).await?; + writer.write_all(member.nick.as_bytes()).await?; + writer.write_all(b" ").await?; + } } ServerMessageBody::N366NamesReplyEnd { client, chan } => { writer.write_all(b"366 ").await?; diff --git a/src/protos/irc/user.rs b/src/protos/irc/user.rs new file mode 100644 index 0000000..4f2d0cd --- /dev/null +++ b/src/protos/irc/user.rs @@ -0,0 +1,30 @@ +use super::*; +use std::fmt; +use crate::core::player::PlayerId; + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum Prefix{ + empty, +} +impl fmt::Display for Prefix { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + Prefix::empty => write!(f, ""), + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct PrefixedNick { + pub prefix: Prefix, + pub nick: Str, +} +impl PrefixedNick { + pub fn fromStr(nick: Str) -> Result { + Ok(PrefixedNick { prefix: Prefix::empty, nick } ) + } + + pub fn fromPlayerId(id: PlayerId) -> Result { + Ok(PrefixedNick { prefix: Prefix::empty, nick: id.into_inner() } ) + } +} \ No newline at end of file