player lists

This commit is contained in:
2023-10-04 05:43:00 -06:00
parent b63db82a99
commit 6e582e11dc
10 changed files with 96 additions and 45 deletions

View File

@@ -7,19 +7,15 @@ export const handler: Handlers = {
let listener: (e: CustomEvent) => void;
const body = new ReadableStream({
async start(controller){
console.log('did the thing')
if (SERVER_STATE.status !== 'running') return;
const players = await getActivePlayers();
const event = `event:players\ndata:${JSON.stringify(players)}\n\n`
controller.enqueue(event);
console.log('sent the thing')
listener = async (e: CustomEvent<string>) => {
console.log('message received')
if (e.detail.includes('joined the game') || e.detail.includes('lost connection')) {
console.log('connection change')
const players = await getActivePlayers();
const event = `event: players\ndata: ${JSON.stringify(players)}\n\n`
@@ -28,10 +24,8 @@ export const handler: Handlers = {
}
globalThis.addEventListener('stdoutmsg' as any, listener);
console.log('listened the thing')
},
cancel() {
console.log('cancelled')
globalThis.removeEventListener('stdoutmsg' as any, listener);
}
})

View File

@@ -1,12 +1,35 @@
import { Content } from "../components/Content.tsx";
import { ActivePlayerList } from "../islands/players.tsx";
import { PlayerList } from "../islands/players.tsx";
import { getPlayerData, PlayerData } from "../util/players.ts";
export default function PlayerManger() {
export default async function PlayerManager() {
// TODO: change these to support instances
const whitelist = await Promise.all<PlayerData[]>(
JSON.parse(await Deno.readTextFile("./server/whitelist.json")).map(async (
p: { name: string },
) => await getPlayerData(p.name)),
);
const banlist = await Promise.all<PlayerData[]>(
JSON.parse(await Deno.readTextFile("./server/banned-players.json")).map(
async (
p: { name: string; reason: string },
) => ({ ...await getPlayerData(p.name), banReason: p.reason }),
),
);
const oplist = await Promise.all<PlayerData[]>(
JSON.parse(await Deno.readTextFile("./server/ops.json")).map(async (
p: { name: string },
) => await getPlayerData(p.name)),
);
return (
<div className="container p-8">
<Content>
<ActivePlayerList />
<PlayerList
whitelist={whitelist}
banlist={banlist}
oplist={oplist}
/>
</Content>
</div>
)
}
);
}