From 52537d8f7bc1db8a640314aa822b824b8aeb0525 Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sat, 20 Aug 2022 18:59:28 +0700 Subject: [PATCH 1/7] ocm fix ranking --- src/modules/ghost.ts | 4 ++-- src/modules/ghost_ocm.ts | 2 +- src/util/games/ghost_ocm.ts | 2 +- start.bat | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index a46df45..f76a7b9 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -47,7 +47,7 @@ export default class GhostModule extends Module { if(cars[i].regionId === 0) { let randomRegionId = Math.floor(Math.random() * 47) + 1; - cars[i].regionId = randomRegionId; // Change car region id to 1 (Hokkaido) + cars[i].regionId = randomRegionId; } } // ---------------------- @@ -210,7 +210,7 @@ export default class GhostModule extends Module { if(car[randomNumber]!.regionId === 0) { let randomRegionId = Math.floor(Math.random() * 47) + 1; - car[randomNumber].regionId = randomRegionId; // Hokkaido + car[randomNumber].regionId = randomRegionId; } // Push user's car data without ghost trail diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index ba885c3..b0f9f92 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -2,6 +2,7 @@ import { Application } from "express"; import { Module } from "module"; import { prisma } from ".."; import { Car, CarGTWing } from "@prisma/client"; +import { Config } from "../config"; // Import Proto import * as wm from "../wmmt/wm.proto"; @@ -10,7 +11,6 @@ import * as wm from "../wmmt/wm.proto"; import * as common from "../util/common"; import * as ghost_ocm from "../util/games/ghost_ocm"; import * as ghost_ocm_area from "../util/games/games_util/ghost_ocm_area"; -import { Config } from "../config"; export default class GhostModule extends Module { diff --git a/src/util/games/ghost_ocm.ts b/src/util/games/ghost_ocm.ts index d035a54..cf0cff1 100644 --- a/src/util/games/ghost_ocm.ts +++ b/src/util/games/ghost_ocm.ts @@ -388,7 +388,7 @@ export async function ocmCompetitionDay(body: wm.protobuf.LoadGhostCompetitionIn currentRank = i + 1; isQualified = true; } - topresult.push(ocmTallyRecord[i].carId); + topresult.push(ocmTallyRecord[i].result); } // Mini game braking point diff --git a/start.bat b/start.bat index 0d6f8f6..5b15038 100644 --- a/start.bat +++ b/start.bat @@ -1,2 +1,2 @@ -node dist +yarn dev pause \ No newline at end of file From aed96ce32bc1499390cced8f1261a74d6420786d Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sat, 20 Aug 2022 19:51:58 +0700 Subject: [PATCH 2/7] ocm fix ranking --- src/util/games/ghost_ocm.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/games/ghost_ocm.ts b/src/util/games/ghost_ocm.ts index cf0cff1..50e433e 100644 --- a/src/util/games/ghost_ocm.ts +++ b/src/util/games/ghost_ocm.ts @@ -388,7 +388,10 @@ export async function ocmCompetitionDay(body: wm.protobuf.LoadGhostCompetitionIn currentRank = i + 1; isQualified = true; } - topresult.push(ocmTallyRecord[i].result); + else + { + topresult.push(ocmTallyRecord[i].result); + } } // Mini game braking point From 8d7b3909f61682c7d8d2efa78ed24df364ec5585 Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sat, 20 Aug 2022 21:44:17 +0700 Subject: [PATCH 3/7] fix if value is 0 will not update to db --- src/modules/cars.ts | 48 ++++++++++++++++++++--------------------- src/util/common.ts | 4 ++++ src/util/games/ghost.ts | 42 +++++++++++++++++++----------------- src/util/games/story.ts | 15 ++++++------- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 3b3b369..5358a9c 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -530,24 +530,24 @@ export default class CarModule extends Module { { // Car update data data = { - customColor: cars.customColor || undefined, - wheel: cars.wheel || undefined, - wheelColor: cars.wheelColor || undefined, - aero: cars.aero || undefined, - bonnet: cars.bonnet || undefined, - wing: cars.wing || undefined, - mirror: cars.mirror || undefined, - neon: cars.neon || undefined, - trunk: cars.trunk || undefined, - plate: cars.plate || undefined, - plateColor: cars.plateColor || undefined, - plateNumber: cars.plateNumber || undefined, - windowSticker: cars.windowSticker || undefined, - windowDecoration: cars.windowDecoration || undefined, - rivalMarker: cars.rivalMarker || undefined, - aura: cars.aura || undefined, - auraMotif: cars.auraMotif || undefined, - rgStamp: body?.rgStamp! || undefined, + customColor: common.sanitizeInput(cars.customColor), + wheel: common.sanitizeInput(cars.wheel), + wheelColor: common.sanitizeInput(cars.wheelColor), + aero: common.sanitizeInput(cars.aero), + bonnet: common.sanitizeInput(cars.bonnet), + wing: common.sanitizeInput(cars.wing), + mirror: common.sanitizeInput(cars.mirror), + neon: common.sanitizeInput(cars.neon), + trunk: common.sanitizeInput(cars.trunk), + plate: common.sanitizeInput(cars.plate), + plateColor: common.sanitizeInput(cars.plateColor), + plateNumber: common.sanitizeInput(cars.plateNumber), + windowSticker: common.sanitizeInput(cars.windowSticker), + windowDecoration: common.sanitizeInput(cars.windowDecoration), + rivalMarker: common.sanitizeInput(cars.rivalMarker), + aura: common.sanitizeInput(cars.aura), + auraMotif: common.sanitizeInput(cars.auraMotif), + rgStamp: common.sanitizeInput(body.rgStamp), } // Update the car info @@ -634,12 +634,12 @@ export default class CarModule extends Module { if (gtWing) { let dataGTWing : any = { - pillar: gtWing.pillar || undefined, - pillarMaterial: gtWing.pillarMaterial || undefined, - mainWing: gtWing.mainWing || undefined, - mainWingColor: gtWing.mainWingColor || undefined, - wingTip: gtWing.wingTip || undefined, - material: gtWing.material || undefined, + pillar: common.sanitizeInput(gtWing.pillar), + pillarMaterial: common.sanitizeInput(gtWing.pillarMaterial), + mainWing: common.sanitizeInput(gtWing.mainWing), + mainWingColor: common.sanitizeInput(gtWing.mainWingColor), + wingTip: common.sanitizeInput(gtWing.wingTip), + material: common.sanitizeInput(gtWing.material), } await prisma.carGTWing.update({ diff --git a/src/util/common.ts b/src/util/common.ts index ef3bdcc..db84cde 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -41,4 +41,8 @@ export function getBigIntFromLong(n: Long) // Return the finished value return Number(bigInt); +} + +export function sanitizeInput(value: any){ + return (value == null || value == undefined) ? undefined : value; } \ No newline at end of file diff --git a/src/util/games/ghost.ts b/src/util/games/ghost.ts index 7752c2c..b7f3a07 100644 --- a/src/util/games/ghost.ts +++ b/src/util/games/ghost.ts @@ -3,8 +3,10 @@ import { prisma } from "../.."; // Import Proto import { wm } from "../../wmmt/wm.proto"; import wmproto from "../../wmmt/wm.proto"; -import * as ghost_history from "../games/games_util/ghost_history"; +// Import Util +import * as common from "../../util/common"; +import * as ghost_history from "../games/games_util/ghost_history"; // Save ghost battle result export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequest, car: any) @@ -34,10 +36,10 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ { // Ghost update data dataGhost = { - rgRegionMapScore: ghostResult.rgRegionMapScore || undefined, - rgPlayCount: ghostResult.rgPlayCount || undefined, - dressupLevel: ghostResult.dressupLevel || undefined, - dressupPoint: ghostResult.dressupPoint || undefined, + rgRegionMapScore: common.sanitizeInput(ghostResult.rgRegionMapScore), + rgPlayCount: common.sanitizeInput(ghostResult.rgPlayCount), + dressupLevel: common.sanitizeInput(ghostResult.dressupLevel), + dressupPoint: common.sanitizeInput(ghostResult.dressupPoint), } } @@ -62,18 +64,18 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ // Car update data dataCar = { - wheel: cars.wheel || undefined, - wheelColor: cars.wheelColor || undefined, - aero: cars.aero || undefined, - bonnet: cars.bonnet || undefined, - wing: cars.wing || undefined, - mirror: cars.mirror || undefined, - neon: cars.neon || undefined, - trunk: cars.trunk || undefined, - plate: cars.plate || undefined, - plateColor: cars.plateColor || undefined, - plateNumber: cars.plateNumber || undefined, - ghostLevel: cars.ghostLevel || undefined, + wheel: common.sanitizeInput(cars.wheel), + wheelColor: common.sanitizeInput(cars.wheelColor), + aero: common.sanitizeInput(cars.aero), + bonnet: common.sanitizeInput(cars.bonnet), + wing: common.sanitizeInput(cars.wing), + mirror: common.sanitizeInput(cars.mirror), + neon: common.sanitizeInput(cars.neon), + trunk: common.sanitizeInput(cars.trunk), + plate: common.sanitizeInput(cars.plate), + plateColor: common.sanitizeInput(cars.plateColor), + plateNumber: common.sanitizeInput(cars.plateNumber), + ghostLevel: common.sanitizeInput(cars.ghostLevel), } } @@ -205,9 +207,9 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ // Ghost Crown update data dataCrown = { carId: carId, - playedAt: body.playedAt || undefined, - tunePower: body.car?.tunePower || undefined, - tuneHandling: body.car?.tuneHandling || undefined, + playedAt: common.sanitizeInput(body.playedAt), + tunePower: common.sanitizeInput(body.car?.tunePower), + tuneHandling: common.sanitizeInput(body.car?.tuneHandling), } // Get the area id and ramp id diff --git a/src/util/games/story.ts b/src/util/games/story.ts index df6688c..ec2ed05 100644 --- a/src/util/games/story.ts +++ b/src/util/games/story.ts @@ -23,12 +23,12 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c { // Story update data let data : any = { - stClearDivCount: storyResult.stClearDivCount || undefined, - stPlayCount: storyResult.stPlayCount || undefined, - stClearCount: storyResult.stClearCount || undefined, - stConsecutiveWins: storyResult.stConsecutiveWins || undefined, - tuningPoints: storyResult.tuningPoint || 0, - stCompleted100Episodes: storyResult.stCompleted_100Episodes || undefined, + stClearDivCount: common.sanitizeInput(storyResult.stClearDivCount), + stPlayCount: common.sanitizeInput(storyResult.stPlayCount), + stClearCount: common.sanitizeInput(storyResult.stClearCount), + stConsecutiveWins: common.sanitizeInput(storyResult.stConsecutiveWins), + tuningPoints: common.sanitizeInput(storyResult.tuningPoint), + stCompleted100Episodes: common.sanitizeInput(storyResult.stCompleted_100Episodes), } // If the current consecutive wins is greater than the previous max @@ -53,8 +53,7 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c } // Check if clearBits is not null, and not lose the story - if (storyResult.stClearBits !== null && storyResult.stClearBits !== undefined - && data.stLoseBits === 0) + if (common.sanitizeInput(storyResult.stClearBits) && data.stLoseBits === 0) { data.stClearBits = storyResult.stClearBits; } From 02646ca8269600a7c278daeee751eafb5f9c6ab9 Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sat, 20 Aug 2022 21:44:25 +0700 Subject: [PATCH 4/7] fix ocm terminal --- src/modules/ghost_ocm.ts | 93 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 6 deletions(-) diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index b0f9f92..1f4517f 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -452,6 +452,20 @@ export default class GhostModule extends Module { } }); + if(!(ocmEventDate)) + { + ocmEventDate = await prisma.oCMEvent.findFirst({ + orderBy: [ + { + dbId: 'desc' + }, + { + competitionEndAt: 'desc', + }, + ], + }); + } + // Declare variable for Top 1 OCM Ghost let ghostCars: wm.wm.protobuf.GhostCar; let ghostTypes; @@ -468,10 +482,9 @@ export default class GhostModule extends Module { // Current date is OCM main draw if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date) - { + { console.log('OCM Competition Day / Main Draw'); - // --- Tally (still not complete) --- // Get Top 1 qualifying car data let ocmTallyRecord = await prisma.oCMTop1Ghost.findFirst({ where:{ @@ -487,6 +500,8 @@ export default class GhostModule extends Module { let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({ where:{ carId: ocmTallyRecord!.carId, + competitionId: ocmEventDate!.competitionId, + periodId: period_id, area: areaVal, ramp: rampVal, path: pathVal, @@ -495,7 +510,6 @@ export default class GhostModule extends Module { playedAt: 'desc' }, }); - // ---------------------------------- // Top 1 OCM Ghost trail data available if(checkGhostTrail) @@ -537,11 +551,12 @@ export default class GhostModule extends Module { // Get the default ghost trail let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({ where:{ + carId: 999999999, + competitionId: ocmEventDate!.competitionId, + periodId: 0, area: areaVal, ramp: rampVal, - path: pathVal, - competitionId: ocmEventDate!.competitionId, - periodId: 0 + path: pathVal }, orderBy:{ playedAt: 'desc' @@ -586,6 +601,72 @@ export default class GhostModule extends Module { ghostTrailId = checkGhostTrail!.dbId!; ghostTypes = wm.wm.protobuf.GhostType.GHOST_NORMAL; } + else if(ocmEventDate!.competitionCloseAt < date && ocmEventDate!.competitionEndAt > date) + { + // TODO: IDK + } + else + { + console.log('OCM has ended'); + + // Get Top 1 qualifying car data + let ocmTallyRecord = await prisma.oCMTop1Ghost.findFirst({ + where:{ + competitionId: competition_id, + periodId: 999999999 + }, + orderBy:{ + result: 'desc' + }, + }); + + // Get Top 1 qualifying ghost trail id + let checkGhostTrail = await prisma.oCMTop1GhostTrail.findFirst({ + where:{ + carId: ocmTallyRecord!.carId, + competitionId: ocmEventDate!.competitionId, + periodId: 999999999, + area: areaVal, + ramp: rampVal, + path: pathVal, + }, + orderBy:{ + playedAt: 'desc' + }, + }); + + // Top 1 OCM Ghost trail data available + if(checkGhostTrail) + { + // Get the Top 1 OCM car data + cars = await prisma.car.findFirst({ + where:{ + carId: checkGhostTrail!.carId + }, + include:{ + gtWing: true + } + }); + + // If regionId is 0 or not set, game will crash after defeating the ghost + if(cars!.regionId === 0) + { + let randomRegionId = Math.floor(Math.random() * 47) + 1; + cars!.regionId = randomRegionId; + } + + // Set the tunePower used when playing ghost crown + cars!.tunePower = ocmTallyRecord!.tunePower; + + // Set the tuneHandling used when playing ghost crown + cars!.tuneHandling = ocmTallyRecord!.tuneHandling; + + // Set Ghost stuff Value + cars!.lastPlayedAt = checkGhostTrail.playedAt + ghostTrailId = checkGhostTrail.dbId!; + ghostTypes = wm.wm.protobuf.GhostType.GHOST_NORMAL; + } + } // Push the Top 1 OCM ghost car data ghostCars = wm.wm.protobuf.GhostCar.create({ From b5f5ea471ad3b1af3c620db74a336506f600031e Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sun, 21 Aug 2022 08:12:03 +0700 Subject: [PATCH 5/7] ocm --- src/modules/users.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/modules/users.ts b/src/modules/users.ts index 9b5436b..351b54d 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -356,15 +356,8 @@ export default class UserModule extends Module { for(let j=0; j Date: Sun, 21 Aug 2022 08:18:46 +0700 Subject: [PATCH 6/7] ocm --- src/modules/ghost_ocm.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index 1f4517f..72fea83 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -122,7 +122,7 @@ export default class GhostModule extends Module { } // Current date is OCM main draw - if(ocmEventDate!.competitionStartAt <= date && ocmEventDate!.competitionCloseAt >= date) + if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date) { console.log('Current OCM Day : Competition Day / Main Draw'); From 1a80cf15e7cdd172755b2c3fad574494b5f04d4b Mon Sep 17 00:00:00 2001 From: ghkkk090 <108461408+ghkkk090@users.noreply.github.com> Date: Sun, 21 Aug 2022 18:30:16 +0700 Subject: [PATCH 7/7] fix ghost crash --- src/util/games/games_util/ghost_history.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/games/games_util/ghost_history.ts b/src/util/games/games_util/ghost_history.ts index 7853aa4..d841b72 100644 --- a/src/util/games/games_util/ghost_history.ts +++ b/src/util/games/games_util/ghost_history.ts @@ -9,6 +9,7 @@ export async function saveGhostHistory(body: wm.protobuf.SaveGameResultRequest) { console.log('Saving Ghost Battle History'); + let updateNewTrail: boolean = true; let saveExGhostHistory: any = {}; if (body.car?.carId !== null && body.car?.carId !== undefined) { @@ -132,6 +133,9 @@ export async function saveGhostHistory(body: wm.protobuf.SaveGameResultRequest) await prisma.ghostBattleRecord.create({ data: saveExGhostHistory }); + + // Return the value to 'BASE_PATH/src/util/games/ghost.ts' + return { updateNewTrail } }