mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
When join new room with password, set pass and password_protected (#2668)
This commit is contained in:
parent
a1dfb7fbe6
commit
a157e22c2f
@ -508,6 +508,23 @@ unregister_routes(Hosts, 1) ->
|
||||
unregister_routes(_, _) ->
|
||||
ok.
|
||||
|
||||
%% Function copied from mod_muc_room.erl
|
||||
-spec extract_password(presence() | iq()) -> binary() | false.
|
||||
extract_password(#presence{} = Pres) ->
|
||||
case xmpp:get_subtag(Pres, #muc{}) of
|
||||
#muc{password = Password} when is_binary(Password) ->
|
||||
Password;
|
||||
_ ->
|
||||
false
|
||||
end;
|
||||
extract_password(#iq{} = IQ) ->
|
||||
case xmpp:get_subtag(IQ, #muc_subscribe{}) of
|
||||
#muc_subscribe{password = Password} when Password /= <<"">> ->
|
||||
Password;
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
-spec route_to_room(stanza(), binary()) -> ok.
|
||||
route_to_room(Packet, ServerHost) ->
|
||||
From = xmpp:get_from(Packet),
|
||||
@ -527,7 +544,8 @@ route_to_room(Packet, ServerHost) ->
|
||||
{error, notfound} when StartType == start ->
|
||||
case check_create_room(ServerHost, Host, Room, From) of
|
||||
true ->
|
||||
case start_new_room(RMod, Host, ServerHost, Room, From, Nick) of
|
||||
Pass = extract_password(Packet),
|
||||
case start_new_room(RMod, Host, ServerHost, Room, Pass, From, Nick) of
|
||||
{ok, Pid} ->
|
||||
mod_muc_room:route(Pid, Packet);
|
||||
_Err ->
|
||||
@ -815,10 +833,19 @@ load_room(RMod, Host, ServerHost, Room) ->
|
||||
end
|
||||
end.
|
||||
|
||||
start_new_room(RMod, Host, ServerHost, Room, From, Nick) ->
|
||||
start_new_room(RMod, Host, ServerHost, Room, Pass, From, Nick) ->
|
||||
?DEBUG("Open new room: ~s", [Room]),
|
||||
DefRoomOpts = mod_muc_opt:default_room_options(ServerHost),
|
||||
start_room(RMod, Host, ServerHost, Room, DefRoomOpts, From, Nick).
|
||||
DefRoomOpts2 = add_password_options(Pass, DefRoomOpts),
|
||||
start_room(RMod, Host, ServerHost, Room, DefRoomOpts2, From, Nick).
|
||||
|
||||
add_password_options(false, DefRoomOpts) ->
|
||||
DefRoomOpts;
|
||||
add_password_options(<<>>, DefRoomOpts) ->
|
||||
DefRoomOpts;
|
||||
add_password_options(Pass, DefRoomOpts) when is_binary(Pass) ->
|
||||
O2 = lists:keystore(password, 1, DefRoomOpts, {password, Pass}),
|
||||
lists:keystore(password_protected, 1, O2, {password_protected, true}).
|
||||
|
||||
start_room(Mod, Host, ServerHost, Room, DefOpts) ->
|
||||
Access = get_access(ServerHost),
|
||||
|
Loading…
Reference in New Issue
Block a user