From 8b099f9be27de46d9ae3e188a3ca9f3e2f403bba Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Sun, 7 Apr 2024 12:06:23 +0000 Subject: [PATCH] xmpp: fix handling of the `bind` iq --- crates/projection-xmpp/src/iq.rs | 4 ++-- crates/projection-xmpp/src/lib.rs | 18 ++++++++++++++---- crates/proto-xmpp/src/bind.rs | 3 +++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/projection-xmpp/src/iq.rs b/crates/projection-xmpp/src/iq.rs index 9c50ecc..01135b1 100644 --- a/crates/projection-xmpp/src/iq.rs +++ b/crates/projection-xmpp/src/iq.rs @@ -24,9 +24,9 @@ impl<'a> XmppConnection<'a> { to: None, r#type: IqType::Result, body: BindResponse(Jid { - name: Some(Name("darova".into())), + name: Some(self.user.xmpp_name.clone()), server: Server("localhost".into()), - resource: Some(Resource("kek".into())), + resource: Some(self.user.xmpp_resource.clone()), }), }; req.serialize(output); diff --git a/crates/projection-xmpp/src/lib.rs b/crates/projection-xmpp/src/lib.rs index e3cb4e5..8474e8f 100644 --- a/crates/projection-xmpp/src/lib.rs +++ b/crates/projection-xmpp/src/lib.rs @@ -52,9 +52,17 @@ struct LoadedConfig { } struct Authenticated { + /// Identifier of the authenticated player. + /// + /// Used when communicating with lavina-core on behalf of the player. player_id: PlayerId, + /// The user's XMPP name. + /// + /// Used in `to` and `from` fields of XMPP messages. xmpp_name: Name, + /// The resource given to this user by the server. xmpp_resource: Resource, + /// The resource used by this user when joining MUCs. xmpp_muc_name: Resource, } @@ -307,11 +315,13 @@ async fn socket_auth( return Err(fail("passwords do not match")); } + let name: Str = name.as_str().into(); + Ok(Authenticated { - player_id: PlayerId::from(name.as_str())?, - xmpp_name: Name(name.to_string().into()), - xmpp_resource: Resource(name.to_string().into()), - xmpp_muc_name: Resource(name.to_string().into()), + player_id: PlayerId::from(name.clone())?, + xmpp_name: Name(name.clone()), + xmpp_resource: Resource(name.clone()), + xmpp_muc_name: Resource(name.clone()), }) } Err(e) => return Err(e), diff --git a/crates/proto-xmpp/src/bind.rs b/crates/proto-xmpp/src/bind.rs index 9984ae5..41c9e45 100644 --- a/crates/proto-xmpp/src/bind.rs +++ b/crates/proto-xmpp/src/bind.rs @@ -11,12 +11,15 @@ pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-bind"; // TODO remove `pub` in newtypes, introduce validation +/// Name (node identifier) of an XMPP entity. Placed before the `@` in a JID. #[derive(PartialEq, Eq, Debug, Clone)] pub struct Name(pub Str); +/// Server name of an XMPP entity. Placed after the `@` and before the `/` in a JID. #[derive(PartialEq, Eq, Debug, Clone)] pub struct Server(pub Str); +/// Resource of an XMPP entity. Placed after the `/` in a JID. #[derive(PartialEq, Eq, Debug, Clone)] pub struct Resource(pub Str);