diff --git a/src/gui/MPServerListGui.hx b/src/gui/MPServerListGui.hx index 134176fb..d91ec9d4 100644 --- a/src/gui/MPServerListGui.hx +++ b/src/gui/MPServerListGui.hx @@ -124,16 +124,24 @@ class MPServerListGui extends GuiImage { backButton.pressedAction = (e) -> MarbleGame.canvas.setContent(new MainMenuGui()); bottomBar.addChild(backButton); + var refreshing = false; + var refreshButton = new GuiXboxButton("Refresh", 220); refreshButton.position = new Vector(750, 0); refreshButton.vertSizing = Bottom; refreshButton.horizSizing = Right; refreshButton.pressedAction = (e) -> { + if (refreshing) + return; + refreshing = true; MasterServerClient.connectToMasterServer(() -> { MasterServerClient.instance.getServerList((servers) -> { ourServerList = servers; updateServerListDisplay(); + refreshing = false; }); + }, () -> { + refreshing = false; }); } bottomBar.addChild(refreshButton); diff --git a/src/net/MasterServerClient.hx b/src/net/MasterServerClient.hx index 29627f38..d9e511c5 100644 --- a/src/net/MasterServerClient.hx +++ b/src/net/MasterServerClient.hx @@ -41,7 +41,7 @@ class MasterServerClient { var stopMutex:sys.thread.Mutex = new sys.thread.Mutex(); #end - public function new(onOpenFunc:() -> Void) { + public function new(onOpenFunc:() -> Void, onErrorFunc:() -> Void) { #if hl wsThread = sys.thread.Thread.create(() -> { hl.Gc.enable(false); @@ -78,9 +78,15 @@ class MasterServerClient { responses.add(() -> { MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to connect to master server: " + m)); }); + if (onErrorFunc != null) + responses.add(() -> { + onErrorFunc(); + }); #end #if js MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to connect to master server: " + m)); + if (onErrorFunc != null) + onErrorFunc(); #end #if hl stopMutex.acquire(); @@ -159,16 +165,16 @@ class MasterServerClient { #end } - public static function connectToMasterServer(onConnect:() -> Void) { + public static function connectToMasterServer(onConnect:() -> Void, onError:() -> Void = null) { if (instance == null) - instance = new MasterServerClient(onConnect); + instance = new MasterServerClient(onConnect, onError); else { if (instance.open) onConnect(); else { if (instance != null && instance.ws != null) instance.ws.close(); - instance = new MasterServerClient(onConnect); + instance = new MasterServerClient(onConnect, onError); } } }