Commit 2820ba2093c7a43319f0a65fd31de4d78e1dd0fa

Authored by zhangqijia
2 parents e2e205be b2afd512

Merge remote-tracking branch 'origin/cn/develop' into cn/develop

src/ProtocolCode.lua
... ... @@ -56,6 +56,8 @@ actionCodes = {
56 56 Role_diamondConvertRpc = 140, -- 钻石兑换成别的物品
57 57 Role_getTimeGiftRpc = 141,
58 58 Role_runeBuyRpc = 142, -- 铭文购买
  59 + Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍
  60 + Role_setBgRpc = 144, -- 设置看板娘
59 61  
60 62 Adv_startAdvRpc = 151,
61 63 Adv_startHangRpc = 152,
... ...
src/actions/EmailAction.lua
... ... @@ -14,19 +14,25 @@ local function loadEmails(roleId)
14 14 end
15 15  
16 16 local function delExpireEmails(roleId)
17   - local sql = [[
18   - DELETE FROM Email
19   - WHERE id IN (
20   - SELECT id FROM (
21   - SELECT id
22   - FROM Email WHERE roleId=%s
23   - ORDER BY createtime DESC, id desc
24   - LIMIT %s, 100000
25   - ) a
26   - );
27   - ]]
  17 + --local sql = [[
  18 + -- DELETE FROM Email
  19 + -- WHERE id IN (
  20 + -- SELECT id FROM (
  21 + -- SELECT id
  22 + -- FROM Email WHERE roleId=%s
  23 + -- ORDER BY createtime DESC, id desc
  24 + -- LIMIT %s, 100000
  25 + -- ) a
  26 + -- );
  27 + --]]
  28 + local sql = "SELECT id FROM Email WHERE roleId=%s ORDER BY createtime DESC, id desc LIMIT %s, 100000"
28 29 sql = string.format(sql, roleId, EMAIL_LIMIT)
29   - mysqlproxy:query(sql)
  30 + local res = mysqlproxy:query(sql)
  31 + local tmp = {}
  32 + for _, v in ipairs(res) do
  33 + table.insert(tmp, v.id)
  34 + end
  35 + mysqlproxy:query(string.format("DELETE FROM Email WHERE id IN (%s)", table.concat(tmp, ",")))
30 36 end
31 37  
32 38 function _M.listRpc(agent, data)
... ...
src/actions/RoleAction.lua
... ... @@ -1604,4 +1604,27 @@ function _M.runeBuyRpc(agent, data)
1604 1604 return true
1605 1605 end
1606 1606  
  1607 +function _M.setFriendTeamRpc(agent, data)
  1608 + local role = agent.role
  1609 + local msg = MsgPack.unpack(data)
  1610 + local team = msg.team
  1611 + local info = {}
  1612 + info.team = role:getTeamHerosInfo(team)
  1613 + info.bInfo = role:getTeamBattleInfo(team)
  1614 + info.v = role:getTeamBattleValue(team.heros)
  1615 + role:updateProperty({field="friendTeam", value=info})
  1616 +
  1617 + SendPacket(actionCodes.Role_setFriendTeamRpc, "")
  1618 + return true
  1619 +end
  1620 +
  1621 +function _M.setBgRpc(agent, data)
  1622 + local role = agent.role
  1623 + local msg = MsgPack.unpack(data)
  1624 + role:updateProperty({field="bgId", value=msg.id})
  1625 +
  1626 + SendPacket(actionCodes.Role_setBgRpc, "")
  1627 + return true
  1628 +end
  1629 +
1607 1630 return _M
1608 1631 \ No newline at end of file
... ...
src/models/Role.lua
... ... @@ -30,6 +30,7 @@ function Role:ctor( properties )
30 30 self.advData = nil
31 31 self.activity = nil
32 32 self._pushToken = nil
  33 + self._lastSaveTs = skynet.timex()
33 34 self.advElChapter = tonum(redisproxy:hget("adv_season", "chapter"), globalCsv.adv_endless_default_chapter) -- 无尽模式记录的赛季对应章节
34 35 self.advOverTime = tonum(redisproxy:hget("adv_season", "overTime")) -- 无尽模式关闭时间戳
35 36 if self.advOverTime == 0 then
... ... @@ -206,6 +207,10 @@ Role.schema = {
206 207 roleIncre = {"table", {}}, -- 角色英雄,铭文,火花自增序列 {heroId = 1, runeId = 1, sparkId = 1}
207 208  
208 209 unlockChap = {"table", {}}, -- 解锁的章节
  210 +
  211 + heroCnt = {"number", 0}, -- 英雄数量
  212 + friendTeam = {"table", {}}, -- 好友切磋队伍信息 {bInfo = {}, team = {}, v = 0}
  213 + bgId = {"number", 0}, -- 看板娘id
209 214 }
210 215  
211 216  
... ... @@ -446,6 +451,8 @@ function Role:data()
446 451 returner = self:getProperty("returner"),
447 452  
448 453 unlockChap = self:getProperty("unlockChap"), -- 解锁的章节
  454 + friendTeam = self:getProperty("friendTeam"),
  455 + bgId = self:getProperty("bgId"),
449 456 }
450 457 end
451 458  
... ...
src/models/RoleCross.lua
... ... @@ -11,7 +11,9 @@ RoleCross.bind = function (Role)
11 11 level = self:getProperty("level"),
12 12 headId = self:getProperty("headId"),
13 13 ltime = self:getProperty("ltime"),
14   - battleV = self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTBVC") or self:getProperty("hangTBV")
  14 +
  15 + battleV = self.getProperty("friendTeam").v or 0,
  16 + --battleV = self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTBVC") or self:getProperty("hangTBV")
