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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -75,6 +75,6 @@ namespace MelonVPNCore
|
||||
public DaemonConfig() => Type = "DaemonConfig";
|
||||
|
||||
[JsonProperty("restart")]
|
||||
public string ShouldRestart { get; set; }
|
||||
public bool ShouldRestart { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user