2022-07-11 09:15:30 +01:00
|
|
|
import { Application } from "express";
|
|
|
|
import {Module} from "module";
|
2022-08-15 10:47:34 +07:00
|
|
|
import { prisma } from "..";
|
|
|
|
|
|
|
|
// Import Proto
|
2022-07-11 14:48:39 +01:00
|
|
|
import * as wm from "../wmmt/wm.proto";
|
2022-08-15 10:47:34 +07:00
|
|
|
|
|
|
|
// Import Util
|
|
|
|
import * as common from "../util/common";
|
|
|
|
|
2022-07-11 09:15:30 +01:00
|
|
|
|
|
|
|
export default class StartupModule extends Module {
|
|
|
|
register(app: Application): void {
|
2022-08-15 10:47:34 +07:00
|
|
|
|
|
|
|
// Register system info upon booting
|
|
|
|
app.post('/method/register_system_info', async (req, res) => {
|
|
|
|
|
|
|
|
// Get the request body for the load stamp target request
|
|
|
|
let body = wm.wm.protobuf.RegisterSystemInfoRequest.decode(req.body);
|
|
|
|
|
|
|
|
// Get current date
|
|
|
|
let date = Math.floor(new Date().getTime() / 1000);
|
|
|
|
|
2022-08-15 18:30:50 +07:00
|
|
|
// Get current / previous active OCM Event
|
2022-08-15 10:47:34 +07:00
|
|
|
let ocmEventDate = await prisma.oCMEvent.findFirst({
|
2022-08-15 18:48:54 +07:00
|
|
|
where: {
|
2022-08-24 16:46:52 +07:00
|
|
|
// qualifyingPeriodStartAt is less than current date
|
|
|
|
qualifyingPeriodStartAt: { lte: date },
|
|
|
|
|
|
|
|
// competitionEndAt is greater than current date
|
|
|
|
competitionEndAt: { gte: date },
|
|
|
|
},
|
2022-08-15 16:37:19 +07:00
|
|
|
orderBy: [
|
|
|
|
{
|
|
|
|
dbId: 'desc'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
competitionEndAt: 'desc',
|
|
|
|
},
|
|
|
|
],
|
2022-08-15 10:47:34 +07:00
|
|
|
});
|
2022-08-15 18:48:54 +07:00
|
|
|
|
2022-08-18 15:15:42 +07:00
|
|
|
let pastEvent = 0;
|
2022-08-15 18:48:54 +07:00
|
|
|
if(!(ocmEventDate))
|
|
|
|
{
|
|
|
|
ocmEventDate = await prisma.oCMEvent.findFirst({
|
2022-08-31 09:36:00 +07:00
|
|
|
orderBy:{
|
|
|
|
dbId: 'desc'
|
|
|
|
}
|
2022-08-15 18:48:54 +07:00
|
|
|
});
|
2022-08-18 15:15:42 +07:00
|
|
|
|
|
|
|
pastEvent = 1;
|
2022-08-15 18:48:54 +07:00
|
|
|
}
|
|
|
|
|
2022-08-15 10:47:34 +07:00
|
|
|
// Declare GhostCompetitionSchedule
|
2022-08-18 15:15:42 +07:00
|
|
|
let competitionSchedule;
|
|
|
|
let lastCompetitionId: number = 0;
|
2022-08-15 16:37:19 +07:00
|
|
|
if(ocmEventDate)
|
|
|
|
{
|
|
|
|
let pastDay = date - ocmEventDate.competitionEndAt
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
if(pastDay < 604800)
|
|
|
|
{
|
|
|
|
// Creating GhostCompetitionSchedule
|
2022-08-18 15:15:42 +07:00
|
|
|
competitionSchedule = wm.wm.protobuf.GhostCompetitionSchedule.create({
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// OCM Competition ID (1 = C1 (Round 16), 4 = Nagoya (Round 19), 8 = Hiroshima (Round 21))
|
|
|
|
competitionId: ocmEventDate.competitionId,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// OCM Qualifying Start Timestamp
|
|
|
|
qualifyingPeriodStartAt: ocmEventDate.qualifyingPeriodStartAt,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// OCM Qualifying Close Timestamp
|
|
|
|
qualifyingPeriodCloseAt: ocmEventDate.qualifyingPeriodCloseAt,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// OCM Competition (Main Draw) Start Timestamp
|
|
|
|
competitionStartAt: ocmEventDate.competitionStartAt,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// OCM Competition (Main Draw) Close Timestamp
|
|
|
|
competitionCloseAt: ocmEventDate.competitionCloseAt,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// OCM Competition (Main Draw) End Timestamp
|
|
|
|
competitionEndAt: ocmEventDate.competitionEndAt,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// idk what this is
|
|
|
|
lengthOfPeriod: ocmEventDate.lengthOfPeriod,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// idk what this is
|
|
|
|
lengthOfInterval: ocmEventDate.lengthOfInterval,
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-15 16:37:19 +07:00
|
|
|
// Area for the event (GID_RUNAREA_*, 8 is GID_RUNAREA_NAGOYA)
|
|
|
|
area: ocmEventDate.area,
|
|
|
|
|
|
|
|
// idk what this is
|
|
|
|
minigamePatternId: ocmEventDate.minigamePatternId
|
|
|
|
});
|
|
|
|
}
|
2022-08-18 15:15:42 +07:00
|
|
|
|
|
|
|
if(pastEvent === 1 && pastDay < 604800)
|
|
|
|
{
|
|
|
|
lastCompetitionId = ocmEventDate.competitionId
|
|
|
|
}
|
2022-08-15 10:47:34 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Response data
|
2022-07-11 11:45:36 +01:00
|
|
|
let msg = {
|
2022-07-11 14:48:39 +01:00
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
2022-08-15 10:47:34 +07:00
|
|
|
regionId: body.allnetRegion0,
|
|
|
|
placeId: body.regionName0,
|
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-08-15 10:47:34 +07:00
|
|
|
},
|
2022-08-18 15:15:42 +07:00
|
|
|
latestCompetitionId: lastCompetitionId || null,
|
|
|
|
competitionSchedule: competitionSchedule || null // OCM Event Available or not
|
2022-07-11 11:45:36 +01:00
|
|
|
}
|
2022-08-15 10:47:34 +07:00
|
|
|
|
|
|
|
// Encode the response
|
|
|
|
let message = wm.wm.protobuf.RegisterSystemInfoResponse.encode(msg);
|
|
|
|
|
|
|
|
// Send the response to the client
|
|
|
|
common.sendResponse(message, res);
|
2022-07-11 13:43:39 +01:00
|
|
|
})
|
|
|
|
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
// Update Event Mode Serial
|
|
|
|
app.post('/method/update_user_session', (req, res) => {
|
2022-07-26 20:09:00 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
let body = wm.wm.protobuf.UpdateUserSessionRequest.decode(req.body);
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
// TODO: Actual stuff here
|
|
|
|
// This is literally just bare-bones so the shit boots
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
// Response data
|
|
|
|
let msg = {
|
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
2022-07-26 20:09:00 +07:00
|
|
|
}
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
// Generate the response message
|
|
|
|
let message = wm.wm.protobuf.UpdateUserSessionResponse.encode(msg);
|
2022-07-26 20:09:00 +07:00
|
|
|
|
2022-08-15 10:47:34 +07:00
|
|
|
// Send the response to the client
|
|
|
|
common.sendResponse(message, res);
|
2022-08-24 16:46:52 +07:00
|
|
|
});
|
2022-07-26 20:09:00 +07:00
|
|
|
|
2022-08-15 10:47:34 +07:00
|
|
|
// Ping
|
2022-07-11 15:19:36 +01:00
|
|
|
app.post('/method/ping', (req, res) => {
|
2022-08-24 16:46:52 +07:00
|
|
|
|
2022-07-11 15:19:36 +01:00
|
|
|
let body = wm.wm.protobuf.PingRequest.decode(req.body);
|
2022-08-15 10:47:34 +07:00
|
|
|
|
|
|
|
// Response data
|
2022-07-11 15:19:36 +01:00
|
|
|
let ping = {
|
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
|
|
|
pong: body.ping || 1
|
|
|
|
};
|
2022-08-15 10:47:34 +07:00
|
|
|
|
|
|
|
// Encode the response
|
|
|
|
let message = wm.wm.protobuf.PingResponse.encode(ping);
|
|
|
|
|
|
|
|
// Send the response to the client
|
|
|
|
common.sendResponse(message, res);
|
2022-07-11 15:19:36 +01:00
|
|
|
})
|
2022-07-28 12:25:59 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
|
|
|
|
app.post('/method/register_system_stats', async (req, res) => {
|
2022-08-15 10:47:34 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
let body = wm.wm.protobuf.RegisterSystemStatsRequest.decode(req.body);
|
2022-08-18 21:33:32 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
// TODO: Actual stuff here
|
|
|
|
// This is literally just bare-bones so the shit boots
|
2022-08-18 21:33:32 +07:00
|
|
|
|
|
|
|
// Response data
|
|
|
|
let msg = {
|
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode the response
|
|
|
|
let message = wm.wm.protobuf.RegisterSystemStatsResponse.encode(msg);
|
|
|
|
|
|
|
|
// Send the response to the client
|
|
|
|
common.sendResponse(message, res);
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
app.post('/method/update_event_mode_serial', async (req, res) => {
|
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
let body = wm.wm.protobuf.UpdateEventModeSerialRequest.decode(req.body);
|
|
|
|
|
|
|
|
// TODO: Actual stuff here
|
|
|
|
// This is literally just bare-bones so the shit boots
|
|
|
|
|
2022-08-18 21:33:32 +07:00
|
|
|
// Response data
|
|
|
|
let msg = {
|
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
2022-08-24 16:46:52 +07:00
|
|
|
serialError: wm.wm.protobuf.EventModeSerialErrorCode.SERIAL_NO_INPUT
|
2022-08-18 21:33:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode the response
|
|
|
|
let message = wm.wm.protobuf.UpdateEventModeSerialResponse.encode(msg);
|
|
|
|
|
|
|
|
// Send the response to the client
|
|
|
|
common.sendResponse(message, res);
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
app.post('/method/submit_client_log', async (req, res) => {
|
2022-08-18 21:33:32 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
let body = wm.wm.protobuf.SubmitClientLogRequest.decode(req.body);
|
2022-08-18 21:33:32 +07:00
|
|
|
|
2022-08-24 16:46:52 +07:00
|
|
|
// TODO: Actual stuff here
|
|
|
|
// This is literally just bare-bones so the shit boots
|
2022-08-18 21:33:32 +07:00
|
|
|
|
|
|
|
// Response data
|
|
|
|
let msg = {
|
|
|
|
error: wm.wm.protobuf.ErrorCode.ERR_SUCCESS,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode the response
|
2022-08-24 16:46:52 +07:00
|
|
|
let message = wm.wm.protobuf.SubmitClientLogResponse.encode(msg);
|
2022-08-18 21:33:32 +07:00
|
|
|
|
|
|
|
// Send the response to the client
|
|
|
|
common.sendResponse(message, res);
|
|
|
|
})
|
2022-07-11 09:15:30 +01:00
|
|
|
}
|
2022-08-04 14:26:37 +07:00
|
|
|
}
|