basic implementation of UDP for web server
This commit is contained in:
parent
8a3cf6e689
commit
e19511f2f2
|
|
@ -7,6 +7,7 @@
|
|||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
|
||||
using LiteNetLib;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
|
@ -142,6 +143,7 @@ public static class GlobalVars
|
|||
public static readonly string ScriptName = "CSMPFunctions";
|
||||
public static readonly string ScriptGenName = "CSMPBoot";
|
||||
public static SimpleHTTPServer WebServer = null;
|
||||
public static NetManager WebServerUDPInstance = null;
|
||||
public static bool IsWebServerOn = false;
|
||||
public static bool IsSnapshot = false;
|
||||
//vars for loader
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ namespace NovetusLauncher
|
|||
//
|
||||
}
|
||||
|
||||
#region UPnP
|
||||
public void InitUPnP()
|
||||
{
|
||||
if (GlobalVars.UPnP == true)
|
||||
|
|
@ -123,7 +124,9 @@ namespace NovetusLauncher
|
|||
ConsolePrint("UPnP: Unable to disconnect device. Reason - " + ex.Message, 2);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Discord
|
||||
public void ReadyCallback()
|
||||
{
|
||||
ConsolePrint("Discord RPC: Ready", 3);
|
||||
|
|
@ -167,7 +170,10 @@ namespace NovetusLauncher
|
|||
LauncherFuncs.UpdateRichPresence(LauncherFuncs.LauncherState.InLauncher, "", true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Web Server
|
||||
//udp clients will connect to the web server alongside the game.
|
||||
void StartWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
|
|
@ -175,6 +181,10 @@ namespace NovetusLauncher
|
|||
try
|
||||
{
|
||||
GlobalVars.WebServer = new SimpleHTTPServer(GlobalVars.ServerDir, GlobalVars.WebServer_Port);
|
||||
if (GlobalVars.UDP)
|
||||
{
|
||||
GlobalVars.WebServerUDPInstance = UDP.StartServer(GlobalVars.WebServer_Port);
|
||||
}
|
||||
ConsolePrint("WebServer: Server is running on port: " + GlobalVars.WebServer.Port.ToString(), 3);
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
|
|
@ -197,6 +207,10 @@ namespace NovetusLauncher
|
|||
try
|
||||
{
|
||||
ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2);
|
||||
if (GlobalVars.UDP)
|
||||
{
|
||||
GlobalVars.WebServerUDPInstance.Stop();
|
||||
}
|
||||
GlobalVars.WebServer.Stop();
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
|
|
@ -209,6 +223,7 @@ namespace NovetusLauncher
|
|||
ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (Did not run as Administrator)", 2);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
async void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ namespace NovetusLauncher
|
|||
//
|
||||
}
|
||||
|
||||
#region UPnP
|
||||
public void InitUPnP()
|
||||
{
|
||||
if (GlobalVars.UPnP == true)
|
||||
|
|
@ -122,7 +123,9 @@ namespace NovetusLauncher
|
|||
ConsolePrint("UPnP: Unable to disconnect device. Reason - " + ex.Message, 2);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Discord
|
||||
public void ReadyCallback()
|
||||
{
|
||||
ConsolePrint("Discord RPC: Ready", 3);
|
||||
|
|
@ -166,7 +169,10 @@ namespace NovetusLauncher
|
|||
LauncherFuncs.UpdateRichPresence(LauncherFuncs.LauncherState.InLauncher, "", true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Web Server
|
||||
//udp clients will connect to the web server alongside the game.
|
||||
void StartWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
|
|
@ -174,6 +180,10 @@ namespace NovetusLauncher
|
|||
try
|
||||
{
|
||||
GlobalVars.WebServer = new SimpleHTTPServer(GlobalVars.ServerDir, GlobalVars.WebServer_Port);
|
||||
if (GlobalVars.UDP)
|
||||
{
|
||||
GlobalVars.WebServerUDPInstance = UDP.StartServer(GlobalVars.WebServer_Port);
|
||||
}
|
||||
ConsolePrint("WebServer: Server is running on port: " + GlobalVars.WebServer.Port.ToString(), 3);
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
|
|
@ -196,6 +206,10 @@ namespace NovetusLauncher
|
|||
try
|
||||
{
|
||||
ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2);
|
||||
if (GlobalVars.UDP)
|
||||
{
|
||||
GlobalVars.WebServerUDPInstance.Stop();
|
||||
}
|
||||
GlobalVars.WebServer.Stop();
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
|
|
@ -208,6 +222,7 @@ namespace NovetusLauncher
|
|||
ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (Did not run as Administrator)", 2);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
async void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue