1
0
mirror of synced 2024-12-04 19:17:58 +01:00

Merge pull request #53 from shiroikitsu8/master-asakura

mersenne twister, fix stamp sheet and gt wing bug, prevent cheated time from being saved
This commit is contained in:
Luna 2023-01-02 16:46:23 +00:00 committed by GitHub
commit 52a13104c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 347 additions and 238 deletions

View File

@ -31,7 +31,8 @@
"@sentry/node": "^7.7.0",
"@sentry/tracing": "^7.7.0",
"@types/pem": "^1.9.6",
"body-parser": "^1.20.0",
"body-parser": "^1.20.1",
"chancer": "^2.0.2",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"form-urlencoded": "^6.0.6",

View File

@ -4,6 +4,7 @@ import { Module } from "module";
import { prisma } from "..";
import { User } from "@prisma/client";
import Long from "long";
let MersenneTwister = require('chancer');
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -49,9 +50,6 @@ export default class CarModule extends Module {
// Convert the database lose bits to a Long
let longLoseBits = Long.fromString(car!.stLoseBits.toString());
// Get current date
let date = Math.floor(new Date().getTime() / 1000);
// Get Registered Target
let getTarget = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
@ -61,6 +59,7 @@ export default class CarModule extends Module {
let opponentGhost;
let opponentTrailId;
let opponentCompetitionId;
let registeredTarget: boolean = false;
if(getTarget)
{
@ -104,84 +103,94 @@ export default class CarModule extends Module {
opponentTrailId = Number(getTargetTrail!.dbId);
opponentCompetitionId = Number(getTarget.competitionId);
}
registeredTarget = true;
}
// Check opponents target
let opponentTargetCount = await prisma.carStampTarget.count({
where:{
stampTargetCarId: body.carId,
recommended: true,
},
orderBy:{
locked: 'desc'
}
})
let carsChallengers;
let returnCount = 1;
if(opponentTargetCount > 0)
// Check opponents stamp target
// Will skip this if user's have Hall of Fame ghost registered
let carsChallengers;
let returnCount = 0;
let opponentTargetCount = 0;
if(registeredTarget === false)
{
console.log('Challengers Available');
// Randomize pick
let random: number = Math.floor(Math.random() * opponentTargetCount);
// Check opponents target
let opponentTarget = await prisma.carStampTarget.findMany({
opponentTargetCount = await prisma.carStampTarget.count({
where:{
stampTargetCarId: body.carId,
recommended: true,
},
orderBy:{
locked: 'desc'
},
skip: random,
take: 1,
});
}
})
returnCount = 1;
// Get all of the friend cars for the carId provided
let challengers = await prisma.carChallenger.findFirst({
where: {
challengerCarId: opponentTarget[0].carId,
carId: body.carId
},
orderBy:{
id: 'desc'
}
});
if(challengers)
if(opponentTargetCount > 0)
{
returnCount = opponentTarget[0].returnCount;
console.log('Challengers Available');
let carTarget = await prisma.car.findFirst({
// Randomize pick
let random: number = MersenneTwister.int(0, opponentTargetCount);
// Check opponents target
let opponentTarget = await prisma.carStampTarget.findMany({
where:{
carId: challengers.challengerCarId
stampTargetCarId: body.carId,
recommended: true,
},
include:{
gtWing: true,
lastPlayedPlace: true
}
})
let result = 0;
if(challengers.result > 0)
{
result = -Math.abs(challengers.result);
}
else{
result = Math.abs(challengers.result);
}
carsChallengers = wm.wm.protobuf.ChallengerCar.create({
car: carTarget!,
stamp: challengers.stamp,
result: result,
area: challengers.area
orderBy:{
locked: 'desc'
},
skip: random,
take: 1,
});
// Get all of the friend cars for the carId provided
let challengers = await prisma.carChallenger.findFirst({
where: {
challengerCarId: opponentTarget[0].carId,
carId: body.carId
},
orderBy:{
id: 'desc'
}
});
if(challengers)
{
returnCount = opponentTarget[0].returnCount;
let carTarget = await prisma.car.findFirst({
where:{
carId: challengers.challengerCarId
},
include:{
gtWing: true,
lastPlayedPlace: true
}
})
let result = 0;
if(challengers.result > 0)
{
result = -Math.abs(challengers.result);
}
else{
result = Math.abs(challengers.result);
}
carsChallengers = wm.wm.protobuf.ChallengerCar.create({
car: carTarget!,
stamp: challengers.stamp,
result: result,
area: challengers.area
});
}
}
}
// Response data
let msg = {
@ -391,11 +400,8 @@ export default class CarModule extends Module {
}
// Randomize regionId
let randomRegionId: number = 18;
for(let i=0; i<5; i++)
{
randomRegionId = Math.floor(Math.random() * 47) + 1;
}
let regionId: number = 18;
regionId = MersenneTwister.int(1, 47);
// Default car values
let carInsert = {
@ -412,7 +418,7 @@ export default class CarModule extends Module {
carSettingsDbId: settings.dbId,
carStateDbId: state.dbId,
carGTWingDbId: gtWing.dbId,
regionId: randomRegionId,
regionId: regionId,
lastPlayedAt: date,
lastPlayedPlaceId: 1, // Server Default
};

View File

@ -1,7 +1,8 @@
import e, { Application } from "express";
import { Application } from "express";
import { Module } from "../module";
import { prisma } from "..";
import { Config } from "../config";
let MersenneTwister = require('chancer');
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -138,8 +139,7 @@ export default class GameModule extends Module {
// Check region id is 0
if(body.car!.regionId! === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
body.car!.regionId = randomRegionId;
body.car!.regionId = MersenneTwister.int(1, 47);
}
// Check playet at timestamp
@ -256,7 +256,7 @@ export default class GameModule extends Module {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
// Set session for saving ghost trail Ghost Battle Mode or Crown Ghost Battle Mode
ghostSessionId: Math.floor(Math.random() * 100) + 1
ghostSessionId: MersenneTwister.int(1, 100)
}
}
// OCM Battle game mode is completed
@ -266,7 +266,7 @@ export default class GameModule extends Module {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
// Set session for saving ghost trail OCM Ghost Battle Mode
ghostSessionId: Math.floor(Math.random() * 100) + 101
ghostSessionId: MersenneTwister.int(101, 200)
}
}
// Story mode or TA mode is completed
@ -438,8 +438,7 @@ export default class GameModule extends Module {
if(ghostOpponentCar!.regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
ghostOpponentCar!.regionId = randomRegionId;
ghostOpponentCar!.regionId = MersenneTwister.int(1, 47);
}
// Get Opponent 1 tune
@ -481,8 +480,7 @@ export default class GameModule extends Module {
if(ghostOpponentCar!.regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
ghostOpponentCar2!.regionId = randomRegionId;
ghostOpponentCar2!.regionId = MersenneTwister.int(1, 47);
}
// Get Opponent 2 tune
@ -521,8 +519,7 @@ export default class GameModule extends Module {
if(ghostOpponentCar!.regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
ghostOpponentCar3!.regionId = randomRegionId;
ghostOpponentCar3!.regionId = MersenneTwister.int(1, 47);
}
// Get Opponent 3 tune

View File

@ -4,6 +4,7 @@ import { prisma } from "..";
import { CarPathandTuning } from "@prisma/client";
import Long from "long";
import { Config } from "../config";
let MersenneTwister = require('chancer');
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -357,7 +358,7 @@ export default class GhostModule extends Module {
while(arr.length < maxNumber)
{
// Pick random car Id
let randomNumber: number = Math.floor(Math.random() * car.length);
let randomNumber = MersenneTwister.int(0, maxNumber-1);
if(arr.indexOf(randomNumber) === -1)
{
// Push current number to array
@ -377,9 +378,8 @@ export default class GhostModule extends Module {
// If regionId is 0 or not set, game will crash after defeating the ghost
if(car[randomNumber]!.regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
car[randomNumber].regionId = randomRegionId;
{
car[randomNumber].regionId = MersenneTwister.int(1, 47);
}
// Push user's car data without ghost trail

View File

@ -1,8 +1,8 @@
import { Application } from "express";
import { Module } from "module";
import { prisma } from "..";
import { Car, CarGTWing } from "@prisma/client";
import { Config } from "../config";
let MersenneTwister = require('chancer');
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -423,7 +423,7 @@ export default class GhostModule extends Module {
ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: [
{
competitionId: 'desc'
dbId: 'desc'
},
],
});
@ -492,8 +492,7 @@ export default class GhostModule extends Module {
// 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;
cars!.regionId = MersenneTwister.int(1, 47);
}
// Set the tunePower used when playing ghost crown
@ -615,8 +614,7 @@ export default class GhostModule extends Module {
// 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;
cars!.regionId = MersenneTwister.int(1, 47);
}
// Set the tunePower used when playing ghost crown
@ -647,7 +645,7 @@ export default class GhostModule extends Module {
let ocmEventDate = await prisma.oCMEvent.findFirst({
where: {
where:{
competitionId: competition_id
}
});
@ -706,7 +704,6 @@ export default class GhostModule extends Module {
let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
competitionId: competition_id,
specialGhostId: competition_id,
ghostCar: ghostCars!,
trailId: ghostTrailId,
updatedAt: date,

View File

@ -1,7 +1,9 @@
import { Application } from "express";
import {Module} from "module";
import e, { Application } from "express";
import { Module } from "module";
import { Config } from "../config";
import { prisma } from "..";
import path from 'path';
let MersenneTwister = require('chancer');
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -49,22 +51,6 @@ export default class ResourceModule extends Module {
}
})
}
else
{
if(checkPlaceList.shopName !== Config.getConfig().shopName)
{
await prisma.placeList.update({
where:{
id: checkPlaceList.id
},
data:{
regionId: Number(Config.getConfig().placeId),
shopName: Config.getConfig().shopName,
country: Config.getConfig().country
}
})
}
}
// Encode the response
let message = wm.wm.protobuf.PlaceList.encode({places});
@ -147,8 +133,8 @@ export default class ResourceModule extends Module {
result: resultTime,
name: '',
regionId: 1, // Hokkaido
model: Math.floor(Math.random() * 50), // Randomizing Car data
visualModel: Math.floor(Math.random() * 100), // Randomizing Car data
model: MersenneTwister.int(0, 50), // Randomizing Car data
visualModel: MersenneTwister.int(0, 100), // Randomizing Car data
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -185,8 +171,8 @@ export default class ResourceModule extends Module {
result: resulttime,
name: '',
regionId: 1, // Hokkaido
model: Math.floor(Math.random() * 50), // Randomizing Car data
visualModel: Math.floor(Math.random() * 100), // Randomizing Car data
model: MersenneTwister.int(0, 50), // Randomizing Car data
visualModel: MersenneTwister.int(0, 100), // Randomizing Car data
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -249,8 +235,8 @@ export default class ResourceModule extends Module {
result: 0,
name: '',
regionId: 1, // Hokkaido
model: Math.floor(Math.random() * 50), // Randomizing Car data
visualModel: Math.floor(Math.random() * 100), // Randomizing Car data
model: MersenneTwister.int(0, 50), // Randomizing Car data
visualModel: MersenneTwister.int(0, 100), // Randomizing Car data
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -312,8 +298,8 @@ export default class ResourceModule extends Module {
result: 0,
name: '',
regionId: 1, // Hokkaido
model: Math.floor(Math.random() * 50), // Randomizing Car data
visualModel: Math.floor(Math.random() * 100), // Randomizing Car data
model: MersenneTwister.int(0, 50), // Randomizing Car data
visualModel: MersenneTwister.int(0, 100), // Randomizing Car data
defaultColor: 0,
tunePower: 0,
tuneHandling: 0,
@ -415,7 +401,6 @@ export default class ResourceModule extends Module {
car: car!
});
// Push it after Kobe
list_crown.splice(11, 0, listCrown);
}
// GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
@ -448,7 +433,6 @@ export default class ResourceModule extends Module {
unlockAt: 0,
});
// Push it after Kobe
list_crown.splice(11, 0, listCrown);
}
// GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE
@ -498,7 +482,7 @@ export default class ResourceModule extends Module {
}));
}
}
}
}
// Response data
let msg = {
@ -512,18 +496,35 @@ export default class ResourceModule extends Module {
common.sendResponse(message, res);
})
app.use("/static", e.static(
path.join(__dirname, '..', '..', 'static'),
{ cacheControl: false }
));
app.get('/resource/file_list', async (req, res) => {
console.log('file_list');
// TODO: Actual stuff here
// This is literally just bare-bones so the shit boots
let files: wm.wm.protobuf.FileList.FileInfo[] = [];
files.push(wm.wm.protobuf.FileList.FileInfo.create({
fileId: 1,
fileType: wm.wm.protobuf.FileType.FILE_PROMOTION_ANNOUNCEMENT,
fileSize: 383791,
url: 'https://'+Config.getConfig().serverIp+':9002/static/000002-bayshore.bin',
sha1sum: Buffer.from('F1A1AF6F7273F2BA5189CDB15165028B56E022E6', "hex"),
notBefore: 0,
notAfter: 2147483647,
}));
// Response data
let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
files: null,
interval: null
files: files,
interval: 2
}
// Encode the response
@ -533,6 +534,7 @@ export default class ResourceModule extends Module {
common.sendResponse(message, res);
})
app.get('/resource/ghost_list', async (req, res) => {
console.log('ghost_list');

View File

@ -1,5 +1,5 @@
import { Application } from "express";
import {Module} from "module";
import { Module } from "module";
import { prisma } from "..";
// Import Proto

View File

@ -3,6 +3,7 @@ import { Config } from "../config";
import { Module } from "module";
import { prisma } from "..";
import { Car } from "@prisma/client";
let MersenneTwister = require('chancer');
// Import Proto
import * as wm from "../wmmt/wm.proto";
@ -252,8 +253,7 @@ export default class TerminalModule extends Module {
{
if(cars[i].regionId === 0)
{
let randomRegionId = Math.floor(Math.random() * 47) + 1;
cars[i].regionId = randomRegionId;
cars[i].regionId = MersenneTwister.int(1, 47);
}
}
@ -900,52 +900,66 @@ export default class TerminalModule extends Module {
common.sendResponse(message, res);
})
// Recieve user items
// Register Opponent Ghost
app.post('/method/register_opponent_ghost', async (req, res) => {
// Get the information from the request
let body = wm.wm.protobuf.RegisterOpponentGhostRequest.decode(req.body);
// Check if target is already registered
let checkOpponent = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
carId: body.carId,
let ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy: {
competitionEndAt: 'desc',
}
});
// Get Target Car ID
let ghostCompetitionTarget = await prisma.oCMTop1Ghost.findFirst({
where:{
competitionId: body.specialGhostId,
},
orderBy:{
periodId: 'desc'
}
});
// Target not yet registerted
if(!(checkOpponent))
if(ocmEventDate)
{
await prisma.ghostRegisteredFromTerminal.create({
data:{
carId: body.carId,
competitionId: body.specialGhostId,
opponentCarId: ghostCompetitionTarget!.carId
}
});
}
else
{
await prisma.ghostRegisteredFromTerminal.update({
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
dbId: checkOpponent.dbId
},
data:{
carId: body.carId,
competitionId: body.specialGhostId,
opponentCarId: ghostCompetitionTarget!.carId
carId: body.carId
}
});
let getNo1OCM = await prisma.oCMTally.findFirst({
where:{
competitionId: ocmEventDate.competitionId,
periodId: 999999999
},
orderBy:{
competitionId: 'desc'
}
});
if(!(checkRegisteredGhost))
{
await prisma.ghostRegisteredFromTerminal.create({
data:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
opponentCarId: getNo1OCM!.carId
}
});
console.log('Creating new Register Ghost Opponent entry')
}
else
{
await prisma.ghostRegisteredFromTerminal.update({
where:{
dbId: checkRegisteredGhost.dbId
},
data:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
opponentCarId: getNo1OCM!.carId
}
});
console.log('Updating Register Ghost Opponent entry')
}
}
// Response data
@ -1006,25 +1020,6 @@ export default class TerminalModule extends Module {
common.sendResponse(message, res);
});
// Save Screenshoot
app.post('/method/save_screenshot', async (req, res) => {
// Get the information from the request
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
// Response data
let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
};
// Encode the response
let message = wm.wm.protobuf.SaveScreenshotResponse.encode(msg);
// Send the response to the client
common.sendResponse(message, res);
})
/*
app.post('/method/load_unreceived_user_items', async (req, res) => {
@ -1045,6 +1040,24 @@ export default class TerminalModule extends Module {
})
app.post('/method/save_screenshot', async (req, res) => {
// Get the information from the request
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
// Response data
let msg = {
error: wmsrv.wm.protobuf.ErrorCode.ERR_SUCCESS,
};
// Encode the response
let message = wmsrv.wm.protobuf.SaveScreenshotResponse.encode(msg);
// Send the response to the client
common.sendResponse(message, res);
})
app.post('/method/check_item_receivable_cars', async (req, res) => {
// Get the information from the request
@ -1063,4 +1076,4 @@ export default class TerminalModule extends Module {
})
*/
}
}
}

