Commit 1b20cfdbbf56544c1a47b33f0ead1b2c473827f1
1 parent
71f716c4
赛季更新完善 无尽冒险排行榜
Showing
13 changed files
with
257 additions
and
46 deletions
Show diff stats
.gitignore
src/ProtocolCode.lua
src/RedisKeys.lua
| ... | ... | @@ -16,38 +16,18 @@ R_EMAIL_ITEM = "email:%d:%d" --邮件 |
| 16 | 16 | RANK_TOWER = "rank:tower" |
| 17 | 17 | RANK_TOWER_INFO = "rank:tower:info" |
| 18 | 18 | |
| 19 | +-- adv | |
| 20 | +RANK_ADV = "rank:adv" | |
| 21 | +RANK_ADV_INFO = "rank:adv:info" | |
| 22 | + | |
| 19 | 23 | RANK_DINER = {"rank:diner1", "rank:diner2"} -- 餐厅排行榜 两个每天互换 |
| 20 | 24 | RANK_DINER_INFO = "rank:diner:info" |
| 21 | 25 | |
| 22 | 26 | RANK_PVP_COMMON = "rank:pvpc" |
| 23 | 27 | RECORD_PVP_COMMON = "record:pvpc:%d" |
| 24 | 28 | RANK_PVP_HIGHT = "rank:pvph" |
| 25 | --- -- role | |
| 26 | --- R_FARM_KEY = "role:%d:farm" | |
| 27 | --- R_TOWER_KEY = "role:%d:tower" | |
| 28 | --- R_COOKLOG_KEY = "role:%d:cooklog" | |
| 29 | --- R_TRADELOG_KEY = "role:%d:tradelog" | |
| 30 | --- R_PVP_KEY = "role:%d:pvp" | |
| 31 | --- R_DINER_KEY = "role:%d:diner" | |
| 32 | --- -- rank | |
| 33 | --- RANK_PVP = "rank:pvp" | |
| 34 | --- RANK_TRADE = "rank:trade" | |
| 35 | --- RANK_TOWER = "rank:tower" | |
| 36 | --- RANK_BOX = "rank:box" -- 盒子舒适度排行榜 | |
| 37 | --- MAP_LIKE = "map:box:like" --点赞个数 | |
| 38 | --- RANK_LEVEL = "rank:level" --等级排名 | |
| 39 | --- RANK_ITEM = "rank:item" --活动物品排行 | |
| 40 | --- -- 日志 | |
| 41 | --- NOTE_COOK_KEY = "note:cook:%d" | |
| 42 | - | |
| 43 | --- TRADE_KEY = "trade:%d" | |
| 44 | --- TRADE_ID_KEY = "tradeIDs" | |
| 45 | 29 | |
| 46 | --- TASK_ACTIVE = "task:%d:active" -- 记录激活的任务 | |
| 47 | --- TASK_FINISH = "task:%d:finish" -- 记录完成的任务 | |
| 48 | 30 | |
| 49 | --- BOSS_SET = "boss:%d:%d" | |
| 50 | --- BOSS_INFO = "boss:battle" | |
| 51 | 31 | |
| 52 | 32 | FRIEND_KEY = "role:%d:friend" --哈希表 好友 |
| 53 | 33 | FRIEND_APPLY_KEY = "role:%d:apply" -- sort set 申请列表 | ... | ... |
src/actions/AdvAction.lua
| ... | ... | @@ -18,6 +18,23 @@ local AdvCommon = require "adv.AdvCommon" |
| 18 | 18 | |
| 19 | 19 | local _M = {} |
| 20 | 20 | |
| 21 | +-- 无尽模式是否开放 | |
| 22 | +local function isOpenEndless(role) | |
| 23 | + if role.advOverTime ~= 0 and skynet.timex() >= role.advOverTime then | |
| 24 | + return false | |
| 25 | + end | |
| 26 | + return true | |
| 27 | +end | |
| 28 | +-- 冒险内的操作是否可以继续 | |
| 29 | +local function isCanContinue(role) | |
| 30 | + local adv = role:getAdvData() | |
| 31 | + if not adv:isRunning() then return false end | |
| 32 | + if adv:isEndless() then | |
| 33 | + if not isOpenEndless(role) then return false end | |
| 34 | + end | |
| 35 | + return true | |
| 36 | +end | |
| 37 | + | |
| 21 | 38 | |
| 22 | 39 | local function checkFormat(role, format, checkAdvTeam) |
| 23 | 40 | local advHang = role:getProperty("advHang") |
| ... | ... | @@ -69,7 +86,7 @@ function _M.startAdvRpc( agent, data ) |
| 69 | 86 | local format = msg.format --编队 |
| 70 | 87 | |
| 71 | 88 | --上一个关卡结束才可以开始新的关卡 |
| 72 | - if next(role:getProperty("advInfo")) then return 8 end | |
| 89 | + if role:getAdvData():isRunning() then return 8 end | |
| 73 | 90 | |
| 74 | 91 | local chapterData = csvdb["adv_chapterCsv"][chapterId] |
| 75 | 92 | if not chapterData or layer < 1 then return 1 end |
| ... | ... | @@ -79,6 +96,8 @@ function _M.startAdvRpc( agent, data ) |
| 79 | 96 | |
| 80 | 97 | local advPass = role:getProperty("advPass") |
| 81 | 98 | if AdvCommon.isEndless(chapterId) then |
| 99 | + if chapterId ~= role.advElChapter then return end -- 不是当前进行的章节 | |
| 100 | + if not isOpenEndless(role) then return end | |
| 82 | 101 | if role.dailyData:getProperty("advElC") >= role:getAdvElLimit() then return 2 end -- 是否有体力 |
| 83 | 102 | if not role:isFuncOpen(FuncOpenType.AdvEndless) or not role:isFuncOpen(FuncOpenType.AdvRelay) then return 11 end -- 开放了中继模式 和 无尽模式 才可以玩儿无尽模式 |
| 84 | 103 | local maxl = math.floor(role:getProperty("advElM") / 10) * 10 |
| ... | ... | @@ -147,7 +166,7 @@ function _M.startHangRpc(agent, data) |
| 147 | 166 | |
| 148 | 167 | if role.dailyData:getProperty("advC") >= role:getAdvHangLimit() then return end -- 是否有体力 |
| 149 | 168 | |
| 150 | - if not checkFormat(role, format, next(role:getProperty("advInfo"))) then return end --编队是否正确 | |
| 169 | + if not checkFormat(role, format, role:getAdvData():isRunning()) then return end --编队是否正确 | |
| 151 | 170 | |
| 152 | 171 | local battleV = 0 |
| 153 | 172 | for _, heroId in pairs(format.heros) do |
| ... | ... | @@ -167,7 +186,7 @@ function _M.startHangRpc(agent, data) |
| 167 | 186 | info.time = skynet.timex() + chapterData.idleTime --挂机时间 |
| 168 | 187 | |
| 169 | 188 | -- 没有在战斗 用team来挂机了 把team清掉 |
| 170 | - if not next(role:getProperty("advInfo")) then | |
| 189 | + if not role:getAdvData():isRunning() then | |
| 171 | 190 | role:updateProperty({field = "advTeam", value = {}}) |
| 172 | 191 | end |
| 173 | 192 | |
| ... | ... | @@ -248,6 +267,7 @@ function _M.finishTaskRpc(agent, data) |
| 248 | 267 | local role = agent.role |
| 249 | 268 | local msg = MsgPack.unpack(data) |
| 250 | 269 | |
| 270 | + if not isCanContinue(role) then return end | |
| 251 | 271 | local adv = role:getAdvData() |
| 252 | 272 | local taskId = msg.taskId -- -1 则是主线任务 |
| 253 | 273 | local status, reward |
| ... | ... | @@ -270,7 +290,9 @@ function _M.clickBlockRpc(agent, data) |
| 270 | 290 | local role = agent.role |
| 271 | 291 | local msg = MsgPack.unpack(data) |
| 272 | 292 | |
| 293 | + if not isCanContinue(role) then return end | |
| 273 | 294 | local adv = role:getAdvData() |
| 295 | + | |
| 274 | 296 | if adv:isWaitChooseArtifact() then return end |
| 275 | 297 | local status, errorCode = adv:clickBlock(msg.roomId, msg.blockId, msg) |
| 276 | 298 | if not status then return errorCode end |
| ... | ... | @@ -290,6 +312,7 @@ function _M.useItemRpc(agent, data) |
| 290 | 312 | local itemData = csvdb["adv_itemCsv"][itemId] |
| 291 | 313 | if not itemData then return end |
| 292 | 314 | |
| 315 | + if not isCanContinue(role) then return end | |
| 293 | 316 | local adv = role:getAdvData() |
| 294 | 317 | if adv:isWaitChooseArtifact() then return end |
| 295 | 318 | --重置数量 |
| ... | ... | @@ -337,7 +360,8 @@ function _M.usePotionRpc(agent, data) |
| 337 | 360 | local potionBag = role:getProperty("potionBag") |
| 338 | 361 | local own = potionBag[potionId] or 0 |
| 339 | 362 | if own <= 0 then return 4 end |
| 340 | - | |
| 363 | + | |
| 364 | + if not isCanContinue(role) then return end | |
| 341 | 365 | local adv = role:getAdvData() |
| 342 | 366 | if adv:isWaitChooseArtifact() then return end |
| 343 | 367 | |
| ... | ... | @@ -359,8 +383,10 @@ end |
| 359 | 383 | function _M.chooseArtifactRpc(agent, data) |
| 360 | 384 | local role = agent.role |
| 361 | 385 | local msg = MsgPack.unpack(data) |
| 362 | - local adv = role:getAdvData() | |
| 363 | 386 | |
| 387 | + if not isCanContinue(role) then return end | |
| 388 | + | |
| 389 | + local adv = role:getAdvData() | |
| 364 | 390 | if not msg.idx then return end |
| 365 | 391 | if not adv:isWaitChooseArtifact() then return end |
| 366 | 392 | local status = adv:chooseArtifact(msg.idx) |
| ... | ... | @@ -378,6 +404,8 @@ function _M.wearArtifactRpc(agent, data) |
| 378 | 404 | local slot = msg.slot |
| 379 | 405 | local id = msg.id |
| 380 | 406 | |
| 407 | + if not isCanContinue(role) then return end | |
| 408 | + | |
| 381 | 409 | local adv = role:getAdvData() |
| 382 | 410 | |
| 383 | 411 | if math.illegalNum(slot, 1, 5) then return 1 end |
| ... | ... | @@ -398,6 +426,8 @@ function _M.upArtifactRpc(agent, data) |
| 398 | 426 | local msg = MsgPack.unpack(data) |
| 399 | 427 | local id = msg.id |
| 400 | 428 | |
| 429 | + if not isCanContinue(role) then return end | |
| 430 | + | |
| 401 | 431 | local adv = role:getAdvData() |
| 402 | 432 | if adv:isWaitChooseArtifact() then return 1 end |
| 403 | 433 | local curLevel = adv:isHaveArtifact(id) |
| ... | ... | @@ -421,6 +451,8 @@ end |
| 421 | 451 | function _M.exitAdvRpc(agent, data) |
| 422 | 452 | local role = agent.role |
| 423 | 453 | -- local msg = MsgPack.unpack(data) |
| 454 | + if not isCanContinue(role) then return end | |
| 455 | + | |
| 424 | 456 | local adv = role:getAdvData() |
| 425 | 457 | local status = adv:exit() -- target {roomId = 1, blockId = 1} 选择的目标 |
| 426 | 458 | SendPacket(actionCodes.Adv_exitAdvRpc, MsgPack.pack({events = adv:popBackEvents()})) |
| ... | ... | @@ -438,8 +470,10 @@ function _M.startBattleRpc(agent, data) |
| 438 | 470 | local monsterId = msg.monsterId |
| 439 | 471 | local enemyId = msg.enemyId |
| 440 | 472 | if not enemyId then return end |
| 473 | + if not isCanContinue(role) then return end | |
| 441 | 474 | |
| 442 | 475 | local adv = role:getAdvData() |
| 476 | + | |
| 443 | 477 | if adv:isWaitChooseArtifact() then return end |
| 444 | 478 | local enemy = adv.battle:getEnemyById(enemyId) |
| 445 | 479 | |
| ... | ... | @@ -467,6 +501,8 @@ function _M.endBattleRpc(agent, data) |
| 467 | 501 | local bySkill = msg.bySkill --死于 技能 |
| 468 | 502 | |
| 469 | 503 | if not player or not player.hp or not player.sp or not enemyId or not key then return end |
| 504 | + if not isCanContinue(role) then return end | |
| 505 | + | |
| 470 | 506 | local adv = role:getAdvData() |
| 471 | 507 | if adv:isWaitChooseArtifact() then return end |
| 472 | 508 | -- 校验 |
| ... | ... | @@ -597,7 +633,7 @@ function _M.finishAchievRpc(agent, data) |
| 597 | 633 | local taskId = msg.taskId -- 领取id |
| 598 | 634 | |
| 599 | 635 | local adv = role:getAdvData() |
| 600 | - | |
| 636 | + | |
| 601 | 637 | local status, reward |
| 602 | 638 | -- if ctype == 1 then |
| 603 | 639 | -- status = adv:finishAchievement(chapterId, taskId) |
| ... | ... | @@ -610,5 +646,40 @@ function _M.finishAchievRpc(agent, data) |
| 610 | 646 | return true |
| 611 | 647 | end |
| 612 | 648 | |
| 649 | +function _M.rankRpc(agent, data) | |
| 650 | + local role = agent.role | |
| 651 | + | |
| 652 | + local list = {} | |
| 653 | + local ids = redisproxy:zrevrange(RANK_ADV, 0 , 99) | |
| 654 | + local redret = {} | |
| 655 | + if ids and next(ids) then | |
| 656 | + redret = redisproxy:pipelining(function (red) | |
| 657 | + for i = 1, #ids do | |
| 658 | + local roleId = ids[i] | |
| 659 | + table.insert(list, {roleId = tonumber(roleId)}) | |
| 660 | + red:hget(RANK_ADV_INFO, roleId) | |
| 661 | + end | |
| 662 | + end) | |
| 663 | + end | |
| 664 | + for i = 1, #redret do | |
| 665 | + local player = MsgPack.unpack(redret[i]) | |
| 666 | + player.format = nil | |
| 667 | + list[i].player = player | |
| 668 | + end | |
| 669 | + local redret = redisproxy:pipelining(function(red) | |
| 670 | + red:ZREVRANK(RANK_ADV, role:getProperty("id")) | |
| 671 | + red:zscore(RANK_ADV, role:getProperty("id")) | |
| 672 | + end) | |
| 673 | + local rank = redret[1] | |
| 674 | + if not rank then | |
| 675 | + rank = -1 | |
| 676 | + else | |
| 677 | + rank = redret[1] + 1 | |
| 678 | + end | |
| 679 | + local score = tonum(redret[2], 0) | |
| 680 | + | |
| 681 | + SendPacket(actionCodes.Adv_rankRpc, MsgPack.pack({list = list, rank = rank, score = score})) | |
| 682 | + return true | |
| 683 | +end | |
| 613 | 684 | |
| 614 | 685 | return _M |
| 615 | 686 | \ No newline at end of file | ... | ... |
src/actions/GmAction.lua
| ... | ... | @@ -204,13 +204,7 @@ end |
| 204 | 204 | |
| 205 | 205 | table.insert(helpDes, {"冒险清除" , "advc"}) |
| 206 | 206 | function _M.advc(role, pms) |
| 207 | - role:updateProperty({field = "advInfo", value = {}}) | |
| 208 | - role:updateProperty({field = "advTask", value = {}}) | |
| 209 | - role:updateProperty({field = "advItems", value = ""}) | |
| 210 | - role:updateProperty({field = "advTeam", value = {}}) | |
| 211 | - role:updateProperty({field = "advAFGet", value = {}}) | |
| 212 | - role:updateProperty({field = "advAFWear", value = {}}) | |
| 213 | - role.advData = nil | |
| 207 | + role:getAdvData():forceOver() | |
| 214 | 208 | return "成功" |
| 215 | 209 | end |
| 216 | 210 | ... | ... |
src/actions/RoleAction.lua
| ... | ... | @@ -116,7 +116,7 @@ function _M.loginRpc( agent, data ) |
| 116 | 116 | SERV_OPEN = redisproxy:hget("autoincrement_set", "server_start") |
| 117 | 117 | |
| 118 | 118 | role:changeStructVersion() -- 数据结构 版本更新 |
| 119 | - role:advEndlessSeasonCheck() -- 冒险赛季更新检查 | |
| 119 | + role:advEndlessSeasonCheck(true) -- 冒险赛季更新检查 | |
| 120 | 120 | |
| 121 | 121 | -- 跨天登陆事件 |
| 122 | 122 | role:onCrossDay(now) | ... | ... |
src/adv/Adv.lua
| ... | ... | @@ -99,9 +99,30 @@ function Adv:clear() |
| 99 | 99 | self.shopStatus = {} |
| 100 | 100 | end |
| 101 | 101 | |
| 102 | +function Adv:isRunning() | |
| 103 | + if self.chapterId then return true end | |
| 104 | + return false | |
| 105 | +end | |
| 106 | + | |
| 107 | +-- 强制结束 | |
| 108 | +function Adv:forceOver(notNotify) | |
| 109 | + if self:isRunning() then | |
| 110 | + self:clear() | |
| 111 | + local advTeam = self.owner:getProperty("advTeam") | |
| 112 | + advTeam.player = nil | |
| 113 | + self.owner:updateProperties({ | |
| 114 | + advInfo = {}, | |
| 115 | + advTeam = advTeam, | |
| 116 | + advItems = "", | |
| 117 | + advAFGet = {}, | |
| 118 | + advAFWear = {}, | |
| 119 | + }, notNotify) | |
| 120 | + end | |
| 121 | +end | |
| 122 | + | |
| 102 | 123 | function Adv:saveDB(notNotify) |
| 103 | 124 | local advInfo, advTeam = {}, self.owner:getProperty("advTeam") |
| 104 | - if self.chapterId then | |
| 125 | + if self:isRunning() then | |
| 105 | 126 | |
| 106 | 127 | advInfo.chapterId = self.chapterId |
| 107 | 128 | advInfo.level = self.level |
| ... | ... | @@ -401,14 +422,33 @@ function Adv:over(success, isAllPass) |
| 401 | 422 | self.owner:checkTaskEnter("AdvAllPass", {id = self.chapterId}) |
| 402 | 423 | end |
| 403 | 424 | |
| 425 | + local roleId = self.owner:getProperty("id") | |
| 426 | + local oldMaxScore = tonum(redisproxy:zscore(RANK_ADV, roleId)) | |
| 427 | + if score > oldMaxScore then | |
| 428 | + local team = self.owner:getProperty("advTeam") | |
| 429 | + local curInfo = { | |
| 430 | + name = self.owner:getProperty("name"), | |
| 431 | + headId = self.owner:getProperty("headId"), | |
| 432 | + lv = self.owner:getProperty("level"), | |
| 433 | + batteV = self:getTeamBattleValue(team.heros), | |
| 434 | + chapter = self.chapterId, | |
| 435 | + format = self.owner:getTeamHerosInfo(team.heros), | |
| 436 | + } | |
| 437 | + redisproxy:pipelining(function (red) | |
| 438 | + red:zadd(RANK_ADV, score, roleId) --更新分数 | |
| 439 | + red:hset(RANK_ADV_INFO, roleId, MsgPack.pack(curInfo)) | |
| 440 | + end) | |
| 441 | + end | |
| 404 | 442 | end |
| 405 | 443 | self:clearAdvUnlockCache() |
| 406 | 444 | self:clear() |
| 407 | 445 | self.owner:checkTaskEnter("AdvScore", {score = score}) |
| 408 | - self.owner:updateProperty({field = "advItems", value = ""}) | |
| 409 | - self.owner:updateProperty({field = "advAFGet", value = {}}) | |
| 410 | - self.owner:updateProperty({field = "advAFWear", value = {}}) | |
| 411 | 446 | |
| 447 | + self.owner:updateProperties({ | |
| 448 | + advItems = "", | |
| 449 | + advAFGet = {}, | |
| 450 | + advAFWear = {}, | |
| 451 | + }) | |
| 412 | 452 | self:backEnd(success, score, scoreInfo, reward) |
| 413 | 453 | end |
| 414 | 454 | ... | ... |
src/models/Role.lua
| ... | ... | @@ -21,6 +21,9 @@ function Role:ctor( properties ) |
| 21 | 21 | self.heros = {} |
| 22 | 22 | self.runeBag = {} |
| 23 | 23 | self.advData = nil |
| 24 | + | |
| 25 | + self.advElChapter = tonum(redisproxy:hget("adv_season", "chapter"), globalCsv.adv_endless_default_chapter) -- 无尽模式记录的赛季对应章节 | |
| 26 | + self.advOverTime = tonum(redisproxy:hget("adv_season", "overTime")) -- 无尽模式关闭时间戳 | |
| 24 | 27 | end |
| 25 | 28 | |
| 26 | 29 | Role.schema = { |
| ... | ... | @@ -64,7 +67,7 @@ Role.schema = { |
| 64 | 67 | advAchiev = {"table", {}}, -- 冒险成就 {chapterId = {achievId = status, -1 = pt, pts = {}}, } |
| 65 | 68 | advL = {"table", {0, 0}}, -- 冒险队等级 {lv, exp} |
| 66 | 69 | advElM = {"number", 0}, -- 无尽模式通关的最高层数 endless max layer |
| 67 | - advElS = {"number", globalCsv.adv_endless_season}, -- 无尽模式记录的赛季 endless season | |
| 70 | + advElS = {"number", 0}, -- 无尽模式记录的赛季 endless season | |
| 68 | 71 | advAFOpen = {"table", {}}, -- 解锁的神器 {[id] = 1} |
| 69 | 72 | advAFGet = {"table", {}}, -- 当前拥有的神器 {[id] = 等级} |
| 70 | 73 | advAFWear = {"table", {}}, -- 当前拥有的神器 {[slot] = id} |
| ... | ... | @@ -254,6 +257,8 @@ function Role:data() |
| 254 | 257 | advAchiev = self:getProperty("advAchiev"), |
| 255 | 258 | advL = self:getProperty("advL"), |
| 256 | 259 | advElM = self:getProperty("advElM"), |
| 260 | + advElChapter = self.advElChapter, | |
| 261 | + advOverTime = self.advOverTime, | |
| 257 | 262 | advAFGet = self:getProperty("advAFGet"), |
| 258 | 263 | advAFWear = self:getProperty("advAFWear"), |
| 259 | 264 | advDrawB = self:getProperty("advDrawB"), | ... | ... |
src/models/RolePlugin.lua
| ... | ... | @@ -772,12 +772,36 @@ function RolePlugin.bind(Role) |
| 772 | 772 | end |
| 773 | 773 | |
| 774 | 774 | -- 赛季检查 |
| 775 | - function Role:advEndlessSeasonCheck() | |
| 776 | - if self:getProperty("advElS") ~= globalCsv.adv_endless_season then | |
| 775 | + function Role:advEndlessSeasonCheck(notNotify) | |
| 776 | + -- 重置一下冒险 | |
| 777 | + local nowSeason = tonum(redisproxy:hget("adv_season", "idx")) | |
| 778 | + if self:getProperty("advElS") ~= nowSeason then | |
| 777 | 779 | local ml = self:getProperty("advElM") |
| 780 | + | |
| 778 | 781 | local nl = math.max(0, ml - (math.floor(ml / 50) + 2) * 10) |
| 779 | 782 | self:setProperty("advElM", math.floor(nl / 10) * 10) |
| 780 | - self:setProperty("advElS", globalCsv.adv_endless_season) | |
| 783 | + self:setProperty("advElS", nowSeason) | |
| 784 | + | |
| 785 | + -- 正在无尽冒险清掉 | |
| 786 | + local adv = self:getAdvData() | |
| 787 | + if adv:isRunning() and adv:isEndless() then | |
| 788 | + adv:forceOver() | |
| 789 | + end | |
| 790 | + | |
| 791 | + -- 重新设定冒险章节和冒险结束时间 | |
| 792 | + self.advElChapter = tonum(redisproxy:hget("adv_season", "chapter"), globalCsv.adv_endless_default_chapter) | |
| 793 | + self.advOverTime = tonum(redisproxy:hget("adv_season", "overTime")) | |
| 794 | + | |
| 795 | + if not notNotify then | |
| 796 | + SendPacket(actionCodes.Role_updateProperties, MsgPack.pack({ | |
| 797 | + advElChapter = self.advElChapter, | |
| 798 | + advOverTime = self.advOverTime, | |
| 799 | + })) | |
| 800 | + end | |
| 801 | + -- 清掉冒险手册 | |
| 802 | + self:updateProperties({ | |
| 803 | + advEAchiev = {}, | |
| 804 | + }, notNotify) | |
| 781 | 805 | end |
| 782 | 806 | end |
| 783 | 807 | ... | ... |
| ... | ... | @@ -0,0 +1,78 @@ |
| 1 | +from redis import Redis | |
| 2 | +import msgpack | |
| 3 | + | |
| 4 | +redisConf = { | |
| 5 | + "host" : "127.0.0.1", | |
| 6 | + "port" : 6100, | |
| 7 | + "db" : 1, | |
| 8 | + "password" : None, | |
| 9 | +} | |
| 10 | + | |
| 11 | + | |
| 12 | +def numberUnpack(n) : | |
| 13 | + if isinstance(n, bytes) : | |
| 14 | + try: | |
| 15 | + return int(n) | |
| 16 | + except ValueError: | |
| 17 | + try: | |
| 18 | + return float(n) | |
| 19 | + except ValueError: | |
| 20 | + pass | |
| 21 | + return n.decode() | |
| 22 | + else : | |
| 23 | + return n | |
| 24 | + | |
| 25 | +def stringUnpack(s) : | |
| 26 | + if isinstance(s, bytes) : | |
| 27 | + return n.decode() | |
| 28 | + else : | |
| 29 | + return s | |
| 30 | + | |
| 31 | +def tableUnpack(t) : | |
| 32 | + if isinstance(t, bytes) : | |
| 33 | + return msgpack.unpackb(t, raw = False) #解包 | |
| 34 | + else : | |
| 35 | + return t | |
| 36 | + | |
| 37 | +redisUnpack = { | |
| 38 | + "number" : numberUnpack, | |
| 39 | + "string" : stringUnpack, | |
| 40 | + "table" : tableUnpack, | |
| 41 | + "default" : numberUnpack, | |
| 42 | +} | |
| 43 | +def commonPack(w) : | |
| 44 | + return w | |
| 45 | + | |
| 46 | +def tablePack(t): | |
| 47 | + return msgpack.packb(t, use_bin_type = True) | |
| 48 | + | |
| 49 | +redisPack = { | |
| 50 | + "default" : commonPack, | |
| 51 | + "table" : tablePack, | |
| 52 | +} | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | +redis = Redis( | |
| 58 | + host = redisConf["host"], | |
| 59 | + port = redisConf["port"], | |
| 60 | + db = redisConf["db"], | |
| 61 | + password = redisConf["password"] | |
| 62 | +) | |
| 63 | + | |
| 64 | +pipe = redis.pipeline() | |
| 65 | + | |
| 66 | +def decode(w, t = "default"): | |
| 67 | + return redisUnpack[t](w) | |
| 68 | + | |
| 69 | +def encode(w, t = "default") : | |
| 70 | + return redisPack[t](w) | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | ... | ... |
src/services/dbseed.lua
| ... | ... | @@ -23,6 +23,9 @@ local function initRedisDb( ... ) |
| 23 | 23 | redisproxy:hsetnx("autoincrement_set", "email", 0) |
| 24 | 24 | redisproxy:hsetnx("autoincrement_set", "emailTimestamp", 0) |
| 25 | 25 | redisproxy:hsetnx("autoincrement_set", "delay_email", 0) |
| 26 | + redisproxy:hsetnx("adv_season", "idx", 0) | |
| 27 | + redisproxy:hsetnx("adv_season", "chapter", globalCsv.adv_endless_default_chapter) | |
| 28 | + redisproxy:hsetnx("adv_season", "overTime", 0) | |
| 26 | 29 | end |
| 27 | 30 | end |
| 28 | 31 | ... | ... |