mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-01-22 18:02:16 +00:00
skip server connection if server is offline
This commit is contained in:
parent
c3deaa23ff
commit
0d75f70177
2 changed files with 40 additions and 9 deletions
|
@ -163,22 +163,29 @@ namespace ShiftOS.Engine
|
|||
bool guidReceived = false;
|
||||
ServerManager.GUIDReceived += (str) =>
|
||||
{
|
||||
//Connection successful! Stop waiting!
|
||||
guidReceived = true;
|
||||
//Connection successful! Stop waiting!
|
||||
guidReceived = true;
|
||||
Console.WriteLine("[inetd] Connection successful.");
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort);
|
||||
//This haults the client until the connection is successful.
|
||||
while (ServerManager.thisGuid == new Guid())
|
||||
if (ServerManager.ServerOnline)
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
ServerManager.Initiate(UserConfig.Get().DigitalSocietyAddress, UserConfig.Get().DigitalSocietyPort);
|
||||
//This haults the client until the connection is successful.
|
||||
while (ServerManager.thisGuid == new Guid())
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
Console.WriteLine("[inetd] DHCP GUID recieved, finished setup");
|
||||
FinishBootstrap();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("[inetd] No suitable network interface card found, skipping network connection.");
|
||||
FinishBootstrap();
|
||||
}
|
||||
Console.WriteLine("[inetd] DHCP GUID recieved, finished setup");
|
||||
FinishBootstrap();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -38,6 +38,7 @@ using System.Net.Sockets;
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace ShiftOS.Engine
|
||||
{
|
||||
|
@ -46,6 +47,29 @@ namespace ShiftOS.Engine
|
|||
/// </summary>
|
||||
public static class ServerManager
|
||||
{
|
||||
|
||||
public static bool ServerOnline
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
Ping myPing = new Ping();
|
||||
String host = UserConfig.Get().DigitalSocietyAddress;
|
||||
byte[] buffer = new byte[32];
|
||||
int timeout = 1000;
|
||||
PingOptions pingOptions = new PingOptions();
|
||||
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
|
||||
return (reply.Status == IPStatus.Success);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Print connection diagnostic information.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in a new issue