Commit ae3753b1461df207bf43a503c317b13ee7078bdb

Authored by zhangqijia
1 parent 7356e583

feat: 增加 role_by_uid http接口和查询所有服的角色信息的协议

src/ProtocolCode.lua
... ... @@ -66,6 +66,7 @@ actionCodes = {
66 66 Role_worldLineRewardRpc = 147, -- 世界线一键领取奖励
67 67 Role_itemConvertDevilTicketRpc = 148, -- 兑换魔鬼训练营门票
68 68 Role_unRegisterRpc = 149, --注销账号
  69 + Role_searchAllRoleRpc = 150, --查询所有服的角色信息
69 70  
70 71 Adv_startAdvRpc = 151,
71 72 Adv_startHangRpc = 152,
... ...
src/actions/HttpAction.lua
  1 +require "utils.MysqlUtil"
1 2  
2 3 local _M = {}
3 4  
... ... @@ -264,4 +265,20 @@ function _M.hero_draw_pro(query)
264 265 return gmFuncs[query.cmd]()
265 266 end
266 267  
  268 +function _M.role_by_uid(query)
  269 + local res = roleByUid(query.uid)
  270 + local rsp = {}
  271 + rsp.code = 0
  272 + if not res then
  273 + rsp.code = -1
  274 + return json.encode(rsp)
  275 + end
  276 +
  277 + rsp.id = res["id"]
  278 + rsp.name = res["name"]
  279 + rsp.level = res["level"]
  280 + rsp.code = 0
  281 + return json.encode(rsp)
  282 +end
  283 +
267 284 return _M
268 285 \ No newline at end of file
... ...
src/actions/RoleAction.lua
... ... @@ -520,6 +520,36 @@ function _M.unRegisterRpc(agent, data)
520 520 return true
521 521 end
522 522  
  523 +function _M.searchAllRoleRpc(agent, data)
  524 + local role = agent.role
  525 + local uid = role:getProperty("uid")
  526 + if not uid then return 0 end
  527 +
  528 + local res = roleByUid(uid)
  529 + if not res then return 1 end
  530 +
  531 +
  532 + local serverId = skynet.getenv("servId")
  533 + local codeurl = skynet.getenv("codeurl")
  534 + local content = {
  535 + serverid = serverId,
  536 + uid = uid,
  537 + }
  538 +
  539 + local status, body = httpc.get(codeurl, "/search_role?" .. httpGetFormatData(content), {})
  540 + if status ~= 200 then return 2 end
  541 +
  542 + local result = json.decode(body)
  543 + local ret = tonum(result.code)
  544 + if ret ~= 0 then return 3 end
  545 +
  546 + local rsp = result.data
  547 + table.insert(rsp, {serverId=serverId, name=res.name, level=res.level} )
  548 + SendPacket(actionCodes.Role_unRegisterRpc, MsgPack.pack(rsp))
  549 + return true
  550 +end
  551 +
  552 +
523 553 function _M.changeNameRpc(agent, data)
524 554 local role = agent.role
525 555 local roleId = role:getProperty("id")
... ...
src/utils/MysqlUtil.lua
... ... @@ -74,4 +74,12 @@ function roleUnRegister(roleId)
74 74 return false
75 75 end
76 76 return true
  77 +end
  78 +
  79 +function roleByUid(uid)
  80 + local res = mysqlproxy:query(string.format("SELECT id, name, level, FROM `Role` WHERE `del` = 0 and `uid` = %s", uid))
  81 + if res["errno"] or not next(res) then
  82 + return false
  83 + end
  84 + return true, res[1]
77 85 end
78 86 \ No newline at end of file
... ...