import { Application } from "express"; import {Module} from "module"; import { Config } from "../config"; import * as wm from "../wmmt/wm.proto"; import * as wmsrv from "../wmmt/service.proto"; import { prisma } from ".."; export default class StartupModule extends Module { register(app: Application): void { app.post('/method/register_system_info', (req, res) => { let msg = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, regionId: 1, placeId: "JPN0123", allowedClientLogTypes: [], ghostSelectionMinRedoWait: 30, ghostSelectionMaxRedoWait: 4000, featureVersion: { version: 9, year: 2022, month: 7, pluses: 0, releaseAt: 0 // idk what this is } } let resp = wm.wm.protobuf.RegisterSystemInfoResponse.encode(msg); let end = resp.finish(); let r = res .header('Server', 'v388 wangan') .header('Content-Type', 'application/x-protobuf; revision=8053') .header('Content-Length', end.length.toString()) .status(200); r.send(Buffer.from(end)); }) app.get('/resource/place_list', (req, res) => { console.log('place list'); let places: wm.wm.protobuf.Place[] = []; places.push(new wm.wm.protobuf.Place({ placeId: "JPN0123", regionId: 1, shopName: Config.getConfig().shopName, country: "JPN" })); let resp = wm.wm.protobuf.PlaceList.encode({places}); let end = resp.finish(); let r = res .header('Server', 'v388 wangan') .header('Content-Type', 'application/x-protobuf; revision=8053') .header('Content-Length', end.length.toString()) .status(200); r.send(Buffer.from(end)); }) app.get('/resource/ranking', async (req, res) => { console.log('ranking'); let lists: wmsrv.wm.protobuf.Ranking.List[] = []; // Get TA Ranking for(let i=0; i<25; i++){ let ta_time = await prisma.timeAttackRecord.findMany({ where: { course: i }, orderBy: { time: 'asc' }, take: 20, }); if(ta_time.length !== 0){ let list_ta: wmsrv.wm.protobuf.Ranking.Entry[] = []; for(let j=0; j { console.log('ping'); let body = wm.wm.protobuf.PingRequest.decode(req.body); let ping = { error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS, pong: body.ping || 1 }; let resp = wm.wm.protobuf.PingResponse.encode(ping); let end = resp.finish(); let r = res .header('Server', 'v388 wangan') .header('Content-Type', 'application/x-protobuf; revision=8053') .header('Content-Length', end.length.toString()) .status(200); r.send(Buffer.from(end)); }) app.get('/resource/crown_list', async (req, res) => { console.log('crown_list'); //-------------FOR TESTING PURPOSE--------------- let list_crown: wmsrv.wm.protobuf.Crown[] = []; /*let car_crown = await prisma.car.findFirst({ where: { OR: [ { name: { startsWith: 'KITSU'}, visualModel: 32 }, { name: { startsWith: 'きつ', }, visualModel: 32 }, ], }, include: { gtWing: true }, orderBy: { carId: 'asc' } });*/ let car_crown: wm.wm.protobuf.Car[] = []; for(let i=29; i<31; i++){ car_crown.push(wm.wm.protobuf.Car.create({ carId: 99969+i, userId: 99969+i, regionId: 1, name: 'Luna', manufacturer: 5, model: 27, visualModel: i, defaultColor: 0, customColor: 0, wheel: 0, wheelColor: 0, aero: 0, bonnet: 0, wing: 0, mirror: 0, neon: 0, trunk: 0, plate: 0, plateColor: 0, plateNumber: 0, tunePower: 34, tuneHandling: 34, title: 'Bayshore', level: 65, windowSticker: true, windowStickerString: 'BAYSHORE', windowStickerFont: 0, windowDecoration: 0, rivalMarker: 0, lastPlayedAt: 0, aura: 0, auraMotif: 0, ghostLevel: 10, country: 'JPN', searchCode: 'JPN123' })); } if(car_crown){ for(let i=0; i<14; i++){ if(i % 2 === 0){ list_crown.push(wmsrv.wm.protobuf.Crown.create({ carId: car_crown[0]!.carId, area: i, unlockAt: 0, car: car_crown[0] })); } else{ list_crown.push(wmsrv.wm.protobuf.Crown.create({ carId: car_crown[1]!.carId, area: i, unlockAt: 0, car: car_crown[1] })); } } list_crown.push(wmsrv.wm.protobuf.Crown.create({ carId: car_crown[0]!.carId, area: 18, unlockAt: 0, car: car_crown[0] })); } else{ for(let i=0; i<14; i++){ list_crown.push(wmsrv.wm.protobuf.Crown.create({ carId: i, area: i, // GID_RUNAREA_C1 - GID_RUNAREA_TURNPIKE unlockAt: 0, })); } list_crown.push(wmsrv.wm.protobuf.Crown.create({ carId: 18, area: 18, // GID_RUNAREA_HIROSHIMA unlockAt: 0, })); } let msg = { crowns: list_crown }; //----------------------------------------------- let resp = wmsrv.wm.protobuf.CrownList.encode(msg); let end = resp.finish(); let r = res .header('Server', 'v388 wangan') .header('Content-Type', 'application/x-protobuf; revision=8053') .header('Content-Length', end.length.toString()) .status(200); r.send(Buffer.from(end)); }) } }