2023-10-13 20:09:08 +00:00
|
|
|
//! Handling of all client2server message stanzas
|
|
|
|
|
2024-04-23 16:26:40 +00:00
|
|
|
use lavina_core::player::PlayerId;
|
2023-10-13 20:09:08 +00:00
|
|
|
use quick_xml::events::Event;
|
|
|
|
|
|
|
|
use lavina_core::prelude::*;
|
|
|
|
use lavina_core::room::RoomId;
|
|
|
|
use proto_xmpp::bind::{Jid, Server};
|
|
|
|
use proto_xmpp::client::{Message, MessageType};
|
|
|
|
use proto_xmpp::xml::{Ignore, ToXml};
|
|
|
|
|
|
|
|
use crate::XmppConnection;
|
|
|
|
|
|
|
|
impl<'a> XmppConnection<'a> {
|
|
|
|
pub async fn handle_message(&mut self, output: &mut Vec<Event<'static>>, m: Message<Ignore>) -> Result<()> {
|
|
|
|
if let Some(Jid {
|
|
|
|
name: Some(name),
|
|
|
|
server,
|
|
|
|
resource: _,
|
|
|
|
}) = m.to
|
|
|
|
{
|
2024-04-15 00:33:26 +00:00
|
|
|
if server.0.as_ref() == &*self.hostname_rooms && m.r#type == MessageType::Groupchat {
|
2024-05-22 09:29:44 +00:00
|
|
|
let Some(body) = &m.body else { return Ok(()) };
|
2024-05-26 11:20:26 +00:00
|
|
|
self.user_handle.send_message(RoomId::try_from(name.0.clone())?, body.clone()).await?;
|
2023-10-13 20:09:08 +00:00
|
|
|
Message::<()> {
|
|
|
|
to: Some(Jid {
|
|
|
|
name: Some(self.user.xmpp_name.clone()),
|
2024-04-15 00:33:26 +00:00
|
|
|
server: Server(self.hostname.clone()),
|
2023-10-13 20:09:08 +00:00
|
|
|
resource: Some(self.user.xmpp_resource.clone()),
|
|
|
|
}),
|
|
|
|
from: Some(Jid {
|
|
|
|
name: Some(name),
|
2024-04-15 00:33:26 +00:00
|
|
|
server: Server(self.hostname_rooms.clone()),
|
2023-10-13 20:09:08 +00:00
|
|
|
resource: Some(self.user.xmpp_muc_name.clone()),
|
|
|
|
}),
|
|
|
|
id: m.id,
|
|
|
|
r#type: MessageType::Groupchat,
|
|
|
|
lang: None,
|
|
|
|
subject: None,
|
|
|
|
body: m.body.clone(),
|
|
|
|
custom: vec![],
|
|
|
|
}
|
|
|
|
.serialize(output);
|
|
|
|
Ok(())
|
2024-04-23 16:26:40 +00:00
|
|
|
} else if server.0.as_ref() == &*self.hostname && m.r#type == MessageType::Chat {
|
2024-05-22 09:29:44 +00:00
|
|
|
let Some(body) = &m.body else { return Ok(()) };
|
|
|
|
self.user_handle.send_dialog_message(PlayerId::from(name.0.clone())?, body.clone()).await?;
|
2024-04-23 16:26:40 +00:00
|
|
|
Ok(())
|
2023-10-13 20:09:08 +00:00
|
|
|
} else {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|