prettier
This commit is contained in:
parent
2881446670
commit
8996ba8e1c
@ -1,8 +1,7 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { deleteSession } from '@/src/managers/sessionManager';
|
import { deleteSession } from "@/src/managers/sessionManager";
|
||||||
|
|
||||||
const deleteSessionController: RequestHandler = (_req, res) => {
|
const deleteSessionController: RequestHandler = (_req, res) => {
|
||||||
|
|
||||||
//res.json({ sessionId: { $oid: "64768f104722f795300c9fc0" }, rewardSeed: 5867309943877621023 });
|
//res.json({ sessionId: { $oid: "64768f104722f795300c9fc0" }, rewardSeed: 5867309943877621023 });
|
||||||
deleteSession(_req.query.sessionId as string);
|
deleteSession(_req.query.sessionId as string);
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
|
@ -1,42 +1,28 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { getSession } from '@/src/managers/sessionManager';
|
import { getSession } from "@/src/managers/sessionManager";
|
||||||
|
|
||||||
const findSessionsController: RequestHandler = (_req, res) => {
|
const findSessionsController: RequestHandler = (_req, res) => {
|
||||||
|
|
||||||
console.log("FindSession Request:", JSON.parse(_req.body));
|
console.log("FindSession Request:", JSON.parse(_req.body));
|
||||||
let r = JSON.parse(_req.body);
|
let r = JSON.parse(_req.body);
|
||||||
if(r != undefined)
|
if (r != undefined) {
|
||||||
{
|
|
||||||
console.log("Found ID");
|
console.log("Found ID");
|
||||||
let s = getSession(r.id);
|
let s = getSession(r.id);
|
||||||
|
|
||||||
if(s)
|
if (s) res.json({ queryId: r.queryId, Sessions: s });
|
||||||
res.json({"queryId":r.queryId,"Sessions":s});
|
else res.json({});
|
||||||
else
|
} else if (r != undefined) {
|
||||||
res.json({});
|
|
||||||
}
|
|
||||||
else if(r != undefined)
|
|
||||||
{
|
|
||||||
console.log("Found OriginalSessionID");
|
console.log("Found OriginalSessionID");
|
||||||
|
|
||||||
let s = getSession(r.originalSessionId);
|
let s = getSession(r.originalSessionId);
|
||||||
if(s)
|
if (s) res.json({ queryId: r.queryId, Sessions: [s] });
|
||||||
res.json({"queryId":r.queryId,"Sessions":[s]});
|
else res.json({});
|
||||||
else
|
} else {
|
||||||
res.json({});
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
console.log("Found SessionRequest");
|
console.log("Found SessionRequest");
|
||||||
|
|
||||||
let s = getSession(_req.body);
|
let s = getSession(_req.body);
|
||||||
if(s)
|
if (s) res.json({ queryId: r.queryId, Sessions: [s] });
|
||||||
res.json({"queryId":r.queryId,"Sessions":[s]});
|
else res.json({});
|
||||||
else
|
|
||||||
res.json({});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { findSessionsController };
|
export { findSessionsController };
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { createNewSession } from '@/src/managers/sessionManager';
|
import { createNewSession } from "@/src/managers/sessionManager";
|
||||||
|
|
||||||
const hostSessionController: RequestHandler = (_req, res) => {
|
const hostSessionController: RequestHandler = (_req, res) => {
|
||||||
console.log("HostSession Request:", JSON.parse(_req.body));
|
console.log("HostSession Request:", JSON.parse(_req.body));
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import { RequestHandler } from "express";
|
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));
|
console.log("JoinSession Request:", JSON.parse(_req.body));
|
||||||
let r = JSON.parse(_req.body);
|
let r = JSON.parse(_req.body);
|
||||||
let s = getSessionByID(r.sessionIds[0])
|
let s = getSessionByID(r.sessionIds[0]);
|
||||||
res.json({"rewardSeed":s?.rewardSeed,"sessionId":{"$oid":s?.sessionId}});
|
res.json({ rewardSeed: s?.rewardSeed, sessionId: { $oid: s?.sessionId } });
|
||||||
};
|
};
|
||||||
|
|
||||||
export { joinSessionController };
|
export { joinSessionController };
|
@ -1,13 +1,13 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
import { updateSession } from '@/src/managers/sessionManager';
|
import { updateSession } from "@/src/managers/sessionManager";
|
||||||
|
|
||||||
const updateSessionGetController: RequestHandler = (_req, res) => {
|
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, _req.body);
|
||||||
res.json({});
|
res.json({});
|
||||||
};
|
};
|
||||||
export { updateSessionGetController, updateSessionPostController };
|
export { updateSessionGetController, updateSessionPostController };
|
||||||
|
@ -44,18 +44,18 @@ interface Session {
|
|||||||
difficulty: sessionData.difficulty || 0,
|
difficulty: sessionData.difficulty || 0,
|
||||||
hasStarted: sessionData.hasStarted || false,
|
hasStarted: sessionData.hasStarted || false,
|
||||||
enableVoice: sessionData.enableVoice || true,
|
enableVoice: sessionData.enableVoice || true,
|
||||||
matchType: sessionData.matchType || 'NORMAL',
|
matchType: sessionData.matchType || "NORMAL",
|
||||||
maps: sessionData.maps || [],
|
maps: sessionData.maps || [],
|
||||||
originalSessionId: sessionData.originalSessionId || '',
|
originalSessionId: sessionData.originalSessionId || "",
|
||||||
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 || 4920386201513015989,
|
||||||
platform: sessionData.platform || 0,
|
platform: sessionData.platform || 0,
|
||||||
xplatform: sessionData.xplatform || true,
|
xplatform: sessionData.xplatform || true,
|
||||||
freePublic: sessionData.freePublic || 3,
|
freePublic: sessionData.freePublic || 3,
|
||||||
freePrivate: sessionData.freePrivate || 0,
|
freePrivate: sessionData.freePrivate || 0,
|
||||||
fullReset:0,
|
fullReset: 0
|
||||||
};
|
};
|
||||||
sessions.push(newSession);
|
sessions.push(newSession);
|
||||||
return newSession;
|
return newSession;
|
||||||
@ -69,21 +69,20 @@ interface Session {
|
|||||||
return sessions.find(session => session.sessionId === sessionId);
|
return sessions.find(session => session.sessionId === sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface FindSessionRequest {
|
interface FindSessionRequest {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSession(sessionIdOrRequest: string | FindSessionRequest): any[] {
|
function getSession(sessionIdOrRequest: string | FindSessionRequest): any[] {
|
||||||
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) {
|
||||||
console.log("Found Sessions:",session)
|
console.log("Found Sessions:", session);
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
createdBy: session.creatorId,
|
createdBy: session.creatorId,
|
||||||
id: session.sessionId,
|
id: session.sessionId
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
@ -91,16 +90,16 @@ interface Session {
|
|||||||
const request = sessionIdOrRequest as FindSessionRequest;
|
const request = sessionIdOrRequest as FindSessionRequest;
|
||||||
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]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Found Matching Sessions:",matchingSessions)
|
console.log("Found Matching Sessions:", matchingSessions);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return matchingSessions.map(session => ({
|
return matchingSessions.map(session => ({
|
||||||
createdBy: session.creatorId,
|
createdBy: session.creatorId,
|
||||||
id: session.sessionId,
|
id: session.sessionId
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,12 +109,12 @@ interface Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getNewSessionID(): string {
|
function getNewSessionID(): string {
|
||||||
const characters = '0123456789abcdef';
|
const characters = "0123456789abcdef";
|
||||||
const maxAttempts = 100;
|
const maxAttempts = 100;
|
||||||
let sessionId = '';
|
let sessionId = "";
|
||||||
|
|
||||||
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
||||||
sessionId = '64';
|
sessionId = "64";
|
||||||
for (let i = 0; i < 22; i++) {
|
for (let i = 0; i < 22; i++) {
|
||||||
const randomIndex = Math.floor(Math.random() * characters.length);
|
const randomIndex = Math.floor(Math.random() * characters.length);
|
||||||
sessionId += characters[randomIndex];
|
sessionId += characters[randomIndex];
|
||||||
@ -126,7 +125,7 @@ interface Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Failed to generate a unique session ID');
|
throw new Error("Failed to generate a unique session ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateSession(sessionId: string, sessionData: string): boolean {
|
function updateSession(sessionId: string, sessionData: string): boolean {
|
||||||
@ -137,7 +136,7 @@ interface Session {
|
|||||||
Object.assign(session, updatedData);
|
Object.assign(session, updatedData);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Invalid JSON string for session update.');
|
console.error("Invalid JSON string for session update.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,5 +152,13 @@ interface Session {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { createNewSession, getAllSessions, getSessionByID, getSessionByCreatorID, getNewSessionID, updateSession, deleteSession, getSession };
|
export {
|
||||||
|
createNewSession,
|
||||||
|
getAllSessions,
|
||||||
|
getSessionByID,
|
||||||
|
getSessionByCreatorID,
|
||||||
|
getNewSessionID,
|
||||||
|
updateSession,
|
||||||
|
deleteSession,
|
||||||
|
getSession
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user