Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Minor refactor of previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LegendaryLinux committed Dec 25, 2021
1 parent defe172 commit b6a7ff7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions assets/serverSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -103,17 +94,24 @@ 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; }

// 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); }
Expand Down

0 comments on commit b6a7ff7

Please sign in to comment.