Active player list

This commit is contained in:
2023-10-04 04:09:01 -06:00
parent 4a4563ba85
commit b63db82a99
27 changed files with 544 additions and 136 deletions

31
routes/api/manage.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Handlers } from "$fresh/server.ts";
import { SERVER_STATE } from "../../state/serverState.ts";
export enum ManageAction {
start = "start",
stop = "stop",
restart = "restart",
}
export const handler: Handlers = {
async POST(req) {
const body: ManageAction & string = await req.text() as ManageAction;
switch (body) {
case ManageAction.start:
SERVER_STATE.startMCServer();
return new Response("started");
case ManageAction.stop:
SERVER_STATE.gracefullyStopMCServer();
return new Response("stopped");
case ManageAction.restart:
SERVER_STATE.restartMCServer();
return new Response("restarted");
default:
SERVER_STATE.sendStdIn(body);
return new Response("action done");
}
},
GET() {
return new Response(SERVER_STATE.status);
}
};