Commit dc9d814faa59914d3c51c95c53c1152d8252b150
1 parent
f603a60f
邮件
Showing
16 changed files
with
561 additions
and
200 deletions
Show diff stats
src/GlobalVar.lua
@@ -146,4 +146,30 @@ DinerTask = { | @@ -146,4 +146,30 @@ DinerTask = { | ||
146 | DishWithGoldType = 4, | 146 | DishWithGoldType = 4, |
147 | SellDishRare = 5, | 147 | SellDishRare = 5, |
148 | DishWithGoldRare = 6, | 148 | DishWithGoldRare = 6, |
149 | -} | ||
150 | \ No newline at end of file | 149 | \ No newline at end of file |
150 | +} | ||
151 | + | ||
152 | +SettingEnum = { | ||
153 | + BgMusic = 1, -- 背景音乐 | ||
154 | + EffectMusic = 2, -- 音效 | ||
155 | + CV = 3, -- cv | ||
156 | +} | ||
157 | + | ||
158 | +SettingStatus = { | ||
159 | + [1] = { | ||
160 | + [1] = 1, -- 开启 | ||
161 | + [0] = 1, -- 关闭 | ||
162 | + ["default"] = 1, -- 默认设置 | ||
163 | + }, | ||
164 | + [2] = { | ||
165 | + [1] = 1, -- 开启 | ||
166 | + [0] = 1, -- 关闭 | ||
167 | + ["default"] = 1, -- 默认设置 | ||
168 | + }, | ||
169 | + [3] = { | ||
170 | + [1] = 1, -- 开启 | ||
171 | + [0] = 1, -- 关闭 | ||
172 | + ["default"] = 1, -- 默认设置 | ||
173 | + }, | ||
174 | +} | ||
175 | + | ||
176 | +EMAIL_LIMIT = 50 --邮件最大数量 |
src/ProtocolCode.lua
@@ -35,6 +35,11 @@ actionCodes = { | @@ -35,6 +35,11 @@ actionCodes = { | ||
35 | Role_chatRpc = 120, | 35 | Role_chatRpc = 120, |
36 | Role_chat = 121, | 36 | Role_chat = 121, |
37 | Role_chatGet = 122, | 37 | Role_chatGet = 122, |
38 | + Role_changeNameRpc = 123, | ||
39 | + Role_changeIntroRpc = 124, | ||
40 | + Role_changeSettingRpc = 125, | ||
41 | + Role_drawCodeRpc = 126, | ||
42 | + Role_changeHeadRpc = 127, | ||
38 | 43 | ||
39 | Adv_startAdvRpc = 151, | 44 | Adv_startAdvRpc = 151, |
40 | Adv_startHangRpc = 152, | 45 | Adv_startHangRpc = 152, |
@@ -143,6 +148,13 @@ actionCodes = { | @@ -143,6 +148,13 @@ actionCodes = { | ||
143 | Store_rechargeRpc = 550, | 148 | Store_rechargeRpc = 550, |
144 | Store_dailyBuyRpc = 551, | 149 | Store_dailyBuyRpc = 551, |
145 | Store_dinerBuyRpc = 552, | 150 | Store_dinerBuyRpc = 552, |
151 | + | ||
152 | + Email_listRpc = 600, | ||
153 | + Email_drawAllAttachRpc = 601, | ||
154 | + Email_drawAttachRpc = 602, | ||
155 | + Email_checkRpc = 603, | ||
156 | + Email_delRpc = 604, | ||
157 | + | ||
146 | } | 158 | } |
147 | 159 | ||
148 | rpcResponseBegin = 10000 | 160 | rpcResponseBegin = 10000 |
src/RedisKeys.lua
@@ -8,6 +8,8 @@ R_PVP = "role:%d:pvp" -- pvp | @@ -8,6 +8,8 @@ R_PVP = "role:%d:pvp" -- pvp | ||
8 | R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录 | 8 | R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录 |
9 | R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id | 9 | R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id |
10 | R_RUNE = "role:%d:rune:%d" -- 符文详细信息 | 10 | R_RUNE = "role:%d:rune:%d" -- 符文详细信息 |
11 | +R_EMAIL = "role:%d:emailIds" --邮件列表 | ||
12 | +R_EMAIL_ITEM = "email:%d:%d" --邮件 | ||
11 | 13 | ||
12 | 14 | ||
13 | -- rank | 15 | -- rank |
@@ -0,0 +1,188 @@ | @@ -0,0 +1,188 @@ | ||
1 | +local _M = {} | ||
2 | +local tarr2tab = table.array2Table | ||
3 | + | ||
4 | +local function loadEmails(roleId) | ||
5 | + local emails = {} | ||
6 | + local rds = string.format(R_EMAIL, roleId) | ||
7 | + local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) | ||
8 | + local redret = redisproxy:pipelining(function (red) | ||
9 | + for _, id in ipairs(ids) do | ||
10 | + red:hgetall(string.format("email:%d:%s", roleId, id)) | ||
11 | + end | ||
12 | + end) | ||
13 | + for index, id in ipairs(ids) do | ||
14 | + local email = require("models.Email").new({key = string.format("email:%d:%s", roleId, id)}) | ||
15 | + if email:load(tarr2tab(redret[index])) then | ||
16 | + table.insert(emails, email) | ||
17 | + end | ||
18 | + end | ||
19 | + return emails | ||
20 | +end | ||
21 | + | ||
22 | +function _M.listRpc(agent, data) | ||
23 | + local role = agent.role | ||
24 | + local roleId = role:getProperty("id") | ||
25 | + local now = skynet.timex() | ||
26 | + local result = {} | ||
27 | + local mid = role:getProperty("sid") | ||
28 | + | ||
29 | + local globalEmail = redisproxy:hget("autoincrement_set", "email") | ||
30 | + globalEmail = tonum(globalEmail) | ||
31 | + local emailSync = role:getProperty("emailSync") | ||
32 | + if globalEmail > emailSync then | ||
33 | + role:setProperty("emailSync", globalEmail) | ||
34 | + emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) | ||
35 | + local result = redisproxy:pipelining(function (red) | ||
36 | + for id = emailSync, globalEmail do | ||
37 | + red:hgetall(string.format("globalEmail:%s", id)) | ||
38 | + end | ||
39 | + end) | ||
40 | + local count = 1 | ||
41 | + for _, data in ipairs(result) do | ||
42 | + local email = tarr2tab(data) | ||
43 | + if tonum(email.createtime) > role:getProperty("ctime") | ||
44 | + and ( not email.mid or tonum(email.mid) == mid ) | ||
45 | + and ( not email.endtime or tonum(email.endtime) > now )then | ||
46 | + local time = email.timestamp and tonum(email.timestamp) or email.createtime | ||
47 | + redisproxy:insertEmail({ | ||
48 | + roleId = roleId, | ||
49 | + emailId = 0, | ||
50 | + createtime = time, | ||
51 | + title = email.title, | ||
52 | + content = email.content, | ||
53 | + attachments = email.attachments | ||
54 | + }) | ||
55 | + --role:log("mail_actions", {desc = "get_global", s1 = email.title, s2 = email.attachments}) | ||
56 | + end | ||
57 | + end | ||
58 | + end | ||
59 | + | ||
60 | + local emails = loadEmails(roleId) | ||
61 | + for _, email in ipairs(emails) do | ||
62 | + table.insert(result, email:data()) | ||
63 | + end | ||
64 | + | ||
65 | + SendPacket(actionCodes.Email_listRpc, MsgPack.pack(result)) | ||
66 | + return true | ||
67 | +end | ||
68 | + | ||
69 | +local function getEmailAttachments( email ) | ||
70 | + if email:getProperty("status") == 2 then | ||
71 | + return "" | ||
72 | + end | ||
73 | + local attachments = email:getProperty("attachments") | ||
74 | + if attachments:len() == 0 then | ||
75 | + local rewardPms = email:getProperty("rewardPms") | ||
76 | + local emailData = csvdb["emailCsv"][email:getProperty("emailId")] | ||
77 | + if emailData then | ||
78 | + attachments = emailData.attachment:format(table.unpack(rewardPms)) | ||
79 | + end | ||
80 | + end | ||
81 | + return attachments | ||
82 | +end | ||
83 | + | ||
84 | +function _M.drawAllAttachRpc(agent, data) | ||
85 | + local role = agent.role | ||
86 | + local roleId = role:getProperty("id") | ||
87 | + | ||
88 | + local reward = {} | ||
89 | + local ids = {} | ||
90 | + | ||
91 | + local emails = loadEmails(roleId) | ||
92 | + redisproxy:pipelining(function (red) | ||
93 | + for _, email in ipairs(emails) do | ||
94 | + local attachments = getEmailAttachments(email) | ||
95 | + if attachments ~= "" then | ||
96 | + local emailId = email:getProperty("id") | ||
97 | + local items = role:award(attachments) | ||
98 | + ids[emailId] = 1 | ||
99 | + red:hset(string.format(R_EMAIL_ITEM, roleId, emailId), "status", 2) | ||
100 | + -- role:log("mail_actions", {desc = "draw_attach", int1 = emailId, s1 = email:getProperty("title"), s2 = attachments}) | ||
101 | + | ||
102 | + for key, v in pairs(items) do | ||
103 | + reward[key] = (reward[key] or 0) + v | ||
104 | + end | ||
105 | + end | ||
106 | + end | ||
107 | + end) | ||
108 | + | ||
109 | + SendPacket(actionCodes.Email_drawAllAttachRpc, MsgPack.pack({ids = ids, reward = reward})) | ||
110 | + return true | ||
111 | +end | ||
112 | + | ||
113 | +function _M.drawAttachRpc(agent, data) | ||
114 | + local role = agent.role | ||
115 | + local roleId = role:getProperty("id") | ||
116 | + local msg = MsgPack.unpack(data) | ||
117 | + local id = msg.id | ||
118 | + | ||
119 | + local rds = string.format(R_EMAIL_ITEM, roleId, id) | ||
120 | + | ||
121 | + local email = require("models.Email").new({key = rds}) | ||
122 | + if not email:load() then return end | ||
123 | + | ||
124 | + local attachments = getEmailAttachments(email) | ||
125 | + if attachments == "" then return end | ||
126 | + | ||
127 | + local reward = role:award(attachments) | ||
128 | + redisproxy:hset(rds, "status", 2) -- 领取标记 | ||
129 | + SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward})) | ||
130 | + | ||
131 | + -- role:log("mail_actions", {desc = "draw_attach", int1 = id, s1 = email:getProperty("title"), s2 = attachments, ucode = ucode}) | ||
132 | + return true | ||
133 | +end | ||
134 | + | ||
135 | +function _M.checkRpc(agent, data) | ||
136 | + local role = agent.role | ||
137 | + local roleId = role:getProperty("id") | ||
138 | + | ||
139 | + local msg = MsgPack.unpack(data) | ||
140 | + local id = msg.id | ||
141 | + | ||
142 | + local rds = string.format(R_EMAIL_ITEM, roleId, id) | ||
143 | + if not redisproxy:exists(rds) then return end | ||
144 | + | ||
145 | + redisproxy:hset(rds, "status", 1) | ||
146 | + -- role:log("mail_actions", {desc = "check_mail", int1 = id}) | ||
147 | + | ||
148 | + SendPacket(actionCodes.Email_checkRpc, '') | ||
149 | + return true | ||
150 | +end | ||
151 | + | ||
152 | +function _M.delRpc(agent, data) | ||
153 | + local role = agent.role | ||
154 | + local roleId = role:getProperty("id") | ||
155 | + | ||
156 | + local rds = string.format(R_EMAIL, roleId) | ||
157 | + local ids = redisproxy:lrange(rds, 0, EMAIL_LIMIT - 1) | ||
158 | + local now = skynet.timex() | ||
159 | + local result = {} | ||
160 | + local emailSet = csvdb["emailCsv"] | ||
161 | + | ||
162 | + redisproxy:pipelining(function (red) | ||
163 | + for _, id in ipairs(ids) do | ||
164 | + local emailRds = string.format("email:%d:%s", roleId, id) | ||
165 | + local email = require("models.Email").new({key = emailRds}) | ||
166 | + if email:load() then | ||
167 | + local status = email:getProperty("status") | ||
168 | + local attachments = email:getProperty("attachments") | ||
169 | + local emailData = emailSet[email:getProperty("emailId")] | ||
170 | + if emailData and attachments:len() == 0 then | ||
171 | + attachments = emailData.attachment | ||
172 | + end | ||
173 | + if status == 2 or (status == 1 and attachments:len() == 0) then | ||
174 | + red:lrem(rds, 0, id) | ||
175 | + red:del(emailRds) | ||
176 | + result[tonum(id)] = 1 | ||
177 | + end | ||
178 | + end | ||
179 | + end | ||
180 | + end) | ||
181 | + -- for delId, _ in ipairs(result) do | ||
182 | + -- role:log("mail_actions", {desc = "del_mail", int1 = delId}) | ||
183 | + -- end | ||
184 | + SendPacket(actionCodes.Email_delRpc, MsgPack.pack({result = result})) | ||
185 | + return true | ||
186 | +end | ||
187 | + | ||
188 | +return _M | ||
0 | \ No newline at end of file | 189 | \ No newline at end of file |
src/actions/RoleAction.lua
@@ -277,7 +277,7 @@ function _M.createRpc(agent, data) | @@ -277,7 +277,7 @@ function _M.createRpc(agent, data) | ||
277 | key = string_format("role:%d", roleId), | 277 | key = string_format("role:%d", roleId), |
278 | id = roleId, | 278 | id = roleId, |
279 | uid = tostring(msg.uid), | 279 | uid = tostring(msg.uid), |
280 | - subId = msg.subId or 0, | 280 | + sid = msg.subId or 0, |
281 | name = roleName, | 281 | name = roleName, |
282 | uname = msg.uname or "", | 282 | uname = msg.uname or "", |
283 | device = tostring(msg.device) | 283 | device = tostring(msg.device) |
@@ -294,16 +294,85 @@ function _M.createRpc(agent, data) | @@ -294,16 +294,85 @@ function _M.createRpc(agent, data) | ||
294 | return true | 294 | return true |
295 | end | 295 | end |
296 | 296 | ||
297 | + newRole:award(globalCsv.birthItem) | ||
297 | -- 欢迎邮件 | 298 | -- 欢迎邮件 |
298 | -- redisproxy:insertEmail({roleId = roleId, emailId = 1}) | 299 | -- redisproxy:insertEmail({roleId = roleId, emailId = 1}) |
299 | -- redisproxy:insertEmail({roleId = roleId, emailId = 2}) | 300 | -- redisproxy:insertEmail({roleId = roleId, emailId = 2}) |
300 | 301 | ||
301 | - newRole:log("create", { ip = agent.ip, ucode = ucode}) | 302 | + newRole:log("create", { ip = agent.ip}) |
302 | 303 | ||
303 | SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) | 304 | SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) |
304 | return true | 305 | return true |
305 | end | 306 | end |
306 | 307 | ||
308 | +function _M.changeNameRpc(agent, data) | ||
309 | + local role = agent.role | ||
310 | + local roleId = role:getProperty("id") | ||
311 | + local msg = MsgPack.unpack(data) | ||
312 | + | ||
313 | + local newName = msg.name | ||
314 | + local oldName = role:getProperty("name") | ||
315 | + | ||
316 | + if not newName or type(newName) ~= "string" then return end | ||
317 | + if newName == oldName then return end | ||
318 | + -- 检查name是否合法 | ||
319 | + local checked = validName(newName) | ||
320 | + if checked ~= "ok" then | ||
321 | + --[[ | ||
322 | + "existed" 已经存在 | ||
323 | + "illegal" 包含非法字符 | ||
324 | + ]] | ||
325 | + local errCodes = { | ||
326 | + ["existed"] = 1, | ||
327 | + ["illegal"] = 2 | ||
328 | + } | ||
329 | + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = errCodes[checked]})) | ||
330 | + return true | ||
331 | + end | ||
332 | + | ||
333 | + if not roleId then | ||
334 | + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 3})) | ||
335 | + return true | ||
336 | + end | ||
337 | + | ||
338 | + local result = redisproxy:setnx(string_format("user:%s", newName), roleId) | ||
339 | + if result == 0 then | ||
340 | + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 1})) | ||
341 | + return true | ||
342 | + end | ||
343 | + redisproxy:pipelining(function (red) | ||
344 | + red:del(string_format("user:%s", oldName)) | ||
345 | + red:set(string_format("uid:%s", role:getProperty("uid")), newName) | ||
346 | + end) | ||
347 | + | ||
348 | + role:updateProperties({ | ||
349 | + ["name"] = newName, | ||
350 | + }) | ||
351 | + SendPacket(actionCodes.Role_changeNameRpc, MsgPack.pack({result = 0})) | ||
352 | + return true | ||
353 | +end | ||
354 | + | ||
355 | +function _M.changeIntroRpc(agent, data) | ||
356 | + local role = agent.role | ||
357 | + local roleId = role:getProperty("id") | ||
358 | + local msg = MsgPack.unpack(data) | ||
359 | + local content = msg.content | ||
360 | + if not content or type(content) ~= "string" then return end | ||
361 | + | ||
362 | + local SERV = string_format("CHATED%d", math.random(1, 5)) | ||
363 | + local legal, mod = skynet.call(SERV, "lua", "check", content) | ||
364 | + if not legal then | ||
365 | + content = mod or "" | ||
366 | + end | ||
367 | + | ||
368 | + if content == "" then | ||
369 | + role:updateProperty({field = "intro", value = content}) | ||
370 | + end | ||
371 | + | ||
372 | + SendPacket(actionCodes.Role_changeIntroRpc, '') | ||
373 | + return true | ||
374 | +end | ||
375 | + | ||
307 | function _M.syncTimeRpc(agent, data) | 376 | function _M.syncTimeRpc(agent, data) |
308 | SendPacket(actionCodes.Role_syncTimeRpc, MsgPack.pack({nowTime = skynet.timex()})) | 377 | SendPacket(actionCodes.Role_syncTimeRpc, MsgPack.pack({nowTime = skynet.timex()})) |
309 | return true | 378 | return true |
@@ -703,4 +772,86 @@ function _M.chatGet(agent, data) | @@ -703,4 +772,86 @@ function _M.chatGet(agent, data) | ||
703 | return true | 772 | return true |
704 | end | 773 | end |
705 | 774 | ||
775 | + | ||
776 | +function _M.changeSettingRpc(agent, data) | ||
777 | + local role = agent.role | ||
778 | + local msg = MsgPack.unpack(data) | ||
779 | + | ||
780 | + local id = msg.id | ||
781 | + local status = msg.status | ||
782 | + | ||
783 | + local statusEnum = SettingStatus[id] | ||
784 | + if not statusEnum then return 1 end | ||
785 | + | ||
786 | + if not statusEnum[status] then return 2 end | ||
787 | + | ||
788 | + local setting = role:getProperty("setting") | ||
789 | + setting[id] = status | ||
790 | + role:updateProperty({field = "setting", value = setting}) | ||
791 | + | ||
792 | + SendPacket(actionCodes.Role_changeSettingRpc, '') | ||
793 | + return true | ||
794 | +end | ||
795 | + | ||
796 | +function _M.drawCodeRpc(agent, data) | ||
797 | + local msg = MsgPack.unpack(data) | ||
798 | + local codeurl = skynet.getenv("codeurl") | ||
799 | + local role = agent.role | ||
800 | + local msg = MsgPack.unpack(data) | ||
801 | + local code = msg.code | ||
802 | + | ||
803 | + if type(code) ~= "string" then return end | ||
804 | + if code:find("[^0-9a-zA-Z]") then return end | ||
805 | + | ||
806 | + local codestr = role:getProperty("codeStr") | ||
807 | + local content = { | ||
808 | + ["platformId"] = role:getProperty("sid"), | ||
809 | + ["code"] = code, | ||
810 | + ["itemIds"] = codestr, | ||
811 | + ["key"] = "zhaolugame20170831", | ||
812 | + } | ||
813 | + local status, body = httpc.get(codeurl, "/libaoma?" .. httpGetFormatData(content), {}) | ||
814 | + if status == 200 then | ||
815 | + local result = json.decode(body) | ||
816 | + local ret = tonum(result.ret) | ||
817 | + if ret == 0 then | ||
818 | + local giftId = tonumber(result.giftId) | ||
819 | + role:setProperty("codeStr", codestr:setv(giftId, 1)) | ||
820 | + local reward = role:award(result.gift) | ||
821 | + | ||
822 | + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({ | ||
823 | + result = ret, | ||
824 | + reward = reward, | ||
825 | + })) | ||
826 | + return true | ||
827 | + end | ||
828 | + -- 1 不存在的礼包码 | ||
829 | + -- 2 已经领取过相同类型物品 | ||
830 | + -- 3 领取数量达到上限 | ||
831 | + -- 4 过期了 | ||
832 | + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = ret})) | ||
833 | + return true | ||
834 | + end | ||
835 | + SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({result = -1})) | ||
836 | + return true | ||
837 | +end | ||
838 | + | ||
839 | +function _M.changeHeadRpc(agent, data) | ||
840 | + local role = agent.role | ||
841 | + local msg = MsgPack.unpack(data) | ||
842 | + | ||
843 | + local id = msg.id | ||
844 | + local icon = csvdb["player_iconCsv"][id] | ||
845 | + if not icon then | ||
846 | + return | ||
847 | + end | ||
848 | + if role:getItemCount(id) < 1 then | ||
849 | + return | ||
850 | + end | ||
851 | + role:updateProperty({field = "headId" ,value = id}) | ||
852 | + SendPacket(actionCodes.Role_changeHeadRpc, "") | ||
853 | + return true | ||
854 | +end | ||
855 | + | ||
856 | + | ||
706 | return _M | 857 | return _M |
707 | \ No newline at end of file | 858 | \ No newline at end of file |
@@ -0,0 +1,56 @@ | @@ -0,0 +1,56 @@ | ||
1 | +local Email = class("Email", require("shared.ModelBase")) | ||
2 | + | ||
3 | +function Email:ctor(properties) | ||
4 | + Email.super.ctor(self, properties) | ||
5 | +end | ||
6 | + | ||
7 | +Email.schema = { | ||
8 | + key = {"string"}, -- redis key | ||
9 | + id = {"number", 0}, -- 数据库ID | ||
10 | + emailId = {"number", 0}, -- 邮件csv ID | ||
11 | + title = {"string", ""}, -- 邮件标题 | ||
12 | + content = {"string", ""}, -- 邮件正文 | ||
13 | + attachments = {"string", ""}, | ||
14 | + status = {"number", 0}, -- 邮件状态: 未读, 已读, 已领取 | ||
15 | + createtime = {"number", skynet.timex()}, | ||
16 | + contentPms = {"table", {}}, | ||
17 | + rewardPms = {"table", {}}, | ||
18 | +} | ||
19 | + | ||
20 | +function Email:data() | ||
21 | + local emailId = self:getProperty("emailId") | ||
22 | + local title = self:getProperty("title") | ||
23 | + local content = self:getProperty("content") | ||
24 | + local attachments = self:getProperty("attachments") | ||
25 | + local contentPms = self:getProperty("contentPms") | ||
26 | + local rewardPms = self:getProperty("rewardPms") | ||
27 | + | ||
28 | + local emailData = csvdb["emailCsv"][emailId] | ||
29 | + | ||
30 | + if emailData then | ||
31 | + -- 如果内容是直接插入到数据库 | ||
32 | + if content == "" and emailData.body ~= "" then | ||
33 | + content = io.readfile("src/" .. emailData.body) | ||
34 | + content = content:format(table.unpack(contentPms)) | ||
35 | + end | ||
36 | + | ||
37 | + if title == "" and emailData.title ~= "" then | ||
38 | + title = emailData.title | ||
39 | + end | ||
40 | + | ||
41 | + if attachments == "" and emailData.attachment ~= "" then | ||
42 | + attachments = emailData.attachment:format(table.unpack(rewardPms)) | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
46 | + return { | ||
47 | + id = self:getProperty("id"), | ||
48 | + status = self:getProperty("status"), | ||
49 | + createtime = self:getProperty("createtime"), | ||
50 | + title = title, | ||
51 | + content = content, | ||
52 | + attachments = attachments, | ||
53 | + } | ||
54 | +end | ||
55 | + | ||
56 | +return Email | ||
0 | \ No newline at end of file | 57 | \ No newline at end of file |
src/models/Role.lua
@@ -27,6 +27,7 @@ Role.schema = { | @@ -27,6 +27,7 @@ Role.schema = { | ||
27 | id = {"number"}, | 27 | id = {"number"}, |
28 | uid = {"string", ""}, | 28 | uid = {"string", ""}, |
29 | name = {"string", ""}, | 29 | name = {"string", ""}, |
30 | + intro = {"string", ""}, | ||
30 | headId = {"number", 3201}, | 31 | headId = {"number", 3201}, |
31 | sid = {"number", 0}, | 32 | sid = {"number", 0}, |
32 | device = {"string", ""}, | 33 | device = {"string", ""}, |
@@ -38,6 +39,8 @@ Role.schema = { | @@ -38,6 +39,8 @@ Role.schema = { | ||
38 | sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本 | 39 | sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本 |
39 | diamond = {"number", 0}, | 40 | diamond = {"number", 0}, |
40 | reDiamond = {"number", 0}, | 41 | reDiamond = {"number", 0}, |
42 | + setting = {"table", {}}, --设置 | ||
43 | + codeStr = {"string", ""}, --已经领过的礼包码 | ||
41 | -- roleInfo | 44 | -- roleInfo |
42 | level = {"number", 1}, | 45 | level = {"number", 1}, |
43 | exp = {"number", 0}, | 46 | exp = {"number", 0}, |
@@ -111,6 +114,8 @@ Role.schema = { | @@ -111,6 +114,8 @@ Role.schema = { | ||
111 | dinerS = {"table", {}}, -- 美食币商城 购买记录 {[id] = count} | 114 | dinerS = {"table", {}}, -- 美食币商城 购买记录 {[id] = count} |
112 | 115 | ||
113 | rmbC = {"number", 0}, -- 人民币重置额 | 116 | rmbC = {"number", 0}, -- 人民币重置额 |
117 | + | ||
118 | + emailSync = {"number", 0}, -- 已经同步到的邮件Id | ||
114 | } | 119 | } |
115 | 120 | ||
116 | 121 | ||
@@ -212,7 +217,9 @@ function Role:data() | @@ -212,7 +217,9 @@ function Role:data() | ||
212 | return { | 217 | return { |
213 | id = self:getProperty("id"), | 218 | id = self:getProperty("id"), |
214 | name = self:getProperty("name"), | 219 | name = self:getProperty("name"), |
220 | + intro = self:getProperty("intro"), | ||
215 | headId = self:getProperty("headId"), | 221 | headId = self:getProperty("headId"), |
222 | + setting = self:getProperty("setting"), | ||
216 | level = self:getProperty("level"), | 223 | level = self:getProperty("level"), |
217 | exp = self:getProperty("exp"), | 224 | exp = self:getProperty("exp"), |
218 | items = self:getProperty("items"):toNumMap(), | 225 | items = self:getProperty("items"):toNumMap(), |
src/models/RolePlugin.lua
@@ -895,6 +895,90 @@ function RolePlugin.bind(Role) | @@ -895,6 +895,90 @@ function RolePlugin.bind(Role) | ||
895 | pvpTBVC = self:getTeamBattleValue(team.heros), | 895 | pvpTBVC = self:getTeamBattleValue(team.heros), |
896 | }) | 896 | }) |
897 | end | 897 | end |
898 | + | ||
899 | + -- update | ||
900 | + function Role:onRecoverTimer(now) | ||
901 | + self:checkNewEvent(now) | ||
902 | + end | ||
903 | + | ||
904 | + local function breath(sec) | ||
905 | + local last_breath = 0 | ||
906 | + return function (now) | ||
907 | + if now >= last_breath then | ||
908 | + last_breath = now + sec | ||
909 | + return true | ||
910 | + end | ||
911 | + return false | ||
912 | + end | ||
913 | + end | ||
914 | + local breathes = { | ||
915 | + ["email"] = breath(120), -- email | ||
916 | + } | ||
917 | + function Role:checkNewEvent(now) | ||
918 | + if now - self:getProperty("ltime") < 5 then | ||
919 | + return | ||
920 | + end | ||
921 | + | ||
922 | + local checks = {} | ||
923 | + -- 检查全局邮件 -- 增加邮件红点 | ||
924 | + checks["email"] = function() | ||
925 | + local mid = self:getProperty("sid") | ||
926 | + local result = redisproxy:hmget("autoincrement_set", "email", "emailTimestamp") | ||
927 | + local globalEmail = tonum(result[1]) | ||
928 | + local timestamp = tonum(result[2]) | ||
929 | + local emailSync = self:getProperty("emailSync") | ||
930 | + if globalEmail > emailSync and timestamp > self:getProperty("ctime") then | ||
931 | + local emailSync = math.max(emailSync + 1, globalEmail - EMAIL_LIMIT + 1) | ||
932 | + local redret = redisproxy:pipelining(function (red) | ||
933 | + for id = emailSync, globalEmail do | ||
934 | + red:hgetall(string.format("globalEmail:%s", id)) | ||
935 | + end | ||
936 | + end) | ||
937 | + for _, data in ipairs(redret) do | ||
938 | + local email = tarr2tab(data) | ||
939 | + if tonum(email.createtime) > self:getProperty("ctime") | ||
940 | + and ( not email.mid or tonum(email.mid) == mid ) | ||
941 | + and ( not email.endtime or tonum(email.endtime) > now )then | ||
942 | + return true | ||
943 | + end | ||
944 | + end | ||
945 | + end | ||
946 | + | ||
947 | + local roleId = self:getProperty("id") | ||
948 | + local email_rds = string.format(R_EMAIL, roleId) | ||
949 | + | ||
950 | + local emailIds = redisproxy:lrange(email_rds, 0, EMAIL_LIMIT - 1) or {} | ||
951 | + local redret = redisproxy:pipelining(function (red) | ||
952 | + for _, id in ipairs(emailIds) do | ||
953 | + red:hget(string.format(R_EMAIL_ITEM, roleId, id), "status") | ||
954 | + end | ||
955 | + end) | ||
956 | + for index, id in ipairs(emailIds) do | ||
957 | + if tonumber(redret[index]) == 0 then | ||
958 | + return true | ||
959 | + end | ||
960 | + end | ||
961 | + end | ||
962 | + | ||
963 | + local events = {} | ||
964 | + for name, breath in pairs(breathes) do | ||
965 | + if breath(now) and checks[name] then | ||
966 | + local status = checks[name]() | ||
967 | + if status then | ||
968 | + if status == true then | ||
969 | + events[name] = 1 | ||
970 | + else | ||
971 | + events[name] = status | ||
972 | + end | ||
973 | + end | ||
974 | + end | ||
975 | + end | ||
976 | + | ||
977 | + if next(events) then | ||
978 | + SendPacket(actionCodes.Role_notifyNewEvent, MsgPack.pack({events = events})) | ||
979 | + end | ||
980 | + end | ||
981 | + | ||
898 | end | 982 | end |
899 | 983 | ||
900 | return RolePlugin | 984 | return RolePlugin |
901 | \ No newline at end of file | 985 | \ No newline at end of file |
src/rdsscripts/RedisScripts.lua
1 | local _M = {} | 1 | local _M = {} |
2 | 2 | ||
3 | -_M["rankDetails"] = { | ||
4 | - file = "src/rdsscripts/rankDetails.lua", | ||
5 | - sha1 = nil, | ||
6 | -} | ||
7 | _M["insertEmail"] = { | 3 | _M["insertEmail"] = { |
8 | file = "src/rdsscripts/insertEmail.lua", | 4 | file = "src/rdsscripts/insertEmail.lua", |
9 | sha1 = nil, | 5 | sha1 = nil, |
10 | } | 6 | } |
11 | -_M["refreshAssist"] = { | ||
12 | - file = "src/rdsscripts/refreshAssist.lua", | ||
13 | - sha1 = nil, | ||
14 | -} | ||
15 | -_M["assistInfo"] = { | ||
16 | - file = "src/rdsscripts/assistInfo.lua", | ||
17 | - sha1 = nil, | ||
18 | -} | ||
19 | 7 | ||
20 | return _M | 8 | return _M |
21 | \ No newline at end of file | 9 | \ No newline at end of file |
src/rdsscripts/assistInfo.lua deleted
@@ -1,55 +0,0 @@ | @@ -1,55 +0,0 @@ | ||
1 | -local roleId = tonumber(KEYS[1]) | ||
2 | - | ||
3 | -local formationJson = redis.call("hget", string.format("role:%d", roleId), "pveFormationJson") | ||
4 | - | ||
5 | -local formation = cjson.decode(formationJson) | ||
6 | - | ||
7 | -local function formatAttrEx(str) | ||
8 | - local tb = {} | ||
9 | - for k, v in str:gmatch("([%d.]+)=([%d.]+)") do | ||
10 | - tb[#tb+1] = {tonumber(k), tonumber(v)} | ||
11 | - end | ||
12 | - return tb | ||
13 | -end | ||
14 | - | ||
15 | -local function formatEquips(str) | ||
16 | - local tb = {} | ||
17 | - for k, v in str:gmatch("([%d.]+)=([%d.]+)") do | ||
18 | - tb[tonumber(k)] = tonumber(v) | ||
19 | - end | ||
20 | - return tb | ||
21 | -end | ||
22 | - | ||
23 | -local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel", "equips"} | ||
24 | -local equipFields = {"type", "level", "evolCount", "attrEx"} | ||
25 | -for _, hero in ipairs(formation.heros) do | ||
26 | - if hero.leader then | ||
27 | - local heroInfo = redis.call("hmget", string.format("hero:%d:%d", roleId, hero.id), unpack(heroFields)) | ||
28 | - local equipstr = heroInfo[7] | ||
29 | - local equips = {} | ||
30 | - for part, equipId in equipstr:gmatch("(%d+)=(%d+)") do | ||
31 | - part, equipId = tonumber(part), tonumber(equipId) | ||
32 | - if equipId ~= 0 then | ||
33 | - local equipInfo = redis.call("hmget", string.format("equip:%d:%d", roleId, equipId), unpack(equipFields)) | ||
34 | - equips[equipId] = {} | ||
35 | - for index, value in ipairs(equipInfo) do | ||
36 | - equips[equipId][equipFields[index]] = index ~= 4 and tonumber(value) or formatAttrEx(equipInfo[4] or "") | ||
37 | - end | ||
38 | - end | ||
39 | - end | ||
40 | - return cmsgpack.pack { | ||
41 | - type = tonumber(heroInfo[1]), | ||
42 | - level = tonumber(heroInfo[2]), | ||
43 | - star = tonumber(heroInfo[3]), | ||
44 | - evolveCount = tonumber(heroInfo[4]), | ||
45 | - wake = tonumber(heroInfo[5]), | ||
46 | - breakLevel = tonumber(heroInfo[6]), | ||
47 | - equips = formatEquips(heroInfo[7]), | ||
48 | - equipDtls = equips, | ||
49 | - } | ||
50 | - end | ||
51 | -end | ||
52 | - | ||
53 | -return cmsgpack.pack {} | ||
54 | - | ||
55 | - |
src/rdsscripts/insertEmail.lua
1 | -local con1 = KEYS[4] or "" | ||
2 | -local con2 = KEYS[5] or "" | ||
3 | -local con3 = KEYS[6] or "" | ||
4 | -local att1 = KEYS[7] or "" | ||
5 | -local att2 = KEYS[8] or "" | ||
6 | -local att3 = KEYS[9] or "" | ||
7 | -local title = KEYS[10] or "" | ||
8 | -local content = KEYS[11] or "" | ||
9 | -local attachments = KEYS[12] or "" | 1 | +local EMAIL_LIMIT = KEYS[1] |
2 | +local roleId = KEYS[2] | ||
3 | +local emailId = KEYS[3] or 0 | ||
4 | +local createTime = KEYS[4] | ||
5 | +local con = KEYS[5] or cmsgpack.pack({}) | ||
6 | +local att = KEYS[6] or cmsgpack.pack({}) | ||
7 | +local title = KEYS[7] or "" | ||
8 | +local content = KEYS[8] or "" | ||
9 | +local attachments = KEYS[9] or "" | ||
10 | 10 | ||
11 | --- local roleInfo = redis.call("HGET", string.format("role:%d", KEYS[1]), "delete") | 11 | + |
12 | +-- local roleInfo = redis.call("HGET", string.format("role:%d", roleId), "delete") | ||
12 | 13 | ||
13 | -- if tonumber(roleInfo) == 1 then return end | 14 | -- if tonumber(roleInfo) == 1 then return end |
14 | 15 | ||
15 | -local id = redis.call("HINCRBY", string.format("role:%d:autoincr", KEYS[1]), "email", 1) | ||
16 | -redis.call("LPUSH", string.format("role:%d:emailIds", KEYS[1]), id) | ||
17 | -local deleteIds = redis.call("LRANGE", string.format("role:%d:emailIds", KEYS[1]), 50, -1) | 16 | +local id = redis.call("HINCRBY", string.format("role:%d:autoincr", roleId), "email", 1) |
17 | +redis.call("LPUSH", string.format("role:%d:emailIds", roleId), id) | ||
18 | +local deleteIds = redis.call("LRANGE", string.format("role:%d:emailIds", roleId), EMAIL_LIMIT, -1) | ||
18 | for _, deleteId in ipairs(deleteIds) do | 19 | for _, deleteId in ipairs(deleteIds) do |
19 | - redis.call("DEL", string.format("email:%d:%d", KEYS[1], deleteId)) | 20 | + redis.call("DEL", string.format("email:%d:%d", roleId, deleteId)) |
20 | end | 21 | end |
21 | 22 | ||
22 | -redis.call("LTRIM", string.format("role:%d:emailIds", KEYS[1]), 0, 49) | ||
23 | -redis.call("HMSET", string.format("email:%d:%d", KEYS[1], id), "id", tostring(id), "emailId", KEYS[2], | ||
24 | - "status", "0", "createtime", KEYS[3], | ||
25 | - "con1", con1, "con2", con2, "con3", con3, | ||
26 | - "att1", att1, "att2", att2, "att3", att3, | ||
27 | - "title", title, "content", content, "attachments", attachments) | 23 | +redis.call("LTRIM", string.format("role:%d:emailIds", roleId), 0, EMAIL_LIMIT - 1) |
24 | +redis.call("HMSET", string.format("email:%d:%d", roleId, id), | ||
25 | + "id", tostring(id), | ||
26 | + "emailId", emailId, | ||
27 | + "status", "0", | ||
28 | + "createtime", createTime, | ||
29 | + "contentPms", con, | ||
30 | + "rewardPms", att, | ||
31 | + "title", title, | ||
32 | + "content", content, | ||
33 | + "attachments", attachments | ||
34 | +) |
src/rdsscripts/rankDetails.lua deleted
@@ -1,30 +0,0 @@ | @@ -1,30 +0,0 @@ | ||
1 | -local field = KEYS[1] | ||
2 | -local roleId = tonumber(KEYS[2]) | ||
3 | - | ||
4 | -local formationJson = redis.call("hget", string.format("role:%d", roleId), field .. "FormationJson") | ||
5 | - | ||
6 | -local formation = cjson.decode(formationJson) | ||
7 | - | ||
8 | -local response = {formation = {}, heros = {}} | ||
9 | - | ||
10 | -if formation.heros then | ||
11 | - for _, hero in ipairs(formation.heros) do | ||
12 | - table.insert(response.formation, hero.id) | ||
13 | - end | ||
14 | -end | ||
15 | - | ||
16 | -local heroIds = redis.call("smembers", string.format("role:%d:heroIds", roleId)) | ||
17 | - | ||
18 | -local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel"} | ||
19 | -for _, heroId in ipairs(heroIds) do | ||
20 | - local heroId = tonumber(heroId) | ||
21 | - local heroInfo = redis.call("hmget", string.format("hero:%d:%d", roleId, heroId), unpack(heroFields)) | ||
22 | - | ||
23 | - local tb = {} | ||
24 | - for k, v in ipairs(heroInfo) do | ||
25 | - tb[heroFields[k]] = tonumber(v) | ||
26 | - end | ||
27 | - response.heros[heroId] = tb | ||
28 | -end | ||
29 | - | ||
30 | -return cmsgpack.pack(response) | ||
31 | \ No newline at end of file | 0 | \ No newline at end of file |
src/rdsscripts/refreshAssist.lua deleted
@@ -1,58 +0,0 @@ | @@ -1,58 +0,0 @@ | ||
1 | -local roleId = tonumber(KEYS[1]) | ||
2 | - | ||
3 | -local friendKey = "role:%d:friend" | ||
4 | -local assistKey = "role:%d:assist" | ||
5 | - | ||
6 | -local function formatTable(tbl) | ||
7 | - local t = {} | ||
8 | - for _, id in ipairs(tbl) do | ||
9 | - t[tonumber(id)] = 1 | ||
10 | - end | ||
11 | - return t | ||
12 | -end | ||
13 | - | ||
14 | -local friendIds = redis.call("smembers", friendKey:format(roleId)) | ||
15 | -local assistIds = formatTable(redis.call("smembers", assistKey:format(roleId))) | ||
16 | - | ||
17 | -local heroFields = {"type", "level", "star", "evolveCount", "wake", "breakLevel", "battleValue", "dress"} | ||
18 | -local function getLeader(id, formation) | ||
19 | - for _, hero in ipairs(formation.heros) do | ||
20 | - if hero.leader then | ||
21 | - local heroInfo = redis.call("hmget", string.format("hero:%d:%d", id, hero.id), unpack(heroFields)) | ||
22 | - return { | ||
23 | - type = tonumber(heroInfo[1]), | ||
24 | - level = tonumber(heroInfo[2]), | ||
25 | - star = tonumber(heroInfo[3]), | ||
26 | - evolveCount = tonumber(heroInfo[4]), | ||
27 | - wake = tonumber(heroInfo[5]), | ||
28 | - breakLevel = tonumber(heroInfo[6]), | ||
29 | - battleValue = tonumber(heroInfo[7]), | ||
30 | - dress = tonumber(heroInfo[8]), | ||
31 | - } | ||
32 | - end | ||
33 | - end | ||
34 | -end | ||
35 | - | ||
36 | -local response = {} | ||
37 | -for _, id in ipairs(friendIds) do | ||
38 | - id = tonumber(id) | ||
39 | - local dtls = redis.call("hmget", string.format("role:%d", id), | ||
40 | - "name", "level", "vip", "pveFormationJson") | ||
41 | - local formation = cjson.decode(dtls[4]) | ||
42 | - local leader = getLeader(id, formation) | ||
43 | - if leader then | ||
44 | - table.insert(response, { | ||
45 | - roleId = id, | ||
46 | - name = dtls[1], | ||
47 | - level = tonumber(dtls[2]), | ||
48 | - vip = tonumber(dtls[3]), | ||
49 | - leader = leader, | ||
50 | - used = assistIds[id] or 0, | ||
51 | - }) | ||
52 | - end | ||
53 | -end | ||
54 | - | ||
55 | -return cmsgpack.pack(response) | ||
56 | - | ||
57 | - | ||
58 | - |
src/services/agent_util.lua
@@ -84,7 +84,7 @@ function _M:update(agent) | @@ -84,7 +84,7 @@ function _M:update(agent) | ||
84 | nextCheckTime = now + HEART_TIMER_INTERVAL | 84 | nextCheckTime = now + HEART_TIMER_INTERVAL |
85 | end | 85 | end |
86 | pcall(check_daily_reset, agent, now) | 86 | pcall(check_daily_reset, agent, now) |
87 | - -- pcall(role.onRecoverTimer, role, now) | 87 | + pcall(role.onRecoverTimer, role, now) |
88 | end | 88 | end |
89 | 89 | ||
90 | function _M:heart_beat(agent) | 90 | function _M:heart_beat(agent) |
src/services/redisd.lua
@@ -13,17 +13,6 @@ function command.open(conf) | @@ -13,17 +13,6 @@ function command.open(conf) | ||
13 | db = conf.redisdb or 0, | 13 | db = conf.redisdb or 0, |
14 | auth = conf.auth, | 14 | auth = conf.auth, |
15 | }) | 15 | }) |
16 | - | ||
17 | - --[[ | ||
18 | - local csvdata = require("csvdata.world_boss_battle") | ||
19 | - for i=1, #csvdata do | ||
20 | - for j=1, #csvdata[i] do | ||
21 | - db:del(string.format("boss:%d:%d", i, j)) | ||
22 | - end | ||
23 | - end | ||
24 | - --]] | ||
25 | - db:del("rtpvp") | ||
26 | - | ||
27 | end | 16 | end |
28 | 17 | ||
29 | skynet.start(function() | 18 | skynet.start(function() |
src/shared/redisproxy.lua
@@ -51,21 +51,15 @@ function redisproxy:insertEmail(params) | @@ -51,21 +51,15 @@ function redisproxy:insertEmail(params) | ||
51 | roleId = params.roleId, | 51 | roleId = params.roleId, |
52 | emailId = params.emailId, | 52 | emailId = params.emailId, |
53 | createtime = params.createtime or skynet.timex(), | 53 | createtime = params.createtime or skynet.timex(), |
54 | - con1 = params.con1 or "", | ||
55 | - con2 = params.con2 or "", | ||
56 | - con3 = params.con3 or "", | ||
57 | - att1 = params.att1 or "", | ||
58 | - att2 = params.att2 or "", | ||
59 | - att3 = params.att3 or "", | 54 | + con = params.con or {}, |
55 | + att = params.att or {}, | ||
60 | title = params.title or "", | 56 | title = params.title or "", |
61 | content = params.content or "", | 57 | content = params.content or "", |
62 | attachments = params.attachments or "", | 58 | attachments = params.attachments or "", |
63 | } | 59 | } |
64 | - self:runScripts("insertEmail", 12, | 60 | + self:runScripts("insertEmail", 9, EMAIL_LIMIT, |
65 | pms.roleId, pms.emailId, pms.createtime, | 61 | pms.roleId, pms.emailId, pms.createtime, |
66 | - pms.con1, pms.con2, pms.con3, | ||
67 | - pms.att1, pms.att2, pms.att3, | ||
68 | - pms.title, pms.content, pms.attachments) | 62 | + MsgPack.pack(pms.con), MsgPack.pack(pms.att), pms.title, pms.content, pms.attachments) |
69 | return true | 63 | return true |
70 | end | 64 | end |
71 | 65 |