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,7 +143,8 @@ public static class GlobalVars
|
|||
public static readonly string ScriptName = "CSMPFunctions";
|
||||
public static readonly string ScriptGenName = "CSMPBoot";
|
||||
public static SimpleHTTPServer WebServer = null;
|
||||
public static bool IsWebServerOn = false;
|
||||
public static NetManager WebServerUDPInstance = null;
|
||||
public static bool IsWebServerOn = false;
|
||||
public static bool IsSnapshot = false;
|
||||
//vars for loader
|
||||
public static bool ReadyToLaunch = false;
|
||||
|
|
|
|||
|
|
@ -41,8 +41,9 @@ namespace NovetusLauncher
|
|||
// TODO: Add constructor code after the InitializeComponent() call.
|
||||
//
|
||||
}
|
||||
|
||||
public void InitUPnP()
|
||||
|
||||
#region UPnP
|
||||
public void InitUPnP()
|
||||
{
|
||||
if (GlobalVars.UPnP == true)
|
||||
{
|
||||
|
|
@ -123,8 +124,10 @@ namespace NovetusLauncher
|
|||
ConsolePrint("UPnP: Unable to disconnect device. Reason - " + ex.Message, 2);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void ReadyCallback()
|
||||
#region Discord
|
||||
public void ReadyCallback()
|
||||
{
|
||||
ConsolePrint("Discord RPC: Ready", 3);
|
||||
}
|
||||
|
|
@ -167,50 +170,62 @@ namespace NovetusLauncher
|
|||
LauncherFuncs.UpdateRichPresence(LauncherFuncs.LauncherState.InLauncher, "", true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
void StartWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
#region Web Server
|
||||
//udp clients will connect to the web server alongside the game.
|
||||
void StartWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
{
|
||||
try
|
||||
{
|
||||
GlobalVars.WebServer = new SimpleHTTPServer(GlobalVars.ServerDir, GlobalVars.WebServer_Port);
|
||||
ConsolePrint("WebServer: Server is running on port: " + GlobalVars.WebServer.Port.ToString(), 3);
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
label17.Visible = false;
|
||||
}
|
||||
{
|
||||
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)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
label17.Visible = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (Did not run as Administrator)", 2);
|
||||
label17.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void StopWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
}
|
||||
|
||||
void StopWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2);
|
||||
GlobalVars.WebServer.Stop();
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
}
|
||||
{
|
||||
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)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
async void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"])//your specific tabname
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ namespace NovetusLauncher
|
|||
// TODO: Add constructor code after the InitializeComponent() call.
|
||||
//
|
||||
}
|
||||
|
||||
public void InitUPnP()
|
||||
|
||||
#region UPnP
|
||||
public void InitUPnP()
|
||||
{
|
||||
if (GlobalVars.UPnP == true)
|
||||
{
|
||||
|
|
@ -122,8 +123,10 @@ namespace NovetusLauncher
|
|||
ConsolePrint("UPnP: Unable to disconnect device. Reason - " + ex.Message, 2);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void ReadyCallback()
|
||||
#region Discord
|
||||
public void ReadyCallback()
|
||||
{
|
||||
ConsolePrint("Discord RPC: Ready", 3);
|
||||
}
|
||||
|
|
@ -166,50 +169,62 @@ namespace NovetusLauncher
|
|||
LauncherFuncs.UpdateRichPresence(LauncherFuncs.LauncherState.InLauncher, "", true);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
void StartWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
#region Web Server
|
||||
//udp clients will connect to the web server alongside the game.
|
||||
void StartWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
{
|
||||
try
|
||||
{
|
||||
GlobalVars.WebServer = new SimpleHTTPServer(GlobalVars.ServerDir, GlobalVars.WebServer_Port);
|
||||
ConsolePrint("WebServer: Server is running on port: " + GlobalVars.WebServer.Port.ToString(), 3);
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
label17.Visible = false;
|
||||
}
|
||||
{
|
||||
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)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
label17.Visible = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to launch WebServer. Some features may not function. (Did not run as Administrator)", 2);
|
||||
label17.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
void StopWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
}
|
||||
|
||||
void StopWebServer()
|
||||
{
|
||||
if (SecurityFuncs.IsElevated)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConsolePrint("WebServer: Server has stopped on port: " + GlobalVars.WebServer.Port.ToString(), 2);
|
||||
GlobalVars.WebServer.Stop();
|
||||
}
|
||||
catch (Exception ex) when (!Env.Debugging)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
}
|
||||
{
|
||||
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)
|
||||
{
|
||||
ConsolePrint("WebServer: Failed to stop WebServer. Some features may not function. (" + ex.Message + ")", 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
async void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"])//your specific tabname
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue