fix typescript errors
This commit is contained in:
parent
3d2f5753da
commit
e6708152c0
@ -1,28 +1,29 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { getSession } from "@/src/managers/sessionManager";
|
||||
import { FindSessionRequest } from "@/src/types/session";
|
||||
|
||||
const findSessionsController: RequestHandler = (_req, res) => {
|
||||
console.log("FindSession Request:", JSON.parse(_req.body));
|
||||
let req = JSON.parse(_req.body);
|
||||
if (req.id != undefined) {
|
||||
console.log("Found ID");
|
||||
let session = getSession(req.id);
|
||||
const sessionRequest = JSON.parse(String(_req.body)) as FindSessionRequest;
|
||||
if (sessionRequest.id != undefined) {
|
||||
const session = getSession(sessionRequest.id);
|
||||
|
||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||
else res.json({});
|
||||
} else if (req.originalSessionId != undefined) {
|
||||
console.log("Found OriginalSessionID");
|
||||
|
||||
let session = getSession(req.originalSessionId);
|
||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||
else res.json({});
|
||||
} else {
|
||||
console.log("Found SessionRequest");
|
||||
|
||||
let session = getSession(_req.body);
|
||||
if (session) res.json({ queryId: req.queryId, Sessions: session });
|
||||
else res.json({});
|
||||
if (session) {
|
||||
return res.json({ queryId: sessionRequest.queryId, Sessions: session });
|
||||
}
|
||||
return res.json({});
|
||||
} else if (sessionRequest.originalSessionId != undefined) {
|
||||
const session = getSession(sessionRequest.originalSessionId);
|
||||
if (session) {
|
||||
return res.json({ queryId: sessionRequest.queryId, Sessions: session });
|
||||
}
|
||||
return res.json({});
|
||||
}
|
||||
|
||||
const session = getSession(sessionRequest);
|
||||
if (session) {
|
||||
return res.json({ queryId: sessionRequest.queryId, Sessions: session });
|
||||
}
|
||||
return res.json({});
|
||||
};
|
||||
|
||||
export { findSessionsController };
|
||||
|
@ -1,10 +1,9 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { createNewSession } from "@/src/managers/sessionManager";
|
||||
import { Session } from "@/src/types/session";
|
||||
|
||||
const hostSessionController: RequestHandler = (_req, res) => {
|
||||
console.log("HostSession Request:", JSON.parse(_req.body));
|
||||
let session = createNewSession(JSON.parse(_req.body), _req.query.accountId as string);
|
||||
console.log("New Session Created: ", session);
|
||||
const session = createNewSession(JSON.parse(String(_req.body)) as Session, _req.query.accountId as string);
|
||||
|
||||
res.json({ sessionId: { $oid: session.sessionId }, rewardSeed: 99999999 });
|
||||
};
|
||||
|
@ -2,9 +2,8 @@ import { RequestHandler } from "express";
|
||||
import { getSessionByID } from "@/src/managers/sessionManager";
|
||||
|
||||
const joinSessionController: RequestHandler = (_req, res) => {
|
||||
console.log("JoinSession Request:", JSON.parse(_req.body));
|
||||
let req = JSON.parse(_req.body);
|
||||
let session = getSessionByID(req.sessionIds[0]);
|
||||
const req = JSON.parse(String(_req.body)) as { sessionIds: string[] };
|
||||
const session = getSessionByID(req.sessionIds[0]);
|
||||
res.json({ rewardSeed: session?.rewardSeed, sessionId: { $oid: session?.sessionId } });
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
const rerollRandomModController: RequestHandler = (_req, res) => {
|
||||
console.log("RerollRandomMod Request:", _req.body.toString("hex").replace(/(.)(.)/g, "$1$2 "));
|
||||
// console.log("RerollRandomMod Request:", _req.body.toString("hex").replace(/(.)(.)/g, "$1$2 "));
|
||||
res.json({});
|
||||
};
|
||||
|
||||
|
@ -5,9 +5,9 @@ const updateSessionGetController: RequestHandler = (_req, res) => {
|
||||
res.json({});
|
||||
};
|
||||
const updateSessionPostController: RequestHandler = (_req, res) => {
|
||||
console.log("UpdateSessions POST Request:", JSON.parse(_req.body));
|
||||
console.log("ReqID:", _req.query.sessionId as string);
|
||||
updateSession(_req.query.sessionId as string, _req.body);
|
||||
// console.log("UpdateSessions POST Request:", JSON.parse(_req.body));
|
||||
// console.log("ReqID:", _req.query.sessionId as string);
|
||||
updateSession(_req.query.sessionId as string, String(_req.body));
|
||||
res.json({});
|
||||
};
|
||||
export { updateSessionGetController, updateSessionPostController };
|
||||
|
@ -2,6 +2,7 @@ import { toCreateAccount, toDatabaseAccount } from "@/src/helpers/customHelpers"
|
||||
import { createAccount } from "@/src/services/loginService";
|
||||
import { RequestHandler } from "express";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
const createAccountController: RequestHandler = async (req, res) => {
|
||||
const createAccountData = toCreateAccount(req.body);
|
||||
const databaseAccount = toDatabaseAccount(createAccountData);
|
||||
|
@ -2,8 +2,6 @@ import http from "http";
|
||||
import https from "https";
|
||||
import fs from "node:fs";
|
||||
import { app } from "./app";
|
||||
//const morgan = require("morgan");
|
||||
//const bodyParser = require("body-parser");
|
||||
|
||||
const options = {
|
||||
key: fs.readFileSync("static/certs/key.pem"),
|
||||
@ -11,9 +9,5 @@ const options = {
|
||||
passphrase: "123456"
|
||||
};
|
||||
|
||||
// const server = http.createServer(app).listen(80);
|
||||
http.createServer(app).listen(80, () => console.log("server started on port 80"));
|
||||
const server = https.createServer(options, app).listen(443, () => console.log("server started on port 443"));
|
||||
|
||||
// server.keepAliveTimeout = 60 * 1000 + 1000;
|
||||
// server.headersTimeout = 60 * 1000 + 2000;
|
||||
https.createServer(options, app).listen(443, () => console.log("server started on port 443"));
|
||||
|
@ -24,7 +24,7 @@ function createNewSession(sessionData: Session, Creator: string): Session {
|
||||
customSettings: sessionData.customSettings || "",
|
||||
rewardSeed: sessionData.rewardSeed || -1,
|
||||
guildId: sessionData.guildId || "",
|
||||
buildId: sessionData.buildId || 4920386201513015989,
|
||||
buildId: sessionData.buildId || 4920386201513015989n,
|
||||
platform: sessionData.platform || 0,
|
||||
xplatform: sessionData.xplatform || true,
|
||||
freePublic: sessionData.freePublic || 3,
|
||||
@ -43,7 +43,10 @@ function getSessionByID(sessionId: string): Session | undefined {
|
||||
return sessions.find(session => session.sessionId === sessionId);
|
||||
}
|
||||
|
||||
function getSession(sessionIdOrRequest: string | FindSessionRequest): any[] {
|
||||
function getSession(sessionIdOrRequest: string | FindSessionRequest): {
|
||||
createdBy: string;
|
||||
id: string;
|
||||
}[] {
|
||||
if (typeof sessionIdOrRequest === "string") {
|
||||
const session = sessions.find(session => session.sessionId === sessionIdOrRequest);
|
||||
if (session) {
|
||||
@ -58,7 +61,7 @@ function getSession(sessionIdOrRequest: string | FindSessionRequest): any[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
const request = sessionIdOrRequest as FindSessionRequest;
|
||||
const request = sessionIdOrRequest;
|
||||
const matchingSessions = sessions.filter(session => {
|
||||
for (const key in request) {
|
||||
if (key !== "eloRating" && key !== "queryId" && request[key] !== session[key as keyof Session]) {
|
||||
@ -100,9 +103,12 @@ function getNewSessionID(): string {
|
||||
|
||||
function updateSession(sessionId: string, sessionData: string): boolean {
|
||||
const session = sessions.find(session => session.sessionId === sessionId);
|
||||
if (!session) return false;
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const updatedData = JSON.parse(sessionData);
|
||||
const updatedData: unknown = JSON.parse(sessionData);
|
||||
Object.assign(session, updatedData);
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
@ -18,7 +18,7 @@ export interface Session {
|
||||
customSettings: string;
|
||||
rewardSeed: number;
|
||||
guildId: string;
|
||||
buildId: number;
|
||||
buildId: number | bigint;
|
||||
platform: number;
|
||||
xplatform: boolean;
|
||||
freePublic: number;
|
||||
@ -27,5 +27,15 @@ export interface Session {
|
||||
}
|
||||
|
||||
export interface FindSessionRequest {
|
||||
[key: string]: any;
|
||||
id?: string;
|
||||
originalSessionId?: string;
|
||||
buildId: number;
|
||||
gameModeId: number;
|
||||
regionId: number;
|
||||
maxEloDifference: number;
|
||||
eloRating: number;
|
||||
enforceElo: boolean;
|
||||
platform: number;
|
||||
xplatform: boolean;
|
||||
queryId: number;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user