24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

* src/mod_muc/mod_muc_room.erl: Implements muc max users option

from XEP-0045 (Thanks to Jerome Sautret) (EJAB-248).

SVN Revision: 892
This commit is contained in:
Mickaël Rémond 2007-08-28 14:35:50 +00:00
parent f314acd142
commit a78037fc3c
2 changed files with 66 additions and 14 deletions

View File

@ -2,6 +2,11 @@
* doc/guide.tex: Described @HOST@ feature (thanks to Badlop)
2007-08-26 Mickael Remond <mremond@process-one.net>
* src/mod_muc/mod_muc_room.erl: Implements muc max users option
from XEP-0045 (Thanks to Jerome Sautret) (EJAB-248).
2007-08-26 Alexey Shchepin <alexey@process-one.net>
* doc/guide.tex: Removed mentions of unexistent 'hosts' modules

View File

@ -30,6 +30,9 @@
-include("ejabberd.hrl").
-include("jlib.hrl").
-define(MAX_USERS_DEFAULT, 100).
-define(MAX_USERS_DEFAULT_LIST, [5, 10, 20, 30, 50, 100, 200, 500, 1000, 2000, 5000]).
-define(SETS, gb_sets).
-define(DICT, dict).
@ -49,6 +52,7 @@
password_protected = false,
password = "",
anonymous = true,
max_users = ?MAX_USERS_DEFAULT,
logging = false
}).
@ -1064,11 +1068,24 @@ is_nick_change(JID, Nick, StateData) ->
add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
Lang = xml:get_attr_s("xml:lang", Attrs),
MaxUsers = (StateData#state.config)#config.max_users,
UsersNb = length(?DICT:to_list(StateData#state.users)),
Affiliation = get_affiliation(From, StateData),
case {is_nick_exists(Nick, StateData),
case {(Affiliation == admin orelse Affiliation == owner)
orelse (MaxUsers == none orelse UsersNb+1 =< MaxUsers),
is_nick_exists(Nick, StateData),
mod_muc:can_use_nick(StateData#state.host, From, Nick),
get_default_role(Affiliation, StateData)} of
{_, _, none} ->
{false, _, _, _} ->
% max user reached and user is not admin or owner
Err = jlib:make_error_reply(
Packet,
?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route( % TODO: s/Nick/""/
jlib:jid_replace_resource(StateData#state.jid, Nick),
From, Err),
StateData;
{_, _, _, none} ->
Err = jlib:make_error_reply(
Packet,
case Affiliation of
@ -1083,7 +1100,7 @@ add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
jlib:jid_replace_resource(StateData#state.jid, Nick),
From, Err),
StateData;
{true, _, _} ->
{_, true, _, _} ->
ErrText = "Nickname is already in use by another occupant",
Err = jlib:make_error_reply(Packet, ?ERRT_CONFLICT(Lang, ErrText)),
ejabberd_router:route(
@ -1091,7 +1108,7 @@ add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
jlib:jid_replace_resource(StateData#state.jid, Nick),
From, Err),
StateData;
{_, false, _} ->
{_, _, false, _} ->
ErrText = "Nickname is registered by another person",
Err = jlib:make_error_reply(Packet, ?ERRT_CONFLICT(Lang, ErrText)),
ejabberd_router:route(
@ -1099,7 +1116,7 @@ add_new_user(From, Nick, {xmlelement, _, Attrs, Els} = Packet, StateData) ->
jlib:jid_replace_resource(StateData#state.jid, Nick),
From, Err),
StateData;
{_, _, Role} ->
{_, _, _, Role} ->
case check_password(Affiliation, Els, StateData) of
true ->
NewState =
@ -2271,6 +2288,22 @@ get_config(Lang, StateData, From) ->
true -> Config#config.password;
false -> ""
end),
{xmlelement, "field",
[{"type", "list-single"},
{"label", translate:translate(Lang, "Maximum Number of Occupants")},
{"var", "muc#roomconfig_maxusers"}],
[{xmlelement, "value", [], [{xmlcdata,
case Config#config.max_users of
none -> "none";
N -> erlang:integer_to_list(N)
end
}]},
{xmlelement, "option", [{"label", translate:translate(Lang, "No limit")}],
[{xmlelement, "value", [], [{xmlcdata, "none"}]}]} |
[{xmlelement, "option", [{"label", erlang:integer_to_list(N)}],
[{xmlelement, "value", [], [{xmlcdata, erlang:integer_to_list(N)}]}]} ||
N <- ?MAX_USERS_DEFAULT_LIST]
]},
{xmlelement, "field",
[{"type", "list-single"},
{"label", translate:translate(Lang, "Present real JIDs to")},
@ -2396,6 +2429,18 @@ set_xoption([{"muc#roomconfig_whois", [Val]} | Opts], Config) ->
_ ->
{error, ?ERR_BAD_REQUEST}
end;
set_xoption([{"muc#roomconfig_maxusers", [Val]} | Opts], Config) ->
case Val of
"none" ->
?SET_STRING_XOPT(max_users, none);
_ ->
case string:to_integer(Val) of
{error, _} ->
{error, ?ERR_BAD_REQUEST};
{I, _} ->
?SET_STRING_XOPT(max_users, I)
end
end;
set_xoption([{"muc#roomconfig_enablelogging", [Val]} | Opts], Config) ->
?SET_BOOL_XOPT(logging, Val);
set_xoption([{"FORM_TYPE", _} | Opts], Config) ->
@ -2463,6 +2508,7 @@ set_opts([{Opt, Val} | Opts], StateData) ->
?CASE_CONFIG_OPT(password);
?CASE_CONFIG_OPT(anonymous);
?CASE_CONFIG_OPT(logging);
?CASE_CONFIG_OPT(max_users);
affiliations ->
StateData#state{affiliations = ?DICT:from_list(Val)};
subject ->
@ -2493,6 +2539,7 @@ make_opts(StateData) ->
?MAKE_CONFIG_OPT(password),
?MAKE_CONFIG_OPT(anonymous),
?MAKE_CONFIG_OPT(logging),
?MAKE_CONFIG_OPT(max_users),
{affiliations, ?DICT:to_list(StateData#state.affiliations)},
{subject, StateData#state.subject},
{subject_author, StateData#state.subject_author}