1
0
mirror of synced 2025-02-23 13:39:03 +01:00

Merge pull request #66 from shiroikitsu8/master

Important fix
This commit is contained in:
Luna 2023-03-16 21:15:31 +00:00 committed by GitHub
commit 1973988ae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 184 additions and 110 deletions

View File

@ -52,6 +52,12 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque
cheatedTime = true;
}
// Check the time again
if (body.taResult!.time <= 0 || body.taResult!.time >= 1200000 || body.taResult!.time.toString() == "-2147483648")
{
cheatedTime = true;
}
// Not Cheated Time
if(cheatedTime === false)
{
@ -84,28 +90,32 @@ export async function saveTimeAttackResult(body: wm.protobuf.SaveGameResultReque
});
}
}
else // Creating a new record
// Creating a new record
else
{
console.log('Creating new time attack record');
if (body.taResult!.time < 1200000)
{
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
}
});
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

@ -186,7 +186,9 @@ export default class TerminalModule extends Module {
// Get the query from the request
let query = req.query;
let cars;
let cars: wm.wm.protobuf.Car[] = [];
let car;
let arr = [];
// Check the query limit
let queryLimit = 10
@ -210,22 +212,23 @@ export default class TerminalModule extends Module {
queryLastPlayedPlaceId = getLastPlayedPlaceId.id;
}
cars = await prisma.car.findMany({
take: queryLimit,
car = await prisma.car.findMany({
where: {
lastPlayedPlaceId: queryLastPlayedPlaceId
},
include:{
gtWing: true,
lastPlayedPlace: true
},
orderBy: {
carId: "asc"
}
});
}
else
{
// Get all of the cars matching the query
cars = await prisma.car.findMany({
take: queryLimit,
car = await prisma.car.findMany({
where: {
OR:[
{
@ -244,9 +247,49 @@ export default class TerminalModule extends Module {
include:{
gtWing: true,
lastPlayedPlace: true
},
orderBy: {
carId: "asc"
}
});
}
if(car.length > 0)
{
if(car.length < queryLimit)
{
queryLimit = car.length;
}
// Choose the user's car data randomly to appear
while(arr.length < queryLimit)
{
// Randomize pick
let random: number = 1;
// Randomize it 5 times
for(let i=0; i<5; i++)
{
random = Math.floor(Math.random() * car.length);
}
// Try randomize it again if it's 1
if(random === 1)
{
random = Math.floor(Math.random() * car.length);
}
if(arr.indexOf(random) === -1)
{
// Push current number to array
arr.push(random);
cars.push(wm.wm.protobuf.Car.create({
...car[random]
}));
}
}
}
let msg = {
hitCount: cars.length,
@ -639,23 +682,18 @@ export default class TerminalModule extends Module {
car: true
},
distinct: ["carId"],
take: 50
})
numOfParticipants = ocmParticipant.length;
periodId = 0;
let ranking = 0;
let maxNumber = 150;
if(numOfParticipants < 151)
{
maxNumber = numOfParticipants;
}
if(numOfParticipants > 0)
{
periodId = ocmParticipant[0].periodId;
for(let i=0; i<maxNumber; i++)
for(let i=0; i<ocmParticipant.length; i++)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
@ -715,39 +753,49 @@ export default class TerminalModule extends Module {
if(!(ownRecords))
{
for(let i=150; i<numOfParticipants; i++)
let ocmPersonalRank = [{ result: 0, position: 0 }];
ocmPersonalRank = await prisma.$queryRaw`
select "result", "position" from
(select *, row_number() over(order by "result" DESC) as "position" from "OCMTally"
where "competitionId" = ${body.competitionId}) "OCMTally" where "carId" = ${body.carId}`;
if(ocmPersonalRank.length > 0)
{
if(ocmParticipant[i].carId === body.carId)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
playedAt: true
}
});
let userCar = await prisma.car.findFirst({
where:{
carId: body.carId
}
});
// User car setting
ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
let userPlayedAt = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: body.carId,
competitionId: body.competitionId
},
select:{
playedAt: true
}
});
break;
}
let myRank = Number(ocmPersonalRank[0].position);
let myResult = Number(ocmPersonalRank[0].result);
ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: myRank,
result: myResult,
carId: userCar!.carId,
name: userCar!.name,
regionId: userCar!.regionId,
model: userCar!.model,
visualModel: userCar!.visualModel,
defaultColor: userCar!.defaultColor,
title: userCar!.title,
level: userCar!.level,
windowStickerString: userCar!.windowStickerString,
playedShopName: playedShopName,
playedAt: userPlayedAt?.playedAt || 0
});
}
}
}
@ -808,37 +856,39 @@ export default class TerminalModule extends Module {
{
console.log('Current / Previous OCM Day : OCM has Ended');
// Get Current OCM Period and All User's Record
let ocmParticipant = await prisma.oCMTally.findMany({
where:{
competitionId: ocmEventDate!.competitionId,
periodId: 999999999
},
orderBy: {
result: 'desc'
},
orderBy: [
{
result: 'desc'
},
{
periodId: 'desc'
}
],
include:{
car: true
},
distinct: ["carId"]
distinct: ["carId"],
take: 10
})
numOfParticipants = ocmParticipant.length;
periodId = 0;
let ranking = 0;
let maxNumber = 150;
if(numOfParticipants < 151)
{
maxNumber = numOfParticipants;
}
if(numOfParticipants > 0)
{
for(let i=0; i<maxNumber; i++)
{
periodId = ocmParticipant[0].periodId;
for(let i=0; i<ocmParticipant.length; i++)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: ocmParticipant[i].carId,
carId: ocmParticipant[0].carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
@ -847,6 +897,11 @@ export default class TerminalModule extends Module {
}
});
if(ocmGhostrecord?.playedShopName !== null && ocmGhostrecord?.playedShopName !== undefined)
{
playedShopName = ocmGhostrecord.playedShopName;
}
if(ocmParticipant[i].carId === body.carId && ranking === 0)
{
// User car setting
@ -862,7 +917,7 @@ export default class TerminalModule extends Module {
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: ocmGhostrecord!.playedShopName,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
@ -882,46 +937,56 @@ export default class TerminalModule extends Module {
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: ocmGhostrecord!.playedShopName,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
}));
}
if(!(ownRecords))
{
for(let i=maxNumber; i<numOfParticipants; i++)
let ocmPersonalRank = [{ result: 0, position: 0 }];
ocmPersonalRank = await prisma.$queryRaw`
select "result", "position" from
(select *, row_number() over(order by "result" DESC) as "position" from "OCMTally"
where "competitionId" = ${body.competitionId}) "OCMTally" where "carId" = ${body.carId}`;
if(ocmPersonalRank.length > 0)
{
if(ocmParticipant[i].carId === body.carId)
{
let ocmGhostrecord = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: body.carId,
competitionId: ocmEventDate!.competitionId,
},
select:{
playedAt: true
}
});
let userCar = await prisma.car.findFirst({
where:{
carId: body.carId
}
});
// User car setting
ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: i + 1,
result: ocmParticipant[i].result,
carId: ocmParticipant[i].carId,
name: ocmParticipant[i].car.name,
regionId: ocmParticipant[i].car.regionId,
model: ocmParticipant[i].car.model,
visualModel: ocmParticipant[i].car.visualModel,
defaultColor: ocmParticipant[i].car.defaultColor,
title: ocmParticipant[i].car.title,
level: ocmParticipant[i].car.level,
windowStickerString: ocmParticipant[i].car.windowStickerString,
playedShopName: playedShopName,
playedAt: ocmGhostrecord!.playedAt
});
let userPlayedAt = await prisma.oCMGhostBattleRecord.findFirst({
where:{
carId: body.carId,
competitionId: body.competitionId
},
select:{
playedAt: true
}
});
break;
}
let myRank = Number(ocmPersonalRank[0].position);
let myResult = Number(ocmPersonalRank[0].result);
ownRecords = wm.wm.protobuf.LoadGhostCompetitionRankingResponse.Entry.create({
rank: myRank,
result: myResult,
carId: userCar!.carId,
name: userCar!.name,
regionId: userCar!.regionId,
model: userCar!.model,
visualModel: userCar!.visualModel,
defaultColor: userCar!.defaultColor,
title: userCar!.title,
level: userCar!.level,
windowStickerString: userCar!.windowStickerString,
playedShopName: playedShopName,
playedAt: userPlayedAt?.playedAt || 0
});
}
}
}

View File

@ -1,2 +1 @@
node dist
pause
node dist