1
0
mirror of synced 2024-11-12 01:10:47 +01:00

detect force finish

This commit is contained in:
Shiroi Kitsu 2023-03-30 13:15:45 +07:00
parent 32cc93c227
commit 8f3be6b168
7 changed files with 196 additions and 13 deletions

View File

@ -0,0 +1,21 @@
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- AlterTable
ALTER TABLE "FileList" ALTER COLUMN "filePath" DROP DEFAULT;
-- CreateTable
CREATE TABLE "CarCrownDetect" (
"id" SERIAL NOT NULL,
"carId" INTEGER NOT NULL,
"status" TEXT NOT NULL DEFAULT '',
"area" INTEGER,
"ramp" INTEGER,
"path" INTEGER,
"trail" BYTEA,
"playedAt" INTEGER,
"tunePower" INTEGER,
"tuneHandling" INTEGER,
CONSTRAINT "CarCrownDetect_pkey" PRIMARY KEY ("id")
);

View File

@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "Car" ALTER COLUMN "stLoseBits" SET DEFAULT 0;
-- AlterTable
ALTER TABLE "CarCrownDetect" ADD COLUMN "opponentCarId" INTEGER;

View File

@ -446,5 +446,19 @@ model FileList {
sha1sum String
notBefore Int
notAfter Int
filePath String @default("")
filePath String
}
model CarCrownDetect {
id Int @id @default(autoincrement())
carId Int
status String @default("")
area Int?
ramp Int?
path Int?
trail Bytes?
playedAt Int?
tunePower Int?
tuneHandling Int?
opponentCarId Int?
}

View File

@ -236,6 +236,99 @@ export default class GameModule extends Module {
// Perform the save screenshot request for the car
await gameFunction.saveScreenshot(body);
// Check retire crown
let getCarCrown = await prisma.carCrownDetect.findFirst({
where:{
carId: body.carId
}
});
if(getCarCrown)
{
if(getCarCrown.status === 'retire')
{
await prisma.carCrownDetect.delete({
where:{
id: getCarCrown.id
}
});
}
else if(getCarCrown.status === 'finish')
{
let timestamp = body.playedAt - body.timestamp;
if(timestamp <= 120)
{
// Update the user status
await prisma.carCrownDetect.update({
where:{
id: getCarCrown.id
},
data:{
status: 'forcefinish'
}
});
// Restore the old crown
await prisma.carCrown.update({
where:{
area: getCarCrown.area!
},
data:{
carId: getCarCrown.opponentCarId!,
area: getCarCrown.area!,
ramp: getCarCrown.ramp!,
path: getCarCrown.path!,
playedAt: getCarCrown.playedAt!,
tunePower: getCarCrown.tunePower!,
tuneHandling: getCarCrown.tuneHandling!,
}
});
await prisma.ghostTrail.updateMany({
where:{
area: getCarCrown.area!,
crownBattle: true
},
data:{
carId: getCarCrown.opponentCarId!,
area: getCarCrown.area!,
ramp: getCarCrown.ramp!,
path: getCarCrown.path!,
playedAt: getCarCrown.playedAt!,
tunePower: getCarCrown.tunePower!,
tuneHandling: getCarCrown.tuneHandling!,
trail: getCarCrown.trail!
}
});
// Banned the user
let getUserId = await prisma.car.findFirst({
where:{
carId: body.carId
},
select:{
userId: true
}
})
if(getUserId)
{
await prisma.user.update({
where:{
id: getUserId.userId
},
data:{
userBanned: true
}
});
}
}
}
}
// Response data
let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,

View File

@ -200,6 +200,9 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
// Declare data
let dataCrown : any;
let area = 0;
let ramp = 0;
let path = 0;
// ghostResultCrown is set
if (ghostResultCrown)
@ -219,9 +222,6 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
}
// Get the area id and ramp id
let area = 0;
let ramp = 0;
let path = 0;
if(body.rgResult?.path)
{
if(body.rgResult?.path >= 0 && body.rgResult?.path <= 9){ // GID_PATH_C1
@ -289,20 +289,33 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
}
// Get the available crown holder data
let carCrowns = await prisma.carCrown.count({
let carCrowns = await prisma.carCrown.findFirst({
where: {
area: area
}
});
// Crown holder data available
if(carCrowns !== 0)
if(carCrowns)
{
// Crown Finish Status
await prisma.carCrownDetect.create({
data:{
carId: body.carId,
status: 'finish',
area: carCrowns.area,
ramp: carCrowns.ramp,
path: carCrowns.path,
playedAt: carCrowns.playedAt,
tunePower: carCrowns.tunePower,
tuneHandling: carCrowns.tuneHandling
}
});
// Update it to the new one
let areaVal = Number(area);
await prisma.carCrown.update({
where: {
area: areaVal
dbId: carCrowns.dbId
},
data: {
...dataCrown,
@ -661,8 +674,15 @@ export async function saveGhostBattleResult(body: wm.protobuf.SaveGameResultRequ
// Retiring Crown Mode
else if(body.rgResult!.selectionMethod === wmproto.wm.protobuf.GhostSelectionMethod.GHOST_SELECT_CROWN_MATCH)
{
// TODO
console.log('Crown Ghost Mode Found but Retiring');
// Crown Finish Status
await prisma.carCrownDetect.create({
data:{
carId: body.carId,
status: 'retire'
}
});
}
// Return the value to 'BASE_PATH/src/modules/game.ts'

View File

@ -64,11 +64,31 @@ export default class GhostModule extends Module {
stampReturnStats: car?.stampSheet || null,
};
// Encode the response
let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg);
let getUserId = await prisma.user.findFirst({
where:{
id: car!.userId
}
});
// Send the response to the client
common.sendResponse(message, res, req.rawHeaders[5], req.rawHeaders[7]);
if(getUserId)
{
if(getUserId.userBanned === false)
{
// Encode the response
let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg);
// Send the response to the client
common.sendResponse(message, res, req.rawHeaders[5], req.rawHeaders[7]);
}
}
else
{
// Encode the response
let message = wm.wm.protobuf.LoadGhostBattleInfoResponse.encode(msg);
// Send the response to the client
common.sendResponse(message, res, req.rawHeaders[5], req.rawHeaders[7]);
}
})

View File

@ -218,6 +218,16 @@ export async function saveCrownGhostTrail(body: wm.protobuf.RegisterGhostTrailRe
console.log('Crown Trail history found');
console.log('Updating crown trail to the newest trail');
await prisma.carCrownDetect.updateMany({
where:{
carId: ghostResult.car.carId!
},
data: {
trail: gtCount.trail,
opponentCarId: gtCount.carId
}
})
// Update the data
await prisma.ghostTrail.update({
where: {