Fix saving config file and remember to listen after binding
This commit is contained in:
parent
c05139a333
commit
18fd6a9d58
@ -26,17 +26,18 @@ namespace MelonVPNCore
|
|||||||
|
|
||||||
public static void StartServer()
|
public static void StartServer()
|
||||||
{
|
{
|
||||||
|
if (File.Exists(daemonConfigPath)) config = DaemonConfig.FromJson(File.ReadAllText(daemonConfigPath));
|
||||||
|
else config = new DaemonConfig();
|
||||||
|
|
||||||
IPHostEntry host = Dns.GetHostEntry("localhost");
|
IPHostEntry host = Dns.GetHostEntry("localhost");
|
||||||
IPAddress ipAddress = host.AddressList[0];
|
IPAddress ipAddress = host.AddressList[0];
|
||||||
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 22035);
|
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 22035);
|
||||||
|
|
||||||
if (File.Exists(daemonConfigPath)) config = DaemonConfig.FromJson(File.ReadAllText(daemonConfigPath));
|
|
||||||
else config = new DaemonConfig();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
listener.Bind(localEndPoint);
|
listener.Bind(localEndPoint);
|
||||||
|
listener.Listen(32);
|
||||||
|
|
||||||
string lastClientUpdate = Messages.EOF;
|
string lastClientUpdate = Messages.EOF;
|
||||||
|
|
||||||
@ -63,12 +64,14 @@ namespace MelonVPNCore
|
|||||||
else if (data == Messages.RestartOnMsg)
|
else if (data == Messages.RestartOnMsg)
|
||||||
{
|
{
|
||||||
shouldRestart = true;
|
shouldRestart = true;
|
||||||
|
config.ShouldRestart = true;
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
Client.SendDataMessage(DataMessage.RestartOn, true);
|
Client.SendDataMessage(DataMessage.RestartOn, true);
|
||||||
}
|
}
|
||||||
else if (data == Messages.RestartOffMsg)
|
else if (data == Messages.RestartOffMsg)
|
||||||
{
|
{
|
||||||
shouldRestart = false;
|
shouldRestart = false;
|
||||||
|
config.ShouldRestart = false;
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
Client.SendDataMessage(DataMessage.RestartOff, true);
|
Client.SendDataMessage(DataMessage.RestartOff, true);
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,6 @@ namespace MelonVPNCore
|
|||||||
public DaemonConfig() => Type = "DaemonConfig";
|
public DaemonConfig() => Type = "DaemonConfig";
|
||||||
|
|
||||||
[JsonProperty("restart")]
|
[JsonProperty("restart")]
|
||||||
public string ShouldRestart { get; set; }
|
public bool ShouldRestart { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user