--注册 localfunctionsignup(c) local req = c.req local body = req.body local account = body.account local password = body.password local channel = body.channel
如何映射到表,通常账号是不支持更改的,我们直接使用账号尾部字符编码 mod 分表数量得到一个索引进行映射。
1 2 3 4 5 6 7 8 9
--注册 functionM.register(account_info, channel) local cli = frpc_client:instance("centerserver", "account_m") cli:set_mod_num(sbyte(account_info.account, account_info.account:len())) local ret = cli:one_mod_call("register", account_info, channel) ifnot ret thenreturnend
local MAX_INCRID = 9999999 localfunctionregister(account_info, channel) assert(channel <= 9999, "overflow channel = ",channel) local account = account_info.account --账号 assert(account:len() >= 6, "account not long enough") local orm_clinet = get_orm_by_account(account) if orm_clinet:get_one_entry(account) then returnnil, CODE.EXISTS_USER, "EXISTS_USER" end
local module_id, svr_id = rpc_hallserver_player_m.get_module_id() assert(module_id, "register err ")
local incrid = g_alloc_client:incr(module_id) assert(incrid <= MAX_INCRID, "incr overflow") local player_id = player_util.builder_player_id(channel, svr_id, incrid) local ret = rpc_hallserver_player_m.register(player_id, account) assert(ret, "register err")
account_info.key = crypt.randomkey() account_info.password = crypt_util.HMAC.SHA256(account_info.password, account_info.key) account_info.key = crypt.base64encode(account_info.key) account_info.player_id = player_id account_info.hall_server_id = svr_id account_info.channel = channel account_info.create_time = time_util.time() if orm_clinet:create_one_entry(account_info) then returntrue else returnnil end end
选择大厅服
1 2 3 4 5 6 7 8 9 10 11 12
-- 获取自增ID所属的模块ID functionM.get_module_id() local cli = frpc_client:instance("hallserver", "player_m") local ret = cli:one_balance_call("get_module_id") ifnot ret thenreturnend
local cluster_name = ret.cluster_name local result = ret.result local module_id = result[1] local svr_id = tonumber(string_util.split(cluster_name, ':')[2]) return module_id, svr_id end