Fix Requests
This commit is contained in:
parent
7d2ca333df
commit
120750b42a
@ -4,13 +4,13 @@ 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.id != undefined) {
|
||||||
console.log("Found ID");
|
console.log("Found ID");
|
||||||
let s = getSession(r.id);
|
let s = getSession(r.id);
|
||||||
|
|
||||||
if (s) res.json({ queryId: r.queryId, Sessions: s });
|
if (s) res.json({ queryId: r.queryId, Sessions: s });
|
||||||
else res.json({});
|
else res.json({});
|
||||||
} else if (r != undefined) {
|
} else if (r.originalSessionId != undefined) {
|
||||||
console.log("Found OriginalSessionID");
|
console.log("Found OriginalSessionID");
|
||||||
|
|
||||||
let s = getSession(r.originalSessionId);
|
let s = getSession(r.originalSessionId);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
const getNewRewardSeedController: RequestHandler = (_req, res) => {
|
const getNewRewardSeedController: RequestHandler = (_req, res) => {
|
||||||
res.json({ rewardSeed: 1111111111 });
|
res.json({ rewardSeed: generateRewardSeed() });
|
||||||
};
|
};
|
||||||
|
|
||||||
function generateRewardSeed(): number {
|
function generateRewardSeed(): number {
|
||||||
|
@ -1,30 +1,4 @@
|
|||||||
interface Session {
|
import { Session, FindSessionRequest } from "@/src/types/session";
|
||||||
sessionId: string;
|
|
||||||
creatorId: string;
|
|
||||||
maxPlayers: number;
|
|
||||||
minPlayers: number;
|
|
||||||
privateSlots: number;
|
|
||||||
scoreLimit: number;
|
|
||||||
timeLimit: number;
|
|
||||||
gameModeId: number;
|
|
||||||
eloRating: number;
|
|
||||||
regionId: number;
|
|
||||||
difficulty: number;
|
|
||||||
hasStarted: boolean;
|
|
||||||
enableVoice: boolean;
|
|
||||||
matchType: string;
|
|
||||||
maps: string[];
|
|
||||||
originalSessionId: string;
|
|
||||||
customSettings: string;
|
|
||||||
rewardSeed: number;
|
|
||||||
guildId: string;
|
|
||||||
buildId: number;
|
|
||||||
platform: number;
|
|
||||||
xplatform: boolean;
|
|
||||||
freePublic: number;
|
|
||||||
freePrivate: number;
|
|
||||||
fullReset: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sessions: Session[] = [];
|
const sessions: Session[] = [];
|
||||||
|
|
||||||
@ -69,10 +43,6 @@ function getSessionByID(sessionId: string): Session | undefined {
|
|||||||
return sessions.find(session => session.sessionId === sessionId);
|
return sessions.find(session => session.sessionId === sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FindSessionRequest {
|
|
||||||
[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);
|
||||||
@ -130,7 +100,7 @@ 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) {
|
if (!session) return false;
|
||||||
try {
|
try {
|
||||||
const updatedData = JSON.parse(sessionData);
|
const updatedData = JSON.parse(sessionData);
|
||||||
Object.assign(session, updatedData);
|
Object.assign(session, updatedData);
|
||||||
@ -139,8 +109,6 @@ function updateSession(sessionId: string, sessionData: string): boolean {
|
|||||||
console.error("Invalid JSON string for session update.");
|
console.error("Invalid JSON string for session update.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteSession(sessionId: string): boolean {
|
function deleteSession(sessionId: string): boolean {
|
||||||
|
27
src/types/session.ts
Normal file
27
src/types/session.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
export interface Session {
|
||||||
|
sessionId: string;
|
||||||
|
creatorId: string;
|
||||||
|
maxPlayers: number;
|
||||||
|
minPlayers: number;
|
||||||
|
privateSlots: number;
|
||||||
|
scoreLimit: number;
|
||||||
|
timeLimit: number;
|
||||||
|
gameModeId: number;
|
||||||
|
eloRating: number;
|
||||||
|
regionId: number;
|
||||||
|
difficulty: number;
|
||||||
|
hasStarted: boolean;
|
||||||
|
enableVoice: boolean;
|
||||||
|
matchType: string;
|
||||||
|
maps: string[];
|
||||||
|
originalSessionId: string;
|
||||||
|
customSettings: string;
|
||||||
|
rewardSeed: number;
|
||||||
|
guildId: string;
|
||||||
|
buildId: number;
|
||||||
|
platform: number;
|
||||||
|
xplatform: boolean;
|
||||||
|
freePublic: number;
|
||||||
|
freePrivate: number;
|
||||||
|
fullReset: number;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user