在 XMPP 中检测使用同一帐户的其他客户端

发布于 2024-12-02 06:37:31 字数 172 浏览 0 评论 0原文

XMPP 允许用户使用同一帐户同时从多个客户端连接到服务器。我构建了一个执行此操作的应用程序,但如果启用了桌面客户端,我不希望用户能够使用移动客户端进行连接。这是针对游戏的,连接到两者都会导致问题。

所以我想知道的是: 是否可以检测是否有其他客户端使用同一帐户连接。如果我可以检查其他客户端,我可以自动注销该用户。

XMPP allows users to connect to the server from multiple clients simultaneously, using the same account. I built an application that does this but if the desktop client is enabled, I do not want the users to be able to connect using a mobile client. This is for a game and being connected to both causes problems.

So what I'm wondering is:
Is it possible to detect if there are other clients connected using the same account. If I can check for other clients, I can auto logout the user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囚我心虐我身 2024-12-09 06:37:31

@Flow 走在正确的轨道上。如果所有客户端实例都使用相同的资源,则在大多数服务器中,稍后连接的客户端将替换较旧的会话。较旧的会话将收到冲突流错误,并且已断开连接。您必须小心不要自动重新连接旧客户端,否则您将编写“决斗资源”错误。

如果您可以控制服务器,则可以将其配置为允许给定用户最多使用一种资源,在这种情况下,较新的连接将因冲突错误而失败,但如果出现以下情况,您将遇到更严重的用户界面问题:你沿着那条路走下去;即使您愿意,也无法让第二个客户端登录。

最后,给定用户的所有资源都会订阅该用户的存在。只要您的客户端发送状态信息:

<presence/>

您就会从每个其他设备接收状态信息:

<presence to='[email protected]/resource1' from='[email protected]/resource2'/>
<presence to='[email protected]/resource1' from='[email protected]/resource3'/>
<presence to='[email protected]/resource1' from='[email protected]/resource4'/>

您可以使用它来确定哪个客户端是当前的,也许可以通过向状态添加扩展,例如 XEP-0115

@Flow was on the right track. If all of your client instances use the same resource, in most servers, the later-connecting client will replace the older session. The older session will get a conflict stream error, and be disconnected. You MUST be careful not to auto-reconnect with the older client, or you will have written the "dueling resources" bug.

If you had control over your server, you have a chance at configuring it to allow a maximum of one resource for a given user, in which case the newer connection will fail with a conflict error, but you'll have worse user interface problems if you head down that path; there will be no way to get the second client logged in, even if you wanted to.

Finally, all resources for a given user are subscribed to that user's presence. As long as your client sends presence in:

<presence/>

you will receive presence from each of your other devices:

<presence to='[email protected]/resource1' from='[email protected]/resource2'/>
<presence to='[email protected]/resource1' from='[email protected]/resource3'/>
<presence to='[email protected]/resource1' from='[email protected]/resource4'/>

You could use this to decide which client is current, perhaps by adding an extension to the presence like XEP-0115.

梦晓ヶ微光ヅ倾城 2024-12-09 06:37:31

为桌面和移动客户端提供固定但不同资源字符串。如果移动客户端登录,它可以通过查找桌面客户端资源的存在/可用性来检测桌面客户端的存在,反之亦然。

那么您只需要实现一个自定义的 XMPP ad-hoc 命令 (XEP-0050)告诉冲突的资源注销。

Give the desktop and mobile client a fixed but different resource string. If the mobile client logs in, it can detect the presence of the desktop client by looking up the presence/availability of the resource of the desktop client and vice versa.

Then you only need to implement an custom XMPP ad-hoc command (XEP-0050) that tells the conflicting resource to log out.

怀中猫帐中妖 2024-12-09 06:37:31

服务器的责任是:拒绝来自不被接受的客户端的登录。我不知道服务器是否能够将 xmpp 客户端列入黑名单,但是如果您使用 openfire,您应该能够编写扩展。

It would be the servers responsibility: to reject a login from a client that is not accepted. I don't know if servers are able to blacklist xmpp clients but, in case you use openfire, you should be able to write an extension.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文