From b373822d0ef975c1a85bc17f7fa84a46903fb017 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Fri, 12 Dec 2025 11:36:06 -0500 Subject: [PATCH] fix: finally fixed the websocket problem, apparently there's no multi-threaded support --- project.godot | 2 +- scenes/game.tscn | 8 +++--- scripts/Connection.cs | 62 +++++++++++-------------------------------- 3 files changed, 20 insertions(+), 52 deletions(-) diff --git a/project.godot b/project.godot index 62b3cb1..464ee4b 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Connect4 Observer" -config/version="0.2.0" +config/version="1.0.0" run/main_scene="uid://dcx5nvs0pa7me" config/features=PackedStringArray("4.5", "C#", "Forward Plus") boot_splash/image="uid://dd7lvnidxr5ss" diff --git a/scenes/game.tscn b/scenes/game.tscn index 0b1f28f..43ebc4c 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -20,10 +20,10 @@ metadata/_snap_enabled = true anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = -659.0 -offset_top = -558.0 -offset_right = 619.0 -offset_bottom = 466.0 +offset_left = -658.0 +offset_top = -547.0 +offset_right = 668.0 +offset_bottom = 657.0 grow_horizontal = 2 grow_vertical = 2 texture = SubResource("GradientTexture2D_yqjtg") diff --git a/scripts/Connection.cs b/scripts/Connection.cs index 162f630..dce4126 100644 --- a/scripts/Connection.cs +++ b/scripts/Connection.cs @@ -58,6 +58,7 @@ public partial class Connection : Node private bool _connected = false; private List<(string, int)> _lastScoreboard = []; private bool _shouldShowTournamentResults = false; + private float _refreshGamePlayerListTimer = 5.0f; public override void _Ready() { @@ -83,11 +84,6 @@ public partial class Connection : Node } } - public override void _ExitTree() - { - StopGameListRefreshLoop(); - } - public override void _Process(double delta) { _webSocket.Poll(); @@ -100,7 +96,18 @@ public partial class Connection : Node _connected = true; LastError = ""; OnWsConnectionSuccess?.Invoke(); - StartGameListRefreshLoop(); + UpdateGameList(); + UpdatePlayerList(); + _refreshGamePlayerListTimer = 5.0f; + } else if (_refreshGamePlayerListTimer <= 0.0f) + { + UpdateGameList(); + UpdatePlayerList(); + _refreshGamePlayerListTimer = 5.0f; + } + else + { + _refreshGamePlayerListTimer -= (float) delta; } while (_webSocket.GetAvailablePacketCount() > 0) @@ -144,7 +151,7 @@ public partial class Connection : Node CurrentWaitTimeout = 5.0; ActiveTournament = false; DemoMode = false; - StopGameListRefreshLoop(); + _refreshGamePlayerListTimer = 5.0f; var code = _webSocket.GetCloseCode(); var reason = _webSocket.GetCloseReason(); LastError = "Unexpected Disconnect. Reason: " + reason + ", Code: " + code; @@ -190,45 +197,6 @@ public partial class Connection : Node SendCommand("GAME", "LIST"); } - private void StartGameListRefreshLoop() - { - if (_gameListThreadRunning) - { - return; - } - - _gameListThreadRunning = true; - _gameListThread = new Thread(() => - { - while (_gameListThreadRunning) - { - if (IsSocketOpen) - { - UpdateGameList(); - UpdatePlayerList(); - } - - Thread.Sleep(TimeSpan.FromSeconds(5)); - } - }) - { - IsBackground = true - }; - _gameListThread.Start(); - } - - private void StopGameListRefreshLoop() - { - if (!_gameListThreadRunning) - { - return; - } - - _gameListThreadRunning = false; - _gameListThread?.Join(); - _gameListThread = null; - } - public void UpdatePlayerList() { SendCommand("PLAYER", "LIST"); @@ -433,8 +401,8 @@ public partial class Connection : Node } case "START": { - OnStartTournamentAck?.Invoke(); ActiveTournament = true; + OnStartTournamentAck?.Invoke(); break; } case "CANCEL":