From 0a025c7ba9a91a7a2f82ce9f380d44d0e8ed81c4 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 4 Jun 2024 01:20:57 +0530 Subject: [PATCH] fix weird master server issues --- src/net/MasterServerClient.hx | 34 ++++++++++++++++++++++++++-------- src/net/Net.hx | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/net/MasterServerClient.hx b/src/net/MasterServerClient.hx index e84c8322..29627f38 100644 --- a/src/net/MasterServerClient.hx +++ b/src/net/MasterServerClient.hx @@ -29,6 +29,8 @@ class MasterServerClient { var open = false; + static var wsToken:Int = 0; + #if hl var wsThread:sys.thread.Thread; @@ -45,6 +47,9 @@ class MasterServerClient { hl.Gc.enable(false); hl.Gc.blocking(true); // Wtf is this shit #end + wsToken++; + + var myToken = wsToken; ws = WebSocket.create(serverIp); #if hl @@ -80,27 +85,35 @@ class MasterServerClient { #if hl stopMutex.acquire(); #end - open = false; - ws = null; - instance = null; + if (myToken == wsToken) { + open = false; + ws = null; + instance = null; + } #if hl stopMutex.acquire(); stopping = true; stopMutex.release(); - wsThread = null; + if (myToken == wsToken) { + wsThread = null; + } #end } ws.onclose = (?e) -> { #if hl stopMutex.acquire(); #end - open = false; - ws = null; - instance = null; + if (myToken == wsToken) { + open = false; + ws = null; + instance = null; + } #if hl stopping = true; stopMutex.release(); - wsThread = null; + if (myToken == wsToken) { + wsThread = null; + } #end } #if hl @@ -163,6 +176,11 @@ class MasterServerClient { public static function disconnectFromMasterServer() { if (instance != null && instance.ws != null) { instance.ws.close(); + if (instance != null) { + instance.open = false; + instance.ws = null; + instance = null; + } } } diff --git a/src/net/Net.hx b/src/net/Net.hx index da4ff059..3c3849d7 100644 --- a/src/net/Net.hx +++ b/src/net/Net.hx @@ -420,7 +420,7 @@ class Net { } } } - if (wsAccum >= 20.0) { + if (wsAccum >= 15.0) { wsAccum = 0; if (Net.isHost) { if (MasterServerClient.instance != null)