diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 2581da2..d832dc3 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -66,6 +66,7 @@ actionCodes = { Role_worldLineRewardRpc = 147, -- 世界线一键领取奖励 Role_itemConvertDevilTicketRpc = 148, -- 兑换魔鬼训练营门票 Role_unRegisterRpc = 149, --注销账号 + Role_searchAllRoleRpc = 150, --查询所有服的角色信息 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/HttpAction.lua b/src/actions/HttpAction.lua index 1b31d7b..8e56191 100644 --- a/src/actions/HttpAction.lua +++ b/src/actions/HttpAction.lua @@ -1,3 +1,4 @@ +require "utils.MysqlUtil" local _M = {} @@ -264,4 +265,20 @@ function _M.hero_draw_pro(query) return gmFuncs[query.cmd]() end +function _M.role_by_uid(query) + local res = roleByUid(query.uid) + local rsp = {} + rsp.code = 0 + if not res then + rsp.code = -1 + return json.encode(rsp) + end + + rsp.id = res["id"] + rsp.name = res["name"] + rsp.level = res["level"] + rsp.code = 0 + return json.encode(rsp) +end + return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 6c43b19..da447ab 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -520,6 +520,36 @@ function _M.unRegisterRpc(agent, data) return true end +function _M.searchAllRoleRpc(agent, data) + local role = agent.role + local uid = role:getProperty("uid") + if not uid then return 0 end + + local res = roleByUid(uid) + if not res then return 1 end + + + local serverId = skynet.getenv("servId") + local codeurl = skynet.getenv("codeurl") + local content = { + serverid = serverId, + uid = uid, + } + + local status, body = httpc.get(codeurl, "/search_role?" .. httpGetFormatData(content), {}) + if status ~= 200 then return 2 end + + local result = json.decode(body) + local ret = tonum(result.code) + if ret ~= 0 then return 3 end + + local rsp = result.data + table.insert(rsp, {serverId=serverId, name=res.name, level=res.level} ) + SendPacket(actionCodes.Role_unRegisterRpc, MsgPack.pack(rsp)) + return true +end + + function _M.changeNameRpc(agent, data) local role = agent.role local roleId = role:getProperty("id") diff --git a/src/utils/MysqlUtil.lua b/src/utils/MysqlUtil.lua index 78e6232..d3182aa 100644 --- a/src/utils/MysqlUtil.lua +++ b/src/utils/MysqlUtil.lua @@ -74,4 +74,12 @@ function roleUnRegister(roleId) return false end return true +end + +function roleByUid(uid) + local res = mysqlproxy:query(string.format("SELECT id, name, level, FROM `Role` WHERE `del` = 0 and `uid` = %s", uid)) + if res["errno"] or not next(res) then + return false + end + return true, res[1] end \ No newline at end of file -- libgit2 0.21.2