diff --git a/src/index.ts b/src/index.ts index afa1cc9..040e03d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,26 +87,23 @@ if (process.env.OPENTELEMETRY_ENABLED === "true") { ]); } -// 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(timestamp+` [ MAIN] ${req.method} ${req.url}`); + common.writeLog(`[ MAIN] ${req.method} ${req.url}`); next() }); muchaApp.use((req, res, next) => { - console.log(timestamp+` [ MUCHA] ${req.method} ${req.url}`); + common.writeLog(`[ MUCHA] ${req.method} ${req.url}`); next() }); allnetApp.use((req, res, next) => { - console.log(timestamp+` [ALLNET] ${req.method} ${req.url}`); + common.writeLog(`[ALLNET] ${req.method} ${req.url}`); next() }); @@ -134,7 +131,7 @@ app.use('/', appRouter); app.use('/wmmt6/', appRouter); app.all('*', (req, res) => { - console.log(timestamp+` [ MAIN] ${req.method} ${req.url} is unhandled`); + common.writeLog(`[ MAIN] ${req.method} ${req.url} is unhandled`); res.status(200).end(); }) diff --git a/src/modules/game/games_util/check_step.ts b/src/modules/game/games_util/check_step.ts index f00c91e..e3a0e55 100644 --- a/src/modules/game/games_util/check_step.ts +++ b/src/modules/game/games_util/check_step.ts @@ -3,7 +3,7 @@ import { wm } from "../../../wmmt/wm.proto"; // Save story result -export async function checkCurrentStep(body: wm.protobuf.SaveGameResultRequest) +export async function checkCurrentStep(body: wm.protobuf.SaveGameResultRequest, car: any) { // Get current step for updating the user's ghost level let currentStep = 0; @@ -11,45 +11,48 @@ export async function checkCurrentStep(body: wm.protobuf.SaveGameResultRequest) // Set current ghost level based on current step let ghostLevel = 1; - if(currentStep >= 0 && currentStep <= 5) + if(car.ghostLevel < 11) { - ghostLevel = 1 - } - else if(currentStep >= 6 && currentStep <= 10) - { - ghostLevel = 2 - } - else if(currentStep >= 11 && currentStep <= 15) - { - ghostLevel = 3 - } - else if(currentStep >= 16 && currentStep <= 20) - { - ghostLevel = 4 - } - else if(currentStep >= 21 && currentStep <= 26) - { - ghostLevel = 5 - } - else if(currentStep >= 27 && currentStep <= 28) - { - ghostLevel = 6 - } - else if(currentStep >= 29 && currentStep <= 30) - { - ghostLevel = 7 - } - else if(currentStep === 31) - { - ghostLevel = 8 - } - else if(currentStep >= 32 && currentStep <= 33) - { - ghostLevel = 9 - } - else if(currentStep === 34) - { - ghostLevel = 10 + if(currentStep >= 0 && currentStep <= 5) + { + ghostLevel = 1 + } + else if(currentStep >= 6 && currentStep <= 10) + { + ghostLevel = 2 + } + else if(currentStep >= 11 && currentStep <= 15) + { + ghostLevel = 3 + } + else if(currentStep >= 16 && currentStep <= 20) + { + ghostLevel = 4 + } + else if(currentStep >= 21 && currentStep <= 26) + { + ghostLevel = 5 + } + else if(currentStep >= 27 && currentStep <= 28) + { + ghostLevel = 6 + } + else if(currentStep >= 29 && currentStep <= 30) + { + ghostLevel = 7 + } + else if(currentStep === 31) + { + ghostLevel = 8 + } + else if(currentStep >= 32 && currentStep <= 33) + { + ghostLevel = 9 + } + else if(currentStep === 34) + { + ghostLevel = 10 + } } // Return the value to 'BASE_PATH/src/util/games/story.ts' diff --git a/src/modules/game/story.ts b/src/modules/game/story.ts index d69b628..a43f7f3 100644 --- a/src/modules/game/story.ts +++ b/src/modules/game/story.ts @@ -57,7 +57,7 @@ export async function saveStoryResult(body: wm.protobuf.SaveGameResultRequest, c } // Calling check step function (BASE_PATH/src/util/games/games_util/check_step.ts) - let check_steps = await check_step.checkCurrentStep(body); + let check_steps = await check_step.checkCurrentStep(body, car); // Set the ghost level to the correct level data.ghostLevel = check_steps.ghostLevel; diff --git a/src/modules/ghost/ghost_stamp.ts b/src/modules/ghost/ghost_stamp.ts index 2805109..2405f3b 100644 --- a/src/modules/ghost/ghost_stamp.ts +++ b/src/modules/ghost/ghost_stamp.ts @@ -16,15 +16,23 @@ export async function sendStamp(body: wm.protobuf.SaveGameResultRequest) if(rgResult) { - // Stamp must bigger than 0 - let rgStamp = rgResult.rgStamp; + // Get Sender Stamp Data + let carStamp = await prisma.car.findFirst({ + where:{ + carId: body.carId + }, + select:{ + rgStamp: true + } + }); + let rgStamp:number = carStamp!.rgStamp; if(rgStamp === 0) { rgStamp = 1; } // Get the area - let area: Number = 0; + let area:number = 0; if(rgResult.path) { let getArea = await ghost_get_area_from_path.getArea(rgResult.path); @@ -110,20 +118,29 @@ export async function shuttleReturnStamp(body: wm.protobuf.SaveGameResultRequest if(rgResult) { - // Stamp must bigger than 0 - let rgStamp = rgResult.rgStamp; + // Get Sender Stamp Data + let carStamp = await prisma.car.findFirst({ + where:{ + carId: body.carId + }, + select:{ + rgStamp: true + } + }) + + let rgStamp:number = carStamp!.rgStamp; if(rgStamp === 0) { rgStamp = 1; } // Get the area - let area; + let area:number = 0; if(rgResult.path) { let getArea = await ghost_get_area_from_path.getArea(rgResult.path); - area = getArea.area; + area = Number(getArea.area); } // Check how many opponents available diff --git a/src/modules/util/common.ts b/src/modules/util/common.ts index e538bb6..23637d6 100644 --- a/src/modules/util/common.ts +++ b/src/modules/util/common.ts @@ -95,4 +95,26 @@ export function getTimeStamp(date: Date = new Date()) { // Return a timestamp string for the current / provided time return String("[" + date.toLocaleString() + "]"); +} + + +// Write Log +export async function writeLog(message: string) +{ + try { + // Get the current timestamp + const timestamp: string = getTimeStamp(); + + // Full message placeholder + let fullMessage: string; + + // Generate the message content, write to console + fullMessage = timestamp + ': ' + message; + + // Log + console.log(fullMessage); + } + catch { + // Failed + } } \ No newline at end of file diff --git a/src/mucha.ts b/src/mucha.ts index da26e63..ee80fcb 100644 --- a/src/mucha.ts +++ b/src/mucha.ts @@ -4,7 +4,7 @@ import moment from "moment"; import { Config } from "./config"; import { Module } from "./module"; -const PORT = 10082; +const PORT = process.env.MUCHA_PORT !== undefined ? parseInt(process.env.MUCHA_PORT) : 10082; export default class MuchaModule extends Module { register(app: Application): void {