Commit e9bfa7a2819114b91443ea2bbc63d5f2b9d1f30d
1 parent
ae0d3358
其他玩家展示界面数据支持, 更新sql版本管理
Showing
8 changed files
with
115 additions
and
26 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -56,6 +56,8 @@ actionCodes = { | @@ -56,6 +56,8 @@ actionCodes = { | ||
| 56 | Role_diamondConvertRpc = 140, -- 钻石兑换成别的物品 | 56 | Role_diamondConvertRpc = 140, -- 钻石兑换成别的物品 |
| 57 | Role_getTimeGiftRpc = 141, | 57 | Role_getTimeGiftRpc = 141, |
| 58 | Role_runeBuyRpc = 142, -- 铭文购买 | 58 | Role_runeBuyRpc = 142, -- 铭文购买 |
| 59 | + Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 | ||
| 60 | + Role_setBgRpc = 144, -- 设置看板娘 | ||
| 59 | 61 | ||
| 60 | Adv_startAdvRpc = 151, | 62 | Adv_startAdvRpc = 151, |
| 61 | Adv_startHangRpc = 152, | 63 | Adv_startHangRpc = 152, |
src/actions/EmailAction.lua
| @@ -14,19 +14,25 @@ local function loadEmails(roleId) | @@ -14,19 +14,25 @@ local function loadEmails(roleId) | ||
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | local function delExpireEmails(roleId) | 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 | sql = string.format(sql, roleId, EMAIL_LIMIT) | 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 | end | 36 | end |
| 31 | 37 | ||
| 32 | function _M.listRpc(agent, data) | 38 | function _M.listRpc(agent, data) |
src/actions/RoleAction.lua
| @@ -1583,4 +1583,27 @@ function _M.runeBuyRpc(agent, data) | @@ -1583,4 +1583,27 @@ function _M.runeBuyRpc(agent, data) | ||
| 1583 | return true | 1583 | return true |
| 1584 | end | 1584 | end |
| 1585 | 1585 | ||
| 1586 | +function _M.setFriendTeamRpc(agent, data) | ||
| 1587 | + local role = agent.role | ||
| 1588 | + local msg = MsgPack.unpack(data) | ||
| 1589 | + local team = msg.team | ||
| 1590 | + local info = {} | ||
| 1591 | + info.team = role:getTeamHerosInfo(team) | ||
| 1592 | + info.bInfo = role:getTeamBattleInfo(team) | ||
| 1593 | + info.v = role:getTeamBattleValue(team.heros) | ||
| 1594 | + role:updateProperty({field="friendTeam", value=info}) | ||
| 1595 | + | ||
| 1596 | + SendPacket(actionCodes.Role_setFriendTeamRpc, "") | ||
| 1597 | + return true | ||
| 1598 | +end | ||
| 1599 | + | ||
| 1600 | +function _M.setBgRpc(agent, data) | ||
| 1601 | + local role = agent.role | ||
| 1602 | + local msg = MsgPack.unpack(data) | ||
| 1603 | + role:updateProperty({field="bgId", value=msg.id}) | ||
| 1604 | + | ||
| 1605 | + SendPacket(actionCodes.Role_setBgRpc, "") | ||
| 1606 | + return true | ||
| 1607 | +end | ||
| 1608 | + | ||
| 1586 | return _M | 1609 | return _M |
| 1587 | \ No newline at end of file | 1610 | \ No newline at end of file |
src/models/Role.lua
| @@ -30,6 +30,7 @@ function Role:ctor( properties ) | @@ -30,6 +30,7 @@ function Role:ctor( properties ) | ||
| 30 | self.advData = nil | 30 | self.advData = nil |
| 31 | self.activity = nil | 31 | self.activity = nil |
| 32 | self._pushToken = nil | 32 | self._pushToken = nil |
| 33 | + self._lastSaveTs = skynet.timex() | ||
| 33 | self.advElChapter = tonum(redisproxy:hget("adv_season", "chapter"), globalCsv.adv_endless_default_chapter) -- 无尽模式记录的赛季对应章节 | 34 | self.advElChapter = tonum(redisproxy:hget("adv_season", "chapter"), globalCsv.adv_endless_default_chapter) -- 无尽模式记录的赛季对应章节 |
| 34 | self.advOverTime = tonum(redisproxy:hget("adv_season", "overTime")) -- 无尽模式关闭时间戳 | 35 | self.advOverTime = tonum(redisproxy:hget("adv_season", "overTime")) -- 无尽模式关闭时间戳 |
| 35 | if self.advOverTime == 0 then | 36 | if self.advOverTime == 0 then |
| @@ -205,6 +206,10 @@ Role.schema = { | @@ -205,6 +206,10 @@ Role.schema = { | ||
| 205 | roleIncre = {"table", {}}, -- 角色英雄,铭文,火花自增序列 {heroId = 1, runeId = 1, sparkId = 1} | 206 | roleIncre = {"table", {}}, -- 角色英雄,铭文,火花自增序列 {heroId = 1, runeId = 1, sparkId = 1} |
| 206 | 207 | ||
| 207 | unlockChap = {"table", {}}, -- 解锁的章节 | 208 | unlockChap = {"table", {}}, -- 解锁的章节 |
| 209 | + | ||
| 210 | + heroCnt = {"number", 0}, -- 英雄数量 | ||
| 211 | + friendTeam = {"table", {}}, -- 好友切磋队伍信息 {bInfo = {}, team = {}, v = 0} | ||
| 212 | + bgId = {"number", 0}, -- 看板娘id | ||
| 208 | } | 213 | } |
| 209 | 214 | ||
| 210 | 215 | ||
| @@ -444,6 +449,8 @@ function Role:data() | @@ -444,6 +449,8 @@ function Role:data() | ||
| 444 | returner = self:getProperty("returner"), | 449 | returner = self:getProperty("returner"), |
| 445 | 450 | ||
| 446 | unlockChap = self:getProperty("unlockChap"), -- 解锁的章节 | 451 | unlockChap = self:getProperty("unlockChap"), -- 解锁的章节 |
| 452 | + friendTeam = self:getProperty("friendTeam"), | ||
| 453 | + bgId = self:getProperty("bgId"), | ||
| 447 | } | 454 | } |
| 448 | end | 455 | end |
| 449 | 456 |
src/models/RoleCross.lua
| @@ -11,7 +11,9 @@ RoleCross.bind = function (Role) | @@ -11,7 +11,9 @@ RoleCross.bind = function (Role) | ||
| 11 | level = self:getProperty("level"), | 11 | level = self:getProperty("level"), |
| 12 | headId = self:getProperty("headId"), | 12 | headId = self:getProperty("headId"), |
| 13 | ltime = self:getProperty("ltime"), | 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 | return info | 18 | return info |
| 17 | end | 19 | end |
| @@ -19,8 +21,13 @@ RoleCross.bind = function (Role) | @@ -19,8 +21,13 @@ RoleCross.bind = function (Role) | ||
| 19 | -- 好友详细队伍信息 | 21 | -- 好友详细队伍信息 |
| 20 | function Role:friendInfo() | 22 | function Role:friendInfo() |
| 21 | local info = self:friendSInfo() | 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 | return info | 31 | return info |
| 25 | end | 32 | end |
| 26 | 33 | ||
| @@ -274,31 +281,42 @@ function CMD.getProperties(roleId, fields) | @@ -274,31 +281,42 @@ function CMD.getProperties(roleId, fields) | ||
| 274 | end | 281 | end |
| 275 | 282 | ||
| 276 | function CMD.friendSInfo(roleId) | 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 | return { | 286 | return { |
| 279 | name = info.name, | 287 | name = info.name, |
| 280 | level = info.level, | 288 | level = info.level, |
| 281 | headId = info.headId, | 289 | headId = info.headId, |
| 282 | ltime = info.ltime, | 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 | end | 294 | end |
| 286 | 295 | ||
| 287 | function CMD.friendInfo(roleId) | 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 | return { | 299 | return { |
| 290 | name = info.name, | 300 | name = info.name, |
| 291 | level = info.level, | 301 | level = info.level, |
| 292 | headId = info.headId, | 302 | headId = info.headId, |
| 293 | ltime = info.ltime, | 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 | end | 313 | end |
| 298 | 314 | ||
| 299 | function CMD.friendBattleInfo(roleId) | 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 | end | 320 | end |
| 303 | 321 | ||
| 304 | function CMD.pvpCInfo(roleId) | 322 | function CMD.pvpCInfo(roleId) |
src/models/RolePlugin.lua
| @@ -603,6 +603,7 @@ function RolePlugin.bind(Role) | @@ -603,6 +603,7 @@ function RolePlugin.bind(Role) | ||
| 603 | SendPacket(actionCodes.Hero_loadInfos, bin) | 603 | SendPacket(actionCodes.Hero_loadInfos, bin) |
| 604 | end | 604 | end |
| 605 | 605 | ||
| 606 | + self:updateProperty({field = "heroCnt", value = #self.heros}) | ||
| 606 | self:logItems(heroType + ItemStartId.Hero, 0, 1, params.log) | 607 | self:logItems(heroType + ItemStartId.Hero, 0, 1, params.log) |
| 607 | 608 | ||
| 608 | if params.log then | 609 | if params.log then |
| @@ -1929,10 +1930,15 @@ function RolePlugin.bind(Role) | @@ -1929,10 +1930,15 @@ function RolePlugin.bind(Role) | ||
| 1929 | function Role:onRecoverTimer(now) | 1930 | function Role:onRecoverTimer(now) |
| 1930 | self:updateTimeReset(now, true) | 1931 | self:updateTimeReset(now, true) |
| 1931 | self:checkNewEvent(now) | 1932 | self:checkNewEvent(now) |
| 1932 | - self:saveRoleData() | 1933 | + self:saveRoleData(now) |
| 1933 | end | 1934 | end |
| 1934 | 1935 | ||
| 1935 | - function Role:saveRoleData() | 1936 | + local SAVE_DATA_INTERVAL = 3 |
| 1937 | + function Role:saveRoleData(now) | ||
| 1938 | + if now - self._lastSaveTs < SAVE_DATA_INTERVAL then | ||
| 1939 | + return | ||
| 1940 | + end | ||
| 1941 | + self._lastSaveTs = now | ||
| 1936 | self:update() | 1942 | self:update() |
| 1937 | local objs = {self.activity, self.dailyData, self.dinerData, self.storeData, self.roleIncre} | 1943 | local objs = {self.activity, self.dailyData, self.dinerData, self.storeData, self.roleIncre} |
| 1938 | for _, info in ipairs(objs) do | 1944 | for _, info in ipairs(objs) do |
src/services/dbseed.lua
| @@ -100,6 +100,9 @@ local function initAutoIncreUidTable() | @@ -100,6 +100,9 @@ local function initAutoIncreUidTable() | ||
| 100 | mysqlproxy:query(string.format(tpl, "seaportTime0", 0)) | 100 | mysqlproxy:query(string.format(tpl, "seaportTime0", 0)) |
| 101 | mysqlproxy:query(string.format(tpl, "seaportTime1", 0)) | 101 | mysqlproxy:query(string.format(tpl, "seaportTime1", 0)) |
| 102 | mysqlproxy:query(string.format(tpl, "seaportTime2", 0)) | 102 | mysqlproxy:query(string.format(tpl, "seaportTime2", 0)) |
| 103 | + | ||
| 104 | + -- 记录当前更新版本 | ||
| 105 | + mysqlproxy:query(string.format(tpl, "db_ver", 0)) | ||
| 103 | end | 106 | end |
| 104 | end | 107 | end |
| 105 | 108 | ||
| @@ -255,6 +258,31 @@ local function selectDb() | @@ -255,6 +258,31 @@ local function selectDb() | ||
| 255 | end | 258 | end |
| 256 | end | 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 | skynet.start(function () | 286 | skynet.start(function () |
| 259 | --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 | 287 | --local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 |
| 260 | --if not new then | 288 | --if not new then |
| @@ -273,6 +301,7 @@ skynet.start(function () | @@ -273,6 +301,7 @@ skynet.start(function () | ||
| 273 | initRedisDb() | 301 | initRedisDb() |
| 274 | initSeaportTask() -- 海港任务数据初始化 | 302 | initSeaportTask() -- 海港任务数据初始化 |
| 275 | loadAllUserInfo() | 303 | loadAllUserInfo() |
| 304 | + doUpdateSql() -- 执行更新sql | ||
| 276 | selectDb() | 305 | selectDb() |
| 277 | skynet.exit() | 306 | skynet.exit() |
| 278 | end) | 307 | end) |
| 279 | \ No newline at end of file | 308 | \ No newline at end of file |
src/utils/MysqlUtil.lua
| @@ -34,7 +34,6 @@ function addFriend(roleId, friendId) | @@ -34,7 +34,6 @@ function addFriend(roleId, friendId) | ||
| 34 | rpcRole(roleId, "addFriend", friendId) | 34 | rpcRole(roleId, "addFriend", friendId) |
| 35 | rpcRole(friendId, "addFriend", roleId) | 35 | rpcRole(friendId, "addFriend", roleId) |
| 36 | end | 36 | end |
| 37 | - dump(r) | ||
| 38 | end | 37 | end |
| 39 | 38 | ||
| 40 | function delFriend(roleId, friendId) | 39 | function delFriend(roleId, friendId) |
| @@ -44,7 +43,6 @@ function delFriend(roleId, friendId) | @@ -44,7 +43,6 @@ function delFriend(roleId, friendId) | ||
| 44 | rpcRole(roleId, "delFriend", friendId) | 43 | rpcRole(roleId, "delFriend", friendId) |
| 45 | rpcRole(friendId, "delFriend", roleId) | 44 | rpcRole(friendId, "delFriend", roleId) |
| 46 | end | 45 | end |
| 47 | - dump(r) | ||
| 48 | end | 46 | end |
| 49 | 47 | ||
| 50 | function roleExists(roleId) | 48 | function roleExists(roleId) |