diff --git a/src/modules/game/time_attack.ts b/src/modules/game/time_attack.ts index e90dfe3..e5c29c4 100644 --- a/src/modules/game/time_attack.ts +++ b/src/modules/game/time_attack.ts @@ -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 diff --git a/src/modules/terminal.ts b/src/modules/terminal.ts index 358e9a9..c76619a 100644 --- a/src/modules/terminal.ts +++ b/src/modules/terminal.ts @@ -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 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 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 + }); } } } diff --git a/start.bat b/start.bat index 0d6f8f6..715b26b 100644 --- a/start.bat +++ b/start.bat @@ -1,2 +1 @@ -node dist -pause \ No newline at end of file +node dist \ No newline at end of file