35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import LoginRequest from "./build/LoginRequest";
|
|
import LoginResponse from "./build/LoginResponse";
|
|
import User from "./build/User";
|
|
import Vector3 from "./build/Vector3";
|
|
|
|
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 {
|
|
const entity = new LoginRequest({}, new Uint8Array(message));
|
|
console.log(entity.Login.Email);
|
|
console.log(entity.Login.Password);
|
|
|
|
const user = new User({
|
|
Name: "Test User",
|
|
Login: entity.Login,
|
|
Position: new Vector3({ x: 0, y: 0, z: 0 }),
|
|
});
|
|
console.log(user.Name);
|
|
|
|
const response = new LoginResponse({ success: true });
|
|
ws.send(response._ptr, { binary: true }); // Echo back the received message
|
|
}
|
|
});
|
|
});
|