从房间配置 MUC 中删除一些选项
Posted
技术标签:
【中文标题】从房间配置 MUC 中删除一些选项【英文标题】:Remove some options from room config MUC 【发布时间】:2018-10-23 14:00:40 【问题描述】:当所有者加入房间并打开房间配置面板时,出现几个配置选项。
我想从配置面板中删除一些选项,例如
最大用户数 > 最大限制为 200,但我想将最大限制设置为 30,并且字段不可编辑。 (没有人可以更改30个限制)
Presence real Jids to -(默认为主持人) 我想设置默认值是所有人和隐藏字段。
广播状态的角色 (默认全选)。只想隐藏这个字段。没有任何变化。
将房间设为已审核(只想隐藏此字段。未选中。)
默认用户为参与者(只想隐藏此字段。默认选中)
允许访问者在状态广播中发送状态文本(只想隐藏此字段。未选中)
允许访问者更改昵称(只想隐藏此字段。未选中)
允许访问者发送语音请求(只想取消选中并隐藏此字段)
允许订阅(只想取消选中并隐藏此字段)
我知道这些所有修改都将在 .erl 文件中完成,我尝试这样做但没有任何反应。任何人都可以知道如何做到这一点。
请帮忙。
【问题讨论】:
【参考方案1】:作为服务器管理员,您可以使用以下 mod_muc 选项在 ejabberd.yml 中设置默认房间值:default_room_options,请参阅https://docs.ejabberd.im/admin/configuration/#mod-muc
然后您必须修改 mod_muc_room.erl 以隐藏该字段,并且如果聪明的房间所有者手动添加选项,也不能使用这些选项。稍后你编译这个文件(或所有ejabberd),并安装修改后的mod_muc_room.beam,覆盖旧的,最后重新启动ejabberd。如果您没有看到更改,则可能是您将 beam 文件复制到了另一个地方(可能您安装了两个 ejabberd,一个正在运行,另一个是旧的并且让您感到困惑?)。
我认为此更改包含您想要的所有选项,但最好您验证一下,也许我忘记了一些。我在 ejabberd 18.09 中尝试了这种更改,它在房间配置公式中隐藏了几个选项:
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index 267514b20..a6fc0e73f 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -58,7 +58,7 @@
-include("mod_muc_room.hrl").
-define(MAX_USERS_DEFAULT_LIST,
- [5, 10, 20, 30, 50, 100, 200, 500, 1000, 2000, 5000]).
+ [30]).
-define(DEFAULT_MAX_USERS_PRESENCE,1000).
@@ -3363,23 +3363,23 @@ get_config(Lang, StateData, From) ->
MaxUsersRoom
| ?MAX_USERS_DEFAULT_LIST]),
N =< ServiceMaxUsers],
- whois, if Config#config.anonymous -> moderators;
- true -> anyone
- end,
- presencebroadcast, Config#config.presence_broadcast,
+ %whois, if Config#config.anonymous -> moderators;
+ % true -> anyone
+ % end,
+ %presencebroadcast, Config#config.presence_broadcast,
membersonly, Config#config.members_only,
- moderatedroom, Config#config.moderated,
- members_by_default, Config#config.members_by_default,
+ %moderatedroom, Config#config.moderated,
+ %members_by_default, Config#config.members_by_default,
changesubject, Config#config.allow_change_subj,
allow_private_messages, Config#config.allow_private_messages,
allow_private_messages_from_visitors,
Config#config.allow_private_messages_from_visitors,
allow_query_users, Config#config.allow_query_users,
allowinvites, Config#config.allow_user_invites,
- allow_visitor_status, Config#config.allow_visitor_status,
- allow_visitor_nickchange, Config#config.allow_visitor_nickchange,
- allow_voice_requests, Config#config.allow_voice_requests,
- allow_subscription, Config#config.allow_subscription,
+ %allow_visitor_status, Config#config.allow_visitor_status,
+ %allow_visitor_nickchange, Config#config.allow_visitor_nickchange,
+ %allow_voice_requests, Config#config.allow_voice_requests,
+ %allow_subscription, Config#config.allow_subscription,
voice_request_min_interval, Config#config.voice_request_min_interval,
pubsub, Config#config.pubsub]
++
@@ -3440,27 +3440,27 @@ set_config(Opts, Config, ServerHost, Lang) ->
C#configallow_private_messages = V;
(allow_private_messages_from_visitors, V, C) ->
C#configallow_private_messages_from_visitors = V;
- (allow_visitor_status, V, C) -> C#configallow_visitor_status = V;
- (allow_visitor_nickchange, V, C) ->
- C#configallow_visitor_nickchange = V;
+ %(allow_visitor_status, V, C) -> C#configallow_visitor_status = V;
+ %(allow_visitor_nickchange, V, C) ->
+ %C#configallow_visitor_nickchange = V;
(publicroom, V, C) -> C#configpublic = V;
(public_list, V, C) -> C#configpublic_list = V;
(persistentroom, V, C) -> C#configpersistent = V;
- (moderatedroom, V, C) -> C#configmoderated = V;
- (members_by_default, V, C) -> C#configmembers_by_default = V;
+ %(moderatedroom, V, C) -> C#configmoderated = V;
+ %(members_by_default, V, C) -> C#configmembers_by_default = V;
(membersonly, V, C) -> C#configmembers_only = V;
(captcha_protected, V, C) -> C#configcaptcha_protected = V;
(allowinvites, V, C) -> C#configallow_user_invites = V;
- (allow_subscription, V, C) -> C#configallow_subscription = V;
+ %(allow_subscription, V, C) -> C#configallow_subscription = V;
(passwordprotectedroom, V, C) -> C#configpassword_protected = V;
(roomsecret, V, C) -> C#configpassword = V;
(anonymous, V, C) -> C#configanonymous = V;
(presencebroadcast, V, C) -> C#configpresence_broadcast = V;
- (allow_voice_requests, V, C) -> C#configallow_voice_requests = V;
+ %(allow_voice_requests, V, C) -> C#configallow_voice_requests = V;
(voice_request_min_interval, V, C) ->
C#configvoice_request_min_interval = V;
- (whois, moderators, C) -> C#configanonymous = true;
- (whois, anyone, C) -> C#configanonymous = false;
+ %(whois, moderators, C) -> C#configanonymous = true;
+ %(whois, anyone, C) -> C#configanonymous = false;
(maxusers, V, C) -> C#configmax_users = V;
(enablelogging, V, C) -> C#configlogging = V;
(pubsub, V, C) -> C#configpubsub = V;
有一个选项不允许访问者更改昵称。如果您希望此选项也禁止参与者,请应用此更改:
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index 267514b20..16ce21ba1 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -1031,7 +1031,7 @@ do_process_presence(Nick, #presencefrom = From, type = available, lang = Lang
StateData#state.host,
From, Nick),
(StateData#state.config)#config.allow_visitor_nickchange,
- is_visitor(From, StateData) of
+ is_visitor_or_participant(From, StateData) of
_, _, false, true ->
Packet1 = Packet#presencesub_els = [#muc],
ErrText = <<"Visitors are not allowed to change their "
@@ -1501,6 +1501,11 @@ get_default_role(Affiliation, StateData) ->
is_visitor(Jid, StateData) ->
get_role(Jid, StateData) =:= visitor.
+is_visitor_or_participant(Jid, StateData) ->
+ (get_role(Jid, StateData) =:= visitor)
+ or
+ (get_role(Jid, StateData) =:= participant).
+
-spec is_moderator(jid(), state()) -> boolean().
is_moderator(Jid, StateData) ->
get_role(Jid, StateData) =:= moderator.
另一方面,如果您想禁止所有角色更改昵称,则更改较小:
diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index 267514b20..2ef75e6ed 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -1032,7 +1032,7 @@ do_process_presence(Nick, #presencefrom = From, type = available, lang = Lang
From, Nick),
(StateData#state.config)#config.allow_visitor_nickchange,
is_visitor(From, StateData) of
- _, _, false, true ->
+ _, _, false, _ ->
Packet1 = Packet#presencesub_els = [#muc],
ErrText = <<"Visitors are not allowed to change their "
"nicknames in this room">>,
【讨论】:
谢谢兄弟。它真的有效。你能再做一个帮助吗?你能告诉我如何停止在房间里更改昵称吗?一个用户输入了真正的 jid,然后他们突然将他们的昵称更改为另一个名字。你能告诉我如何禁用它吗? 我在评论中为此添加了另一个补丁。 谢谢兄弟。但我想禁用所有附属机构的昵称更改。所有者、管理员、成员和参与者。 然后,代替上一个补丁,应用我刚刚添加到评论中的那个。 谢谢兄弟。你很善良。 :-)以上是关于从房间配置 MUC 中删除一些选项的主要内容,如果未能解决你的问题,请参考以下文章
xmpp/smack : muc(MultiUserChat:多人聊天)房间配置表单