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