拦截登录/注销ejabberd [英] Intercept login/logout ejabberd

查看:106
本文介绍了拦截登录/注销ejabberd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道用户在自定义模块中的ejabberd会话中登录和注销的时间,而不改变ejabberd代码。

I want to know when a user is logged in and logged out from an ejabberd session in a custom module, without changing the ejabberd code.

我需要,因为当用户登录并清理用户注销时执行的操作时,我必须执行一些操作。此外,我需要能够在某些情况下注销用户。

I need that because I have to execute some actions when a user logs in and clean up the actions I did when the user logs out. Also, I need to be able to logoff a user given some circumstances.

那么,有没有办法扩展一些模块来获得这些功能?我仍然在寻找一些可以帮助我的文档。

So, is there a way to extend some module to get those feature? I'm still looking for some documentation that could help me with that.

推荐答案

你可以编写自己的代码并构建它一个插件与ejabberd给你的行为gen_mod。
这个开始的好地方是这个 blog /教程,并遵循下一部分
这应该是足够的,但你会发现更多在同一个博客。

You can write your own code and build it has a plugin with the behaviour gen_mod that ejabberd gives you. A nice place to begin with is this blog/tutorial and follow to next part. This should be enough but you will find more on the same blog.

在你建立自己的模块后,我建议你采取一个看看钩子 set_presence_hook unset_presence_hook

After you get a little more comfortable with building your own module I suggest you take a look at the hooks set_presence_hook and unset_presence_hook

只要注意,set_presence_hook在每次存在设置时都被激活,而不是只有登录时,你只需要工作,如果可以的话。

Just notice that set_presence_hook is activated every time a presence is set, not only on log in, you just have to work that around, if you can.

长篇小说你最终会得到以下的一些东西:

Long story short you will end up with something like the following

-module(mod_your_mod).

-behavior(gen_mod).
-include("ejabberd.hrl").

-export([start/2, stop/1, on_set/4, on_unset/4]).

start(Host, _Opts) ->
   ejabberd_hooks:add(set_presence_hook, Host, ?MODULE, on_set, 50),
   ejabberd_hooks:add(unset_presence_hook, Host, ?MODULE, on_unset, 50),
   ok.

stop(Host) ->
   ejabberd_hooks:delete(set_presence_hook, Host, ?MODULE, on_set, 50),
   ejabberd_hooks:delete(unset_presence_hook, Host, ?MODULE, on_unset, 50),
   ok.

on_set(User, Server, _Resource, _Packet) ->
<presence code>    

on_unset(User, Server, _Resource, _Packet) ->
<offline code>

希望这个帮助

这篇关于拦截登录/注销ejabberd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