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

Merge pull request #40 from ghkkk090/master

fix terminal ocm ranking bug
This commit is contained in:
Luna 2022-09-04 18:43:25 +01:00 committed by GitHub
commit ce588459b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 237 additions and 58 deletions

View File

@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "rgStamp" SET DEFAULT 1,
ALTER COLUMN "stLoseBits" SET DEFAULT 0;

View File

@ -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)

View File

@ -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();
})

View File

@ -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 &&

View File

@ -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);

View File

@ -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);
})
@ -583,31 +573,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;

View File

@ -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() + "]");
}

View File

@ -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<gbRecordTally.length; i++)
{
// Get the Top 1 Advantage
@ -90,6 +93,9 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ
currentResult = -Math.abs(currentResult);
}
// Pushing carId to array
arr.push(gbRecordTally[i].carId);
// Moving data to OCM Tally
let data : any = {
carId: gbRecordTally[i].carId,
@ -113,9 +119,40 @@ export async function ocmTallying(body: wm.protobuf.LoadGhostCompetitionInfoRequ
data: data
});
}
}
}
// Check if someone is retiring or use cheat engine time up
let checkPlayRecord = await prisma.oCMPlayRecord.findMany({
where:{
NOT: {
carId:{ in: arr }
}
}
});
if(checkPlayRecord)
{
for(let i=0; i<checkPlayRecord.length; i++)
{
// Moving data to OCM Tally
let dataLeft : any = {
carId: checkPlayRecord[i].carId,
result: -9999999,
tunePower: 17,
tuneHandling: 17,
competitionId: body.competitionId,
periodId: periodId + 1
}
// Create the data
await prisma.oCMTally.create({
data: dataLeft
});
}
}
}
// Current day is main draw period 2 (and so on..) and tallying main draw period 1 (and so on..)
else
{
console.log('Tallying data from previous Period');

View File

@ -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
}
})

View File

@ -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<checkUserItem.length; i++)
{
await prisma.userItem.delete({
where:{
userItemId: checkUserItem[i].userItemId
}
})
}
console.log('Item used - ID '+ checkUserItem[0].itemId);
console.log('Item deleted!');
console.log(`Item category was ${checkUserItem[0].category} and item game ID was ${checkUserItem[0].itemId}`);
}
}