Files
gd-editor-mutiyplayer/server.js
T
2026-03-17 20:32:03 -04:00

25 lines
529 B
JavaScript

const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 3000 });
let level = [];
wss.on("connection", (ws) => {
ws.send(JSON.stringify({ type: "init", level }));
ws.on("message", (msg) => {
const data = JSON.parse(msg);
if (data.type === "add") {
level.push(data.object);
}
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(data));
}
});
});
});
console.log("Server running on ws://localhost:3000");