I want the Erling code to determine the length of the visitor nickname

I use the Ejabberd server . How do I add the option to specify the number of characters of the visitor nickname within the room configuration ?

Upvotes: 0

Views: 33

Answers (2)

Badlop
Badlop

Reputation: 4120

This small patch limits the length of the occupants nicknames to 5 characters or less. It is not configurable, simply edit the source code:

diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
index ea2b069d7..bfc5b143a 100644
--- a/src/mod_muc_room.erl
+++ b/src/mod_muc_room.erl
@@ -1216,26 +1216,33 @@ do_process_presence(Nick, #presence{from = From, type = available, lang = Lang}
        case is_nick_change(From, Nick, StateData) of
        true ->
            case {nick_collision(From, Nick, StateData),
+             string:length(Nick) > 5,
              mod_muc:can_use_nick(StateData#state.server_host,
                           StateData#state.host,
                           From, Nick),
              {(StateData#state.config)#config.allow_visitor_nickchange,
               is_visitor(From, StateData)}} of
-           {_, _, {false, true}} ->
+           {_, true, _, _} ->
+               Packet1 = Packet#presence{sub_els = [#muc{}]},
+               ErrText = ?T("That nickname exceeds the maximum allowed length"),
+               Err = xmpp:err_conflict(ErrText, Lang),
+               ejabberd_router:route_error(Packet1, Err),
+               StateData;
+           {_, _, _, {false, true}} ->
                Packet1 = Packet#presence{sub_els = [#muc{}]},
                ErrText = ?T("Visitors are not allowed to change their "
                     "nicknames in this room"),
                Err = xmpp:err_not_allowed(ErrText, Lang),
                ejabberd_router:route_error(Packet1, Err),
                StateData;
-           {true, _, _} ->
+           {true, _, _, _} ->
                Packet1 = Packet#presence{sub_els = [#muc{}]},
                ErrText = ?T("That nickname is already in use by another "
                     "occupant"),
                Err = xmpp:err_conflict(ErrText, Lang),
                ejabberd_router:route_error(Packet1, Err),
                StateData;
-           {_, false, _} ->
+           {_, _, false, _} ->
                Packet1 = Packet#presence{sub_els = [#muc{}]},
                Err = case Nick of
                      <<>> ->

Upvotes: 0

Badlop
Badlop

Reputation: 4120

I see no option to restrict the length of a room occupant nickname.

Upvotes: 1

Related Questions