1
0
mirror of synced 2025-01-22 11:23:40 +01:00

Merge pull request #72 from shiroikitsu8/master

fix user's stamp value when sending stamp
This commit is contained in:
Astelle Nightshade 2023-06-01 19:12:46 +01:00 committed by GitHub
commit f603423fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 55 deletions

View File

@ -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();
})

View File

@ -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,6 +11,8 @@ export async function checkCurrentStep(body: wm.protobuf.SaveGameResultRequest)
// Set current ghost level based on current step
let ghostLevel = 1;
if(car.ghostLevel < 11)
{
if(currentStep >= 0 && currentStep <= 5)
{
ghostLevel = 1
@ -51,6 +53,7 @@ export async function checkCurrentStep(body: wm.protobuf.SaveGameResultRequest)
{
ghostLevel = 10
}
}
// Return the value to 'BASE_PATH/src/util/games/story.ts'
return {ghostLevel}

View File

@ -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;

View File

@ -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

View File

@ -96,3 +96,25 @@ 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
}
}

View File

@ -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 {