From 44b39c3b0e02aef20c56711794107c5f0baecb55 Mon Sep 17 00:00:00 2001 From: Bitl Date: Sat, 2 Sep 2017 11:48:14 -0700 Subject: [PATCH] UPNP: now WITHOUT Java! --- 3DView.rbxl | 450 ++++++++++++++++++ .../RBXLegacyLauncher/MainForm.cs | 70 ++- .../RBXLegacyLauncher.csproj | 10 + .../RBXLegacyLauncher/SecurityFuncs.cs | 16 + 4 files changed, 520 insertions(+), 26 deletions(-) create mode 100644 3DView.rbxl diff --git a/3DView.rbxl b/3DView.rbxl new file mode 100644 index 0000000..9a1cda5 --- /dev/null +++ b/3DView.rbxl @@ -0,0 +1,450 @@ + + null + nil + + + RBX1 + 0 + + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + + Workspace + null + true + + + + null + 0 + + 2.8825047 + 16.8061104 + 19.8420525 + 0.990262866 + -0.0670645982 + 0.121990994 + 3.7252903e-009 + 0.876308203 + 0.481750816 + -0.139210135 + -0.477059931 + 0.8677755 + + + -0.167192921 + 4.76264477 + -1.85178542 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + + Camera + true + + + + + + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + + Base + null + true + + + + true + -0.5 + 0.5 + 0 + 0 + -0.5 + 0.5 + 0 + 0 + 194 + + 0 + 1.99999952 + -0.5 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + + true + 0.5 + 2 + 0.300000012 + -0.5 + 0.5 + 0 + 0 + -0.5 + 0.5 + 0 + 0 + false + 256 + Part + 0 + -0.5 + 0.5 + 0 + 0 + + 0 + 0 + 0 + + -0.5 + 0.5 + 0 + 0 + 0 + + 0 + 0 + 0 + + true + 1 + + 18 + 0.400000006 + 18 + + + + + + false + true + -0.5 + 0.5 + 0 + 0 + -0.5 + 0.5 + 4 + 0 + 194 + + 0 + 2.39999986 + -0.5 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + + false + 0 + 0.5 + 2 + 0.300000012 + -0.5 + 0.5 + 0 + 0 + -0.5 + 0.5 + 0 + 0 + true + 256 + SpawnLocation + true + 0 + -0.5 + 0.5 + 0 + 0 + + 0 + 0 + 0 + + 194 + -0.5 + 0.5 + 3 + 0 + 1 + + 0 + 0 + 0 + + true + 1 + + 2 + 0.400000006 + 1 + + + + + + + + Run Service + true + + + + + Instance + true + + + + + ContentFilter + true + + + + + Instance + true + + + + + 12 + Players + true + + + + + StarterPack + true + + + + + StarterGui + true + true + + + + 3DViewUI + true + + + + true + true + 4288914085 + 0.400000006 + 4279970357 + 0 + 0 + 0 + Transparency + + 1 + -155 + 1 + -50 + + false + + 0 + 150 + 0 + 20 + + 0 + 0 + Change Base Transparency + 4283256141 + 0 + false + 2 + 1 + true + 1 + true + + + + false + + LocalScript + function onClicked() + if (game.Workspace.Base.Part.Transparency == 0) then + game.Workspace.Base.Part.Transparency = 0.5 + elseif (game.Workspace.Base.Part.Transparency == 0.5) then + game.Workspace.Base.Part.Transparency = 1 + elseif (game.Workspace.Base.Part.Transparency == 1) then + game.Workspace.Base.Part.Transparency = 0 + end +end + +script.Parent.MouseButton1Down:connect(onClicked) + true + + + + + + + + 0 + 10 + 1 + Soundscape + 1 + true + + + + + CollectionService + true + + + + + PhysicsService + true + + + + + BadgeService + true + + + + + Geometry + true + + + + + RenderHooksService + true + + + + + SocialService + true + + + + + 1000 + Debris + true + + + + + Instance + true + + + + + Instance + true + + + + + Selection + true + + + + + 4286874756 + 1 + 4278190080 + 4278190080 + 41.7332993 + Lighting + 4290230204 + 14:00:00 + true + + + + false + Sky + rbxasset://Sky/null_plainsky512_bk.jpg + rbxasset://Sky/null_plainsky512_dn.jpg + rbxasset://Sky/null_plainsky512_ft.jpg + rbxasset://Sky/null_plainsky512_lf.jpg + rbxasset://Sky/null_plainsky512_rt.jpg + rbxasset://Sky/null_plainsky512_up.jpg + 3000 + true + + + + + + ChangeHistoryService + true + + + + + Instance + true + + + + + Instance + true + + + \ No newline at end of file diff --git a/RBXLegacyLauncher/RBXLegacyLauncher/MainForm.cs b/RBXLegacyLauncher/RBXLegacyLauncher/MainForm.cs index 3bf8781..230eb26 100644 --- a/RBXLegacyLauncher/RBXLegacyLauncher/MainForm.cs +++ b/RBXLegacyLauncher/RBXLegacyLauncher/MainForm.cs @@ -110,12 +110,10 @@ namespace RBXLegacyLauncher { if (GlobalVars.upnp == true) { - Process pmap = new Process(); - pmap.StartInfo.FileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\jreportable\\bin\\java.exe"; - pmap.StartInfo.Arguments = "-jar upnp.jar -externalPort" + GlobalVars.ServerPort + " -internalPort" + GlobalVars.ServerPort + "-ip \"localhost\" -protocol udp"; - pmap.StartInfo.UseShellExecute = false; - pmap.StartInfo.CreateNoWindow = true; - pmap.Start(); + NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass(); + NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; + mappings.Add(GlobalVars.ServerPort, "TCP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port TCP"); + mappings.Add(GlobalVars.ServerPort, "UDP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port UDP"); } WriteConfigValues(); StartServer(); @@ -772,7 +770,14 @@ namespace RBXLegacyLauncher try { ConsolePrint("Server Loaded.", 4); - Process.Start(rbxexe, args); + Process server = new Process(); + server.StartInfo.FileName = rbxexe; + server.StartInfo.Arguments = args; + if (GlobalVars.upnp == true) + { + server.Exited += new EventHandler(ServerExited); + } + server.Start(); } catch (Exception ex) { @@ -799,7 +804,14 @@ namespace RBXLegacyLauncher try { ConsolePrint("Server Loaded in No3D mode.", 4); - Process.Start(rbxexe, args); + Process server = new Process(); + server.StartInfo.FileName = rbxexe; + server.StartInfo.Arguments = args; + if (GlobalVars.upnp == true) + { + server.Exited += new EventHandler(ServerExited); + } + server.Start(); } catch (Exception ex) { @@ -808,6 +820,15 @@ namespace RBXLegacyLauncher } } + void ServerExited(object sender, EventArgs e) + { + NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass(); + NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; + + mappings.Remove(GlobalVars.ServerPort, "TCP"); + mappings.Remove(GlobalVars.ServerPort, "UDP"); + } + void StartStudio() { string mapfile = GlobalVars.MapsDir + @"\\" + GlobalVars.Map; @@ -850,12 +871,10 @@ namespace RBXLegacyLauncher { if (GlobalVars.upnp == true) { - Process pmap = new Process(); - pmap.StartInfo.FileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\jreportable\\bin\\java.exe"; - pmap.StartInfo.Arguments = "-jar upnp.jar -externalPort" + GlobalVars.ServerPort + " -internalPort" + GlobalVars.ServerPort + "-ip \"localhost\" -protocol udp"; - pmap.StartInfo.UseShellExecute = false; - pmap.StartInfo.CreateNoWindow = true; - pmap.Start(); + NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass(); + NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; + mappings.Add(GlobalVars.ServerPort, "TCP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port TCP"); + mappings.Add(GlobalVars.ServerPort, "UDP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port UDP"); } StartServer(); } @@ -863,23 +882,22 @@ namespace RBXLegacyLauncher { if (GlobalVars.upnp == true) { - Process pmap = new Process(); - pmap.StartInfo.FileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\jreportable\\bin\\java.exe"; - pmap.StartInfo.Arguments = "-jar upnp.jar -externalPort" + GlobalVars.ServerPort + " -internalPort" + GlobalVars.ServerPort + "-ip \"localhost\" -protocol udp"; - pmap.StartInfo.UseShellExecute = false; - pmap.StartInfo.CreateNoWindow = true; - pmap.Start(); + NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass(); + NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; + mappings.Add(GlobalVars.ServerPort, "TCP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port TCP"); + mappings.Add(GlobalVars.ServerPort, "UDP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port UDP"); } StartServerNo3D(); } else if (command.Equals("rbxlegacy no3d")) { - Process pmap = new Process(); - pmap.StartInfo.FileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\jreportable\\bin\\java.exe"; - pmap.StartInfo.Arguments = "-jar upnp.jar -externalPort" + GlobalVars.ServerPort + " -internalPort" + GlobalVars.ServerPort + "-ip \"localhost\" -protocol udp"; - pmap.StartInfo.UseShellExecute = false; - pmap.StartInfo.CreateNoWindow = true; - pmap.Start(); + if (GlobalVars.upnp == true) + { + NATUPNPLib.UPnPNATClass upnpnat = new NATUPNPLib.UPnPNATClass(); + NATUPNPLib.IStaticPortMappingCollection mappings = upnpnat.StaticPortMappingCollection; + mappings.Add(GlobalVars.ServerPort, "TCP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port TCP"); + mappings.Add(GlobalVars.ServerPort, "UDP", GlobalVars.ServerPort, SecurityFuncs.GetLocalIPAddress(), true, "RBXLegacy Server Port UDP"); + } StartServerNo3D(); } else if (command.Equals("rbxlegacy client")) diff --git a/RBXLegacyLauncher/RBXLegacyLauncher/RBXLegacyLauncher.csproj b/RBXLegacyLauncher/RBXLegacyLauncher/RBXLegacyLauncher.csproj index 97ef50d..698424e 100644 --- a/RBXLegacyLauncher/RBXLegacyLauncher/RBXLegacyLauncher.csproj +++ b/RBXLegacyLauncher/RBXLegacyLauncher/RBXLegacyLauncher.csproj @@ -119,5 +119,15 @@ + + + {1C565858-F302-471E-B409-F180AA4ABEC6} + 1 + 0 + 0 + tlbimp + False + + \ No newline at end of file diff --git a/RBXLegacyLauncher/RBXLegacyLauncher/SecurityFuncs.cs b/RBXLegacyLauncher/RBXLegacyLauncher/SecurityFuncs.cs index a46adf1..53a9540 100644 --- a/RBXLegacyLauncher/RBXLegacyLauncher/SecurityFuncs.cs +++ b/RBXLegacyLauncher/RBXLegacyLauncher/SecurityFuncs.cs @@ -6,6 +6,8 @@ using System.Reflection; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; +using System.Net; +using System.Net.Sockets; using Microsoft.Win32; namespace RBXLegacyLauncher @@ -83,5 +85,19 @@ namespace RBXLegacyLauncher } } } + + public static string GetLocalIPAddress() + { + string str = ""; + foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList) + { + if (address.AddressFamily == AddressFamily.InterNetwork) + { + str = address.ToString(); + break; + } + } + return str; + } } }