2024-05-27 19:03:58 -04:00
|
|
|
import Entity from "./out/Entity"
|
|
|
|
|
2024-05-27 18:54:12 -04:00
|
|
|
var decoder = new TextDecoder("utf-8");
|
|
|
|
var port = 8089;
|
|
|
|
var ws = require("ws");
|
|
|
|
var wss = new ws.WebSocketServer({ port: port });
|
|
|
|
console.log("WebSocket server listening on ws://localhost:" + port + "/");
|
|
|
|
wss.on("connection", function (ws) {
|
|
|
|
console.log("Client connected!");
|
|
|
|
ws.on("message", function (message, isBinary) {
|
|
|
|
if (!isBinary) {
|
|
|
|
var text = decoder.decode(new Uint8Array(message).buffer);
|
|
|
|
console.log("received TEXT: " + text.length + " characters:");
|
|
|
|
console.log(' "' + text + '"');
|
|
|
|
} else {
|
2024-05-27 19:03:58 -04:00
|
|
|
const entity = new Entity({}, new Uint8Array(message));
|
|
|
|
console.log(entity.Camera.position.x, entity.Camera.position.y, entity.Camera.position.z);
|
|
|
|
console.log(entity.Name);
|
|
|
|
console.log(entity.Luck);
|
|
|
|
console.log(entity.bytes);
|
2024-05-27 18:54:12 -04:00
|
|
|
|
2024-05-27 19:03:58 -04:00
|
|
|
ws.send(entity.bytes, { binary: true }); // Echo back the received message
|
2024-05-27 18:54:12 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|