diff --git a/MLAPI/Data/NetworkingConfiguration.cs b/MLAPI/Data/NetworkingConfiguration.cs index a49e98f..072e221 100644 --- a/MLAPI/Data/NetworkingConfiguration.cs +++ b/MLAPI/Data/NetworkingConfiguration.cs @@ -27,8 +27,6 @@ namespace MLAPI //Should only be used for dedicated servers and will require the servers RSA keypair being hard coded into clients in order to exchange a AES key //TODO public bool EncryptMessages = false; - public bool UseUPnP = false; - public Action UPnPCompleteCallback = null; //Cached config hash private byte[] ConfigHash = null; diff --git a/MLAPI/Helper/UPnPHelper.cs b/MLAPI/Helper/UPnPHelper.cs deleted file mode 100644 index 979f971..0000000 --- a/MLAPI/Helper/UPnPHelper.cs +++ /dev/null @@ -1,87 +0,0 @@ -using Open.Nat; -using System; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using UnityEngine; - -namespace MLAPI.Helper -{ - public static class UPnPHelper - { - //Needs to be threaded, Currently freezes the game for up to 10 sec - internal static void AttemptPortMap(int port, Action callback) - { - bool invoked = false; - NatDiscoverer nat = new NatDiscoverer(); - CancellationTokenSource cts = new CancellationTokenSource(); - cts.CancelAfter(10000); - - NatDevice device = null; - StringBuilder sb = new StringBuilder(); - Task natTask = nat.DiscoverDeviceAsync(PortMapper.Upnp, cts); - Mapping tcpMapping = new Mapping(Protocol.Tcp, port, port, 0, Application.productName + " (TCP)"); - Mapping udpMapping = new Mapping(Protocol.Udp, port, port, 0, Application.productName + " (UDP)"); - IPAddress publicIPAddress = null; - natTask.ContinueWith(tt => - { - device = tt.Result; - device.GetExternalIPAsync() - .ContinueWith(task => - { - publicIPAddress = task.Result; - return device.CreatePortMapAsync(udpMapping); - }) - .Unwrap() - .ContinueWith(task => - { - return device.CreatePortMapAsync(udpMapping); - }) - .Unwrap() - .ContinueWith(task => - { - return device.GetAllMappingsAsync(); - }) - .Unwrap() - .ContinueWith(task => - { - Mapping[] mappings = task.Result.ToArray(); - if(mappings.Length == 0) - { - if (!invoked && callback != null) - callback(false, publicIPAddress); - invoked = true; - } - else - { - for (int i = 0; i < mappings.Length; i++) - { - if(mappings[i].PrivatePort == port) - { - if (!invoked && callback != null) - callback(true, publicIPAddress); - invoked = true; - } - } - } - }); - }, TaskContinuationOptions.OnlyOnRanToCompletion); - - try - { - natTask.Wait(); - } - catch (AggregateException e) - { - if (e.InnerException is NatDeviceNotFoundException) - { - if (!invoked && callback != null) - callback(false, publicIPAddress); - invoked = true; - } - } - } - } -} diff --git a/MLAPI/MLAPI.csproj b/MLAPI/MLAPI.csproj index 3090e03..05867b9 100644 --- a/MLAPI/MLAPI.csproj +++ b/MLAPI/MLAPI.csproj @@ -34,14 +34,8 @@ 4 - - ..\packages\Open.NAT.2.1.0.0\lib\net35\Open.Nat.dll - - - ..\packages\Open.NAT.2.1.0.0\lib\net35\System.Threading.dll - @@ -52,7 +46,6 @@ - @@ -62,8 +55,5 @@ - - - \ No newline at end of file diff --git a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs index 179e2ca..3ea4cf7 100644 --- a/MLAPI/MonoBehaviours/Core/NetworkingManager.cs +++ b/MLAPI/MonoBehaviours/Core/NetworkingManager.cs @@ -1,5 +1,4 @@ -using MLAPI.Helper; -using MLAPI.NetworkingManagerComponents; +using MLAPI.NetworkingManagerComponents; using System; using System.Collections; using System.Collections.Generic; @@ -124,10 +123,6 @@ namespace MLAPI Debug.LogWarning("MLAPI: No ConnectionApproval callback defined. Connection approval will timeout"); } } - if (NetworkConfig.UseUPnP) - { - UPnPHelper.AttemptPortMap(NetworkConfig.Port, NetworkConfig.UPnPCompleteCallback); - } HostTopology hostTopology = new HostTopology(cConfig, NetworkConfig.MaxConnections); hostId = NetworkTransport.AddHost(hostTopology, NetworkConfig.Port); isServer = true; @@ -192,10 +187,6 @@ namespace MLAPI Debug.LogWarning("MLAPI: No ConnectionApproval callback defined. Connection approval will timeout"); } } - if(NetworkConfig.UseUPnP) - { - UPnPHelper.AttemptPortMap(NetworkConfig.Port, NetworkConfig.UPnPCompleteCallback); - } HostTopology hostTopology = new HostTopology(cConfig, NetworkConfig.MaxConnections); hostId = NetworkTransport.AddHost(hostTopology, NetworkConfig.Port, null); isServer = true; diff --git a/MLAPI/packages.config b/MLAPI/packages.config deleted file mode 100644 index 409883c..0000000 --- a/MLAPI/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/README.md b/README.md index 5108c7b..5955d5c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ It's licenced under the MIT licence :D ## Done features * Host support (Client hosts the server) (done) -* Port forwarding using Open.NAT using the UPnP protcol (done) * Object and player spawning (done) * Connection approval (done) * Message names (done) @@ -33,8 +32,4 @@ That's all I can think of right now. But there is more to come, especially if pe ## Indepth -The project is not yet very tested. Examples will be created when it's more functional. - - -## Dependencies -Open.NAT - https://github.com/lontivero/Open.NAT (MIT) \ No newline at end of file +The project is not yet very tested. Examples will be created when it's more functional. \ No newline at end of file