From a97fcacb0ce4d2f30fbe989ec1f62f6bd95c7e9a Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 25 Jul 2022 22:34:33 -0400 Subject: Change handshake code again --- scripts/client.js | 13 +++++++------ scripts/socket/sock.js | 7 ++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/client.js b/scripts/client.js index c243d9f..3c73793 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -94,26 +94,27 @@ class Client{ // Callback when negotiating with the server for the first time and we are determining versions handshake (e) { - switch (e.detail) { + let m = e.detail + switch (m.type) { case "verr": this.socket.close(); - alert(`Error connecting to server: version of client (${this.version}) not accepted.`); + alert(`Error connecting to server: version of client (${VERSION}) not accepted.`); - console.error(`Error connecting to server: version of client (${this.version}) not accepted.`); + console.error(`Error connecting to server: version of client (${VERSION}) not accepted.`); console.error(m.data); return; case "ready": - console.log(`Handshake with server OK. Running client version ${this.version}`); + console.log(`Handshake with server OK. Running client version ${VERSION}`); this.settings.cleanup(); this.gameOptions.cleanup(); - //this.settings = new Settings(m.data.user); - //this.gameOptions = new Settings(m.data.game); + this.settings = new Settings(m.data.user); + this.gameOptions = new Settings(m.data.game); this.gameOptions.putSettings(this.lobby.top.newGame); diff --git a/scripts/socket/sock.js b/scripts/socket/sock.js index a52faf4..73e20ee 100644 --- a/scripts/socket/sock.js +++ b/scripts/socket/sock.js @@ -20,6 +20,11 @@ class SockWorker extends EventTarget{ if(this.server == "" || this.server == null) { return; } + + if(this.socket != null) { + this.socket.close(); + } + try { this.socket = new WebSocket(this.server); @@ -47,7 +52,7 @@ class SockWorker extends EventTarget{ if (this.handshake) { if (dat.type == "ready") this.handshake = false; - this.dispatchEvent(new CustomEvent("handshake", {detail: dat.type})); + this.dispatchEvent(new CustomEvent("handshake", {detail: dat})); return; } -- cgit v1.2.3