From 1974db9d719640f5cd5a8b51fa1b97f801f5a809 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 17 Oct 2020 01:19:45 +0200 Subject: change connecting with channel name instead of id --- mumlib/src/command.rs | 2 +- mumlib/src/error.rs | 4 ++-- mumlib/src/state.rs | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index b2ac321..a0673f4 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; #[derive(Clone, Debug, Deserialize, Serialize)] pub enum Command { ChannelJoin { - channel_id: u32, + channel_identifier: String, }, ChannelList, ServerConnect { diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index cb88aa7..3e514fd 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -8,7 +8,7 @@ pub type Result = std::result::Result; pub enum Error { DisconnectedError, AlreadyConnectedError, - InvalidChannelIdError(u32), + InvalidChannelIdentifierError(String), InvalidServerAddrError(String, u16), } @@ -17,7 +17,7 @@ impl Display for Error { match self { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), - Error::InvalidChannelIdError(id) => write!(f, "Invalid channel id: {}", id), + Error::InvalidChannelIdentifierError(id) => write!(f, "Couldn't find channel {}", id), Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}:{}", addr, port), } } diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index f90634e..51fb492 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -128,6 +128,13 @@ impl Channel { pub fn name(&self) -> &str { &self.name } + + pub fn path(&self, channels: &HashMap) -> String { + match &self.parent { + Some(t) => format!("{}/{}", channels.get(t).unwrap().path(channels), self.name), + None => self.name.clone(), + } + } } #[derive(Clone, Debug, Deserialize, Serialize)] -- cgit v1.2.1 From b1c1c227a0f5c171726f16f4f474536a718fd56f Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 17 Oct 2020 01:37:53 +0200 Subject: add error checking if there are multiple valid channels to connect to --- mumlib/src/error.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'mumlib/src') diff --git a/mumlib/src/error.rs b/mumlib/src/error.rs index 3e514fd..6c66c1f 100644 --- a/mumlib/src/error.rs +++ b/mumlib/src/error.rs @@ -8,17 +8,33 @@ pub type Result = std::result::Result; pub enum Error { DisconnectedError, AlreadyConnectedError, - InvalidChannelIdentifierError(String), + ChannelIdentifierError(String, ChannelIdentifierError), InvalidServerAddrError(String, u16), } + impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Error::DisconnectedError => write!(f, "Not connected to a server"), Error::AlreadyConnectedError => write!(f, "Already connected to a server"), - Error::InvalidChannelIdentifierError(id) => write!(f, "Couldn't find channel {}", id), - Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}:{}", addr, port), + Error::ChannelIdentifierError(id, kind) => write!(f, "{}: {}", kind, id), + Error::InvalidServerAddrError(addr, port) => write!(f, "Invalid server address: {}: {}", addr, port), + } + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub enum ChannelIdentifierError { + Invalid, + Ambiguous, +} + +impl Display for ChannelIdentifierError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ChannelIdentifierError::Invalid => write!(f, "Invalid channel identifier"), + ChannelIdentifierError::Ambiguous => write!(f, "Ambiguous channel identifier"), } } } \ No newline at end of file -- cgit v1.2.1