diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index f093107..261af76 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -1139,4 +1139,14 @@ function _M.get_draw_hero_pro(role, pms) return json.encode(result) end +function _M.draw_code(role, pms) + local code = pms.pm1 + if type(code) ~= "string" then return -2 end + if code:find("[^0-9a-zA-Z]") then return -3 end + + local ret, _, _= role:getCodeGift(code) + return ret +end + + return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index c1e386d..db50bf7 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1355,53 +1355,23 @@ end function _M.drawCodeRpc(agent, data) local msg = MsgPack.unpack(data) - local codeurl = skynet.getenv("codeurl") local role = agent.role - local msg = MsgPack.unpack(data) local code = msg.code - if type(code) ~= "string" then return end - if code:find("[^0-9a-zA-Z]") then return end + if type(code) ~= "string" then return 1 end + if code:find("[^0-9a-zA-Z]") then return 2 end - local codestr = role:getProperty("codeStr") - local content = { - ["platformId"] = role:getProperty("sid"), - ["code"] = code, - ["itemIds"] = codestr, - ["key"] = "zhaolugame20170831", - } - local status, body = httpc.get(codeurl, "/libaoma?" .. httpGetFormatData(content), {}) - if status == 200 then - local result = json.decode(body) - local ret = tonum(result.ret) - if ret == 0 then - local giftId = tonumber(result.giftId) - role:setProperty("codeStr", codestr:setv(giftId, 1)) - local reward, change = role:award(result.gift, {log = {desc = "drawCode", int1 = giftId}}) - - role:log("get_gift", { - gift_id = giftId, -- 礼包ID - gift_key = code, -- 礼包key - gift_reward = reward, -- 礼包奖励,json格式记录,{"itemid1":123,"itemid2":12,……….} - gift_name = "", -- 礼包名称 - gift_reason = 0, -- 礼包发放原因,见发放原因枚举表 - }) - role:mylog("role_action", {desc = "drawCode", int1 = giftId, key1 = code, key2 = role:getRewardLogStr(result.gift)}) - SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({ - result = ret, - reward = reward, - change = change, - })) - return true - end - -- 1 不存在的礼包码 - -- 2 已经领取过相同类型物品 - -- 3 领取数量达到上限 - -- 4 过期了 - SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = ret})) - return true + local ret, reward, change= role:getCodeGift(code) + if ret == 0 then + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({ + result = ret, + reward = reward, + change = change, + })) + return true end - SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = -1})) + + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = ret})) return true end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index a9dee62..9684dcb 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -3303,6 +3303,43 @@ function RolePlugin.bind(Role) end self:updateProperty({field = "worldChangePoints", value = worldChangePoints}) end + + function Role:getCodeGift(code) + local codeurl = skynet.getenv("codeurl") + local codestr = self:getProperty("codeStr") + local content = { + ["platformId"] = self:getProperty("sid"), + ["code"] = code, + ["itemIds"] = codestr, + ["key"] = "zhaolugame20170831", + } + local status, body = httpc.get(codeurl, "/libaoma?" .. httpGetFormatData(content), {}) + if status == 200 then + local result = json.decode(body) + local ret = tonum(result.ret) + if ret == 0 then + local giftId = tonumber(result.giftId) + self:setProperty("codeStr", codestr:setv(giftId, 1)) + local reward, change = self:award(result.gift, {log = {desc = "drawCode", int1 = giftId}}) + + self:log("get_gift", { + gift_id = giftId, -- 礼包ID + gift_key = code, -- 礼包key + gift_reward = reward, -- 礼包奖励,json格式记录,{"itemid1":123,"itemid2":12,……….} + gift_name = "", -- 礼包名称 + gift_reason = 0, -- 礼包发放原因,见发放原因枚举表 + }) + self:mylog("role_action", {desc = "drawCode", int1 = giftId, key1 = code, key2 = self:getRewardLogStr(result.gift)}) + return ret, result, reward, change + end + -- 1 不存在的礼包码 + -- 2 已经领取过相同类型物品 + -- 3 领取数量达到上限 + -- 4 过期了 + return ret + end + return -1 + end end return RolePlugin \ No newline at end of file -- libgit2 0.21.2