Commit edf2ee12a3461caaa9af524aebe7db4cf86631e9
1 parent
1c1ea691
防作弊
Showing
9 changed files
with
255 additions
and
31 deletions
Show diff stats
src/actions/ActivityAction.lua
... | ... | @@ -511,6 +511,7 @@ function _M.startBattleRpc(agent, data) |
511 | 511 | key = tostring(math.random()), |
512 | 512 | actid = actid, |
513 | 513 | id = id, |
514 | + format = msg.format, | |
514 | 515 | } |
515 | 516 | SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack({key = role.__actBattleCache.key})) |
516 | 517 | else |
... | ... | @@ -579,6 +580,18 @@ function _M.endBattleRpc(agent, data) |
579 | 580 | SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({errorCode = 1})) |
580 | 581 | end |
581 | 582 | |
583 | + -- 防作弊 | |
584 | + if not role:checkBattleCheat("act_battle", { | |
585 | + id = id, | |
586 | + isWin = isWin, | |
587 | + info = msg.info, | |
588 | + format = role.__actBattleCache.format | |
589 | + }) then | |
590 | + SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({errorCode = 1})) | |
591 | + return true | |
592 | + end | |
593 | + role.__actBattleCache = nil | |
594 | + | |
582 | 595 | local actCfg = csvdb["activity_battleCsv"][actid] |
583 | 596 | if not actCfg then return 3 end |
584 | 597 | ... | ... |
src/actions/GmAction.lua
... | ... | @@ -36,26 +36,15 @@ function _M.ban(role, pms) |
36 | 36 | local time = tonum(pms.pm1, 1) |
37 | 37 | local ctype = tonum(pms.pm2, 0) |
38 | 38 | |
39 | - local isBan = role:getProperty("banTime") <= now | |
40 | 39 | role:setBan(time, ctype) |
41 | - if time > 0 then | |
42 | - role:sendGmMsg("server_accountBanned_1") | |
43 | - local agent = datacenter.get("agent", role:getProperty("id")) | |
44 | - if agent then | |
45 | - skynet.timeout(50, function () | |
46 | - skynet.call(agent.gate_serv, "lua", "forcekick", agent.fd) | |
47 | - end) | |
48 | - end | |
49 | - end | |
50 | - | |
51 | 40 | role:mylog("gm_action", {desc = "ban", int1 = time, int2 = ctype, key1 = pms.sender}) |
52 | - | |
53 | - return isBan and "解封杀成功" or "封杀成功" | |
41 | + return "封杀成功" | |
54 | 42 | end |
55 | 43 | |
44 | + | |
56 | 45 | function _M.unban(role, pms) |
57 | 46 | role:setBan(0, 0) |
58 | - | |
47 | + role:setProperty("cheatCount", 0) -- 清除作弊次数 | |
59 | 48 | role:mylog("gm_action", {desc = "unban", key1 = pms.sender}) |
60 | 49 | |
61 | 50 | return "解封杀成功" |
... | ... | @@ -63,18 +52,17 @@ end |
63 | 52 | |
64 | 53 | function _M.gmmsg(role, pms) |
65 | 54 | role:sendGmMsg(pms.pm1, true) |
66 | - | |
67 | - local agent = datacenter.get("agent", role:getProperty("id")) | |
68 | - if agent then | |
69 | - skynet.timeout(50, function () | |
70 | - skynet.call(agent.gate_serv, "lua", "forcekick", agent.fd) | |
71 | - end) | |
72 | - end | |
73 | 55 | role:mylog("gm_action", {desc = "gmmsg", text1 = pms.pm1, key1 = pms.sender}) |
74 | - | |
75 | 56 | return "指令成功" |
76 | 57 | end |
77 | 58 | |
59 | + | |
60 | +function _M.reset_rank(role, pms) | |
61 | + role:resetRank() | |
62 | + role:mylog("gm_action", {desc = "reset_rank", key1 = pms.sender}) | |
63 | + return "封杀成功" | |
64 | +end | |
65 | + | |
78 | 66 | function _M.silent(role, pms) |
79 | 67 | local pm1 = tonum(pms.pm1) |
80 | 68 | if pm1 < 1 then | ... | ... |
src/actions/HangAction.lua
... | ... | @@ -235,6 +235,16 @@ function _M.endBattleRpc(agent, data) |
235 | 235 | return 4 |
236 | 236 | end |
237 | 237 | |
238 | + -- 防作弊 | |
239 | + if not role:checkBattleCheat("hang", { | |
240 | + id = carbonId, | |
241 | + isWin = isWin, | |
242 | + info = msg.info | |
243 | + }) then | |
244 | + SendPacket(actionCodes.Hang_endBattleRpc, MsgPack.pack({errorCode = 1})) | |
245 | + return true | |
246 | + end | |
247 | + | |
238 | 248 | local reward, change |
239 | 249 | if isWin then --win |
240 | 250 | role:hangFinish(carbonId) |
... | ... | @@ -607,6 +617,18 @@ function _M.endBonusBattleRpc(agent, data) |
607 | 617 | SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({errorCode = 1})) |
608 | 618 | return true |
609 | 619 | end |
620 | + role.__bonusBattleCache = nil | |
621 | + | |
622 | + -- 防作弊 | |
623 | + if not role:checkBattleCheat("bonus", { | |
624 | + id = id, | |
625 | + isWin = starNum and starNum > 0, | |
626 | + info = msg.info | |
627 | + }) then | |
628 | + SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({errorCode = 1})) | |
629 | + return true | |
630 | + end | |
631 | + | |
610 | 632 | local bonusData = csvdb["bonus_battleCsv"][id] |
611 | 633 | |
612 | 634 | local reward, change = {} | ... | ... |
src/actions/PvpAction.lua
... | ... | @@ -372,6 +372,16 @@ function _M.endBattleRpc(agent, data) |
372 | 372 | |
373 | 373 | if not match then return end |
374 | 374 | |
375 | + -- 防作弊 | |
376 | + if not role:checkBattleCheat("pvpc", { | |
377 | + isWin = isWin, | |
378 | + info = msg.info, | |
379 | + format = _pvpStartBattleCacheC.pvpTC, | |
380 | + }) then | |
381 | + SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({errorCode = 1})) | |
382 | + return true | |
383 | + end | |
384 | + | |
375 | 385 | local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, true) |
376 | 386 | local reward, change = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleC"}}) |
377 | 387 | local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = 0, 0, 0, 0, -1, -1 |
... | ... | @@ -652,13 +662,22 @@ function _M.endBattleHRpc(agent, data) |
652 | 662 | end |
653 | 663 | end |
654 | 664 | |
665 | + -- 防作弊 | |
666 | + if not role:checkBattleCheat("pvph", { | |
667 | + isWin = isWin, | |
668 | + info = msg.info, | |
669 | + format = _pvpStartBattleCacheH.pvpTH[#_pvpStartBattleCacheH.result] | |
670 | + }) then | |
671 | + SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({errorCode = 1})) | |
672 | + return true | |
673 | + end | |
674 | + | |
655 | 675 | if winCount >= 2 then |
656 | 676 | isWin = true |
657 | 677 | elseif loseCount >= 2 then |
658 | 678 | isWin = false |
659 | 679 | else -- 没结束 |
660 | 680 | -- 返回继续战斗 |
661 | - | |
662 | 681 | local key = tostring(math.random()) |
663 | 682 | _pvpStartBattleCacheH.key = key |
664 | 683 | local round = #_pvpStartBattleCacheH.result + 1 | ... | ... |
src/actions/TowerAction.lua
... | ... | @@ -65,6 +65,15 @@ function _M.endBattleRpc(agent, data) |
65 | 65 | local curTower = csvdb["tower_battleCsv"][id] |
66 | 66 | if not curTower then return 2 end |
67 | 67 | |
68 | + -- 防作弊 | |
69 | + if not role:checkBattleCheat("tower", { | |
70 | + isWin = msg.starNum and msg.starNum > 0, | |
71 | + info = msg.info | |
72 | + }) then | |
73 | + SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({errorCode = 1})) | |
74 | + return true | |
75 | + end | |
76 | + | |
68 | 77 | local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t) |
69 | 78 | |
70 | 79 | ... | ... |
src/models/Role.lua
... | ... | @@ -53,6 +53,7 @@ Role.schema = { |
53 | 53 | banTime = {"number", 0}, |
54 | 54 | banType = {"number", 0}, |
55 | 55 | heartWarning = {"number", 0}, |
56 | + cheatCount = {"number", 0}, | |
56 | 57 | ltime = {"number", 0}, -- 最后登录时间 |
57 | 58 | ctime = {"number", skynet.timex()}, -- 创建时间 |
58 | 59 | ignoreMt = {"number", 0}, -- 忽略维护拦截 | ... | ... |
src/models/RoleBattle.lua
... | ... | @@ -21,13 +21,153 @@ local BattleType = { |
21 | 21 | |
22 | 22 | RoleBattle.bind = function (Role) |
23 | 23 | |
24 | +local checkCheatAttrs = { | |
25 | + ["hp"] = 1, | |
26 | + ["atk"] = 1, | |
27 | + ["def"] = 1, | |
28 | + ["hit"] = 1, | |
29 | + ["miss"] = 1, | |
30 | + ["crit"] = 1, | |
31 | + ["atkSpeed"] = 1, | |
32 | + ["critHurt"] = 1, | |
33 | + -- ["vampire"] = 1, | |
34 | + -- ["pierce"] = 1, | |
35 | +} | |
24 | 36 | |
25 | --- TODO 检查战斗是否作弊 | |
26 | -local function checkBattleCheat() | |
27 | - | |
37 | +local function checkOneCheat(selfTeamClient, selfTeamServer, enemyClient, enemyServer) | |
38 | + if not selfTeamClient or type(selfTeamClient) ~= "table" then return end | |
39 | + for unitType, clientInfo in pairs(selfTeamClient) do | |
40 | + local serverInfo = selfTeamServer[unitType] | |
41 | + if not serverInfo then return end | |
42 | + for attr, pm in pairs(checkCheatAttrs) do | |
43 | + if not clientInfo[attr] then return end | |
44 | + end | |
45 | + local b1 = ((clientInfo["hp"] + clientInfo["def"] * 7 + clientInfo["miss"] * 4) * (clientInfo["atk"] * 4 + clientInfo["hit"] * 2) * (1 + clientInfo["crit"]/100 * clientInfo["critHurt"]/100) * clientInfo["atkSpeed"] / 600000) ^ 0.8 | |
46 | + local b2 = ((serverInfo["hp"] + serverInfo["def"] * 7 + serverInfo["miss"] * 4) * (serverInfo["atk"] * 4 + serverInfo["hit"] * 2) * (1 + serverInfo["crit"]/100 * serverInfo["critHurt"]/100) * serverInfo["atkSpeed"] / 600000) ^ 0.8 | |
47 | + if b1 >= b2 * 2 then | |
48 | + return | |
49 | + end | |
50 | + end | |
51 | + return true | |
28 | 52 | end |
29 | 53 | |
54 | +-- local function getRobotAttrs(info, strength) | |
55 | +-- strength = strength or 10000 | |
56 | +-- local unitData = csvdb["unitCsv"][info.unitType] | |
57 | +-- local enemy = {} | |
58 | +-- for arr, _ in pairs(checkCheatAttrs) do | |
59 | +-- enemy[arr] = unitData[attr] * info[attr] * strength / 10000 | |
60 | +-- end | |
61 | +-- return enemy | |
62 | +-- end | |
63 | + | |
64 | +-- --通过配表构建敌人队伍 通用 | |
65 | +-- function BattleEnter:packBattleEnemyCommon( carbonData ) | |
66 | +-- local enemys = {} | |
67 | +-- local monsterSet = csvdb[carbonData.monster:match("/([^/]*)$") .. "Csv"] | |
68 | +-- for phase = 1, #monsterSet do | |
69 | +-- local allEnemys = table.values(monsterSet[phase]) | |
70 | +-- table.sort(allEnemys, function(a, b) return a.id < b.id end) | |
71 | +-- local heros = {} | |
72 | +-- for idx, enemy in ipairs(allEnemys) do | |
73 | +-- local info = getRobotAttrs(enemy, carbonData.strength) | |
74 | +-- enemys[idx] = info | |
75 | +-- end | |
76 | +-- break | |
77 | +-- end | |
78 | +-- return enemys | |
79 | +-- end | |
80 | + | |
81 | +-- 检查战斗是否作弊 | |
82 | +function Role:checkBattleCheat(battleType, params) | |
83 | + if not params.isWin then return true end | |
84 | + local clientInfo = params.info or {} | |
85 | + | |
86 | + if not BattleType[battleType] then | |
87 | + print(string.format("NO find battleType: %s", battleType)) | |
88 | + return true | |
89 | + end | |
90 | + local selfTeamServer = {} | |
91 | + local enemyServer = {} | |
92 | + | |
93 | + local cheat = {} | |
94 | + cheat["hang"] = function() | |
95 | + local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.Hang)) | |
96 | + for slot, hero in pairs(team.heros) do | |
97 | + local temp = {} | |
98 | + for arr, _ in pairs(checkCheatAttrs) do | |
99 | + temp[arr] = hero[arr] | |
100 | + end | |
101 | + selfTeamServer[hero.type] = temp | |
102 | + end | |
103 | + -- local carbonData = csvdb["idle_battleCsv"][params.id] | |
104 | + -- enemyServer = packBattleEnemyCommon(carbonData) | |
105 | + end | |
106 | + cheat["tower"] = function() | |
107 | + local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.Tower)) | |
108 | + for slot, hero in pairs(team.heros) do | |
109 | + local temp = {} | |
110 | + for arr, _ in pairs(checkCheatAttrs) do | |
111 | + temp[arr] = hero[arr] | |
112 | + end | |
113 | + selfTeamServer[hero.type] = temp | |
114 | + end | |
115 | + -- local carbonData = csvdb["tower_battleCsv"][params.id] | |
116 | + -- enemyServer = packBattleEnemyCommon(carbonData) | |
117 | + end | |
118 | + cheat["bonus"] = function() | |
119 | + local team = self:getTeamBattleInfo(self:getTeamFormatByType(TeamSystemType.BonusBattle)) | |
120 | + for slot, hero in pairs(team.heros) do | |
121 | + local temp = {} | |
122 | + for arr, _ in pairs(checkCheatAttrs) do | |
123 | + temp[arr] = hero[arr] | |
124 | + end | |
125 | + selfTeamServer[hero.type] = temp | |
126 | + end | |
127 | + -- local carbonData = csvdb["bonus_battleCsv"][params.id] | |
128 | + -- enemyServer = packBattleEnemyCommon(carbonData) | |
129 | + end | |
130 | + cheat["pvpc"] = function() | |
131 | + if not params.format then return end | |
132 | + local team = self:getTeamBattleInfo(params.format) | |
133 | + for slot, hero in pairs(team.heros) do | |
134 | + local temp = {} | |
135 | + for arr, _ in pairs(checkCheatAttrs) do | |
136 | + temp[arr] = hero[arr] | |
137 | + end | |
138 | + selfTeamServer[hero.type] = temp | |
139 | + end | |
140 | + end | |
141 | + cheat["pvph"] = cheat["pvpc"] | |
142 | + cheat["act_battle"] = cheat["pvpc"] | |
143 | + | |
144 | + cheat[battleType]() | |
30 | 145 | |
146 | + local status = checkOneCheat(clientInfo.selfAttr, selfTeamServer, clientInfo.enemyAttr, enemyServer) | |
147 | + if not status then | |
148 | + local cheatCount = self:getProperty("cheatCount") | |
149 | + cheatCount = cheatCount + 1 | |
150 | + self:setProperty("cheatCount", cheatCount) | |
151 | + | |
152 | + local result = {clientSelf = {}, serverSelf = {}} | |
153 | + for k , v in pairs(clientInfo.selfAttr) do | |
154 | + result.clientSelf[tostring(k)] = v | |
155 | + end | |
156 | + for k , v in pairs(selfTeamServer) do | |
157 | + result.serverSelf[tostring(k)] = v | |
158 | + end | |
159 | + result = json.encode(result) | |
160 | + self:mylog("cheat", {desc = battleType, int1 = cheatCount, text1 = result}) | |
161 | + | |
162 | + for _, v in ipairs(globalCsv.cheat_check) do | |
163 | + if cheatCount == v[1] then | |
164 | + self:setBan(v[2] / 86400, 5) | |
165 | + break | |
166 | + end | |
167 | + end | |
168 | + end | |
169 | + return status | |
170 | +end | |
31 | 171 | |
32 | 172 | function Role:checkBattle(battleType, params) |
33 | 173 | local clientInfo = params.info or {} | ... | ... |
src/models/RoleLog.lua
src/models/RolePlugin.lua
... | ... | @@ -830,7 +830,6 @@ function RolePlugin.bind(Role) |
830 | 830 | self:setProperty("heartWarning", heartWarning) |
831 | 831 | if heartWarning == 50 then |
832 | 832 | self:setBan(30, 1) --封禁 30天 |
833 | - self:sendGmMsg("server_accountBanned_inGame_1") | |
834 | 833 | return |
835 | 834 | end |
836 | 835 | if heartWarning < 50 and heartWarning % 5 == 0 then |
... | ... | @@ -843,21 +842,53 @@ function RolePlugin.bind(Role) |
843 | 842 | time = time or 0 |
844 | 843 | banType = banType or 0 |
845 | 844 | local now = skynet.timex() |
846 | - if time == 0 then | |
845 | + if time <= 0 then | |
847 | 846 | self:setProperty("banTime", 0) |
848 | 847 | self:setProperty("banType", 0) |
849 | 848 | self:setProperty("heartWarning", 0) |
850 | - | |
851 | 849 | self:mylog("role_action", {desc = "ban_rm"}) |
852 | 850 | else |
853 | - self:setProperty("banTime", now + 86400 * time) | |
851 | + self:sendGmMsg(globalCsv.ban_tips[banType] or globalCsv.ban_tips[0]) | |
852 | + print(86400 * time) | |
853 | + self:setProperty("banTime", math.ceil(now + 86400 * time)) | |
854 | 854 | self:setProperty("banType", banType) |
855 | - self:mylog("role_action", {desc = "ban", int1 = time, int2 = banType}) | |
855 | + self:resetRank() | |
856 | + self:mylog("role_action", {desc = "ban", int1 = math.ceil(time), int2 = banType}) | |
856 | 857 | end |
857 | 858 | end |
858 | 859 | |
860 | + -- 清掉所有排行榜 | |
861 | + function Role:resetRank() | |
862 | + local roleId = self:getProperty("id") | |
863 | + redisproxy:pipelining(function (red) | |
864 | + red:zrem(RANK_TOWER, roleId) | |
865 | + for _, rk in pairs(RANK_ADV) do | |
866 | + red:zrem(rk, roleId) | |
867 | + end | |
868 | + for _, rk in pairs(RANK_DINER) do | |
869 | + red:zrem(rk, roleId) | |
870 | + end | |
871 | + for _, rk in pairs(RANK_PVP_COMMON_KEY) do | |
872 | + red:zrem(rk, roleId) | |
873 | + end | |
874 | + for _, rk in pairs(RANK_PVP_HIGHT_KEY) do | |
875 | + red:zrem(rk, roleId) | |
876 | + end | |
877 | + for _, ct in pairs(RANK_TYPE) do | |
878 | + red:zrem(RANK_COMMON .. ct, roleId) | |
879 | + end | |
880 | + end) | |
881 | + end | |
882 | + | |
859 | 883 | function Role:sendGmMsg(text, isNotKey) |
860 | 884 | SendPacket(actionCodes.Sys_maintainNotice, MsgPack.pack({ body = text, iskey = not isNotKey})) |
885 | + | |
886 | + local agent = datacenter.get("agent", self:getProperty("id")) | |
887 | + if agent then | |
888 | + skynet.timeout(50, function () | |
889 | + skynet.call(agent.gate_serv, "lua", "forcekick", agent.fd) | |
890 | + end) | |
891 | + end | |
861 | 892 | end |
862 | 893 | |
863 | 894 | -- function Role:getHeroActiveRelationData(heros) | ... | ... |