23 lines
727 B
JavaScript
23 lines
727 B
JavaScript
const Game = require("../../../Game/Game");
|
|
|
|
const isAuthenticated = require("../../../Utility/isAuthenticated");
|
|
|
|
module.exports = async (res, req) => {
|
|
res.onAborted(() => res.isAborted = true);
|
|
|
|
const playerID = req.getQuery("playerId");
|
|
|
|
const hasPermission = await isAuthenticated(res, req);
|
|
if (!hasPermission) return;
|
|
|
|
if (!playerID) return res.cork(() => res.writeStatus("400").end("Missing player id"));
|
|
|
|
const player = Game.players[playerID];
|
|
if (!player) return res.cork(() => res.writeStatus("400").end("Unknown player"));
|
|
|
|
player.disconnect();
|
|
|
|
res.cork(() => res
|
|
.writeStatus("200")
|
|
.end("Player has been disconnected"));
|
|
}; |