prototype web server
This commit is contained in:
parent
ceeff5b78d
commit
be8fa8a3d9
|
|
@ -0,0 +1,135 @@
|
||||||
|
#if LAUNCHER || URI
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Titanium.Web.Proxy;
|
||||||
|
using Titanium.Web.Proxy.EventArguments;
|
||||||
|
using Titanium.Web.Proxy.Http;
|
||||||
|
using Titanium.Web.Proxy.Models;
|
||||||
|
|
||||||
|
public class WebProxy
|
||||||
|
{
|
||||||
|
private static ProxyServer Server = new ProxyServer();
|
||||||
|
private static ExplicitProxyEndPoint end;
|
||||||
|
|
||||||
|
public bool HasStarted()
|
||||||
|
{
|
||||||
|
return Server.ProxyRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//load ext
|
||||||
|
Server.BeforeRequest += new AsyncEventHandler<SessionEventArgs>(OnRequest);
|
||||||
|
UpdateEndPoint(true);
|
||||||
|
Util.ConsolePrint("Web Proxy started on port " + GlobalVars.WebProxyPort, 3);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Util.LogExceptions(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateEndPoint(bool shouldRunServer = false, bool decrypt = true)
|
||||||
|
{
|
||||||
|
if (Server.ProxyEndPoints.Count > 0)
|
||||||
|
{
|
||||||
|
Server.RemoveEndPoint(end);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalVars.WebProxyPort = GlobalVars.UserConfiguration.RobloxPort + 1;
|
||||||
|
end = new ExplicitProxyEndPoint(IPAddress.Any, GlobalVars.WebProxyPort, decrypt);
|
||||||
|
end.BeforeTunnelConnectRequest += new AsyncEventHandler<TunnelConnectSessionEventArgs>(OnBeforeTunnelConnectRequest);
|
||||||
|
Server.AddEndPoint(end);
|
||||||
|
|
||||||
|
if (!Server.ProxyRunning && shouldRunServer)
|
||||||
|
{
|
||||||
|
Server.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Server.ProxyRunning)
|
||||||
|
{
|
||||||
|
foreach (ProxyEndPoint endPoint in Server.ProxyEndPoints)
|
||||||
|
{
|
||||||
|
Server.SetAsSystemHttpProxy(end);
|
||||||
|
Server.SetAsSystemHttpsProxy(end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.ConsolePrint("Web Proxy Endpoint updated with port " + GlobalVars.WebProxyPort, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsURIAllowed(HttpWebClient client)
|
||||||
|
{
|
||||||
|
string uri = client.Request.RequestUri.Host;
|
||||||
|
|
||||||
|
if ((!uri.StartsWith("www.") &&
|
||||||
|
!uri.StartsWith("web.") &&
|
||||||
|
!uri.StartsWith("assetgame.") &&
|
||||||
|
!uri.StartsWith("wiki.") &&
|
||||||
|
!uri.EndsWith("api.roblox.com") &&
|
||||||
|
!uri.StartsWith("roblox.com") || !uri.EndsWith("roblox.com")) &&
|
||||||
|
!uri.EndsWith("robloxlabs.com"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//we check the header
|
||||||
|
HeaderCollection headers = client.Request.Headers;
|
||||||
|
List<HttpHeader> userAgents = headers.GetHeaders("User-Agent");
|
||||||
|
|
||||||
|
if (userAgents == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(userAgents.FirstOrDefault().Value))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
string ua = userAgents.FirstOrDefault().Value.ToLowerInvariant();
|
||||||
|
|
||||||
|
Util.ConsolePrint(ua);
|
||||||
|
|
||||||
|
return ua.Contains("roblox");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e)
|
||||||
|
{
|
||||||
|
if (!IsURIAllowed(e.HttpClient))
|
||||||
|
{
|
||||||
|
e.DecryptSsl = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
|
private async Task OnRequest(object sender, SessionEventArgs e)
|
||||||
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
||||||
|
{
|
||||||
|
if (!IsURIAllowed(e.HttpClient))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.ConsolePrint("we should be returning a 404 here.");
|
||||||
|
e.GenericResponse("", HttpStatusCode.NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
Util.ConsolePrint("Web Proxy stopping on port " + GlobalVars.WebProxyPort, 3);
|
||||||
|
Server.BeforeRequest -= new AsyncEventHandler<SessionEventArgs>(OnRequest);
|
||||||
|
Server.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IWebProxyExtention
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<Import_RootNamespace>NovetusCore</Import_RootNamespace>
|
<Import_RootNamespace>NovetusCore</Import_RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Classes\WebProxy.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)StorageAndFunctions\ClientManagement.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)StorageAndFunctions\ClientManagement.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Classes\Downloader.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Classes\Downloader.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Classes\CommandLineArguments.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Classes\CommandLineArguments.cs" />
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,11 @@ public static class GlobalVars
|
||||||
public static string ExternalIP = SecurityFuncs.GetExternalIPAddress();
|
public static string ExternalIP = SecurityFuncs.GetExternalIPAddress();
|
||||||
public static ScriptType GameOpened = ScriptType.None;
|
public static ScriptType GameOpened = ScriptType.None;
|
||||||
public static string PlayerTripcode = "";
|
public static string PlayerTripcode = "";
|
||||||
#endregion
|
#if LAUNCHER || URI
|
||||||
|
public static int WebProxyPort = 0;
|
||||||
|
public static WebProxy Proxy = new WebProxy();
|
||||||
|
#endif
|
||||||
|
#endregion
|
||||||
|
|
||||||
#if LAUNCHER
|
#if LAUNCHER
|
||||||
#region Novetus Launcher
|
#region Novetus Launcher
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ namespace NovetusLauncher
|
||||||
|
|
||||||
void Button22Click(object sender, EventArgs e)
|
void Button22Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
launcherForm.ResetCurPort(numericUpDown2, GlobalVars.UserConfiguration.RobloxPort);
|
launcherForm.ResetCurPort(numericUpDown2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeView1AfterSelect(object sender, TreeViewEventArgs e)
|
void TreeView1AfterSelect(object sender, TreeViewEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ namespace NovetusLauncher
|
||||||
|
|
||||||
void Button22Click(object sender, EventArgs e)
|
void Button22Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
launcherForm.ResetCurPort(numericUpDown2, GlobalVars.UserConfiguration.RobloxPort);
|
launcherForm.ResetCurPort(numericUpDown2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeView1AfterSelect(object sender, TreeViewEventArgs e)
|
void TreeView1AfterSelect(object sender, TreeViewEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,10 @@ namespace NovetusLauncher
|
||||||
{
|
{
|
||||||
DiscordRPC.Shutdown();
|
DiscordRPC.Shutdown();
|
||||||
}
|
}
|
||||||
|
if (GlobalVars.Proxy.HasStarted())
|
||||||
|
{
|
||||||
|
GlobalVars.Proxy.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
if (!GlobalVars.AppClosed)
|
if (!GlobalVars.AppClosed)
|
||||||
{
|
{
|
||||||
|
|
@ -578,6 +582,7 @@ namespace NovetusLauncher
|
||||||
Tree.Focus();
|
Tree.Focus();
|
||||||
IPBox.Text = GlobalVars.CurrentServer.ToString();
|
IPBox.Text = GlobalVars.CurrentServer.ToString();
|
||||||
HostPortBox.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort);
|
HostPortBox.Value = Convert.ToDecimal(GlobalVars.UserConfiguration.RobloxPort);
|
||||||
|
GlobalVars.Proxy.UpdateEndPoint();
|
||||||
IPLabel.Text = GlobalVars.CurrentServer.ServerIP;
|
IPLabel.Text = GlobalVars.CurrentServer.ServerIP;
|
||||||
PortLabel.Text = GlobalVars.CurrentServer.ServerPort.ToString();
|
PortLabel.Text = GlobalVars.CurrentServer.ServerPort.ToString();
|
||||||
DiscordPresenceCheckbox.Checked = GlobalVars.UserConfiguration.DiscordPresence;
|
DiscordPresenceCheckbox.Checked = GlobalVars.UserConfiguration.DiscordPresence;
|
||||||
|
|
@ -923,10 +928,9 @@ namespace NovetusLauncher
|
||||||
IPBox.Text = GlobalVars.CurrentServer.ToString();
|
IPBox.Text = GlobalVars.CurrentServer.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetCurPort(NumericUpDown box, int value)
|
public void ResetCurPort(NumericUpDown box)
|
||||||
{
|
{
|
||||||
box.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort);
|
box.Value = Convert.ToDecimal(GlobalVars.DefaultRobloxPort);
|
||||||
value = GlobalVars.DefaultRobloxPort;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeServerAddress()
|
public void ChangeServerAddress()
|
||||||
|
|
@ -953,6 +957,7 @@ namespace NovetusLauncher
|
||||||
public void ChangeServerPort()
|
public void ChangeServerPort()
|
||||||
{
|
{
|
||||||
GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(HostPortBox.Value);
|
GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(HostPortBox.Value);
|
||||||
|
GlobalVars.Proxy.UpdateEndPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeClient()
|
public void ChangeClient()
|
||||||
|
|
|
||||||
|
|
@ -340,6 +340,7 @@ namespace NovetusLauncher
|
||||||
if (!IsLoaded)
|
if (!IsLoaded)
|
||||||
return;
|
return;
|
||||||
GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(serverPortBox.Text);
|
GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(serverPortBox.Text);
|
||||||
|
GlobalVars.Proxy.UpdateEndPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maxPlayersBox_TextChanged(object sender, TextChangedEventArgs e)
|
private void maxPlayersBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ namespace NovetusLauncher
|
||||||
if (ConsoleArgs["hostport"] != null)
|
if (ConsoleArgs["hostport"] != null)
|
||||||
{
|
{
|
||||||
GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(ConsoleArgs["hostport"]);
|
GlobalVars.UserConfiguration.RobloxPort = Convert.ToInt32(ConsoleArgs["hostport"]);
|
||||||
|
GlobalVars.Proxy.UpdateEndPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConsoleArgs["upnp"] != null)
|
if (ConsoleArgs["upnp"] != null)
|
||||||
|
|
@ -356,6 +357,11 @@ namespace NovetusLauncher
|
||||||
de.Show();
|
de.Show();
|
||||||
Util.ConsolePrint("???", 2);
|
Util.ConsolePrint("???", 2);
|
||||||
break;
|
break;
|
||||||
|
case string proxy when proxy.Contains("proxytest", StringComparison.InvariantCultureIgnoreCase) == true:
|
||||||
|
GlobalVars.Proxy.Start();
|
||||||
|
//Util.Delay(5000);
|
||||||
|
//GlobalVars.Proxy.Stop();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Util.ConsolePrint("Command is either not registered or valid", 2);
|
Util.ConsolePrint("Command is either not registered or valid", 2);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@
|
||||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Net" />
|
<Reference Include="System.Net" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Numerics" />
|
<Reference Include="System.Numerics" />
|
||||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<HintPath>C:\Users\Bitl\Documents\GitHub\Novetus\Novetus_src\Novetus\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
<HintPath>C:\Users\Bitl\Documents\GitHub\Novetus\Novetus_src\Novetus\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,11 @@ namespace NovetusURI
|
||||||
{
|
{
|
||||||
GlobalVars.GameOpened = ScriptType.None;
|
GlobalVars.GameOpened = ScriptType.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GlobalVars.Proxy.HasStarted())
|
||||||
|
{
|
||||||
|
GlobalVars.Proxy.Stop();
|
||||||
|
}
|
||||||
ClientManagement.UpdateRichPresence(ClientManagement.GetStateForType(GlobalVars.GameOpened));
|
ClientManagement.UpdateRichPresence(ClientManagement.GetStateForType(GlobalVars.GameOpened));
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue