1
0
mirror of synced 2024-12-05 03:27:57 +01:00

Merge pull request #62 from shiroikitsu8/master

randomizer, default place regionid must not 0, blocking vanilla tp chip id
This commit is contained in:
Luna 2023-02-21 11:18:56 +00:00 committed by GitHub
commit 5d4f1c4336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 196 additions and 81 deletions

3
.gitignore vendored
View File

@ -9,4 +9,5 @@ key.pem
config.json config.json
package-lock.json package-lock.json
ecosystem.config.js ecosystem.config.js
static/* static/*
screenshot/*

View File

@ -12,6 +12,7 @@
"scratchEnabled": 1, "scratchEnabled": 1,
"scratchType": 1, "scratchType": 1,
"giveMeterReward": 0, "giveMeterReward": 0,
"newCardsBanned": 0 "newCardsBanned": 0,
"enableScreenshot": 0
} }
} }

View File

@ -4,6 +4,7 @@ import { unzipSync } from "zlib";
import { Module } from "./module"; import { Module } from "./module";
import iconv from "iconv-lite"; import iconv from "iconv-lite";
import { Config } from "./config"; import { Config } from "./config";
import * as common from "./modules/util/common";
// TODO: Move this into the config // TODO: Move this into the config
const STARTUP_URI = `https://${Config.getConfig().serverIp || "localhost"}:9002`; const STARTUP_URI = `https://${Config.getConfig().serverIp || "localhost"}:9002`;
@ -75,7 +76,7 @@ export default class AllnetModule extends Module {
let regionName = Config.getConfig().regionName; let regionName = Config.getConfig().regionName;
let placeId = Config.getConfig().placeId; let placeId = Config.getConfig().placeId;
let country = Config.getConfig().country; let country = Config.getConfig().country;
let regionId = Config.getConfig().regionId; let regionId = common.sanitizeInputNotZero(Number(Config.getConfig().regionId)) || 1;
// TODO: Implement board authentication here. // TODO: Implement board authentication here.

View File

@ -47,12 +47,16 @@ export interface GameOptions {
grantFullTuneTicketToNewUsers: number; grantFullTuneTicketToNewUsers: number;
// Give meter reward every n*100 play // Give meter reward every n*100 play
giveMeterReward: number; //1 is on, 0 is off giveMeterReward: number; // 1 is on, 0 is off
// if the new card is not in the User databese // if the new card is not in the User databese
// set this option to 1 will not create a new card // set this option to 1 will not create a new card
// and prevent new card registration // and prevent new card registration
newCardsBanned: number;//1 is on, 0 is off newCardsBanned: number; // 1 is on, 0 is off
// revision check
// set this option to 1 to enable screenshot feature
enableScreenshot: number; // 1 is on, 0 is off
} }
export class Config { export class Config {

View File

@ -1,4 +1,5 @@
import { Application } from "express"; import { Application } from "express";
import { Config } from "../config";
import { Module } from "module"; import { Module } from "module";
import { prisma } from ".."; import { prisma } from "..";
@ -28,6 +29,19 @@ export default class CarModule extends Module {
// Get Challenger Data // Get Challenger Data
let opponentsTarget = await carFunctions.getOpponentsTarget(body.carId, registeredTarget.registeredargetAvailable); let opponentsTarget = await carFunctions.getOpponentsTarget(body.carId, registeredTarget.registeredargetAvailable);
// Set Screenshot Count
let screenshotCount = 0;
// Check if screenshot feature enabled or not
let enableScreenshot = Config.getConfig().gameOptions.enableScreenshot || 0;
// Screenshot feature enabled
if(enableScreenshot === 1)
{
// Set the screnshot chance count
screenshotCount = 99;
}
// Response data // Response data
let msg = { let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
@ -43,7 +57,7 @@ export default class CarModule extends Module {
rgPreviousVersionPlayCount: 0, rgPreviousVersionPlayCount: 0,
stCompleted_100Episodes: car!.stCompleted100Episodes, stCompleted_100Episodes: car!.stCompleted100Episodes,
auraMotifAutoChange: false, auraMotifAutoChange: false,
screenshotCount: 0, screenshotCount: screenshotCount,
transferred: false, transferred: false,
// Stamp or Challenger // Stamp or Challenger
@ -136,33 +150,52 @@ export default class CarModule extends Module {
// Get the request body for the update car request // Get the request body for the update car request
let body = wm.wm.protobuf.UpdateCarRequest.decode(req.body); let body = wm.wm.protobuf.UpdateCarRequest.decode(req.body);
// Update the car // Not deleting car
await carFunctions.updateCar(body); if(body.toBeDeleted === false || body.toBeDeleted === undefined || body.toBeDeleted === null)
// Update the car setting
await carFunctions.updateCarSetting(body);
// Update the car window Sticker
await carFunctions.updateCarWindowSticker(body);
// Update the car Custom Wing
await carFunctions.updateCarCustomWing(body);
// Get car item (custom color or discarded card)
if(body.earnedItems.length !== 0)
{ {
console.log('Car Item reward available, continuing ...'); // Update the car
for(let i=0; i<body.earnedItems.length; i++){ await carFunctions.updateCar(body);
await prisma.carItem.create({
data: { // Update the car setting
carId: body.carId, await carFunctions.updateCarSetting(body);
category: body.earnedItems[i].category,
itemId: body.earnedItems[i].itemId, // Update the car window Sticker
amount: 1 await carFunctions.updateCarWindowSticker(body);
}
}); // Update the car Custom Wing
await carFunctions.updateCarCustomWing(body);
// Get car item (custom color or discarded card)
if(body.earnedItems.length !== 0)
{
console.log('Car Item reward available, continuing ...');
for(let i=0; i<body.earnedItems.length; i++){
await prisma.carItem.create({
data: {
carId: body.carId,
category: body.earnedItems[i].category,
itemId: body.earnedItems[i].itemId,
amount: 1
}
});
}
} }
} }
// Deleting car
else
{
console.log('Deleting Car ID : ' + body.carId);
// Mark Deleted Car
await prisma.carState.update({
where:{
dbId: body.carId
},
data:{
toBeDeleted: body.toBeDeleted
}
})
}
// Response data // Response data
let msg = { let msg = {

View File

@ -138,18 +138,37 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
// Randomize pick // Randomize pick
let random: number = 1; let random: number = 1;
let randomArray: number[] = [];
let maxNumber = 5;
if(opponentTargetCount < 5)
{
maxNumber = opponentTargetCount;
}
// Randomize it 5 times // Randomize it 5 times
for(let i=0; i<5; i++) while(randomArray.length < 5)
{ {
random = Math.floor(Math.random() * opponentTargetCount); // Pick random car Id
random = Math.floor(Math.random() * opponentTargetCount + 0.9);
// Try randomize it again if it's 0, and fix if more than car length
if(random < 1 || random >= opponentTargetCount)
{
random = Math.floor(Math.random() * opponentTargetCount + 0.9);
}
// Random Number not yet selected
if(randomArray.indexOf(random) === -1)
{
// Push current number to array
randomArray.push(random);
}
} }
// Try randomize it again if it's 1 // Pick the array number
if(random === 1) let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9);
{ random = randomArray[pickRandom];
random = Math.floor(Math.random() * opponentTargetCount);
}
// Check opponents target // Check opponents target
let opponentTarget = await prisma.carStampTarget.findMany({ let opponentTarget = await prisma.carStampTarget.findMany({
@ -157,9 +176,14 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
stampTargetCarId: carId, stampTargetCarId: carId,
recommended: true, recommended: true,
}, },
orderBy:{ orderBy: [
locked: 'desc' {
}, id: 'asc'
},
{
recommended: 'desc'
}
],
skip: random, skip: random,
take: 1, take: 1,
}); });
@ -205,6 +229,12 @@ export async function getOpponentsTarget(carId: number, registeredargetAvailable
result = Math.abs(carChallengers.result); result = Math.abs(carChallengers.result);
} }
// Error handling if regionId is below 1 or above 47
if(carTarget!.regionId < 1 || carTarget!.regionId > 47)
{
carTarget!.regionId = Math.floor(Math.random() * 10) + 10;
}
// Push the data // Push the data
challenger = wmproto.wm.protobuf.ChallengerCar.create({ challenger = wmproto.wm.protobuf.ChallengerCar.create({
car: carTarget, car: carTarget,
@ -322,26 +352,33 @@ export async function createCar(body: wm.protobuf.CreateCarRequest)
} }
} }
// Randomize regionId // Randomize pick
let regionId: number = 18; let random: number = 1;
let randomArray: number[] = [];
// Randomize it 5 times // Randomize it 5 times
for(let i=0; i<5; i++) while(randomArray.length < 5)
{ {
regionId = Math.floor(Math.random() * 47) + 1; // Pick random car Id
random = Math.floor(Math.random() * 47 + 0.9) + 1;
// Try randomize it again if it's 0, and fix if more than car length
if(random < 1 || random > 47)
{
random = Math.floor(Math.random() * 47 + 0.9) + 1;
}
// Random Number not yet selected
if(randomArray.indexOf(random) === -1)
{
// Push current number to array
randomArray.push(random);
}
} }
// Try randomize it again if it's 1 // Pick the array number
if(regionId === 1) let pickRandom = Math.floor(Math.random() * randomArray.length + 0.9);
{ random = randomArray[pickRandom];
regionId = Math.floor(Math.random() * 47) + 1;
}
// Error handling if regionId is below 1 or above 47
if(regionId < 1 || regionId > 47)
{
regionId = Math.floor(Math.random() * 10) + 10;
}
// Default car values // Default car values
let carInsert = { let carInsert = {
@ -358,7 +395,7 @@ export async function createCar(body: wm.protobuf.CreateCarRequest)
carSettingsDbId: settings.dbId, carSettingsDbId: settings.dbId,
carStateDbId: state.dbId, carStateDbId: state.dbId,
carGTWingDbId: gtWing.dbId, carGTWingDbId: gtWing.dbId,
regionId: regionId, regionId: random,
lastPlayedAt: date, lastPlayedAt: date,
lastPlayedPlaceId: 1, // Server Default lastPlayedPlaceId: 1, // Server Default
}; };

View File

@ -230,22 +230,22 @@ export default class GameModule extends Module {
// Save Screenshot // Save Screenshot
app.post('/method/save_screenshot', async (req, res) => { app.post('/method/save_screenshot', async (req, res) => {
// Get the information from the request // Get the request body
let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body); let body = wm.wm.protobuf.SaveScreenshotRequest.decode(req.body);
// TODO: Actual stuff here // Perform the save screenshot request for the car
// This is literally just bare-bones so the shit boots await gameFunction.saveScreenshot(body);
// Response data // Response data
let msg = { let msg = {
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
}; };
// Encode the response // Encode the response
let message = wm.wm.protobuf.SaveScreenshotResponse.encode(msg); let message = wm.wm.protobuf.SaveScreenshotResponse.encode(msg);
// Send the response to the client // Send the response to the client
common.sendResponse(message, res); common.sendResponse(message, res);
}); })
} }
} }

View File

@ -1,4 +1,7 @@
import { prisma } from "../.."; import { prisma } from "../..";
import { Config } from "../../config";
import path from "path";
import fs from "fs";
// Import Proto // Import Proto
import { wm } from "../../wmmt/wm.proto"; import { wm } from "../../wmmt/wm.proto";
@ -407,4 +410,41 @@ export async function getGhostBattleRecord(body: wm.protobuf.LoadGameHistoryRequ
} }
return { ghostBattle_records } return { ghostBattle_records }
}
// Save Screenshot
export async function saveScreenshot(body: wm.protobuf.SaveScreenshotRequest)
{
// Check if screenshot feature enabled or not
let enableScreenshot = Config.getConfig().gameOptions.enableScreenshot || 0;
// Screenshot feature enabled
if(enableScreenshot === 1)
{
let filename: string | undefined = undefined;
filename = `${body.timestamp}_${body.carId}_${body.imageType}.png`;
let dir = path.join('screenshot');
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
// Combine the filename with the save location
let fullname = path.join('screenshot', filename);
// Attempt to write to the file
fs.writeFile(fullname, body.image, (err) => {
if (err)
{
console.log(err);
}
else
{
console.log(`Screenshot saved successfully as '${filename}'`)
}
});
}
} }

View File

@ -195,7 +195,6 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
where:{ where:{
carId: saveExGhostHistory.carId, carId: saveExGhostHistory.carId,
ocmMainDraw: saveExGhostHistory.ocmMainDraw, ocmMainDraw: saveExGhostHistory.ocmMainDraw,
area: saveExGhostHistory.area,
competitionId: ocmEventDate!.competitionId, competitionId: ocmEventDate!.competitionId,
periodId: 0 periodId: 0
} }
@ -207,7 +206,7 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
if(countGBR) if(countGBR)
{ {
// Check if the newest advantage distance is bigger than the older advantage distance // Check if the newest advantage distance is bigger than the older advantage distance
if(countGBR!.result < saveExGhostHistory.result) if(countGBR.result < saveExGhostHistory.result)
{ {
console.log('OCM Ghost Tally found'); console.log('OCM Ghost Tally found');
@ -217,7 +216,6 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
// Get OCM Period ID // Get OCM Period ID
let OCM_periodId = await prisma.oCMPeriod.findFirst({ let OCM_periodId = await prisma.oCMPeriod.findFirst({
where:{ where:{
competitionDbId: ocmEventDate!.dbId,
competitionId: ocmEventDate!.competitionId, competitionId: ocmEventDate!.competitionId,
startAt: startAt:
{ {
@ -248,7 +246,6 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
let getGBR = await prisma.oCMGhostBattleRecord.findFirst({ let getGBR = await prisma.oCMGhostBattleRecord.findFirst({
where:{ where:{
carId: saveExGhostHistory.carId, carId: saveExGhostHistory.carId,
area: saveExGhostHistory.area,
competitionId: ocmEventDate!.competitionId, competitionId: ocmEventDate!.competitionId,
} }
}); });
@ -323,7 +320,7 @@ export async function saveOCMGhostHistory(body: wm.protobuf.SaveGameResultReques
else else
{ {
console.log('OCM Ghost Battle Record not found'); console.log('OCM Ghost Battle Record not found');
console.log('Creating new OOCM Ghost Battle Record entry'); console.log('Creating new OCM Ghost Battle Record entry');
// Current date is OCM Main Draw // Current date is OCM Main Draw
if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date) if(ocmEventDate!.competitionStartAt < date && ocmEventDate!.competitionCloseAt > date)

View File

@ -25,10 +25,13 @@ export default class ResourceModule extends Module {
// Empty list of place records // Empty list of place records
let places: wm.wm.protobuf.Place[] = []; let places: wm.wm.protobuf.Place[] = [];
// Region ID must not 0
let regionId = common.sanitizeInputNotZero(Number(Config.getConfig().regionId)) || 1;
// Response data // Response data
places.push(new wm.wm.protobuf.Place({ places.push(new wm.wm.protobuf.Place({
placeId: Config.getConfig().placeId || 'JPN0123', placeId: Config.getConfig().placeId || 'JPN0123',
regionId: Number(Config.getConfig().regionId) || 1, regionId: regionId,
shopName: Config.getConfig().shopName || 'Bayshore', shopName: Config.getConfig().shopName || 'Bayshore',
country: Config.getConfig().country || 'JPN' country: Config.getConfig().country || 'JPN'
})); }));
@ -46,7 +49,7 @@ export default class ResourceModule extends Module {
await prisma.placeList.create({ await prisma.placeList.create({
data:{ data:{
placeId: Config.getConfig().placeId || 'JPN0123', placeId: Config.getConfig().placeId || 'JPN0123',
regionId: Number(Config.getConfig().regionId) || 1, regionId: regionId,
shopName: Config.getConfig().shopName || 'Bayshore', shopName: Config.getConfig().shopName || 'Bayshore',
country: Config.getConfig().country || 'JPN' country: Config.getConfig().country || 'JPN'
} }
@ -61,7 +64,7 @@ export default class ResourceModule extends Module {
id: checkPlaceList.id id: checkPlaceList.id
}, },
data:{ data:{
regionId: Number(Config.getConfig().regionId), regionId: regionId,
shopName: Config.getConfig().shopName, shopName: Config.getConfig().shopName,
country: Config.getConfig().country country: Config.getConfig().country
} }

View File

@ -20,8 +20,8 @@ export default class UserModule extends Module {
// Get the request body for the load user request // Get the request body for the load user request
let body = wm.wm.protobuf.LoadUserRequest.decode(req.body); let body = wm.wm.protobuf.LoadUserRequest.decode(req.body);
// Block blank card.ini data // Block blank card.ini data and vanilla TP blank card data
if(body.cardChipId.match(/7F5C9744F11111114326.*/)) if(body.cardChipId.match(/7F5C9744F11111114326.*/) || body.cardChipId.match(/0000000000.*/))
{ {
body.cardChipId = ''; body.cardChipId = '';
body.accessCode = ''; body.accessCode = '';
@ -39,6 +39,9 @@ export default class UserModule extends Module {
state: true, state: true,
gtWing: true, gtWing: true,
lastPlayedPlace: true lastPlayedPlace: true
},
where:{
state: { toBeDeleted: false } // except deleted car
} }
} }
} }
@ -59,12 +62,7 @@ export default class UserModule extends Module {
if (!body.cardChipId || !body.accessCode) if (!body.cardChipId || !body.accessCode)
{ {
let msg = { msg.error = wm.wm.protobuf.ErrorCode.ERR_USER_SUCCEEDED;
error: wm.wm.protobuf.ErrorCode.ERR_USER_SUCCEEDED,
numOfOwnedCars: 0,
spappState: wm.wm.protobuf.SmartphoneAppState.SPAPP_UNREGISTERED,
transferState: wm.wm.protobuf.TransferState.NOT_REGISTERED
}
// Encode the response // Encode the response
let message = wm.wm.protobuf.LoadUserResponse.encode(msg); let message = wm.wm.protobuf.LoadUserResponse.encode(msg);