SpaceNinjaServer/src/controllers/api/hostSessionController.ts

25 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-05-19 15:22:48 -03:00
import { RequestHandler } from "express";
import { getAccountForRequest } from "@/src/services/loginService";
import { createNewSession } from "@/src/managers/sessionManager";
2024-01-06 16:26:58 +01:00
import { logger } from "@/src/utils/logger";
import { ISession } from "@/src/types/session";
import { JSONParse } from "json-with-bigint";
import { toOid2, version_compare } from "@/src/helpers/inventoryHelpers";
2023-05-23 20:53:26 -04:00
2024-05-28 13:45:06 +02:00
const hostSessionController: RequestHandler = async (req, res) => {
const account = await getAccountForRequest(req);
const hostSessionRequest = JSONParse(String(req.body)) as ISession;
2024-01-06 16:26:58 +01:00
logger.debug("HostSession Request", { hostSessionRequest });
const session = createNewSession(hostSessionRequest, account._id);
2024-01-06 16:26:58 +01:00
logger.debug(`New Session Created`, { session });
2023-06-01 17:08:05 -07:00
if (account.BuildLabel && version_compare(account.BuildLabel, "2015.03.21.08.17") < 0) {
// U15 or below
res.send(session.sessionId.toString());
} else {
res.json({ sessionId: toOid2(session.sessionId, account.BuildLabel), rewardSeed: 99999999 });
}
2023-05-19 15:22:48 -03:00
};
export { hostSessionController };