20161103_ejabberd為游戲免除注冊限制
(金慶的專欄 2016.11)
ejabberd聊天服務器默認會限制同一IP注冊帳號須間隔600s。
在游戲中需要為每個角色注冊一個聊天帳號,不應該有此限制。
可以更改服務器代碼,為游戲服務器免除這一注冊間隔時間。
假設游戲服用專用的帳號登錄ejabberd, 然后為這種帳號免除注冊限制。
在ejabberd.yml配置訪問控制列表(ACL)中添加 game_master:
acl:
game_master:
user:
- "game_master_1@localhost"
- "game_master_2@localhost"
game_master 帳號預先創建,供游戲服務器登錄ejabberd.
mod_register的配置中,將 "access_from: deny" 改為 "access_from: all".
"access_from: deny" 表示任何用戶都不能注冊帳號,只能是登錄前注冊。
"access_from: all" 表示登錄用戶也能注冊帳號。
這樣game_master帳號先登錄,然后就可以注冊新帳號了。
添加 access_from_without_time_limit,允許game_master無注冊限制。
mod_register:
access_from: all
access: register
## Allow some user register accounts without registration_timeout limit.
access_from_without_time_limit:
- allow: game_master
實際上也可以這樣直接配置:
access_from_without_time_limit:
- allow:
- user: game_master_1@localhost
- user: game_master_2@localhost
配置成 acl 的好處是,可以用
ejabberdctl reload_config
重新加載 acl, 而模塊配置部分無法重新加載。
acl 配置還可以在 http admin 界面更改。
代碼需稍加更改,修改mod_register.erl.
try_register/5 添加 From 參數改為 try_register/6
try_register(User, Server, Password, From, SourceRaw, Lang)
并將其中
case check_timeout(Source) of
改成
CheckTimeout = case check_from_without_time_limit(From, Server) of
allow -> true;
_ -> check_timeout(Source)
end,
case CheckTimeout of
即如果From是gm帳號時,CheckTimeout直接通過,不再判斷600s的間隔。
check_from_without_time_limit/2 仿照check_from/2,這樣實現:
check_from_without_time_limit(JID, Server) ->
Access = gen_mod:get_module_opt(Server, ?MODULE, access_from_without_time_limit,
fun(A) -> A end,
none),
acl:match_rule(Server, Access, JID).
添加:
mod_opt_type(access_from_without_time_limit) ->
fun acl:access_rules_validator/1;
...
mod_opt_type(_) ->
[..., access_from_without_time_limit, ...].
(金慶的專欄 2016.11)
ejabberd聊天服務器默認會限制同一IP注冊帳號須間隔600s。
在游戲中需要為每個角色注冊一個聊天帳號,不應該有此限制。
可以更改服務器代碼,為游戲服務器免除這一注冊間隔時間。
假設游戲服用專用的帳號登錄ejabberd, 然后為這種帳號免除注冊限制。
在ejabberd.yml配置訪問控制列表(ACL)中添加 game_master:
acl:
game_master:
user:
- "game_master_1@localhost"
- "game_master_2@localhost"
game_master 帳號預先創建,供游戲服務器登錄ejabberd.
mod_register的配置中,將 "access_from: deny" 改為 "access_from: all".
"access_from: deny" 表示任何用戶都不能注冊帳號,只能是登錄前注冊。
"access_from: all" 表示登錄用戶也能注冊帳號。
這樣game_master帳號先登錄,然后就可以注冊新帳號了。
添加 access_from_without_time_limit,允許game_master無注冊限制。
mod_register:
access_from: all
access: register
## Allow some user register accounts without registration_timeout limit.
access_from_without_time_limit:
- allow: game_master
實際上也可以這樣直接配置:
access_from_without_time_limit:
- allow:
- user: game_master_1@localhost
- user: game_master_2@localhost
配置成 acl 的好處是,可以用
ejabberdctl reload_config
重新加載 acl, 而模塊配置部分無法重新加載。
acl 配置還可以在 http admin 界面更改。
代碼需稍加更改,修改mod_register.erl.
try_register/5 添加 From 參數改為 try_register/6
try_register(User, Server, Password, From, SourceRaw, Lang)
并將其中
case check_timeout(Source) of
改成
CheckTimeout = case check_from_without_time_limit(From, Server) of
allow -> true;
_ -> check_timeout(Source)
end,
case CheckTimeout of
即如果From是gm帳號時,CheckTimeout直接通過,不再判斷600s的間隔。
check_from_without_time_limit/2 仿照check_from/2,這樣實現:
check_from_without_time_limit(JID, Server) ->
Access = gen_mod:get_module_opt(Server, ?MODULE, access_from_without_time_limit,
fun(A) -> A end,
none),
acl:match_rule(Server, Access, JID).
添加:
mod_opt_type(access_from_without_time_limit) ->
fun acl:access_rules_validator/1;
...
mod_opt_type(_) ->
[..., access_from_without_time_limit, ...].