15 17 }
16 18 return info
17 19 end
... ... @@ -19,8 +21,13 @@ RoleCross.bind = function (Role)
19 21 -- 好友详细队伍信息
20 22 function Role:friendInfo()
21 23 local info = self:friendSInfo()
22   - local team = self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTSC") or self:getProperty("hangTS")
23   - info.team = team
  24 + --local team = self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTSC") or self:getProperty("hangTS")
  25 + --info.team = team
  26 + info.team = self:getProperty("friendTeam").team or {}
  27 + info.heroCnt = self:getProperty("heroCnt")
  28 + info.achieveCnt = table.numbers(self:getProperty("achiveV"))
  29 + info.bgId = self:getProperty("bgId")
  30 + info.hangPass = self:getProperty("hangPass")
24 31 return info
25 32 end
26 33  
... ... @@ -274,31 +281,42 @@ function CMD.getProperties(roleId, fields)
274 281 end
275 282  
276 283 function CMD.friendSInfo(roleId)
277   - local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "pvpTBVC", "hangTBV"})
  284 + --local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "pvpTBVC", "hangTBV"})
  285 + local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "friendTeam"})
278 286 return {
279 287 name = info.name,
280 288 level = info.level,
281 289 headId = info.headId,
282 290 ltime = info.ltime,
283   - battleV = info.pvpTBVC ~= 0 and info.pvpTBVC or info.hangTBV,
  291 + --battleV = info.pvpTBVC ~= 0 and info.pvpTBVC or info.hangTBV,
  292 + battleV = info.friendTeam.v or 0,
284 293 }
285 294 end
286 295  
287 296 function CMD.friendInfo(roleId)
288   - local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "pvpTBVC", "hangTBV", "pvpTSC", "hangTS"})
  297 + --local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "pvpTBVC", "hangTBV", "pvpTSC", "hangTS"})
  298 + local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "friendTeam", "heroCnt", "achiveV", "bgId", "hangPass"})
289 299 return {
290 300 name = info.name,
291 301 level = info.level,
292 302 headId = info.headId,
293 303 ltime = info.ltime,
294   - battleV = info.pvpTBVC ~= 0 and info.pvpTBVC or info.hangTBV,
295   - team = info.pvpTBVC ~= 0 and info.pvpTSC or info.hangTS
  304 + --battleV = info.pvpTBVC ~= 0 and info.pvpTBVC or info.hangTBV,
  305 + --team = info.pvpTBVC ~= 0 and info.pvpTSC or info.hangTS
  306 + battleV = info.friendTeam.v or 0,
  307 + team = info.friendTeam.team or {},
  308 + heroCnt = info.heroCnt,
  309 + achieveCnt = table.numbers(info.achiveV),
  310 + bgId = info.bgId,
  311 + hangPass = info.hangPass,
296 312 }
297 313 end
298 314  
299 315 function CMD.friendBattleInfo(roleId)
300   - local info = CMD.getProperties(roleId, {"pvpTBC", "hangTB"})
301   - return (next(info.pvpTBC) and next(info.pvpTBC.heros)) and info.pvpTBC or info.hangTB
  316 + --local info = CMD.getProperties(roleId, {"pvpTBC", "hangTB"})
  317 + local info = CMD.getProperties(roleId, {"friendTeam"})
  318 + --return (next(info.pvpTBC) and next(info.pvpTBC.heros)) and info.pvpTBC or info.hangTB
  319 + return info.friendTeam.bInfo or {}
302 320 end
303 321  
304 322 function CMD.pvpCInfo(roleId)
... ...
src/models/RolePlugin.lua
... ... @@ -604,6 +604,7 @@ function RolePlugin.bind(Role)
604 604 SendPacket(actionCodes.Hero_loadInfos, bin)
605 605 end
606 606  
  607 + self:updateProperty({field = "heroCnt", value = #self.heros})
607 608 self:logItems(heroType + ItemStartId.Hero, 0, 1, params.log)
608 609  
609 610 if params.log then
... ... @@ -1930,10 +1931,15 @@ function RolePlugin.bind(Role)
1930 1931 function Role:onRecoverTimer(now)
1931 1932 self:updateTimeReset(now, true)
1932 1933 self:checkNewEvent(now)
1933   - self:saveRoleData()
  1934 + self:saveRoleData(now)
1934 1935 end
1935 1936  
1936   - function Role:saveRoleData()
  1937 + local SAVE_DATA_INTERVAL = 3
  1938 + function Role:saveRoleData(now)
  1939 + if now - self._lastSaveTs < SAVE_DATA_INTERVAL then
  1940 + return
  1941 + end
  1942 + self._lastSaveTs = now
1937 1943 self:update()
1938 1944 local objs = {self.activity, self.dailyData, self.dinerData, self.storeData, self.roleIncre}
1939 1945 for _, info in ipairs(objs) do
... ...
src/services/dbseed.lua
... ... @@ -100,6 +100,9 @@ local function initAutoIncreUidTable()
100 100 mysqlproxy:query(string.format(tpl, "seaportTime0", 0))
101 101 mysqlproxy:query(string.format(tpl, "seaportTime1", 0))
102 102 mysqlproxy:query(string.format(tpl, "seaportTime2", 0))
  103 +
  104 + -- 记录当前更新版本
  105 + mysqlproxy:query(string.format(tpl, "db_ver", 0))
103 106 end
104 107 end
105 108  
... ... @@ -255,6 +258,31 @@ local function selectDb()
255 258 end
256 259 end
257 260  
  261 +local function doUpdateSql()
  262 + local updates = {
  263 + [1] = {
  264 + "ALTER TABLE `Email` ADD INDEX roleid_createtime_id(`roleId`,`createtime`,`id`),DROP INDEX roleId_Index",
  265 + "ALTER TABLE `Role` ADD INDEX uid_Index(`uid`)",
  266 + },
  267 + }
  268 + -- 更新记录表
  269 + local res = mysqlproxy:query("SELECT `value` FROM `autoincrement_set` WHERE `key` = 'db_ver';")
  270 + local ver = res[1].value
  271 + for k, sqls in ipairs(updates) do
  272 + if ver < k then
  273 + skynet.error("do update sql, version:"..k)
  274 + for _, sql in ipairs(sqls) do
  275 + local r = mysqlproxy:query(sql)
  276 + if r["errno"] then
  277 + skynet.error(string.format("%s, err:%s",sql, r["err"]))
  278 + return
  279 + end
  280 + end
  281 + mysqlproxy:query(string.format("UPDATE `autoincrement_set` SET `value` = %d WHERE `key` = 'db_ver';", k))
  282 + end
  283 + end
  284 +end
  285 +
258 286 skynet.start(function ()
259 287 --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1
260 288 --if not new then
... ... @@ -273,6 +301,7 @@ skynet.start(function ()
273 301 initRedisDb()
274 302 initSeaportTask() -- 海港任务数据初始化
275 303 loadAllUserInfo()
  304 + doUpdateSql() -- 执行更新sql
276 305 selectDb()
277 306 skynet.exit()
278 307 end)
279 308 \ No newline at end of file
... ...
src/utils/MysqlUtil.lua
... ... @@ -34,7 +34,6 @@ function addFriend(roleId, friendId)
34 34 rpcRole(roleId, "addFriend", friendId)
35 35 rpcRole(friendId, "addFriend", roleId)
36 36 end
37   - dump(r)
38 37 end
39 38  
40 39 function delFriend(roleId, friendId)
... ... @@ -44,7 +43,6 @@ function delFriend(roleId, friendId)
44 43 rpcRole(roleId, "delFriend", friendId)
45 44 rpcRole(friendId, "delFriend", roleId)
46 45 end
47   - dump(r)
48 46 end
49 47  
50 48 function roleExists(roleId)
... ...