Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
const Game = require("../../../Game/Game");
|
||||
|
||||
const MaintenanceScheduledPacket = require("../../../Packets/MaintenanceScheduled");
|
||||
|
||||
const isAuthenticated = require("../../../Utility/isAuthenticated");
|
||||
|
||||
module.exports = async (res, req) => {
|
||||
res.onAborted(() => res.isAborted = true);
|
||||
|
||||
const maintenanceTimeSeconds = req.getQuery("time");
|
||||
const timestamp = req.getQuery("timestamp");
|
||||
|
||||
const hasPermission = await isAuthenticated(res, req);
|
||||
if (!hasPermission) return;
|
||||
|
||||
if (!Game.listeningServer) return res.cork(() => res.writeStatus("400").end("Server is offline!"));
|
||||
if (!maintenanceTimeSeconds) return res.cork(() => res.writeStatus("400").end("No approximate time was provided!"));
|
||||
if (!timestamp) return res.cork(() => res.writeStatus("400").end("No timestamp was provided!"));
|
||||
|
||||
const parsedTimestamp = parseInt(timestamp);
|
||||
if (parsedTimestamp < Date.now()) return res.cork(() => res.writeStatus("400").end("Incorrect timestamp was provided!"));
|
||||
|
||||
const event = {
|
||||
fn: Game.disconnectAll.bind(Game),
|
||||
arguments: []
|
||||
};
|
||||
|
||||
Game.eventsFixed.add(parsedTimestamp, event);
|
||||
|
||||
const packet = MaintenanceScheduledPacket({
|
||||
timestamp: parsedTimestamp / 1000,
|
||||
timeSeconds: maintenanceTimeSeconds
|
||||
});
|
||||
|
||||
Game.maps.forEach(map => app.publish(map.id.toString(), packet, true, true));
|
||||
|
||||
res.cork(() => res
|
||||
.writeStatus("200")
|
||||
.end("Shutdown has been scheduled!"));
|
||||
};
|
||||
Reference in New Issue
Block a user