XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
UTF-8
import type { RequestHandler } from "express";
import { Account } from "../../models/loginModel.ts";
import { handleNonceInvalidation } from "../../services/wsService.ts";

export const logoutController: RequestHandler = async (req, res) => {
    if (!req.query.accountId) {
        throw new Error("Request is missing accountId parameter");
    }
    const nonce: number = parseInt(req.query.nonce as string);
    if (!nonce) {
        throw new Error("Request is missing nonce parameter");
    }

    const stat = await Account.updateOne(
        {
            _id: req.query.accountId,
            Nonce: nonce
        },
        {
            Nonce: 0,
            $unset: { Dropped: 1 }
        }
    );
    if (stat.modifiedCount) {
        handleNonceInvalidation(req.query.accountId as string);
    }

    res.writeHead(200, {
        "Content-Type": "text/html",
        "Content-Length": 1
    });
    res.end("1");
};