Implement MOTD command
Diff
src/client.rs | 20 +++++++++++++++++++-
src/messages.rs | 7 +++++++
src/server.rs | 12 ++++++++++++
3 files changed, 36 insertions(+), 3 deletions(-)
@@ -16,7 +16,7 @@
messages::{
Broadcast, ChannelFetchTopic, ChannelInvite, ChannelJoin, ChannelKickUser, ChannelList,
ChannelMemberList, ChannelMessage, ChannelPart, ChannelUpdateTopic, FetchClientDetails,
ServerDisconnect, UserKickedFromChannel, UserNickChange,
ServerDisconnect, ServerFetchMotd, UserKickedFromChannel, UserNickChange,
},
server::Server,
SERVER_NAME,
@@ -438,7 +438,23 @@
}
}
Command::NOTICE(_, _) => {}
Command::MOTD(_) => {}
Command::MOTD(_) => {
let span = Span::current();
let fut = self
.server
.send(ServerFetchMotd { span })
.into_actor(self)
.map(|result, this, _ctx| {
for message in result
.unwrap()
.into_messages(this.connection.nick.to_string())
{
this.writer.write(message);
}
});
ctx.spawn(fut);
}
Command::LUSERS(_, _) => {}
Command::VERSION(_) => {
self.writer.write(Message {
@@ -83,6 +83,13 @@
pub reason: Option<String>,
}
#[derive(Message)]
#[rtype(result = "super::server::response::Motd")]
pub struct ServerFetchMotd {
pub span: Span,
}
#[derive(Message)]
#[rtype(result = "()")]
@@ -15,7 +15,7 @@
connection::InitiatedConnection,
messages::{
Broadcast, ChannelFetchTopic, ChannelJoin, ChannelList, ChannelMemberList,
FetchClientByNick, ServerDisconnect, UserConnected, UserNickChange,
FetchClientByNick, ServerDisconnect, ServerFetchMotd, UserConnected, UserNickChange,
},
server::response::Motd,
SERVER_NAME,
@@ -85,6 +85,16 @@
}
self.clients.insert(msg.handle, msg.connection);
}
}
impl Handler<ServerFetchMotd> for Server {
type Result = MessageResult<ServerFetchMotd>;
#[instrument(parent = &msg.span, skip_all)]
fn handle(&mut self, msg: ServerFetchMotd, _ctx: &mut Self::Context) -> Self::Result {
MessageResult(Motd::new(self))
}
}