2023-05-19 15:22:48 -03:00
|
|
|
import { RequestHandler } from "express";
|
2025-05-18 19:06:24 -07:00
|
|
|
import { getAccountForRequest } from "@/src/services/loginService";
|
2023-06-03 19:24:57 -07:00
|
|
|
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";
|
2025-05-18 19:06:24 -07:00
|
|
|
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) => {
|
2025-05-18 19:06:24 -07:00
|
|
|
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 });
|
2025-05-18 19:06:24 -07:00
|
|
|
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
|
|
|
|
2025-05-18 19:06:24 -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 };
|