From 4554e7935a7f1ea8cf2b747728b4a59eeb33907e Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Tue, 6 Sep 2022 19:24:34 +0700 Subject: [PATCH 01/20] remove console log --- src/modules/cars.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 8eb9a02..2ba98dd 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -588,7 +588,6 @@ export default class CarModule extends Module { // Get the request body for the update car request let body = wm.wm.protobuf.UpdateCarRequest.decode(req.body); - console.log(body); // Get the ghost result for the car let cars = body?.car; From 26f29cdf7905d5a6cc56ae6b2038d290434feaf1 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Wed, 7 Sep 2022 11:31:42 +0700 Subject: [PATCH 02/20] ghost play count retiring ocm --- src/util/games/ghost.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/games/ghost.ts b/src/util/games/ghost.ts index cb932f0..9f0cfbd 100644 --- a/src/util/games/ghost.ts +++ b/src/util/games/ghost.ts @@ -581,6 +581,21 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ } } } + + // Ghost update data + let dataGhost = { + rgPlayCount: common.sanitizeInput(body.rgResult!.rgPlayCount), + } + + // Update the car properties + await prisma.car.update({ + where: { + carId: body.carId + }, + data: { + ...dataGhost + } + }); } // Return the value to 'BASE_PATH/src/modules/game.ts' From 1d7f12411998d7b1998bca9cf65fa51e50041447 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Thu, 8 Sep 2022 22:18:29 +0700 Subject: [PATCH 03/20] api for ocm ranking (alpha) --- src/api.ts | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 22 ++++++++-- start.bat | 2 +- 3 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 src/api.ts diff --git a/src/api.ts b/src/api.ts new file mode 100644 index 0000000..f3b88c0 --- /dev/null +++ b/src/api.ts @@ -0,0 +1,112 @@ +import express, { Application } from "express"; +import { prisma } from "."; +import { Module } from "./module"; + + +export default class ApiModule extends Module { + register(app: Application): void { + app.use(express.urlencoded({ + type: '*/*', + extended: true + })); + + app.use(express.json({ + type: '*/*' + })); + + // API Get Requests + // Get Current Competition Id + app.get('/api/get_competition_id', async (req, res) => { + + // Get current date + let date = Math.floor(new Date().getTime() / 1000); + + // Message Response + let message: any = { + competitionId: 1 // default + }; + + // Get current / previous active OCM Event + let ocmEventDate = await prisma.oCMEvent.findFirst({ + where: { + // qualifyingPeriodStartAt is less than current date + qualifyingPeriodStartAt: { lte: date }, + + // competitionEndAt is greater than current date + competitionEndAt: { gte: date }, + }, + orderBy: [ + { + dbId: 'desc' + }, + { + competitionEndAt: 'desc', + }, + ], + select:{ + competitionId: true + } + }); + + if(ocmEventDate) + { + message.competitionId = ocmEventDate.competitionId; + + // Send the response to the client + res.send(message); + } + else{ + ocmEventDate = await prisma.oCMEvent.findFirst({ + orderBy: { + dbId: 'desc' + }, + select:{ + competitionId: true + } + }); + + message.competitionId = ocmEventDate!.competitionId; + + // Send the response to the client + res.send(message); + } + }); + + // Get Competition Ranking + app.get('/api/get_competition_ranking', async (req, res) => { + + // Get url query + let competitionId = Number(req.query.competitionId); + + // Message Response + let message: any = { + cars: [] + }; + + // Get all of the cars matching the query + message.cars = await prisma.oCMTally.findMany({ + where:{ + competitionId: competitionId + }, + orderBy: { + result: 'desc' + }, + include:{ + car: { + select:{ + carId: true, + name: true, + visualModel: true, + level: true, + title: true, + regionId: true, + } + } + } + }); + + // Send the response to the client + res.send(message); + }); + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index df3baad..25223b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import fs from 'fs'; import bodyParser from 'body-parser'; import AllnetModule from './allnet'; import MuchaModule from './mucha'; +import ApiModule from './api'; import { Config } from './config'; import process from 'process'; import * as Sentry from '@sentry/node'; @@ -30,8 +31,13 @@ const appRouter = Router(); const PORT_ALLNET = 80; const PORT_MUCHA = 10082; const PORT_BNGI = 9002; +const PORT_API = 9003; const app = express(); +const muchaApp = express(); +const allnetApp = express(); +const apiApp = express(); + app.use(bodyParser.raw({ type: '*/*' })); @@ -51,9 +57,6 @@ if (useSentry) { }); } -const muchaApp = express(); -const allnetApp = express(); - // Get the current timestamp let timestamp: string = common.getTimeStamp(); @@ -77,6 +80,11 @@ allnetApp.use((req, res, next) => { next() }); +apiApp.use((req, res, next) => { + console.log(timestamp+` [ API] ${req.method} ${req.url}`); + next() +}); + // Get all of the files in the modules directory let dirs = fs.readdirSync('dist/modules'); // Loop over the files @@ -108,11 +116,12 @@ app.all('*', (req, res) => { // Register the ALL.NET / Mucha Server new AllnetModule().register(allnetApp); new MuchaModule().register(muchaApp); +new ApiModule().register(apiApp); // Sentry is in use if (useSentry) { - // Use the sentry error handler + // Use the sentry error handler app.use(Sentry.Handlers.errorHandler()); } @@ -141,3 +150,8 @@ https.createServer({key, cert}, muchaApp).listen(PORT_MUCHA, '0.0.0.0', 511, () https.createServer({key, cert}, app).listen(PORT_BNGI, '0.0.0.0', 511, () => { console.log(`Game server listening on port ${PORT_BNGI}!`); }) + +// Create the API server +http.createServer(apiApp).listen(PORT_API, '0.0.0.0', 511, () => { + console.log(`API server listening on port ${PORT_API}!`); +}) diff --git a/start.bat b/start.bat index 5b15038..0d6f8f6 100644 --- a/start.bat +++ b/start.bat @@ -1,2 +1,2 @@ -yarn dev +node dist pause \ No newline at end of file From 3e90f073c333382038325cabb153b7f81ce903b4 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Thu, 8 Sep 2022 22:18:56 +0700 Subject: [PATCH 04/20] yarn dev --- start.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1e71a61584cb6975c760df4d73fd6293efce73fc Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Fri, 9 Sep 2022 09:27:22 +0700 Subject: [PATCH 05/20] api for ocm ranking (alpha) --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 25223b0..c9f84f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,10 +80,10 @@ allnetApp.use((req, res, next) => { next() }); -apiApp.use((req, res, next) => { +/*apiApp.use((req, res, next) => { console.log(timestamp+` [ API] ${req.method} ${req.url}`); next() -}); +});*/ // Get all of the files in the modules directory let dirs = fs.readdirSync('dist/modules'); From e557a428adeab4cce33209a5768729a508450e48 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Fri, 9 Sep 2022 11:42:23 +0700 Subject: [PATCH 06/20] api for ocm ranking (alpha) --- src/api.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index f3b88c0..b82e768 100644 --- a/src/api.ts +++ b/src/api.ts @@ -95,7 +95,8 @@ export default class ApiModule extends Module { car: { select:{ carId: true, - name: true, + name: true, + defaultColor: true, visualModel: true, level: true, title: true, From 0a64596ae10f63672a5b0567c155ee8ad8d10389 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Fri, 9 Sep 2022 13:35:47 +0700 Subject: [PATCH 07/20] api for ocm ranking (alpha) --- src/api.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api.ts b/src/api.ts index b82e768..33e99ad 100644 --- a/src/api.ts +++ b/src/api.ts @@ -80,7 +80,8 @@ export default class ApiModule extends Module { // Message Response let message: any = { - cars: [] + cars: [], + lastPlayedPlace: 'Bayshore' }; // Get all of the cars matching the query @@ -102,10 +103,18 @@ export default class ApiModule extends Module { title: true, regionId: true, } - } + }, } }); + let getLastPlayedPlace = await prisma.placeList.findFirst({ + where:{ + id: message.cars[0].lastPlayedPlace + } + }) + + message.lastPlayedPlace = getLastPlayedPlace?.shopName; + // Send the response to the client res.send(message); }); From 814f1882d88b8d7f33424eeaff146bb98d115e0f Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sat, 10 Sep 2022 10:47:53 +0700 Subject: [PATCH 08/20] fix ghost stamp bug --- src/modules/ghost.ts | 23 +++++++++++++++++++++-- src/modules/terminal.ts | 6 ++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index fda1877..c3bb9b7 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -110,10 +110,29 @@ export default class GhostModule extends Module { } } - // Get all of the friend cars for the carId provided + // Get all of the challenger car for the carId provided except beated car + let checkBeatedCar = await prisma.carStampTarget.findMany({ + where: { + stampTargetCarId: body.carId, + recommended: false + }, + orderBy:{ + carId: 'asc' + } + }); + + let arrChallengerCarId = []; + for(let i=0; i Date: Sat, 10 Sep 2022 10:59:45 +0700 Subject: [PATCH 09/20] Update index.ts --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c9f84f3..bb33a3a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -152,6 +152,6 @@ https.createServer({key, cert}, app).listen(PORT_BNGI, '0.0.0.0', 511, () => { }) // Create the API server -http.createServer(apiApp).listen(PORT_API, '0.0.0.0', 511, () => { +http.createServer(apiApp).listen(PORT_API, '0.0.0.0', 4369, () => { console.log(`API server listening on port ${PORT_API}!`); }) From 4f275d383f7d711696772d9d153b0adbe344ce05 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sun, 11 Sep 2022 08:21:42 +0700 Subject: [PATCH 10/20] fix give meter bug when playcount still 0 --- src/modules/game.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/game.ts b/src/modules/game.ts index 805f924..73a00ec 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -193,7 +193,7 @@ export default class GameModule extends Module { let giveMeterReward = Config.getConfig().gameOptions.giveMeterReward; // Check if this feature activated and check if user's play count is n*100 play - if(giveMeterReward === 1 && body.playCount % 100 === 0) + if(giveMeterReward === 1 && body.playCount % 100 === 0 && body.playCount !== 0) { // Calling give meter reward function (BASE_PATH/src/util/meter_reward.ts) await meter_reward.giveMeterRewards(body); From 0add6f57c9005411791ff480da9fab31d796cb9a Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sun, 11 Sep 2022 16:33:45 +0700 Subject: [PATCH 11/20] ghost level saving --- src/modules/game.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/game.ts b/src/modules/game.ts index 73a00ec..1a1d030 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -173,6 +173,7 @@ export default class GameModule extends Module { windowSticker: body.car!.windowSticker!, lastPlayedAt: timestamps, regionId: body.car!.regionId!, + ghostLevel: body.car!.ghostLevel!, rgStamp: common.sanitizeInputNotZero(body.rgResult?.rgStamp), stampSheetCount: common.sanitizeInputNotZero(body.rgResult?.stampSheetCount) } From 1f209a7cb92527b9774de2d7e1828a4b04d3c665 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sun, 11 Sep 2022 16:51:16 +0700 Subject: [PATCH 12/20] Revert "ghost level saving" This reverts commit 0add6f57c9005411791ff480da9fab31d796cb9a. --- src/modules/game.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/game.ts b/src/modules/game.ts index 1a1d030..73a00ec 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -173,7 +173,6 @@ export default class GameModule extends Module { windowSticker: body.car!.windowSticker!, lastPlayedAt: timestamps, regionId: body.car!.regionId!, - ghostLevel: body.car!.ghostLevel!, rgStamp: common.sanitizeInputNotZero(body.rgResult?.rgStamp), stampSheetCount: common.sanitizeInputNotZero(body.rgResult?.stampSheetCount) } From 1ea17a1abf9d845ac64bc09e546c8351b48d5c88 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Mon, 12 Sep 2022 12:35:50 +0700 Subject: [PATCH 13/20] hopefully fix ocm HoF --- src/api.ts | 12 ++++++------ src/modules/cars.ts | 38 +++++++++++++++++++++++++++++++++++--- src/modules/users.ts | 7 ++++++- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/src/api.ts b/src/api.ts index 33e99ad..497219b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -10,10 +10,12 @@ export default class ApiModule extends Module { extended: true })); + app.use(express.json({ type: '*/*' })); + // API Get Requests // Get Current Competition Id app.get('/api/get_competition_id', async (req, res) => { @@ -51,9 +53,6 @@ export default class ApiModule extends Module { if(ocmEventDate) { message.competitionId = ocmEventDate.competitionId; - - // Send the response to the client - res.send(message); } else{ ocmEventDate = await prisma.oCMEvent.findFirst({ @@ -66,12 +65,13 @@ export default class ApiModule extends Module { }); message.competitionId = ocmEventDate!.competitionId; - - // Send the response to the client - res.send(message); } + + // Send the response to the client + res.send(message); }); + // Get Competition Ranking app.get('/api/get_competition_ranking', async (req, res) => { diff --git a/src/modules/cars.ts b/src/modules/cars.ts index 2ba98dd..3859d44 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -37,10 +37,12 @@ export default class CarModule extends Module { }); // Error handling if ghostLevel accidentally set to 0 or more than 10 - if(car!.ghostLevel < 1){ + if(car!.ghostLevel < 1) + { car!.ghostLevel = 1; } - if(car!.ghostLevel > 11){ + if(car!.ghostLevel > 11) + { car!.ghostLevel = 10; } @@ -160,7 +162,37 @@ export default class CarModule extends Module { trailId: trailIdNo1 }); } - + else + { + ghostTrailNo1 = await prisma.oCMGhostTrail.findFirst({ + where:{ + carId: getNo1OCM.carId, + competitionId: ocmEventDate.competitionId + }, + orderBy:{ + playedAt: 'desc' + } + }); + + if(ghostTrailNo1) + { + console.log('Getting registered ghost trail from other table'); + + trailIdNo1 = ghostTrailNo1.dbId; + + ghostCarsNo1 = wm.wm.protobuf.GhostCar.create({ + car: { + ...cars!, + }, + area: ghostTrailNo1.area, + ramp: ghostTrailNo1.ramp, + path: ghostTrailNo1.path, + nonhuman: false, + type: wm.wm.protobuf.GhostType.GHOST_NORMAL, + trailId: trailIdNo1 + }); + } + } } } } diff --git a/src/modules/users.ts b/src/modules/users.ts index 036f88f..db8e421 100644 --- a/src/modules/users.ts +++ b/src/modules/users.ts @@ -487,7 +487,8 @@ export default class UserModule extends Module { { let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({ where:{ - carId: user.cars[i].carId + carId: user.cars[i].carId, + competitionId: ocmEventDate.competitionId } }); @@ -495,6 +496,10 @@ export default class UserModule extends Module { { carStates[i].hasOpponentGhost = true; } + else + { + carStates[i].hasOpponentGhost = false; + } } } } From cf4fd399f68bf11ede9034d7251744576b52c90f Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Mon, 12 Sep 2022 12:52:42 +0700 Subject: [PATCH 14/20] hopefully fix ocm HoF --- src/util/ghost/ghost_ocm.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/ghost/ghost_ocm.ts b/src/util/ghost/ghost_ocm.ts index dd5bd6d..c53a141 100644 --- a/src/util/ghost/ghost_ocm.ts +++ b/src/util/ghost/ghost_ocm.ts @@ -300,11 +300,11 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ // Get the Top 1 Advantage if(top1advantage === null) { - top1advantage = OCMTally[i].result; + top1advantage = OCMTally[0].result; let getTrail = await prisma.oCMGhostTrail.findFirst({ where:{ - carId: OCMTally[i].carId, + carId: OCMTally[0].carId, competitionId: body.competitionId, ocmMainDraw: true } From 59b890f9b2f03a99b0190fe33043d58689963ee2 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Mon, 12 Sep 2022 19:59:40 +0700 Subject: [PATCH 15/20] Update api.ts --- src/api.ts | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/api.ts b/src/api.ts index 497219b..19f4045 100644 --- a/src/api.ts +++ b/src/api.ts @@ -5,6 +5,7 @@ import { Module } from "./module"; export default class ApiModule extends Module { register(app: Application): void { + app.use(express.urlencoded({ type: '*/*', extended: true @@ -17,6 +18,69 @@ export default class ApiModule extends Module { // API Get Requests + // Get Current Bayshore Version + app.get('/api/bayshore_version', async (req, res) => { + let message: any = { + error: null, + version: null + }; + + message.version = 'v1.0.0'; + + // Send the response to the client + res.send(message); + }) + + // Post Login + app.post('/api/login', async (req, res) => { + + // Get the request body + let query = req.query; + + // Message Response + let message: any = { + error: null, + user: null + }; + + // Get the user from the database + let user = await prisma.user.findFirst({ + where: { + chipId: query.cardChipId?.toString(), + accessCode: query.accessCode?.toString() + }, + include: { + cars: { + select: { + state: true, + gtWing: true, + lastPlayedPlace: true, + carId: true, + name: true, + defaultColor: true, + visualModel: true, + level: true, + title: true, + regionId: true, + } + } + } + }); + + if(user) + { + message.user = user; + } + else + { + message.error = 404 + } + + // Send the response to the client + res.send(message); + }) + + // Get Current Competition Id app.get('/api/get_competition_id', async (req, res) => { @@ -25,6 +89,7 @@ export default class ApiModule extends Module { // Message Response let message: any = { + error: null, competitionId: 1 // default }; @@ -80,6 +145,7 @@ export default class ApiModule extends Module { // Message Response let message: any = { + error: null, cars: [], lastPlayedPlace: 'Bayshore' }; From 3eeda4020a15ad46465213ad048e96dfc1e8f597 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Tue, 13 Sep 2022 13:11:19 +0700 Subject: [PATCH 16/20] Update api.ts --- src/api.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/api.ts b/src/api.ts index 19f4045..46265ea 100644 --- a/src/api.ts +++ b/src/api.ts @@ -25,7 +25,15 @@ export default class ApiModule extends Module { version: null }; - message.version = 'v1.0.0'; + let myJSON = '{"version": "v1.0.0", "log": ['+ + '"• Fix ghost play count when retiring ocm",'+ + '"• API for ocm ranking",'+ + '"• Fix unlimited ghost stamp return (hopefully no more of this)",'+ + '"• Fix give meter reward bug if playCount still 0",'+ + '"• Hopefully fix ocm HoF bug"'+ + ']'+ + '}'; + message.version = JSON.parse(myJSON); // Send the response to the client res.send(message); @@ -173,13 +181,14 @@ export default class ApiModule extends Module { } }); - let getLastPlayedPlace = await prisma.placeList.findFirst({ + let getLastPlayedPlace = await prisma.oCMGhostBattleRecord.findFirst({ where:{ - id: message.cars[0].lastPlayedPlace + carId: message.cars[0].carId, + competitionId: competitionId } }) - message.lastPlayedPlace = getLastPlayedPlace?.shopName; + message.lastPlayedPlace = getLastPlayedPlace?.playedShopName; // Send the response to the client res.send(message); From 349248e8be5d9032e830d132528b5fbf08e99c81 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Tue, 13 Sep 2022 13:17:14 +0700 Subject: [PATCH 17/20] Update api.ts --- src/api.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index 46265ea..9e113f0 100644 --- a/src/api.ts +++ b/src/api.ts @@ -25,13 +25,16 @@ export default class ApiModule extends Module { version: null }; - let myJSON = '{"version": "v1.0.0", "log": ['+ - '"• Fix ghost play count when retiring ocm",'+ - '"• API for ocm ranking",'+ - '"• Fix unlimited ghost stamp return (hopefully no more of this)",'+ - '"• Fix give meter reward bug if playCount still 0",'+ - '"• Hopefully fix ocm HoF bug"'+ - ']'+ + let myJSON = '{'+ + '"version": "v1.0.0",'+ + '"log":'+ + '['+ + '"• Fix ghost play count when retiring ocm",'+ + '"• API for ocm ranking",'+ + '"• Fix unlimited ghost stamp return (hopefully no more of this)",'+ + '"• Fix give meter reward bug if playCount still 0",'+ + '"• Hopefully fix ocm HoF bug"'+ + ']'+ '}'; message.version = JSON.parse(myJSON); @@ -54,7 +57,9 @@ export default class ApiModule extends Module { // Get the user from the database let user = await prisma.user.findFirst({ where: { - chipId: query.cardChipId?.toString(), + chipId: { + startsWith: query.cardChipId?.toString() + }, accessCode: query.accessCode?.toString() }, include: { From cbabc2c095178f0907f6e2ec7b77bef6e1e9d31e Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Wed, 14 Sep 2022 14:52:56 +0700 Subject: [PATCH 18/20] fix duplicate id in carOrder --- src/api.ts | 1 + src/modules/game.ts | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api.ts b/src/api.ts index 9e113f0..54575f4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -34,6 +34,7 @@ export default class ApiModule extends Module { '"• Fix unlimited ghost stamp return (hopefully no more of this)",'+ '"• Fix give meter reward bug if playCount still 0",'+ '"• Hopefully fix ocm HoF bug"'+ + '"• Fix duplicate id in carOrder"'+ ']'+ '}'; message.version = JSON.parse(myJSON); diff --git a/src/modules/game.ts b/src/modules/game.ts index 73a00ec..00ce9de 100644 --- a/src/modules/game.ts +++ b/src/modules/game.ts @@ -223,16 +223,15 @@ export default class GameModule extends Module { // Get the index of the selected car let index = carOrder.indexOf(body.carId); - // If the selected car is not first - if (index > 0) - { - // Remove that index from the array - carOrder.slice(index); - - // Add it back to the front - carOrder.unshift(body.carId); + // Only splice array when item is found + if (index > -1) + { + carOrder.splice(index, 1); // 2nd parameter means remove one item only } + // Add it back to the front + carOrder.unshift(body.carId); + // Otherwise, just ignore it // Update the values From a58ce3e2e390e19beb19bde82e63a4d5de61d1c3 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Wed, 14 Sep 2022 15:22:19 +0700 Subject: [PATCH 19/20] Fix OCM HoF wrong shopName --- src/api.ts | 1 + src/modules/ghost_ocm.ts | 132 ++++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 57 deletions(-) diff --git a/src/api.ts b/src/api.ts index 54575f4..4561cf3 100644 --- a/src/api.ts +++ b/src/api.ts @@ -35,6 +35,7 @@ export default class ApiModule extends Module { '"• Fix give meter reward bug if playCount still 0",'+ '"• Hopefully fix ocm HoF bug"'+ '"• Fix duplicate id in carOrder"'+ + '"• Fix OCM HoF wrong shopName"'+ ']'+ '}'; message.version = JSON.parse(myJSON); diff --git a/src/modules/ghost_ocm.ts b/src/modules/ghost_ocm.ts index bd63c9f..4e5a226 100644 --- a/src/modules/ghost_ocm.ts +++ b/src/modules/ghost_ocm.ts @@ -432,7 +432,7 @@ export default class GhostModule extends Module { // Declare variable for Top 1 OCM Ghost let ghostCars: wm.wm.protobuf.GhostCar; let ghostTypes; - let cars: wm.wm.protobuf.ICar | (Car & { gtWing: CarGTWing; }) | null; + let cars: wm.wm.protobuf.ICar | null; let playedPlace = wm.wm.protobuf.Place.create({ placeId: Config.getConfig().placeId, regionId: Config.getConfig().regionId, @@ -607,70 +607,88 @@ export default class GhostModule extends Module { carId: checkGhostTrail!.carId }, include:{ - gtWing: true, - lastPlayedPlace: true + lastPlayedPlace: true, + gtWing: true } }); - // If regionId is 0 or not set, game will crash after defeating the ghost - if(cars!.regionId === 0) + if(cars) { - 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; - - let ocmEventDate = await prisma.oCMEvent.findFirst({ - where: { - competitionId: competition_id + // 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; } - }); - if(ocmEventDate) - { - // Creating GhostCompetitionSchedule - competitionSchedule = wm.wm.protobuf.GhostCompetitionSchedule.create({ + // Set the tunePower used when playing ghost crown + cars.tunePower = ocmTallyRecord!.tunePower; - // OCM Competition ID (1 = C1 (Round 16), 4 = Nagoya (Round 19), 8 = Hiroshima (Round 21)) - competitionId: ocmEventDate.competitionId, - - // OCM Qualifying Start Timestamp - qualifyingPeriodStartAt: ocmEventDate.qualifyingPeriodStartAt, - - // OCM Qualifying Close Timestamp - qualifyingPeriodCloseAt: ocmEventDate.qualifyingPeriodCloseAt, - - // OCM Competition (Main Draw) Start Timestamp - competitionStartAt: ocmEventDate.competitionStartAt, - - // OCM Competition (Main Draw) Close Timestamp - competitionCloseAt: ocmEventDate.competitionCloseAt, - - // OCM Competition (Main Draw) End Timestamp - competitionEndAt: ocmEventDate.competitionEndAt, - - // idk what this is - lengthOfPeriod: ocmEventDate.lengthOfPeriod, - - // idk what this is - lengthOfInterval: ocmEventDate.lengthOfInterval, - - // Area for the event (GID_RUNAREA_*, 8 is GID_RUNAREA_NAGOYA) - area: ocmEventDate.area, - - // idk what this is - minigamePatternId: ocmEventDate.minigamePatternId + // 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; + + let checkShopName = await prisma.oCMGhostBattleRecord.findFirst({ + where:{ + carId: checkGhostTrail!.carId, + competitionId: competition_id + }, + select:{ + playedShopName: true + } + }) + + if(checkShopName) + { + cars.lastPlayedPlace!.shopName = checkShopName.playedShopName; + } + + let ocmEventDate = await prisma.oCMEvent.findFirst({ + where: { + competitionId: competition_id + } }); + + if(ocmEventDate) + { + // Creating GhostCompetitionSchedule + competitionSchedule = wm.wm.protobuf.GhostCompetitionSchedule.create({ + + // OCM Competition ID (1 = C1 (Round 16), 4 = Nagoya (Round 19), 8 = Hiroshima (Round 21)) + competitionId: ocmEventDate.competitionId, + + // OCM Qualifying Start Timestamp + qualifyingPeriodStartAt: ocmEventDate.qualifyingPeriodStartAt, + + // OCM Qualifying Close Timestamp + qualifyingPeriodCloseAt: ocmEventDate.qualifyingPeriodCloseAt, + + // OCM Competition (Main Draw) Start Timestamp + competitionStartAt: ocmEventDate.competitionStartAt, + + // OCM Competition (Main Draw) Close Timestamp + competitionCloseAt: ocmEventDate.competitionCloseAt, + + // OCM Competition (Main Draw) End Timestamp + competitionEndAt: ocmEventDate.competitionEndAt, + + // idk what this is + lengthOfPeriod: ocmEventDate.lengthOfPeriod, + + // idk what this is + lengthOfInterval: ocmEventDate.lengthOfInterval, + + // Area for the event (GID_RUNAREA_*, 8 is GID_RUNAREA_NAGOYA) + area: ocmEventDate.area, + + // idk what this is + minigamePatternId: ocmEventDate.minigamePatternId + }); + } } } } From 1dbf2392e2f3847e282e0daaf6a884ed695bae09 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Wed, 14 Sep 2022 18:07:41 +0700 Subject: [PATCH 20/20] api for ocm hof --- src/api.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/api.ts b/src/api.ts index 4561cf3..279f0ce 100644 --- a/src/api.ts +++ b/src/api.ts @@ -152,6 +152,38 @@ export default class ApiModule extends Module { }); + // Get Current Competition Id + app.get('/api/get_hof_competition_id', async (req, res) => { + + // Message Response + let message: any = { + error: null, + competitionId: 1 // default + }; + + // Get current / previous active OCM Event + let ocmEventDate = await prisma.oCMTally.findFirst({ + where:{ + periodId: 999999999 + }, + orderBy: { + competitionId: 'desc' + }, + select:{ + competitionId: true + } + }); + + if(ocmEventDate) + { + message.competitionId = ocmEventDate.competitionId; + } + + // Send the response to the client + res.send(message); + }); + + // Get Competition Ranking app.get('/api/get_competition_ranking', async (req, res) => {