View File

@ -1,4 +1,4 @@
import e, { Application } from "express";
import { Application } from "express";
import { Config } from "../config";
import { Module } from "module";
import { prisma } from "..";
@ -484,33 +484,27 @@ export default class UserModule extends Module {
if(!ocmEventDate)
{
let ocmEventDate = await prisma.oCMEvent.findFirst({
orderBy:
{
orderBy: {
competitionEndAt: 'desc',
}
});
if(ocmEventDate)
{
let pastDay = date - ocmEventDate.competitionEndAt;
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
carId: user.cars[i].carId,
competitionId: ocmEventDate.competitionId
}
});
if(pastDay < 604800)
if(checkRegisteredGhost)
{
let checkRegisteredGhost = await prisma.ghostRegisteredFromTerminal.findFirst({
where:{
carId: user.cars[i].carId,
competitionId: ocmEventDate.competitionId
}
});
if(checkRegisteredGhost)
{
carStates[i].hasOpponentGhost = true;
}
else
{
carStates[i].hasOpponentGhost = false;
}
carStates[i].hasOpponentGhost = true;
}
else
{
carStates[i].hasOpponentGhost = false;
}
}
}

View File

@ -28,6 +28,7 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
// Declare data
let dataGhost : any;
let dataCar : any;
let dataCarGTWing: any;
// Get the ghost result for the car
let cars = body?.car;
@ -63,6 +64,18 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
plateNumber: common.sanitizeInput(cars.plateNumber),
ghostLevel: common.sanitizeInput(cars.ghostLevel),
}
if(cars.gtWing)
{
dataCarGTWing = {
pillar: common.sanitizeInput(cars.gtWing.pillar),
pillarMaterial: common.sanitizeInput(cars.gtWing.pillarMaterial),
mainWing: common.sanitizeInput(cars.gtWing.mainWing),
mainWingColor: common.sanitizeInput(cars.gtWing.mainWingColor),
wingTip: common.sanitizeInput(cars.gtWing.wingTip),
material: common.sanitizeInput(cars.gtWing.material),
}
}
}
// Get the ghost result for the car
@ -72,7 +85,15 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
if (ghostResult)
{
let stampSheet: any = undefined;
if(ghostResult.stampSheet!.length > 0)
if(ghostResult.stampSheet!.length === 0)
{
if(ghostResult.stampSheetCount !== null && ghostResult.stampSheetCount !== undefined && ghostResult.stampSheetCount !== 0)
{
stampSheet = ghostResult.stampSheet;
}
}
// Stamp Sheet available
else if(ghostResult.stampSheet!.length > 0)
{
stampSheet = ghostResult.stampSheet;
}
@ -112,7 +133,8 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
},
data: {
...dataGhost,
...dataCar
...dataCar,
...dataCarGTWing,
}
});

