Skip to content

Commit d4e8275

Browse files
committed
[F] Fix race
1 parent e81fdc9 commit d4e8275

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

mod/WorldLink/FutariClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public FutariClient(string keychip, string host, int port) : this(keychip, host,
5757
private readonly long[] _delayWindow = new int[20].Select(_ => -1L).ToArray();
5858
public int _delayIndex = 0;
5959
public long _delayAvg = 0;
60-
private readonly string host;
61-
private readonly int port;
60+
61+
public string host { get; set; }
62+
public int port { get; set; }
6263

6364
public IPAddress StubIP => FutariExt.KeychipToStubIp(keychip).ToIP();
6465

mod/WorldLink/FutariPatch.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void OnBeforePatch()
5858
if (StartUpStateType == null) Log.Error("StartUpStateType not found");
5959

6060
// Send HTTP request to get the futari client address
61-
// client = new FutariClient("A1234567890", , 20101);
61+
client = new FutariClient("A1234567890", "", 20101);
6262
$"{FutariClient.LOBBY_BASE}/info".GetAsync((sender, e) =>
6363
{
6464
if (e.Error != null)
@@ -68,7 +68,8 @@ public static void OnBeforePatch()
6868
}
6969
// Response Format: {"relayHost": "google.com", "relayPort": 20101}
7070
var info = JsonUtility.FromJson<ServerInfo>(e.Result);
71-
client = new FutariClient("A1234567890", info.relayHost, info.relayPort);
71+
client.host = info.relayHost;
72+
client.port = info.relayPort;
7273
Log.Info($"WorldLink server address: {info.relayHost}:{info.relayPort}");
7374
});
7475
}
@@ -96,8 +97,8 @@ public static bool CheckAuth_Proc()
9697
// Wait until the client is initialized
9798
new System.Threading.Thread(() =>
9899
{
99-
while (client == null && !stopping) Thread.Sleep(100);
100-
if (client == null) return;
100+
while (client.host == "" && !stopping) Thread.Sleep(100);
101+
if (client.host == "") return;
101102
client.keychip = keychip;
102103
client.ConnectAsync();
103104
isInit = true;

0 commit comments

Comments
 (0)