Permalink
Browse files

Fix wrong condition in isValid

  • Loading branch information...
jkelin committed Jun 17, 2018
1 parent 5b7a5a2 commit 0fc59aad14d15ee275805003130d3bb332b948c7
Showing with 141 additions and 4 deletions.
  1. +2 −1 package.json
  2. +133 −0 scripts/test_anticheat.ts
  3. +5 −2 src/anticheat.ts
  4. +1 −1 src/types.ts
@@ -47,7 +47,8 @@
"start:web": "cross-env STATS_REPORT=false yarn start",
"start:report": "cross-env STATS_WEB=false yarn start",
"script:recalculate_identities": "ts-node scripts/recalculate_identities.ts",
"script:export_anticheat_data": "ts-node scripts/export_anticheat_data.ts"
"script:export_anticheat_data": "ts-node scripts/export_anticheat_data.ts",
"script:test_anticheat": "ts-node scripts/test_anticheat.ts"
},
"devDependencies": {
"@types/axios": "^0.14.0"
@@ -0,0 +1,133 @@
import { flatMap, groupBy, mapValues, Dictionary, pickBy, keys, values } from "lodash";
import { isValid } from "../src/anticheat";
require('dotenv').config()
const data = {
"serverreport" : "true",
"ended" : "True",
"name" : "Capture the Flag",
"timelimit" : 20,
"players" : [
{
"name" : "Mentos Aquakiss",
"ping" : 13,
"starttime" : 0,
"voice" : "QuickChatPhoenix1",
"team" : "Blood Eagle",
"score" : 6,
"kills" : 1,
"deaths" : 3,
"offense" : 1,
"defense" : 2,
"style" : 3,
"isUntracked" : true,
"killStatCTF" : 1,
"suicideStatCTF" : 2,
"StatTeamKill" : 0,
"StatHighestSpeed" : 222,
"StatDamageBlaster" : 0,
"StatDamageBuckler" : 0,
"StatDamageBurner" : 0,
"StatDamageChaingun" : 0,
"StatDamageGrenadeLauncher" : 0,
"StatDamageMortar" : 0,
"StatDamageRocketPod" : 0,
"StatDamageSpinfusor" : 172,
"statHS" : 0,
"xsExtendedStat" : 0,
"statEBMA" : 0,
"statMA" : 3,
"statMAPlus" : 0,
"statMASupreme" : 0,
"statEatDisc" : 0,
"statDistanceSpinfusor" : 117,
"statDistanceSniper" : 0,
"statPMA" : 0,
"statGLMA" : 0,
"statMMA" : 0,
"statSweetShot" : 0,
"statOMG" : 0,
"statRocketeer" : 0,
"StatDestroyGenerator" : 0,
"StatDestroySensor" : 0,
"StatRepairGenerator" : 0,
"StatRepairSensor" : 0,
"StatRepairInventory" : 0,
"StatFlagDefend" : 0,
"StatFlagAttack" : 0,
"flagPickupStat" : 1,
"StatFlagCarrierKill" : 1,
"flagCaptureStat" : 0,
"flagReturnStat" : 1
},
{
"name" : "keelei4",
"ping" : 30,
"starttime" : 0,
"voice" : "QuickChatBloodEagle1",
"team" : "Phoenix",
"score" : 5,
"kills" : 1,
"deaths" : 3,
"offense" : 1,
"defense" : 1,
"style" : 3,
"isUntracked" : true,
"killStatCTF" : 1,
"suicideStatCTF" : 2,
"StatTeamKill" : 0,
"StatHighestSpeed" : 238,
"StatDamageBlaster" : 0,
"StatDamageBuckler" : 0,
"StatDamageBurner" : 0,
"StatDamageChaingun" : 0,
"StatDamageGrenadeLauncher" : 0,
"StatDamageMortar" : 0,
"StatDamageRocketPod" : 0,
"StatDamageSpinfusor" : 131,
"statHS" : 0,
"xsExtendedStat" : 0,
"statEBMA" : 0,
"statMA" : 1,
"statMAPlus" : 2,
"statMASupreme" : 0,
"statEatDisc" : 0,
"statDistanceSpinfusor" : 0,
"statDistanceSniper" : 0,
"statPMA" : 0,
"statGLMA" : 0,
"statMMA" : 0,
"statSweetShot" : 0,
"statOMG" : 0,
"statRocketeer" : 0,
"StatDestroyGenerator" : 0,
"StatDestroySensor" : 0,
"StatRepairGenerator" : 0,
"StatRepairSensor" : 0,
"StatRepairInventory" : 0,
"StatFlagDefend" : 0,
"StatFlagAttack" : 0,
"flagPickupStat" : 3,
"StatFlagCarrierKill" : 0,
"flagCaptureStat" : 0,
"flagReturnStat" : 1
}
],
"port" : "7777"
}
async function main() {
console.warn(isValid(data.players[0], data), isValid(data.players[1], data));
}
main()
.then(() => {
console.info('All done');
process.exit(0);
})
.catch(ex => {
console.error("Fatal in main");
console.error(ex);
process.exit(1);
});
@@ -51,10 +51,13 @@ export function isValid(player: IUploadedPlayer, data: IUploadedData) {
.mapValues((diff, key) => diff / stats[key].p99) // percentage differences
.values() // percentages
.sum();
const tolerance = Math.max(0, data.players.length - 4) * 0.025; // 2.5% per player in games with more than 4 players
// console.warn({ difference });
// console.warn({ tolerance });
if (data.players.length >= 2 && difference < tolerance) {
if (data.players.length >= 2 && difference <= tolerance) {
return true;
} else {
console.log("Player stats not tracked", player.name, data);
@@ -1,5 +1,5 @@
export interface IUploadedPlayer {
ip: string;
ip?: string;
name: string;
score: number;
kills: number;

0 comments on commit 0fc59aa

Please sign in to comment.