View File

@ -7,8 +7,11 @@ import { wm } from "../../wmmt/wm.proto";
// Save time attack result
export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultRequest)
{
let cheatedTime: boolean = false;
// If the game was not retired / timed out
if (!(body.retired || body.timeup)) {
if (!(body.retired || body.timeup))
{
console.log('Game not retired / timed out, continuing ...')
// Get the current time attack record for the car
@ -19,20 +22,79 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque
}
});
// Record already exists
if (currentRecord)
// Check the time
if((body.taResult?.course === 0 && body.taResult?.time <= 169000) || // C1 Inward (2'49"000)
(body.taResult?.course === 1 && body.taResult?.time <= 168000) || // C1 Outward (2'48"000)
(body.taResult?.course === 2 && body.taResult?.time <= 210000) || // NBL CCW (3'30"000)
(body.taResult?.course === 3 && body.taResult?.time <= 266000) || // NBL CW (4'26"000)
(body.taResult?.course === 4 && body.taResult?.time <= 205000) || // Shibuya/Shinjuku (3'25"000)
(body.taResult?.course === 5 && body.taResult?.time <= 250000) || // Ikebukuro/Yamate Tunnel (4'10"000)
(body.taResult?.course === 6 && body.taResult?.time <= 232000) || // Wangan Eastbound (3'52"000)
(body.taResult?.course === 7 && body.taResult?.time <= 231000) || // Wangan Westbound (3'51"000)
(body.taResult?.course === 8 && body.taResult?.time <= 165000) || // Yokohane Downline (2'45"000)
(body.taResult?.course === 9 && body.taResult?.time <= 172000) || // Yokohane Upline (2'52"000)
(body.taResult?.course === 10 && body.taResult?.time <= 215000) || // Yaesu Inward (3'35"000)
(body.taResult?.course === 11 && body.taResult?.time <= 189000) || // Yaesu Outward (3'09"000)
(body.taResult?.course === 12 && body.taResult?.time <= 180000) || // Minato Mirai Inward (3'00"000)
(body.taResult?.course === 13 && body.taResult?.time <= 180000) || // Minato Mirai Outward (3'00"000)
(body.taResult?.course === 14 && body.taResult?.time <= 181000) || // Nagoya (3'01"000)
(body.taResult?.course === 15 && body.taResult?.time <= 225000) || // Osaka (3'45"000)
(body.taResult?.course === 16 && body.taResult?.time <= 243000) || // Kobe (4'03"000)
(body.taResult?.course === 17 && body.taResult?.time <= 206000) || // Fukuoka (3'26"000)
(body.taResult?.course === 18 && body.taResult?.time <= 144000) || // Hakone Outbound (2'24"000)
(body.taResult?.course === 19 && body.taResult?.time <= 143000) || // Hakone Inbound (2'23"000)
(body.taResult?.course === 20 && body.taResult?.time <= 168000) || // Mt. Taikan Uphill (2'48"000)
(body.taResult?.course === 21 && body.taResult?.time <= 174000) || // Mt. Taikan Downhill (2'54"000)
(body.taResult?.course === 22 && body.taResult?.time <= 718000) || // Metro Hwy Tokyo (11'58"000)
(body.taResult?.course === 23 && body.taResult?.time <= 546000) || // Metro Hwy Kanagawa (9'06"000)
(body.taResult?.course === 24 && body.taResult?.time <= 209000)) // Hiroshima (3'29"000)
{
// If the existing record is faster, do not continue
if (body.taResult!.time < currentRecord.time){
console.log('Updating time attack record...')
await prisma.timeAttackRecord.update({
where: {
// Could be null - if it is null, this will insert.
dbId: currentRecord!.dbId
},
cheatedTime = true;
}
// Not Cheated Time
if(cheatedTime === false)
{
// Record already exists
if (currentRecord)
{
// If the existing record is faster, do not continue
if (body.taResult!.time < currentRecord.time)
{
console.log('Updating time attack record...');
await prisma.timeAttackRecord.update({
where: {
// Could be null - if it is null, this will insert.
dbId: currentRecord!.dbId
},
data: {
model: body.car!.model!,
time: body.taResult!.time,
section1Time: body!.taResult!.section_1Time,
section2Time: body!.taResult!.section_2Time,
section3Time: body!.taResult!.section_3Time,
section4Time: body!.taResult!.section_4Time,
section5Time: body!.taResult!.section_5Time,
section6Time: body!.taResult!.section_6Time,
section7Time: body!.taResult!.section_7Time,
tunePower: body!.car!.tunePower,
tuneHandling: body!.car!.tuneHandling
}
});
}
}
else // Creating a new record
{
console.log('Creating new time attack record');
await prisma.timeAttackRecord.create({
data: {
carId: body.carId,
model: body.car!.model!,
time: body.taResult!.time,
isMorning: body.taResult!.isMorning,
course: body.taResult!.course,
section1Time: body!.taResult!.section_1Time,
section2Time: body!.taResult!.section_2Time,
section3Time: body!.taResult!.section_3Time,
@ -46,28 +108,6 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque
});
}
}
else // Creating a new record
{
console.log('Creating new time attack record');
await prisma.timeAttackRecord.create({
data: {
carId: body.carId,
model: body.car!.model!,
time: body.taResult!.time,
isMorning: body.taResult!.isMorning,
course: body.taResult!.course,
section1Time: body!.taResult!.section_1Time,
section2Time: body!.taResult!.section_2Time,
section3Time: body!.taResult!.section_3Time,
section4Time: body!.taResult!.section_4Time,
section5Time: body!.taResult!.section_5Time,
section6Time: body!.taResult!.section_6Time,
section7Time: body!.taResult!.section_7Time,
tunePower: body!.car!.tunePower,
tuneHandling: body!.car!.tuneHandling
}
});
}
// else {} cheated time, ignore it
}
}

View File

@ -1271,7 +1271,7 @@ bluebird@^3.7.2:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
body-parser@1.20.0, body-parser@^1.20.0:
body-parser@1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.0.tgz#3de69bd89011c11573d7bfee6a64f11b6bd27cc5"
integrity sha512-DfJ+q6EPcGKZD1QWUjSpqp+Q7bDQTsQIF4zfUAtZ6qk+H/3/QRhg9CEp39ss+/T2vw0+HaidC0ecJj/DRLIaKg==
@ -1289,6 +1289,24 @@ body-parser@1.20.0, body-parser@^1.20.0:
type-is "~1.6.18"
unpipe "1.0.0"
body-parser@^1.20.1:
version "1.20.1"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.1.tgz#b1812a8912c195cd371a3ee5e66faa2338a5c668"
integrity sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==
dependencies:
bytes "3.1.2"
content-type "~1.0.4"
debug "2.6.9"
depd "2.0.0"
destroy "1.2.0"
http-errors "2.0.0"
iconv-lite "0.4.24"
on-finished "2.4.1"
qs "6.11.0"
raw-body "2.5.1"
type-is "~1.6.18"
unpipe "1.0.0"
brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@ -1342,6 +1360,13 @@ chalk@^4.0.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
chancer@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/chancer/-/chancer-2.0.2.tgz#20b5e6a2009a2987a639f64d93670532ac6f4868"
integrity sha512-MFRbifjvvkHTTDyWtDDv5tWhRyFfR6ZvWVuRxdMnycaGFipjn5MHZC593MTuhNZatyQlys1eAfW+eUX4L2eJpA==
dependencies:
mersenne-twister "^1.0.1"
charenc@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
@ -1939,6 +1964,11 @@ merge-descriptors@1.0.1:
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
integrity sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==
mersenne-twister@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mersenne-twister/-/mersenne-twister-1.1.0.tgz#f916618ee43d7179efcf641bec4531eb9670978a"
integrity sha512-mUYWsMKNrm4lfygPkL3OfGzOPTR2DBlTkBNHM//F6hGp8cLThY897crAlk3/Jo17LEOOjQUrNAx6DvgO77QJkA==
methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
@ -2253,6 +2283,13 @@ qs@6.10.3:
dependencies:
side-channel "^1.0.4"
qs@6.11.0:
version "6.11.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a"
integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==
dependencies:
side-channel "^1.0.4"
range-parser@~1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"