From 17d3c920d7e254b6ca8a61bef4be794bbc07a02d Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Thu, 1 Sep 2022 18:42:15 +0700 Subject: [PATCH 1/7] fix terminal ocm ranking bug --- src/modules/terminal.ts | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index ea8e4d6..e458aaa 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -583,31 +583,10 @@ export default class TerminalModule extends Module { // Get current 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' - } - }); - - if(!(ocmEventDate)) - { - ocmEventDate = await prisma.oCMEvent.findFirst({ - where:{ - competitionId: body.competitionId - } - }); - - if(ocmEventDate) - { - console.log('Previous OCM found'); + where:{ + competitionId: body.competitionId } - } + }); // Declare GhostCompetitionSchedule let compeSch; From 59174ac2e056b9051fe09124605f09b5d900b16c Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Thu, 1 Sep 2022 21:34:14 +0700 Subject: [PATCH 2/7] clean up --- src/modules/terminal.ts | 42 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index e458aaa..8855a6c 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -169,17 +169,15 @@ export default class TerminalModule extends Module { }) // Generate the response to the terminal (success messsage) - let resp = wm.wm.protobuf.LoadBookmarksResponse.encode({ + let msg = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS - }); + }; - let end = resp.finish(); - let r = res - .header('Server', 'v388 wangan') - .header('Content-Type', 'application/x-protobuf; revision=8053') - .header('Content-Length', end.length.toString()) - .status(200); - r.send(Buffer.from(end)); + // Encode the response + let message = wm.wm.protobuf.LoadBookmarksResponse.encode(msg); + + // Send the response to the client + common.sendResponse(message, res); }) @@ -264,15 +262,11 @@ export default class TerminalModule extends Module { cars: cars } - let resp = wm.wm.protobuf.CarSummary.encode(msg); - let end = resp.finish(); - let r = res - .header('Server', 'v388 wangan') - .header('Content-Type', 'application/x-protobuf; revision=8053') - .header('Content-Length', end.length.toString()) - .status(200); - r.send(Buffer.from(end)); + // Encode the response + let message = wm.wm.protobuf.CarSummary.encode(msg); + // Send the response to the client + common.sendResponse(message, res); }) @@ -328,15 +322,11 @@ export default class TerminalModule extends Module { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, } - // Encode the save terminal result response - let resp = wm.wm.protobuf.SaveTerminalResultResponse.encode(msg); - let end = resp.finish(); - let r = res - .header('Server', 'v388 wangan') - .header('Content-Type', 'application/x-protobuf; revision=8053') - .header('Content-Length', end.length.toString()) - .status(200); - r.send(Buffer.from(end)); + // Encode the response + let message = wm.wm.protobuf.SaveTerminalResultResponse.encode(msg); + + // Send the response to the client + common.sendResponse(message, res); }) From bf568b864d869d86366b5aa81792095c5ef84d26 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Fri, 2 Sep 2022 11:47:40 +0700 Subject: [PATCH 3/7] rgStamp default to 1 --- prisma/migrations/20220902044646_rg_stamp/migration.sql | 3 +++ prisma/schema.prisma | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/20220902044646_rg_stamp/migration.sql diff --git a/prisma/migrations/20220902044646_rg_stamp/migration.sql b/prisma/migrations/20220902044646_rg_stamp/migration.sql new file mode 100644 index 0000000..2740c3d --- /dev/null +++ b/prisma/migrations/20220902044646_rg_stamp/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "Car" ALTER COLUMN "rgStamp" SET DEFAULT 1, +ALTER COLUMN "stLoseBits" SET DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 418715a..1555160 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -114,7 +114,7 @@ model Car { rgWinCount Int @default(0) rgTrophy Int @default(0) rgScore Int @default(0) - rgStamp Int @default(0) + rgStamp Int @default(1) rgAcquireAllCrowns Boolean @default(false) rgRegionMapScore Int[] stampSheetCount Int @default(0) From ab1ff0fbbd0930e262c6fc4e69e48dfe2f0ff021 Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sat, 3 Sep 2022 09:49:58 +0700 Subject: [PATCH 4/7] add timestamp --- src/index.ts | 12 ++++++++---- src/util/common.ts | 11 ++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index e31e15b..df3baad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ import { Config } from './config'; import process from 'process'; import * as Sentry from '@sentry/node'; import * as Tracing from '@sentry/tracing'; +import * as common from './util/common'; import * as dotenv from "dotenv"; dotenv.config({path: __dirname + '/.env'}); @@ -53,23 +54,26 @@ if (useSentry) { const muchaApp = express(); const allnetApp = express(); +// Get the current timestamp +let timestamp: string = common.getTimeStamp(); + if (useSentry) { app.use(Sentry.Handlers.requestHandler()); app.use(Sentry.Handlers.tracingHandler()); } app.use((req, res, next) => { - console.log(`[ MAIN] ${req.method} ${req.url}`); + console.log(timestamp+` [ MAIN] ${req.method} ${req.url}`); next() }); muchaApp.use((req, res, next) => { - console.log(`[ MUCHA] ${req.method} ${req.url}`); + console.log(timestamp+` [ MUCHA] ${req.method} ${req.url}`); next() }); allnetApp.use((req, res, next) => { - console.log(`[ALLNET] ${req.method} ${req.url}`); + console.log(timestamp+` [ALLNET] ${req.method} ${req.url}`); next() }); @@ -97,7 +101,7 @@ app.use('/', appRouter); app.use('/wmmt6/', appRouter); app.all('*', (req, res) => { - console.log(`[ MAIN] ${req.method} ${req.url} is unhandled`); + console.log(timestamp+` [ MAIN] ${req.method} ${req.url} is unhandled`); res.status(200).end(); }) diff --git a/src/util/common.ts b/src/util/common.ts index 77c19bf..35b5dd9 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -48,6 +48,15 @@ export function sanitizeInput(value: any) return (value == null || value == undefined) ? undefined : value; } -export function sanitizeInputNotZero(value: any){ + +export function sanitizeInputNotZero(value: any) +{ return (value !== null && value !== undefined && value !== 0) ? value : undefined; +} + + +export function getTimeStamp(date: Date = new Date()) +{ + // Return a timestamp string for the current / provided time + return String("[" + date.toLocaleString() + "]"); } \ No newline at end of file From 427c7539af4449acfd39b82590cf7701c15056df Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sat, 3 Sep 2022 19:37:54 +0700 Subject: [PATCH 5/7] fix terminal scratch immediately pick up car --- src/modules/cars.ts | 5 ++ src/util/terminal/check_car.ts | 150 +++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/util/terminal/check_car.ts diff --git a/src/modules/cars.ts b/src/modules/cars.ts index d58488a..0ebafe3 100644 --- a/src/modules/cars.ts +++ b/src/modules/cars.ts @@ -11,6 +11,7 @@ import * as wm from "../wmmt/wm.proto"; // Import Util import * as common from "../util/common"; import * as scratch from "../util/scratch"; +import * as terminal from "../util/terminal/check_car"; export default class CarModule extends Module { @@ -275,6 +276,7 @@ export default class CarModule extends Module { // Get the request body for the create car request let body = wm.wm.protobuf.CreateCarRequest.decode(req.body); + console.log(body); // Get the current date/time (unix epoch) let date = Math.floor(new Date().getTime() / 1000) @@ -408,6 +410,9 @@ export default class CarModule extends Module { { // Car is fully tuned tune = 2; + + // Check if created car is from terminal scratch car + await terminal.checkScratchCar(body.userId, body.car.visualModel!) } // User item not used, but car has 600 HP by default else if (body.car && diff --git a/src/util/terminal/check_car.ts b/src/util/terminal/check_car.ts new file mode 100644 index 0000000..2493c1b --- /dev/null +++ b/src/util/terminal/check_car.ts @@ -0,0 +1,150 @@ +import { prisma } from "../.."; + +// Sends the server response to the client +export async function checkScratchCar(userId: number, visualModel: number) +{ + let checkUserItem: any; + + if(visualModel === 55) // R2 + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 4 + } + }) + } + else if(visualModel === 73) // Corolla + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 3 + } + }) + } + else if(visualModel === 98) // HIACE Van + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 1 + } + }) + } + else if(visualModel === 26) // Pajero Evolution + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 2 + } + }) + } + else if(visualModel === 118) // GT-R Nismo + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 5 + } + }) + } + else if(visualModel === 119) // Z34 Nismo + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 6 + } + }) + } + else if(visualModel === 72) // Aristo Taxi + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 16 + } + }) + } + else if(visualModel === 11) // Atenza Taxi + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 17 + } + }) + } + else if(visualModel === 66) // Celsior Taxi + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 18 + } + }) + } + else if(visualModel === 75) // HIACE Wagon + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 19 + } + }) + } + else if(visualModel === 132) // GT-R Pure Edition + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 20 + } + }) + } + else if(visualModel === 129) // NSX-R + { + checkUserItem = await prisma.userItem.findMany({ + where:{ + userId: userId, + category: 201, + itemId: 21 + } + }) + } + else + { + checkUserItem = []; + } + + // Check if user item is available or not + if(checkUserItem.length > 0) + { + for(let i=0; i Date: Sun, 4 Sep 2022 08:21:02 +0700 Subject: [PATCH 6/7] update ghost stamp --- src/util/ghost/ghost_stamp.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/ghost/ghost_stamp.ts b/src/util/ghost/ghost_stamp.ts index e890c30..3025fd6 100644 --- a/src/util/ghost/ghost_stamp.ts +++ b/src/util/ghost/ghost_stamp.ts @@ -154,6 +154,7 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest where:{ carId: rgResult.opponents![i].carId, stampTargetCarId: body.carId, + recommended: true } }) @@ -212,6 +213,7 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest where:{ carId: body.carId, stampTargetCarId: rgResult.opponents![i].carId, + recommended: false } }) From 1c473e7211f398e057c7e3cdfbdba66f5390e1cb Mon Sep 17 00:00:00 2001 From: ghkkk090 Date: Sun, 4 Sep 2022 19:03:11 +0700 Subject: [PATCH 7/7] update ocm tally --- src/modules/ghost.ts | 4 ++-- src/util/ghost/ghost_ocm.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/modules/ghost.ts b/src/modules/ghost.ts index 25b19d5..fda1877 100644 --- a/src/modules/ghost.ts +++ b/src/modules/ghost.ts @@ -339,8 +339,8 @@ export default class GhostModule extends Module { { // Pick random car Id let randomNumber: number = Math.floor(Math.random() * car.length); - if(arr.indexOf(randomNumber) === -1){ - + if(arr.indexOf(randomNumber) === -1) + { // Push current number to array arr.push(randomNumber); diff --git a/src/util/ghost/ghost_ocm.ts b/src/util/ghost/ghost_ocm.ts index c3de04c..dd5bd6d 100644 --- a/src/util/ghost/ghost_ocm.ts +++ b/src/util/ghost/ghost_ocm.ts @@ -13,6 +13,7 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ { periodId = periodId - 1; + // Current day is main draw and tallying qualifying period if(periodId === 0) { console.log('Tallying data from Qualifying'); @@ -28,12 +29,14 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ result: 'desc', } }); + let arr = []; // gbRecordTally is set if(gbRecordTally) { let top1advantage = null; let currentResult = 0; + for(let i=0; i