From e8de9fdf81a396d11c9aff5fabe2f608e8b704ad Mon Sep 17 00:00:00 2001 From: Shiroi Kitsu <108461408+shiroikitsu8@users.noreply.github.com> Date: Sun, 5 Mar 2023 14:15:42 +0700 Subject: [PATCH 1/2] limit terminal ocm ranking to 150, fix ghost search by region, prevent TA record more than 20 minutes --- src/modules/cars.ts | 2 +- src/modules/cars/functions.ts | 12 +- src/modules/game/time_attack.ts | 4 +- src/modules/ghost.ts | 4 +- src/modules/ghost/functions.ts | 230 +++++++++++++-------------- src/modules/ghost/ghost_ocm.ts | 6 +- src/modules/startup/functions.ts | 15 +- src/modules/terminal.ts | 256 +++++++++++++++++++------------ src/modules/users.ts | 4 +- 9 files changed, 304 insertions(+), 229 deletions(-) diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 50c2e83..dfbad24 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -23,7 +23,7 @@ export default class CarModule extends Module { // Get the car (required data only) with the given id let car = await carFunctions.getCar(body.carId); - // Get Challenger Data + // Get Registered HoF Data let registeredTarget = await carFunctions.getRegisteredTarget(body.carId); // Get Challenger Data diff --git a/src/modules/cars/functions.ts b/src/modules/cars/functions.ts index 5a0a440..3de7a16 100644 --- a/src/modules/cars/functions.ts +++ b/src/modules/cars/functions.ts @@ -150,12 +150,12 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable while(randomArray.length < maxNumber) { // Pick random car Id - random = Math.floor(Math.random() * opponentTargetCount + 0.9); + random = Math.floor(Math.random() * opponentTargetCount); // Try randomize it again if it's 0, and fix if more than car length if(random < 1 || random >= opponentTargetCount) { - random = Math.floor(Math.random() * opponentTargetCount + 0.9); + random = Math.floor(Math.random() * opponentTargetCount); } // Random Number not yet selected @@ -167,7 +167,7 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable } // Pick the array number - let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9); + let pickRandom = Math.floor(Math.random() * randomArray.length); random = randomArray[pickRandom]; // Check opponents target @@ -360,12 +360,12 @@ export async function createCar(body: wm.protobuf.CreateCarRequest) while(randomArray.length < 5) { // Pick random car Id - random = Math.floor(Math.random() * 47 + 0.9) + 1; + random = Math.floor(Math.random() * 47) + 1; // Try randomize it again if it's 0, and fix if more than car length if(random < 1 || random > 47) { - random = Math.floor(Math.random() * 47 + 0.9) + 1; + random = Math.floor(Math.random() * 47) + 1; } // Random Number not yet selected @@ -377,7 +377,7 @@ export async function createCar(body: wm.protobuf.CreateCarRequest) } // Pick the array number - let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9); + let pickRandom = Math.floor(Math.random() * randomArray.length); random = randomArray[pickRandom]; // Default car values diff --git a/src/modules/game/time_attack.ts b/src/modules/game/time_attack.ts index 6578e97..e90dfe3 100644 --- a/src/modules/game/time_attack.ts +++ b/src/modules/game/time_attack.ts @@ -58,8 +58,8 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque // Record already exists if (currentRecord) { - // If the existing record is faster, do not continue - if (body.taResult!.time < currentRecord.time) + // Current time record is faster than previous time record and time record is below 20 minutes + if (body.taResult!.time < currentRecord.time && body.taResult!.time < 1200000) { console.log('Updating time attack record...'); diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index 2381ff2..4906363 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -149,9 +149,9 @@ export default class GhostModule extends Module { let lists_ghostcar = getGhostCar.lists_ghostcar; // Check again if car list for that selected region is available of not - if(body.regionId !== null && body.regionId !== undefined && body.regionId !== 0) + if(body.regionId !== null && body.regionId !== undefined && body.regionId !== 0 && car.length < 1) { - let checkGhostSearchByRegion = await ghostFunctions.checkGhostSearchByRegion(car, body.ghostLevel, body.regionId); + let checkGhostSearchByRegion = await ghostFunctions.checkGhostSearchByRegion(body.ghostLevel, body.regionId); lists_ghostcar = checkGhostSearchByRegion.lists_ghostcar; } diff --git a/src/modules/ghost/functions.ts b/src/modules/ghost/functions.ts index 1bc67ba..6ebbcc1 100644 --- a/src/modules/ghost/functions.ts +++ b/src/modules/ghost/functions.ts @@ -64,7 +64,8 @@ export async function getStampTarget(carId: number) }, orderBy:{ locked: 'desc' - } + }, + take: 10 }); let stampTarget: wmproto.wm.protobuf.StampTargetCar[] = []; @@ -119,18 +120,21 @@ export async function getChallengers(carId: number) let challengers: wmproto.wm.protobuf.ChallengerCar[] = []; let arrChallengerCarId = []; + // Push beated carId to array for(let i=0; i 100) + // Participant is more than certain number (100 is default) + if(participantLength > 25) { - participantLength = 100 + participantLength = 25; } // 16th - C1 diff --git a/src/modules/startup/functions.ts b/src/modules/startup/functions.ts index 3eb11c7..950faa2 100644 --- a/src/modules/startup/functions.ts +++ b/src/modules/startup/functions.ts @@ -101,7 +101,20 @@ export async function competitionSchedule(date: any, competitionId: any) // It's previous Competition (OCM) event if(pastEvent === 1) { - lastCompetitionId = ghostCompetitionSchedule.competitionId; + // Get current date + let dates = Math.floor(new Date().getTime() / 1000); + + let lastScheduleCompetitionId = await prisma.oCMEvent.findFirst({ + where: { + competitionCloseAt: { lte: dates } + }, + orderBy:{ + competitionId: 'desc' + } + }); + + + lastCompetitionId = lastScheduleCompetitionId?.competitionId || 0; } // Competition (OCM) Response Message diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index f0e0777..358e9a9 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -635,32 +635,36 @@ export default class TerminalModule extends Module { periodId: 'desc' } ], + include:{ + car: true + }, + distinct: ["carId"], }) numOfParticipants = ocmParticipant.length; periodId = 0; let ranking = 0; + let maxNumber = 150; - if(ocmParticipant) + if(numOfParticipants < 151) { + maxNumber = numOfParticipants; + } + + if(numOfParticipants > 0) + { periodId = ocmParticipant[0].periodId; - for(let i=0; i 0) { - for(let i=0; i 0) + { + for(let i=0; i 0) { // Sort the player's car list using the car order property - user.cars = user.cars.sort(function(a, b){ - + user.cars = user.cars.sort(function(a, b) + { // User, and both car IDs exist if (user) { From 9c8b63e5bf994b278567693ba7f65da95d1cf337 Mon Sep 17 00:00:00 2001 From: Shiroi Kitsu <108461408+shiroikitsu8@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:32:13 +0700 Subject: [PATCH 2/2] fix error --- src/modules/ghost/functions.ts | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/modules/ghost/functions.ts b/src/modules/ghost/functions.ts index 6ebbcc1..6063820 100644 --- a/src/modules/ghost/functions.ts +++ b/src/modules/ghost/functions.ts @@ -15,9 +15,10 @@ export async function getOpponentHistory(carId: number) orderBy:{ lastPlayedAt: 'desc' }, - take: 10 - }) + take: 20 + }); let opponentHistory: wmproto.wm.protobuf.Car[] = []; + let inserted = 0; if(findChallenger.length > 0) { @@ -30,22 +31,28 @@ export async function getOpponentHistory(carId: number) include:{ gtWing: true, lastPlayedPlace: true - }, - orderBy: { - carId: 'asc' - }, - take: 10 + } }); - // Error handling if regionId is below 1 or above 47 - if(car!.regionId < 1 || car!.regionId > 47) + if(car) { - car!.regionId = Math.floor(Math.random() * 10) + 10; + // Error handling if regionId is below 1 or above 47 + if(car!.regionId < 1 || car!.regionId > 47) + { + car!.regionId = Math.floor(Math.random() * 10) + 10; + } + + opponentHistory.push(wmproto.wm.protobuf.Car.create({ + ...car! + })); + + inserted++; } - opponentHistory.push(wmproto.wm.protobuf.Car.create({ - ...car! - })) + if(inserted > 10) + { + break; + } } }