2022-07-11 09:15:30 +01:00
|
|
|
|
import { Application } from "express";
|
|
|
|
|
import {Module} from "module";
|
2022-07-12 15:25:54 +01:00
|
|
|
|
import { Config } from "../config";
|
2022-07-11 14:48:39 +01:00
|
|
|
|
import * as wm from "../wmmt/wm.proto";
|
2022-07-27 18:38:50 +07:00
|
|
|
|
import * as wmsrv from "../wmmt/service.proto";
|
2022-07-26 20:09:00 +07:00
|
|
|
|
import { prisma } from "..";
|
2022-07-11 09:15:30 +01:00
|
|
|
|
|
|
|
|
|
export default class StartupModule extends Module {
|
|
|
|
|
register(app: Application): void {
|
2022-07-11 11:45:36 +01:00
|
|
|
|
app.post('/method/register_system_info', (req, res) => {
|
|
|
|
|
let msg = {
|
2022-07-11 14:48:39 +01:00
|
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
2022-07-11 13:43:39 +01:00
|
|
|
|
regionId: 1,
|
2022-07-11 12:29:28 +01:00
|
|
|
|
placeId: "JPN0123",
|
2022-07-11 13:43:39 +01:00
|
|
|
|
allowedClientLogTypes: [],
|
|
|
|
|
ghostSelectionMinRedoWait: 30,
|
|
|
|
|
ghostSelectionMaxRedoWait: 4000,
|
2022-07-11 11:45:36 +01:00
|
|
|
|
featureVersion: {
|
2022-07-11 13:43:39 +01:00
|
|
|
|
version: 9,
|
2022-07-11 11:45:36 +01:00
|
|
|
|
year: 2022,
|
|
|
|
|
month: 7,
|
2022-07-11 13:43:39 +01:00
|
|
|
|
pluses: 0,
|
|
|
|
|
releaseAt: 0 // idk what this is
|
2022-07-11 14:48:39 +01:00
|
|
|
|
}
|
2022-07-11 11:45:36 +01:00
|
|
|
|
}
|
2022-07-11 14:48:39 +01:00
|
|
|
|
let resp = wm.wm.protobuf.RegisterSystemInfoResponse.encode(msg);
|
2022-07-11 11:45:36 +01:00
|
|
|
|
let end = resp.finish();
|
|
|
|
|
let r = res
|
2022-07-11 13:43:39 +01:00
|
|
|
|
.header('Server', 'v388 wangan')
|
|
|
|
|
.header('Content-Type', 'application/x-protobuf; revision=8053')
|
2022-07-11 11:38:21 +01:00
|
|
|
|
.header('Content-Length', end.length.toString())
|
2022-07-11 13:43:39 +01:00
|
|
|
|
.status(200);
|
|
|
|
|
r.send(Buffer.from(end));
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
app.get('/resource/place_list', (req, res) => {
|
|
|
|
|
console.log('place list');
|
2022-07-11 14:48:39 +01:00
|
|
|
|
let places: wm.wm.protobuf.Place[] = [];
|
|
|
|
|
places.push(new wm.wm.protobuf.Place({
|
2022-07-11 12:29:28 +01:00
|
|
|
|
placeId: "JPN0123",
|
2022-07-11 13:43:39 +01:00
|
|
|
|
regionId: 1,
|
2022-07-12 15:25:54 +01:00
|
|
|
|
shopName: Config.getConfig().shopName,
|
2022-07-11 13:43:39 +01:00
|
|
|
|
country: "JPN"
|
2022-07-11 14:48:39 +01:00
|
|
|
|
}));
|
|
|
|
|
let resp = wm.wm.protobuf.PlaceList.encode({places});
|
2022-07-11 12:29:28 +01:00
|
|
|
|
let end = resp.finish();
|
2022-07-11 13:43:39 +01:00
|
|
|
|
let r = res
|
|
|
|
|
.header('Server', 'v388 wangan')
|
|
|
|
|
.header('Content-Type', 'application/x-protobuf; revision=8053')
|
2022-07-11 11:38:21 +01:00
|
|
|
|
.header('Content-Length', end.length.toString())
|
2022-07-11 13:43:39 +01:00
|
|
|
|
.status(200);
|
2022-07-11 12:29:28 +01:00
|
|
|
|
r.send(Buffer.from(end));
|
2022-07-11 11:45:36 +01:00
|
|
|
|
})
|
2022-07-11 15:19:36 +01:00
|
|
|
|
|
2022-07-26 20:09:00 +07:00
|
|
|
|
app.get('/resource/ranking', async (req, res) => {
|
|
|
|
|
console.log('ranking');
|
2022-07-27 18:38:50 +07:00
|
|
|
|
let lists: wmsrv.wm.protobuf.Ranking.List[] = [];
|
2022-07-26 20:09:00 +07:00
|
|
|
|
|
|
|
|
|
// Get TA Ranking
|
|
|
|
|
for(let i=0; i<25; i++){
|
|
|
|
|
let ta_time = await prisma.timeAttackRecord.findMany({
|
|
|
|
|
where: {
|
|
|
|
|
course: i
|
|
|
|
|
},
|
|
|
|
|
orderBy: {
|
|
|
|
|
time: 'asc'
|
2022-07-28 12:25:59 +07:00
|
|
|
|
},
|
|
|
|
|
take: 20,
|
2022-07-26 20:09:00 +07:00
|
|
|
|
});
|
|
|
|
|
if(ta_time.length !== 0){
|
2022-07-27 18:38:50 +07:00
|
|
|
|
let list_ta: wmsrv.wm.protobuf.Ranking.Entry[] = [];
|
2022-07-26 20:09:00 +07:00
|
|
|
|
for(let j=0; j<ta_time.length; j++){
|
|
|
|
|
let car_ta = await prisma.car.findFirst({
|
|
|
|
|
where: {
|
|
|
|
|
carId: ta_time[j].carId
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-27 18:38:50 +07:00
|
|
|
|
list_ta.push(wmsrv.wm.protobuf.Ranking.Entry.create({
|
2022-07-26 20:09:00 +07:00
|
|
|
|
carId: car_ta!.carId,
|
|
|
|
|
rank: car_ta!.level,
|
|
|
|
|
result: ta_time[j].time,
|
|
|
|
|
name: car_ta!.name,
|
|
|
|
|
regionId: car_ta!.regionId,
|
|
|
|
|
model: car_ta!.model,
|
|
|
|
|
visualModel: car_ta!.visualModel,
|
|
|
|
|
defaultColor: car_ta!.defaultColor,
|
|
|
|
|
tunePower: car_ta!.tunePower,
|
|
|
|
|
tuneHandling: car_ta!.tuneHandling,
|
|
|
|
|
title: car_ta!.title,
|
|
|
|
|
level: car_ta!.level
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if(ta_time.length < 20){
|
|
|
|
|
for(let j=ta_time.length; j<20; j++){
|
|
|
|
|
let resulttime = 599999;
|
|
|
|
|
if(i === 22 || i === 23){
|
|
|
|
|
resulttime = 1199999
|
|
|
|
|
}
|
2022-07-27 18:38:50 +07:00
|
|
|
|
list_ta.push(wmsrv.wm.protobuf.Ranking.Entry.create({
|
2022-07-26 20:09:00 +07:00
|
|
|
|
carId: 0,
|
|
|
|
|
rank: 0,
|
|
|
|
|
result: resulttime,
|
|
|
|
|
name: 'GUEST',
|
|
|
|
|
regionId: 0,
|
2022-07-27 12:41:07 +07:00
|
|
|
|
model: Math.floor(Math.random() * 106) + 1,
|
|
|
|
|
visualModel: Math.floor(Math.random() * 106) + 1,
|
2022-07-26 20:09:00 +07:00
|
|
|
|
defaultColor: 0,
|
|
|
|
|
tunePower: 0,
|
|
|
|
|
tuneHandling: 0,
|
|
|
|
|
title: 'Wangan Beginner',
|
|
|
|
|
level: 0
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-27 18:38:50 +07:00
|
|
|
|
lists.push(new wmsrv.wm.protobuf.Ranking.List({
|
|
|
|
|
rankingType: i, // RANKING_TA_*AREA*
|
2022-07-26 20:09:00 +07:00
|
|
|
|
topRecords: list_ta
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get VS Star Ranking
|
|
|
|
|
let car_vs = await prisma.car.findMany({
|
|
|
|
|
orderBy: {
|
|
|
|
|
vsStarCount: 'desc'
|
2022-07-28 12:25:59 +07:00
|
|
|
|
},
|
|
|
|
|
take: 20,
|
2022-07-26 20:09:00 +07:00
|
|
|
|
});
|
2022-07-27 18:38:50 +07:00
|
|
|
|
let list_vs: wmsrv.wm.protobuf.Ranking.Entry[] = [];
|
2022-07-26 20:09:00 +07:00
|
|
|
|
for(let i=0; i<car_vs.length; i++){
|
2022-07-27 18:38:50 +07:00
|
|
|
|
list_vs.push(wmsrv.wm.protobuf.Ranking.Entry.create({
|
2022-07-26 20:09:00 +07:00
|
|
|
|
carId: car_vs[i].carId,
|
|
|
|
|
rank: car_vs[i].level,
|
|
|
|
|
result: car_vs[i].vsStarCount,
|
|
|
|
|
name: car_vs[i].name,
|
|
|
|
|
regionId: car_vs[i].regionId,
|
|
|
|
|
model: car_vs[i].model,
|
|
|
|
|
visualModel: car_vs[i].visualModel,
|
|
|
|
|
defaultColor: car_vs[i].defaultColor,
|
|
|
|
|
tunePower: car_vs[i].tunePower,
|
|
|
|
|
tuneHandling: car_vs[i].tuneHandling,
|
|
|
|
|
title: car_vs[i].title,
|
|
|
|
|
level: car_vs[i].level
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if(car_vs.length < 20){
|
|
|
|
|
for(let j=car_vs.length; j<20; j++){
|
2022-07-27 18:38:50 +07:00
|
|
|
|
list_vs.push(wmsrv.wm.protobuf.Ranking.Entry.create({
|
2022-07-26 20:09:00 +07:00
|
|
|
|
carId: 0,
|
|
|
|
|
rank: 0,
|
|
|
|
|
result: 0,
|
|
|
|
|
name: 'GUEST',
|
|
|
|
|
regionId: 0,
|
2022-07-27 12:41:07 +07:00
|
|
|
|
model: Math.floor(Math.random() * 106) + 1,
|
|
|
|
|
visualModel: Math.floor(Math.random() * 106) + 1,
|
2022-07-26 20:09:00 +07:00
|
|
|
|
defaultColor: 0,
|
|
|
|
|
tunePower: 0,
|
|
|
|
|
tuneHandling: 0,
|
|
|
|
|
title: 'Wangan Beginner',
|
|
|
|
|
level: 0
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-27 18:38:50 +07:00
|
|
|
|
lists.push(new wmsrv.wm.protobuf.Ranking.List({
|
|
|
|
|
rankingType: 100, // RANKING_VS_STAR
|
2022-07-26 20:09:00 +07:00
|
|
|
|
topRecords: list_vs
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
2022-07-27 18:38:50 +07:00
|
|
|
|
// Get Ghost Defeated Ranking
|
2022-07-26 20:09:00 +07:00
|
|
|
|
let car_ghost = await prisma.car.findMany({
|
|
|
|
|
orderBy: {
|
|
|
|
|
rgWinCount: 'desc'
|
2022-07-28 12:25:59 +07:00
|
|
|
|
},
|
|
|
|
|
take: 20,
|
2022-07-26 20:09:00 +07:00
|
|
|
|
});
|
2022-07-27 18:38:50 +07:00
|
|
|
|
let list_ghost: wmsrv.wm.protobuf.Ranking.Entry[] = [];
|
2022-07-26 20:09:00 +07:00
|
|
|
|
for(let i=0; i<car_ghost.length; i++){
|
2022-07-27 18:38:50 +07:00
|
|
|
|
list_ghost.push(wmsrv.wm.protobuf.Ranking.Entry.create({
|
2022-07-26 20:09:00 +07:00
|
|
|
|
carId: car_ghost[i].carId,
|
|
|
|
|
rank: car_ghost[i].level,
|
|
|
|
|
result: car_ghost[i].rgWinCount,
|
|
|
|
|
name: car_ghost[i].name,
|
|
|
|
|
regionId: car_ghost[i].regionId,
|
|
|
|
|
model: car_ghost[i].model,
|
|
|
|
|
visualModel: car_ghost[i].visualModel,
|
|
|
|
|
defaultColor: car_ghost[i].defaultColor,
|
|
|
|
|
tunePower: car_ghost[i].tunePower,
|
|
|
|
|
tuneHandling: car_ghost[i].tuneHandling,
|
|
|
|
|
title: car_ghost[i].title,
|
|
|
|
|
level: car_ghost[i].level
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if(car_ghost.length < 20){
|
|
|
|
|
for(let j=car_ghost.length; j<20; j++){
|
2022-07-27 18:38:50 +07:00
|
|
|
|
list_ghost.push(wmsrv.wm.protobuf.Ranking.Entry.create({
|
2022-07-26 20:09:00 +07:00
|
|
|
|
carId: 0,
|
|
|
|
|
rank: 0,
|
|
|
|
|
result: 0,
|
|
|
|
|
name: 'GUEST',
|
|
|
|
|
regionId: 0,
|
2022-07-27 12:41:07 +07:00
|
|
|
|
model: Math.floor(Math.random() * 106) + 1,
|
|
|
|
|
visualModel: Math.floor(Math.random() * 106) + 1,
|
2022-07-26 20:09:00 +07:00
|
|
|
|
defaultColor: 0,
|
|
|
|
|
tunePower: 0,
|
|
|
|
|
tuneHandling: 0,
|
|
|
|
|
title: 'Wangan Beginner',
|
|
|
|
|
level: 0
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-27 18:38:50 +07:00
|
|
|
|
lists.push(new wmsrv.wm.protobuf.Ranking.List({
|
|
|
|
|
rankingType: 101, // RANKING_GHOST_DEFEATED_COUNT
|
2022-07-26 20:09:00 +07:00
|
|
|
|
topRecords: list_ghost
|
|
|
|
|
}));
|
|
|
|
|
|
2022-07-27 18:38:50 +07:00
|
|
|
|
let resp = wmsrv.wm.protobuf.Ranking.encode({lists});
|
2022-07-26 20:09:00 +07:00
|
|
|
|
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));
|
|
|
|
|
})
|
|
|
|
|
|
2022-07-11 15:19:36 +01:00
|
|
|
|
app.post('/method/ping', (req, res) => {
|
|
|
|
|
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));
|
|
|
|
|
})
|
2022-07-28 12:25:59 +07:00
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(car_crown){
|
|
|
|
|
for(let i=0; i<14; i++){
|
|
|
|
|
list_crown.push(wmsrv.wm.protobuf.Crown.create({
|
|
|
|
|
carId: car_crown!.carId,
|
|
|
|
|
area: i,
|
|
|
|
|
unlockAt: 0,
|
|
|
|
|
car: car_crown
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
list_crown.push(wmsrv.wm.protobuf.Crown.create({
|
|
|
|
|
carId: car_crown!.carId,
|
|
|
|
|
area: 18,
|
|
|
|
|
unlockAt: 0,
|
|
|
|
|
car: car_crown
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
})
|
2022-07-11 09:15:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|