This commit is contained in:
Bitl 2017-09-03 09:52:14 -07:00
parent 57013daeec
commit 9abedc9bc7
3 changed files with 48 additions and 25 deletions

View File

@ -18,6 +18,45 @@ namespace RBXLegacyLauncher
{ {
InitializeComponent(); InitializeComponent();
} }
public event EventHandler<evNATdoneargs> evNATdone;
public class evNATdoneargs : EventArgs
{
public string IP;
public int port;
}
//this class contains network connectivity stuff
public void StartUPNP()
{
Mono.Nat.NatUtility.DeviceFound += new EventHandler<Mono.Nat.DeviceEventArgs>(NatUtility_DeviceFound);
Mono.Nat.NatUtility.DeviceLost += new EventHandler<Mono.Nat.DeviceEventArgs>(NatUtility_DeviceLost);
Mono.Nat.NatUtility.StartDiscovery();
}
private void NatUtility_DeviceFound(object sender, Mono.Nat.DeviceEventArgs e)
{
//do port forwarding with UPNP
Mono.Nat.INatDevice natd = e.Device;
natd.CreatePortMap(new Mono.Nat.Mapping(Mono.Nat.Protocol.Tcp,GlobalVars.ServerPort,GlobalVars.ServerPort));
natd.CreatePortMap(new Mono.Nat.Mapping(Mono.Nat.Protocol.Udp,GlobalVars.ServerPort,GlobalVars.ServerPort));
ConsolePrint("Port " + GlobalVars.ServerPort.ToString() + " registered to device " + natd.GetExternalIP().ToString(), 3);
evNATdoneargs args = new evNATdoneargs();
args.IP = natd.GetExternalIP().ToString();
args.port = GlobalVars.ServerPort;
evNATdone(this, args);
//MessageBox.Show("NAT done! My public IP is " + IP);
}
private void NatUtility_DeviceLost(object sender, Mono.Nat.DeviceEventArgs e)
{
//do port forwarding with UPNP
Mono.Nat.INatDevice natd = e.Device;
natd.DeletePortMap(new Mono.Nat.Mapping(Mono.Nat.Protocol.Tcp,GlobalVars.ServerPort,GlobalVars.ServerPort));
natd.DeletePortMap(new Mono.Nat.Mapping(Mono.Nat.Protocol.Udp,GlobalVars.ServerPort,GlobalVars.ServerPort));
}
void tabControl1_SelectedIndexChanged(object sender, EventArgs e) void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"]) if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"])
@ -110,7 +149,7 @@ namespace RBXLegacyLauncher
{ {
if (GlobalVars.upnp == true) if (GlobalVars.upnp == true)
{ {
//TODO: find good libary for UPNP StartUPNP();
} }
WriteConfigValues(); WriteConfigValues();
StartServer(); StartServer();
@ -767,14 +806,7 @@ namespace RBXLegacyLauncher
try try
{ {
ConsolePrint("Server Loaded.", 4); ConsolePrint("Server Loaded.", 4);
Process server = new Process(); Process.Start(rbxexe, args);
server.StartInfo.FileName = rbxexe;
server.StartInfo.Arguments = args;
if (GlobalVars.upnp == true)
{
server.Exited += new EventHandler(ServerExited);
}
server.Start();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -801,14 +833,7 @@ namespace RBXLegacyLauncher
try try
{ {
ConsolePrint("Server Loaded in No3D mode.", 4); ConsolePrint("Server Loaded in No3D mode.", 4);
Process server = new Process(); Process.Start(rbxexe, args);
server.StartInfo.FileName = rbxexe;
server.StartInfo.Arguments = args;
if (GlobalVars.upnp == true)
{
server.Exited += new EventHandler(ServerExited);
}
server.Start();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -817,11 +842,6 @@ namespace RBXLegacyLauncher
} }
} }
void ServerExited(object sender, EventArgs e)
{
//TODO: find good libary for UPNP
}
void StartStudio() void StartStudio()
{ {
string mapfile = GlobalVars.MapsDir + @"\\" + GlobalVars.Map; string mapfile = GlobalVars.MapsDir + @"\\" + GlobalVars.Map;
@ -864,7 +884,7 @@ namespace RBXLegacyLauncher
{ {
if (GlobalVars.upnp == true) if (GlobalVars.upnp == true)
{ {
//TODO: find good libary for UPNP StartUPNP();
} }
StartServer(); StartServer();
} }
@ -872,7 +892,7 @@ namespace RBXLegacyLauncher
{ {
if (GlobalVars.upnp == true) if (GlobalVars.upnp == true)
{ {
//TODO: find good libary for UPNP StartUPNP();
} }
StartServerNo3D(); StartServerNo3D();
} }
@ -880,7 +900,7 @@ namespace RBXLegacyLauncher
{ {
if (GlobalVars.upnp == true) if (GlobalVars.upnp == true)
{ {
//TODO: find good libary for UPNP StartUPNP();
} }
StartServerNo3D(); StartServerNo3D();
} }

View File

@ -49,6 +49,9 @@
<StartProgram>..\..\..\RBXLegacy\release\RBXLegacy\RBXLegacyLauncher.exe</StartProgram> <StartProgram>..\..\..\RBXLegacy\release\RBXLegacy\RBXLegacyLauncher.exe</StartProgram>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Mono.Nat">
<HintPath>Resources\Mono.Nat.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />