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

Commit

Permalink
Fix a bug which would cause the client communication with the Lua to …
Browse files Browse the repository at this point in the history
…silently fail if the Lua script was stopped manually, then restarted
  • Loading branch information
LegendaryLinux committed Dec 25, 2021
1 parent 1fadca6 commit defe172
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 0 additions & 9 deletions assets/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@ window.addEventListener('load', () => {
statusDisplay.classList.remove(connected ? 'disconnected' : 'connected');
statusDisplay.innerText = connected ? 'Connected' : 'Disconnected';

// If an n64 is not connected, stop the interval if running and clear all active requests
if (!n64Connected) {
if (n64Interval) {
clearInterval(n64Interval);
n64Interval = null;
n64IntervalComplete = true;
window.oot.disconnectAllClients();
Object.keys(activeRequests).forEach((key) => delete activeRequests[key]);
}

// Disconnect from the AP server
await connectToServer(null);
return;
Expand Down
12 changes: 12 additions & 0 deletions assets/serverSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ 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 @@ -93,6 +102,9 @@ const connectToServer = async (address, password=null) => {
serverSocket = null;
}

// n64 networking must always be reset before initiating a server connection
resetN64Networking();

// If an empty string is passed as the address, do not attempt to connect
if (!address) { return; }

Expand Down

0 comments on commit defe172

Please sign in to comment.