Fix saving config file and remember to listen after binding

This commit is contained in:
Melon 2021-03-23 21:07:45 +00:00
parent c05139a333
commit 18fd6a9d58
2 changed files with 7 additions and 4 deletions

View File

@ -26,17 +26,18 @@ namespace MelonVPNCore
public static void StartServer()
{
if (File.Exists(daemonConfigPath)) config = DaemonConfig.FromJson(File.ReadAllText(daemonConfigPath));
else config = new DaemonConfig();
IPHostEntry host = Dns.GetHostEntry("localhost");
IPAddress ipAddress = host.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 22035);
if (File.Exists(daemonConfigPath)) config = DaemonConfig.FromJson(File.ReadAllText(daemonConfigPath));
else config = new DaemonConfig();
try
{
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(localEndPoint);
listener.Listen(32);
string lastClientUpdate = Messages.EOF;
@ -63,12 +64,14 @@ namespace MelonVPNCore
else if (data == Messages.RestartOnMsg)
{
shouldRestart = true;
config.ShouldRestart = true;
SaveConfig();
Client.SendDataMessage(DataMessage.RestartOn, true);
}
else if (data == Messages.RestartOffMsg)
{
shouldRestart = false;
config.ShouldRestart = false;
SaveConfig();
Client.SendDataMessage(DataMessage.RestartOff, true);
}

View File

@ -75,6 +75,6 @@ namespace MelonVPNCore
public DaemonConfig() => Type = "DaemonConfig";
[JsonProperty("restart")]
public string ShouldRestart { get; set; }
public bool ShouldRestart { get; set; }
}
}