Skip to content

Commit

Permalink
Ping EU IP when EU region is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Apr 19, 2018
1 parent a15fbd8 commit 5ae239a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions BNSBoost/Form.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 34 additions & 15 deletions BNSBoost/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,28 @@ private IniFile GetLauncherIni()
return new IniFile(launcherIni);
}

private void InitializePingThread()
private string GetServerIP()
{
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer { Interval = 1000 };
timer.Tick += (sender, e) =>
// > netstat -atn | grep 10100
// TCP 192.168.20.103:64029 64.25.37.235:10100 ESTABLISHED InHost
switch (Properties.Settings.Default.Region)
{
PingLabel.Text = "Game delay: " + (Ping != null ? Ping?.ToString("0.00") + "ms" : "N/A");
};
timer.Start();
case "NA":
return "64.25.37.235";
case "EU":
return "18.194.180.254";
}

throw new ArgumentException();
}

new Thread(() =>
private void InitializePingThread()
{
var worker = new BackgroundWorker();
worker.DoWork += (_, arg) =>
{
while (Visible)
{
// This is only NA IP, but that's all we support right now
// > netstat -atn | grep 10100
// TCP 192.168.20.103:64029 64.25.37.235:10100 ESTABLISHED InHost
string ip = "64.25.37.235";

var time = new Stopwatch();
time.Start();
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Expand All @@ -146,7 +150,7 @@ private void InitializePingThread()

try
{
socket.Connect(ip, 10100);
socket.Connect(GetServerIP(), 10100);
}
catch (SocketException ex)
{
Expand All @@ -161,9 +165,19 @@ private void InitializePingThread()

socket.Close();

worker.ReportProgress(0, Ping);

Thread.Sleep(2000);
}
}).Start();
};

worker.ProgressChanged += (_, arg) =>
{
PingLabel.Text = "Game delay: " + (Ping != null ? Ping?.ToString("0.00") + "ms" : "N/A");
};

worker.WorkerReportsProgress = true;
worker.RunWorkerAsync();
}

private void Form_Load(object sender, EventArgs e)
Expand Down Expand Up @@ -262,7 +276,7 @@ private void ToggleLoadingScreens(bool disabled)
}
}

private async void LaunchButton_Click(object sender, EventArgs e)
private void LaunchButton_Click(object sender, EventArgs e)
{
LaunchButton.Enabled = false;

Expand Down Expand Up @@ -536,6 +550,11 @@ private void EnableSkillbookDelayCheckbox_CheckStateChanged(object sender, Event
{
SkillbookDelayUpDown.Enabled = EnableSkillbookDelayCheckbox.CheckState == CheckState.Checked;
}

private void RegionComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
Properties.Settings.Default.Region = RegionComboBox.SelectedItem as string;
}
}

class BufferedTreeView : TreeView
Expand Down

0 comments on commit 5ae239a

Please sign in to comment.