Added dotenv to the requirements, fixed bug with time attack saving
This commit is contained in:
parent
3f01261828
commit
69b1c898bb
@ -25,6 +25,7 @@
|
|||||||
"@sentry/tracing": "^7.7.0",
|
"@sentry/tracing": "^7.7.0",
|
||||||
"@types/pem": "^1.9.6",
|
"@types/pem": "^1.9.6",
|
||||||
"body-parser": "^1.20.0",
|
"body-parser": "^1.20.0",
|
||||||
|
"dotenv": "^16.0.1",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"form-urlencoded": "^6.0.6",
|
"form-urlencoded": "^6.0.6",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
|
@ -13,6 +13,10 @@ import { Config } from './config';
|
|||||||
import process from 'process';
|
import process from 'process';
|
||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from '@sentry/node';
|
||||||
import * as Tracing from '@sentry/tracing';
|
import * as Tracing from '@sentry/tracing';
|
||||||
|
|
||||||
|
import * as dotenv from "dotenv";
|
||||||
|
dotenv.config({path: __dirname + '/.env'});
|
||||||
|
|
||||||
globalAgent.options.keepAlive = true;
|
globalAgent.options.keepAlive = true;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -85,20 +85,50 @@ export default class GameModule extends Module {
|
|||||||
}
|
}
|
||||||
case wm.wm.protobuf.GameMode.MODE_TIME_ATTACK:
|
case wm.wm.protobuf.GameMode.MODE_TIME_ATTACK:
|
||||||
{
|
{
|
||||||
if (!body.retired && !body.timeup) {
|
console.log(body);
|
||||||
|
|
||||||
|
// If the game was not timed out / retired
|
||||||
|
if (!(body.retired || body.timeup)) {
|
||||||
|
|
||||||
|
console.log('Game not retired / timed out, continuing ...')
|
||||||
|
|
||||||
|
// Get the current time attack record for the car
|
||||||
let currentRecord = await prisma.timeAttackRecord.findFirst({
|
let currentRecord = await prisma.timeAttackRecord.findFirst({
|
||||||
where: {
|
where: {
|
||||||
carId: body.carId,
|
carId: body.carId, // , model: body.car!.model!,
|
||||||
model: body.car!.model!,
|
course: body.taResult!.course
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure we don't save a worse record!
|
// Record already exists
|
||||||
if (currentRecord && body.taResult!.time > currentRecord.time)
|
if (currentRecord)
|
||||||
break;
|
{
|
||||||
|
// If the existing record is faster, do not continue
|
||||||
|
if (body.taResult!.time > currentRecord.time) break;
|
||||||
|
|
||||||
if (!currentRecord) {
|
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: {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else // Creating a new record
|
||||||
|
{
|
||||||
console.log('Creating new time attack record');
|
console.log('Creating new time attack record');
|
||||||
|
|
||||||
await prisma.timeAttackRecord.create({
|
await prisma.timeAttackRecord.create({
|
||||||
data: {
|
data: {
|
||||||
carId: body.carId,
|
carId: body.carId,
|
||||||
@ -117,24 +147,6 @@ export default class GameModule extends Module {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
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: {
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -496,6 +496,11 @@ diff@^4.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
||||||
|
|
||||||
|
dotenv@^16.0.1:
|
||||||
|
version "16.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d"
|
||||||
|
integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==
|
||||||
|
|
||||||
ee-first@1.1.1:
|
ee-first@1.1.1:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
||||||
|
Loading…
Reference in New Issue
Block a user