From b6a7ff7dc5920911aa12da8ad3345404760b856d Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 25 Dec 2021 03:28:30 -0500 Subject: [PATCH] Minor refactor of previous commit --- assets/serverSocket.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/assets/serverSocket.js b/assets/serverSocket.js index 82a9208..fe3c434 100644 --- a/assets/serverSocket.js +++ b/assets/serverSocket.js @@ -61,15 +61,6 @@ const getRandomDeathLinkMessage = (playerName) => { return deathLinkMessages[Math.floor(Math.random() * (deathLinkMessages.length))]; }; -// Clear the Lua request queue, stop n64 interval, reset flags -const resetN64Networking = () => { - if (n64Interval) { clearInterval(n64Interval); } - n64Interval = null; - n64IntervalComplete = true; - if (!n64Connected) { window.oot.disconnectAllClients(); } - Object.keys(activeRequests).forEach((key) => delete activeRequests[key]); -}; - window.addEventListener('load', async () => { // Handle server address change document.getElementById('server-address').addEventListener('keydown', async (event) => { @@ -103,7 +94,17 @@ const connectToServer = async (address, password=null) => { } // n64 networking must always be reset before initiating a server connection - resetN64Networking(); + // Clear the Lua request queue, stop n64 interval, reset flags + if (n64Interval) { clearInterval(n64Interval); } + n64Interval = null; + n64IntervalComplete = true; + Object.keys(activeRequests).forEach((key) => delete activeRequests[key]); + + // If there are no n64 devices available, do nothing + if (!n64Connected) { + window.oot.disconnectAllClients(); + return; + } // If an empty string is passed as the address, do not attempt to connect if (!address) { return; } @@ -111,9 +112,6 @@ const connectToServer = async (address, password=null) => { // This is a new connection attempt, no auth error has occurred yet serverAuthError = false; - // If there are no n64 devices available, do nothing - if (!n64Connected) { return; } - // Determine the server address let serverAddress = address; if (serverAddress.search(/^\/connect /) > -1) { serverAddress = serverAddress.substring(9); }