diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 1f84cef..e1253fe 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -146,4 +146,30 @@ DinerTask = { DishWithGoldType = 4, SellDishRare = 5, DishWithGoldRare = 6, -} \ No newline at end of file +} + +SettingEnum = { + BgMusic = 1, -- 背景音乐 + EffectMusic = 2, -- 音效 + CV = 3, -- cv +} + +SettingStatus = { + [1] = { + [1] = 1, -- 开启 + [0] = 1, -- 关闭 + ["default"] = 1, -- 默认设置 + }, + [2] = { + [1] = 1, -- 开启 + [0] = 1, -- 关闭 + ["default"] = 1, -- 默认设置 + }, + [3] = { + [1] = 1, -- 开启 + [0] = 1, -- 关闭 + ["default"] = 1, -- 默认设置 + }, +} + +EMAIL_LIMIT = 50 --邮件最大数量 diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index c7f06b6..33c29e4 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -35,6 +35,11 @@ actionCodes = { Role_chatRpc = 120, Role_chat = 121, Role_chatGet = 122, + Role_changeNameRpc = 123, + Role_changeIntroRpc = 124, + Role_changeSettingRpc = 125, + Role_drawCodeRpc = 126, + Role_changeHeadRpc = 127, Adv_startAdvRpc = 151, Adv_startHangRpc = 152, @@ -143,6 +148,13 @@ actionCodes = { Store_rechargeRpc = 550, Store_dailyBuyRpc = 551, Store_dinerBuyRpc = 552, + + Email_listRpc = 600, + Email_drawAllAttachRpc = 601, + Email_drawAttachRpc = 602, + Email_checkRpc = 603, + Email_delRpc = 604, + } rpcResponseBegin = 10000 diff --git a/src/RedisKeys.lua b/src/RedisKeys.lua index e63b23e..83a3be7 100644 --- a/src/RedisKeys.lua +++ b/src/RedisKeys.lua @@ -8,6 +8,8 @@ R_PVP = "role:%d:pvp" -- pvp R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录 R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id R_RUNE = "role:%d:rune:%d" -- 符文详细信息 +R_EMAIL = "role:%d:emailIds" --邮件列表 +R_EMAIL_ITEM = "email:%d:%d" --邮件 -- rank diff --git a/src/actions/EmailAction.lua b/src/actions/EmailAction.lua new file mode 100644 index 0000000..d7e9951 --- /dev/null +++ b/src/actions/EmailAction.lua @@ -0,0 +1,188 @@ +local _M = {} +local tarr2tab = table.array2Table + +local function loadEmails(roleId) + local emails = {} + local rds = string.format(R_EMAIL, roleId) + local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) + local redret = redisproxy:pipelining(function (red) + for _, id in ipairs(ids) do + red:hgetall(string.format("email:%d:%s", roleId, id)) + end + end) + for index, id in ipairs(ids) do + local email = require("models.Email").new({key = string.format("email:%d:%s", roleId, id)}) + if email:load(tarr2tab(redret[index])) then + table.insert(emails, email) + end + end + return emails +end + +function _M.listRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + local now = skynet.timex() + local result = {} + local mid = role:getProperty("sid") + + local globalEmail = redisproxy:hget("autoincrement_set", "email") + globalEmail = tonum(globalEmail) + local emailSync = role:getProperty("emailSync") + if globalEmail > emailSync then + role:setProperty("emailSync", globalEmail) + emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) + local result = redisproxy:pipelining(function (red) + for id = emailSync, globalEmail do + red:hgetall(string.format("globalEmail:%s", id)) + end + end) + local count = 1 + for _, data in ipairs(result) do + local email = tarr2tab(data) + if tonum(email.createtime) > role:getProperty("ctime") + and ( not email.mid or tonum(email.mid) == mid ) + and ( not email.endtime or tonum(email.endtime) > now )then + local time = email.timestamp and tonum(email.timestamp) or email.createtime + redisproxy:insertEmail({ + roleId = roleId, + emailId = 0, + createtime = time, + title = email.title, + content = email.content, + attachments = email.attachments + }) + --role:log("mail_actions", {desc = "get_global", s1 = email.title, s2 = email.attachments}) + end + end + end + + local emails = loadEmails(roleId) + for _, email in ipairs(emails) do + table.insert(result, email:data()) + end + + SendPacket(actionCodes.Email_listRpc, MsgPack.pack(result)) + return true +end + +local function getEmailAttachments( email ) + if email:getProperty("status") == 2 then + return "" + end + local attachments = email:getProperty("attachments") + if attachments:len() == 0 then + local rewardPms = email:getProperty("rewardPms") + local emailData = csvdb["emailCsv"][email:getProperty("emailId")] + if emailData then + attachments = emailData.attachment:format(table.unpack(rewardPms)) + end + end + return attachments +end + +function _M.drawAllAttachRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + + local reward = {} + local ids = {} + + local emails = loadEmails(roleId) + redisproxy:pipelining(function (red) + for _, email in ipairs(emails) do + local attachments = getEmailAttachments(email) + if attachments ~= "" then + local emailId = email:getProperty("id") + local items = role:award(attachments) + ids[emailId] = 1 + red:hset(string.format(R_EMAIL_ITEM, roleId, emailId), "status", 2) + -- role:log("mail_actions", {desc = "draw_attach", int1 = emailId, s1 = email:getProperty("title"), s2 = attachments}) + + for key, v in pairs(items) do + reward[key] = (reward[key] or 0) + v + end + end + end + end) + + SendPacket(actionCodes.Email_drawAllAttachRpc, MsgPack.pack({ids = ids, reward = reward})) + return true +end + +function _M.drawAttachRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + local msg = MsgPack.unpack(data) + local id = msg.id + + local rds = string.format(R_EMAIL_ITEM, roleId, id) + + local email = require("models.Email").new({key = rds}) + if not email:load() then return end + + local attachments = getEmailAttachments(email) + if attachments == "" then return end + + local reward = role:award(attachments) + redisproxy:hset(rds, "status", 2) -- 领取标记 + SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward})) + + -- role:log("mail_actions", {desc = "draw_attach", int1 = id, s1 = email:getProperty("title"), s2 = attachments, ucode = ucode}) + return true +end + +function _M.checkRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + + local msg = MsgPack.unpack(data) + local id = msg.id + + local rds = string.format(R_EMAIL_ITEM, roleId, id) + if not redisproxy:exists(rds) then return end + + redisproxy:hset(rds, "status", 1) + -- role:log("mail_actions", {desc = "check_mail", int1 = id}) + + SendPacket(actionCodes.Email_checkRpc, '') + return true +end + +function _M.delRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + + local rds = string.format(R_EMAIL, roleId) + local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) + local now = skynet.timex() + local result = {} + local emailSet = csvdb["emailCsv"] + + redisproxy:pipelining(function (red) + for _, id in ipairs(ids) do + local emailRds = string.format("email:%d:%s", roleId, id) + local email = require("models.Email").new({key = emailRds}) + if email:load() then + local status = email:getProperty("status") + local attachments = email:getProperty("attachments") + local emailData = emailSet[email:getProperty("emailId")] + if emailData and attachments:len() == 0 then + attachments = emailData.attachment + end + if status == 2 or (status == 1 and attachments:len() == 0) then + red:lrem(rds, 0, id) + red:del(emailRds) + result[tonum(id)] = 1 + end + end + end + end) + -- for delId, _ in ipairs(result) do + -- role:log("mail_actions", {desc = "del_mail", int1 = delId}) + -- end + SendPacket(actionCodes.Email_delRpc, MsgPack.pack({result = result})) + return true +end + +return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index ea2a949..8c3f663 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -277,7 +277,7 @@ function _M.createRpc(agent, data) key = string_format("role:%d", roleId), id = roleId, uid = tostring(msg.uid), - subId = msg.subId or 0, + sid = msg.subId or 0, name = roleName, uname = msg.uname or "", device = tostring(msg.device) @@ -294,16 +294,85 @@ function _M.createRpc(agent, data) return true end + newRole:award(globalCsv.birthItem) -- 欢迎邮件 -- redisproxy:insertEmail({roleId = roleId, emailId = 1}) -- redisproxy:insertEmail({roleId = roleId, emailId = 2}) - newRole:log("create", { ip = agent.ip, ucode = ucode}) + newRole:log("create", { ip = agent.ip}) SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) return true end +function _M.changeNameRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + local msg = MsgPack.unpack(data) + + local newName = msg.name + local oldName = role:getProperty("name") + + if not newName or type(newName) ~= "string" then return end + if newName == oldName then return end + -- 检查name是否合法 + local checked = validName(newName) + if checked ~= "ok" then + --[[ + "existed" 已经存在 + "illegal" 包含非法字符 + ]] + local errCodes = { + ["existed"] = 1, + ["illegal"] = 2 + } + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = errCodes[checked]})) + return true + end + + if not roleId then + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 3})) + return true + end + + local result = redisproxy:setnx(string_format("user:%s", newName), roleId) + if result == 0 then + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 1})) + return true + end + redisproxy:pipelining(function (red) + red:del(string_format("user:%s", oldName)) + red:set(string_format("uid:%s", role:getProperty("uid")), newName) + end) + + role:updateProperties({ + ["name"] = newName, + }) + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 0})) + return true +end + +function _M.changeIntroRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + local msg = MsgPack.unpack(data) + local content = msg.content + if not content or type(content) ~= "string" then return end + + local SERV = string_format("CHATED%d", math.random(1, 5)) + local legal, mod = skynet.call(SERV, "lua", "check", content) + if not legal then + content = mod or "" + end + + if content == "" then + role:updateProperty({field = "intro", value = content}) + end + + SendPacket(actionCodes.Role_changeIntroRpc, '') + return true +end + function _M.syncTimeRpc(agent, data) SendPacket(actionCodes.Role_syncTimeRpc, MsgPack.pack({nowTime = skynet.timex()})) return true @@ -703,4 +772,86 @@ function _M.chatGet(agent, data) return true end + +function _M.changeSettingRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local id = msg.id + local status = msg.status + + local statusEnum = SettingStatus[id] + if not statusEnum then return 1 end + + if not statusEnum[status] then return 2 end + + local setting = role:getProperty("setting") + setting[id] = status + role:updateProperty({field = "setting", value = setting}) + + SendPacket(actionCodes.Role_changeSettingRpc, '') + return true +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 + + 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 = role:award(result.gift) + + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({ + result = ret, + reward = reward, + })) + return true + end + -- 1 不存在的礼包码 + -- 2 已经领取过相同类型物品 + -- 3 领取数量达到上限 + -- 4 过期了 + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = ret})) + return true + end + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = -1})) + return true +end + +function _M.changeHeadRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local id = msg.id + local icon = csvdb["player_iconCsv"][id] + if not icon then + return + end + if role:getItemCount(id) < 1 then + return + end + role:updateProperty({field = "headId" ,value = id}) + SendPacket(actionCodes.Role_changeHeadRpc, "") + return true +end + + return _M \ No newline at end of file diff --git a/src/models/Email.lua b/src/models/Email.lua new file mode 100644 index 0000000..aef1e98 --- /dev/null +++ b/src/models/Email.lua @@ -0,0 +1,56 @@ +local Email = class("Email", require("shared.ModelBase")) + +function Email:ctor(properties) + Email.super.ctor(self, properties) +end + +Email.schema = { + key = {"string"}, -- redis key + id = {"number", 0}, -- 数据库ID + emailId = {"number", 0}, -- 邮件csv ID + title = {"string", ""}, -- 邮件标题 + content = {"string", ""}, -- 邮件正文 + attachments = {"string", ""}, + status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 + createtime = {"number", skynet.timex()}, + contentPms = {"table", {}}, + rewardPms = {"table", {}}, +} + +function Email:data() + local emailId = self:getProperty("emailId") + local title = self:getProperty("title") + local content = self:getProperty("content") + local attachments = self:getProperty("attachments") + local contentPms = self:getProperty("contentPms") + local rewardPms = self:getProperty("rewardPms") + + local emailData = csvdb["emailCsv"][emailId] + + if emailData then + -- 如果内容是直接插入到数据库 + if content == "" and emailData.body ~= "" then + content = io.readfile("src/" .. emailData.body) + content = content:format(table.unpack(contentPms)) + end + + if title == "" and emailData.title ~= "" then + title = emailData.title + end + + if attachments == "" and emailData.attachment ~= "" then + attachments = emailData.attachment:format(table.unpack(rewardPms)) + end + end + + return { + id = self:getProperty("id"), + status = self:getProperty("status"), + createtime = self:getProperty("createtime"), + title = title, + content = content, + attachments = attachments, + } +end + +return Email \ No newline at end of file diff --git a/src/models/Role.lua b/src/models/Role.lua index 4a7c707..4a6b3d3 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -27,6 +27,7 @@ Role.schema = { id = {"number"}, uid = {"string", ""}, name = {"string", ""}, + intro = {"string", ""}, headId = {"number", 3201}, sid = {"number", 0}, device = {"string", ""}, @@ -38,6 +39,8 @@ Role.schema = { sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本 diamond = {"number", 0}, reDiamond = {"number", 0}, + setting = {"table", {}}, --设置 + codeStr = {"string", ""}, --已经领过的礼包码 -- roleInfo level = {"number", 1}, exp = {"number", 0}, @@ -111,6 +114,8 @@ Role.schema = { dinerS = {"table", {}}, -- 美食币商城 购买记录 {[id] = count} rmbC = {"number", 0}, -- 人民币重置额 + + emailSync = {"number", 0}, -- 已经同步到的邮件Id } @@ -212,7 +217,9 @@ function Role:data() return { id = self:getProperty("id"), name = self:getProperty("name"), + intro = self:getProperty("intro"), headId = self:getProperty("headId"), + setting = self:getProperty("setting"), level = self:getProperty("level"), exp = self:getProperty("exp"), items = self:getProperty("items"):toNumMap(), diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 3cb48d5..c052c7c 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -895,6 +895,90 @@ function RolePlugin.bind(Role) pvpTBVC = self:getTeamBattleValue(team.heros), }) end + + -- update + function Role:onRecoverTimer(now) + self:checkNewEvent(now) + end + + local function breath(sec) + local last_breath = 0 + return function (now) + if now >= last_breath then + last_breath = now + sec + return true + end + return false + end + end + local breathes = { + ["email"] = breath(120), -- email + } + function Role:checkNewEvent(now) + if now - self:getProperty("ltime") < 5 then + return + end + + local checks = {} + -- 检查全局邮件 -- 增加邮件红点 + checks["email"] = function() + local mid = self:getProperty("sid") + local result = redisproxy:hmget("autoincrement_set", "email", "emailTimestamp") + local globalEmail = tonum(result[1]) + local timestamp = tonum(result[2]) + local emailSync = self:getProperty("emailSync") + if globalEmail > emailSync and timestamp > self:getProperty("ctime") then + local emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) + local redret = redisproxy:pipelining(function (red) + for id = emailSync, globalEmail do + red:hgetall(string.format("globalEmail:%s", id)) + end + end) + for _, data in ipairs(redret) do + local email = tarr2tab(data) + if tonum(email.createtime) > self:getProperty("ctime") + and ( not email.mid or tonum(email.mid) == mid ) + and ( not email.endtime or tonum(email.endtime) > now )then + return true + end + end + end + + local roleId = self:getProperty("id") + local email_rds = string.format(R_EMAIL, roleId) + + local emailIds = redisproxy:lrange(email_rds, 0, EMAIL_LIMIT - 1) or {} + local redret = redisproxy:pipelining(function (red) + for _, id in ipairs(emailIds) do + red:hget(string.format(R_EMAIL_ITEM, roleId, id), "status") + end + end) + for index, id in ipairs(emailIds) do + if tonumber(redret[index]) == 0 then + return true + end + end + end + + local events = {} + for name, breath in pairs(breathes) do + if breath(now) and checks[name] then + local status = checks[name]() + if status then + if status == true then + events[name] = 1 + else + events[name] = status + end + end + end + end + + if next(events) then + SendPacket(actionCodes.Role_notifyNewEvent, MsgPack.pack({events = events})) + end + end + end return RolePlugin \ No newline at end of file diff --git a/src/rdsscripts/RedisScripts.lua b/src/rdsscripts/RedisScripts.lua index c3182e6..1cd2442 100644 --- a/src/rdsscripts/RedisScripts.lua +++ b/src/rdsscripts/RedisScripts.lua @@ -1,20 +1,8 @@ local _M = {} -_M["rankDetails"] = { - file = "src/rdsscripts/rankDetails.lua", - sha1 = nil, -} _M["insertEmail"] = { file = "src/rdsscripts/insertEmail.lua", sha1 = nil, } -_M["refreshAssist"] = { - file = "src/rdsscripts/refreshAssist.lua", - sha1 = nil, -} -_M["assistInfo"] = { - file = "src/rdsscripts/assistInfo.lua", - sha1 = nil, -} return _M \ No newline at end of file diff --git a/src/rdsscripts/assistInfo.lua b/src/rdsscripts/assistInfo.lua deleted file mode 100644 index 7d2c0bc..0000000 --- a/src/rdsscripts/assistInfo.lua +++ /dev/null @@ -1,55 +0,0 @@ -local roleId = tonumber(KEYS[1]) - -local formationJson = redis.call("hget", string.format("role:%d", roleId), "pveFormationJson") - -local formation = cjson.decode(formationJson) - -local function formatAttrEx(str) - local tb = {} - for k, v in str:gmatch("([%d.]+)=([%d.]+)") do - tb[#tb+1] = {tonumber(k), tonumber(v)} - end - return tb -end - -local function formatEquips(str) - local tb = {} - for k, v in str:gmatch("([%d.]+)=([%d.]+)") do - tb[tonumber(k)] = tonumber(v) - end - return tb -end - -local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel", "equips"} -local equipFields = {"type", "level", "evolCount", "attrEx"} -for _, hero in ipairs(formation.heros) do - if hero.leader then - local heroInfo = redis.call("hmget", string.format("hero:%d:%d", roleId, hero.id), unpack(heroFields)) - local equipstr = heroInfo[7] - local equips = {} - for part, equipId in equipstr:gmatch("(%d+)=(%d+)") do - part, equipId = tonumber(part), tonumber(equipId) - if equipId ~= 0 then - local equipInfo = redis.call("hmget", string.format("equip:%d:%d", roleId, equipId), unpack(equipFields)) - equips[equipId] = {} - for index, value in ipairs(equipInfo) do - equips[equipId][equipFields[index]] = index ~= 4 and tonumber(value) or formatAttrEx(equipInfo[4] or "") - end - end - end - return cmsgpack.pack { - type = tonumber(heroInfo[1]), - level = tonumber(heroInfo[2]), - star = tonumber(heroInfo[3]), - evolveCount = tonumber(heroInfo[4]), - wake = tonumber(heroInfo[5]), - breakLevel = tonumber(heroInfo[6]), - equips = formatEquips(heroInfo[7]), - equipDtls = equips, - } - end -end - -return cmsgpack.pack {} - - diff --git a/src/rdsscripts/insertEmail.lua b/src/rdsscripts/insertEmail.lua index c26f66d..c111fde 100644 --- a/src/rdsscripts/insertEmail.lua +++ b/src/rdsscripts/insertEmail.lua @@ -1,27 +1,34 @@ -local con1 = KEYS[4] or "" -local con2 = KEYS[5] or "" -local con3 = KEYS[6] or "" -local att1 = KEYS[7] or "" -local att2 = KEYS[8] or "" -local att3 = KEYS[9] or "" -local title = KEYS[10] or "" -local content = KEYS[11] or "" -local attachments = KEYS[12] or "" +local EMAIL_LIMIT = KEYS[1] +local roleId = KEYS[2] +local emailId = KEYS[3] or 0 +local createTime = KEYS[4] +local con = KEYS[5] or cmsgpack.pack({}) +local att = KEYS[6] or cmsgpack.pack({}) +local title = KEYS[7] or "" +local content = KEYS[8] or "" +local attachments = KEYS[9] or "" --- local roleInfo = redis.call("HGET", string.format("role:%d", KEYS[1]), "delete") + +-- local roleInfo = redis.call("HGET", string.format("role:%d", roleId), "delete") -- if tonumber(roleInfo) == 1 then return end -local id = redis.call("HINCRBY", string.format("role:%d:autoincr", KEYS[1]), "email", 1) -redis.call("LPUSH", string.format("role:%d:emailIds", KEYS[1]), id) -local deleteIds = redis.call("LRANGE", string.format("role:%d:emailIds", KEYS[1]), 50, -1) +local id = redis.call("HINCRBY", string.format("role:%d:autoincr", roleId), "email", 1) +redis.call("LPUSH", string.format("role:%d:emailIds", roleId), id) +local deleteIds = redis.call("LRANGE", string.format("role:%d:emailIds", roleId), EMAIL_LIMIT, -1) for _, deleteId in ipairs(deleteIds) do - redis.call("DEL", string.format("email:%d:%d", KEYS[1], deleteId)) + redis.call("DEL", string.format("email:%d:%d", roleId, deleteId)) end -redis.call("LTRIM", string.format("role:%d:emailIds", KEYS[1]), 0, 49) -redis.call("HMSET", string.format("email:%d:%d", KEYS[1], id), "id", tostring(id), "emailId", KEYS[2], - "status", "0", "createtime", KEYS[3], - "con1", con1, "con2", con2, "con3", con3, - "att1", att1, "att2", att2, "att3", att3, - "title", title, "content", content, "attachments", attachments) +redis.call("LTRIM", string.format("role:%d:emailIds", roleId), 0, EMAIL_LIMIT - 1) +redis.call("HMSET", string.format("email:%d:%d", roleId, id), + "id", tostring(id), + "emailId", emailId, + "status", "0", + "createtime", createTime, + "contentPms", con, + "rewardPms", att, + "title", title, + "content", content, + "attachments", attachments +) diff --git a/src/rdsscripts/rankDetails.lua b/src/rdsscripts/rankDetails.lua deleted file mode 100644 index fa2234b..0000000 --- a/src/rdsscripts/rankDetails.lua +++ /dev/null @@ -1,30 +0,0 @@ -local field = KEYS[1] -local roleId = tonumber(KEYS[2]) - -local formationJson = redis.call("hget", string.format("role:%d", roleId), field .. "FormationJson") - -local formation = cjson.decode(formationJson) - -local response = {formation = {}, heros = {}} - -if formation.heros then - for _, hero in ipairs(formation.heros) do - table.insert(response.formation, hero.id) - end -end - -local heroIds = redis.call("smembers", string.format("role:%d:heroIds", roleId)) - -local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel"} -for _, heroId in ipairs(heroIds) do - local heroId = tonumber(heroId) - local heroInfo = redis.call("hmget", string.format("hero:%d:%d", roleId, heroId), unpack(heroFields)) - - local tb = {} - for k, v in ipairs(heroInfo) do - tb[heroFields[k]] = tonumber(v) - end - response.heros[heroId] = tb -end - -return cmsgpack.pack(response) \ No newline at end of file diff --git a/src/rdsscripts/refreshAssist.lua b/src/rdsscripts/refreshAssist.lua deleted file mode 100644 index ed466df..0000000 --- a/src/rdsscripts/refreshAssist.lua +++ /dev/null @@ -1,58 +0,0 @@ -local roleId = tonumber(KEYS[1]) - -local friendKey = "role:%d:friend" -local assistKey = "role:%d:assist" - -local function formatTable(tbl) - local t = {} - for _, id in ipairs(tbl) do - t[tonumber(id)] = 1 - end - return t -end - -local friendIds = redis.call("smembers", friendKey:format(roleId)) -local assistIds = formatTable(redis.call("smembers", assistKey:format(roleId))) - -local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel", "battleValue", "dress"} -local function getLeader(id, formation) - for _, hero in ipairs(formation.heros) do - if hero.leader then - local heroInfo = redis.call("hmget", string.format("hero:%d:%d", id, hero.id), unpack(heroFields)) - return { - type = tonumber(heroInfo[1]), - level = tonumber(heroInfo[2]), - star = tonumber(heroInfo[3]), - evolveCount = tonumber(heroInfo[4]), - wake = tonumber(heroInfo[5]), - breakLevel = tonumber(heroInfo[6]), - battleValue = tonumber(heroInfo[7]), - dress = tonumber(heroInfo[8]), - } - end - end -end - -local response = {} -for _, id in ipairs(friendIds) do - id = tonumber(id) - local dtls = redis.call("hmget", string.format("role:%d", id), - "name", "level", "vip", "pveFormationJson") - local formation = cjson.decode(dtls[4]) - local leader = getLeader(id, formation) - if leader then - table.insert(response, { - roleId = id, - name = dtls[1], - level = tonumber(dtls[2]), - vip = tonumber(dtls[3]), - leader = leader, - used = assistIds[id] or 0, - }) - end -end - -return cmsgpack.pack(response) - - - diff --git a/src/services/agent_util.lua b/src/services/agent_util.lua index d6a45a3..622651b 100644 --- a/src/services/agent_util.lua +++ b/src/services/agent_util.lua @@ -84,7 +84,7 @@ function _M:update(agent) nextCheckTime = now + HEART_TIMER_INTERVAL end pcall(check_daily_reset, agent, now) - -- pcall(role.onRecoverTimer, role, now) + pcall(role.onRecoverTimer, role, now) end function _M:heart_beat(agent) diff --git a/src/services/redisd.lua b/src/services/redisd.lua index 465f63d..25673d4 100644 --- a/src/services/redisd.lua +++ b/src/services/redisd.lua @@ -13,17 +13,6 @@ function command.open(conf) db = conf.redisdb or 0, auth = conf.auth, }) - - --[[ - local csvdata = require("csvdata.world_boss_battle") - for i=1, #csvdata do - for j=1, #csvdata[i] do - db:del(string.format("boss:%d:%d", i, j)) - end - end - --]] - db:del("rtpvp") - end skynet.start(function() diff --git a/src/shared/redisproxy.lua b/src/shared/redisproxy.lua index 0fe77c5..884d43a 100644 --- a/src/shared/redisproxy.lua +++ b/src/shared/redisproxy.lua @@ -51,21 +51,15 @@ function redisproxy:insertEmail(params) roleId = params.roleId, emailId = params.emailId, createtime = params.createtime or skynet.timex(), - con1 = params.con1 or "", - con2 = params.con2 or "", - con3 = params.con3 or "", - att1 = params.att1 or "", - att2 = params.att2 or "", - att3 = params.att3 or "", + con = params.con or {}, + att = params.att or {}, title = params.title or "", content = params.content or "", attachments = params.attachments or "", } - self:runScripts("insertEmail", 12, + self:runScripts("insertEmail", 9, EMAIL_LIMIT, pms.roleId, pms.emailId, pms.createtime, - pms.con1, pms.con2, pms.con3, - pms.att1, pms.att2, pms.att3, - pms.title, pms.content, pms.attachments) + MsgPack.pack(pms.con), MsgPack.pack(pms.att), pms.title, pms.content, pms.attachments) return true end -- libgit2 0.21.2