static void NatUtility_DeviceFound(object sender, Mono.Nat.DeviceEventArgs e)
        {
#if ENABLE_NAT
            try
            {
                if (e.Device is Mono.Nat.Upnp.UpnpNatDevice) //TODO, see if Pmp should work as well
                {
//                    var current = e.Device.GetAllMappings();
//                    if (current != null)
//                    {
//                        foreach (var map in current)
//                        {
//                            if (map.Protocol == Mono.Nat.Protocol.Tcp && map.PrivatePort == Terraria.Netplay.portForwardPort && map.PublicPort == Terraria.Netplay.portForwardPort)
//                            {
//                                Terraria.Netplay.portForwardOpen = true;
//                            }
//                        }
//                    }

                    if (!Terraria.Netplay.portForwardOpen)
                    {
                        _devices.Add(e.Device);
                        _map = new Mono.Nat.Mapping(Mono.Nat.Protocol.Tcp, Terraria.Netplay.portForwardPort, Terraria.Netplay.portForwardPort)
                        {
                            Description = "Terraria Server"
                        };

                        e.Device.CreatePortMap(_map);
                        ProgramLog.Admin.Log("Created a new NAT map record for Terraria Server");
                        Terraria.Netplay.portForwardOpen = true;
                    }
                    else
                    {
                        ProgramLog.Admin.Log("Detected an existing NAT map record for Terraria Server");
                    }
                }
            }
            catch (Exception ex)
            {
                ProgramLog.Log(ex, "Failed to create NAT device mapping");
            }
#endif
        }
Example #2
0
        static void NatUtility_DeviceFound(object sender, Mono.Nat.DeviceEventArgs e)
        {
#if ENABLE_NAT
            try
            {
                if (e.Device is Mono.Nat.Upnp.UpnpNatDevice) //TODO, see if Pmp should work as well
                {
//                    var current = e.Device.GetAllMappings();
//                    if (current != null)
//                    {
//                        foreach (var map in current)
//                        {
//                            if (map.Protocol == Mono.Nat.Protocol.Tcp && map.PrivatePort == Terraria.Netplay.portForwardPort && map.PublicPort == Terraria.Netplay.portForwardPort)
//                            {
//                                Terraria.Netplay.portForwardOpen = true;
//                            }
//                        }
//                    }

                    if (!Terraria.Netplay.portForwardOpen)
                    {
                        _devices.Add(e.Device);
                        _map = new Mono.Nat.Mapping(Mono.Nat.Protocol.Tcp, Terraria.Netplay.portForwardPort, Terraria.Netplay.portForwardPort)
                        {
                            Description = "Terraria Server"
                        };

                        e.Device.CreatePortMap(_map);
                        ProgramLog.Admin.Log("Created a new NAT map record for Terraria Server");
                        Terraria.Netplay.portForwardOpen = true;
                    }
                    else
                    {
                        ProgramLog.Admin.Log("Detected an existing NAT map record for Terraria Server");
                    }
                }
            }
            catch (Exception ex)
            {
                ProgramLog.Log(ex, "Failed to create NAT device mapping");
            }
#endif
        }
        static void NatUtility_DeviceFound(object sender, Mono.Nat.DeviceEventArgs e)
        {
            #if ENABLE_NAT
            try
            {
                if(e.Device is Mono.Nat.Upnp.UpnpNatDevice) //TODO, see if Pmp should work as well
                {
                    var current = e.Device.GetAllMappings();
                    if (current != null)
                    {
                        foreach (var map in current)
                        {
                            if (map.Protocol == Mono.Nat.Protocol.Tcp && map.PrivatePort == Netplay.portForwardPort && map.PublicPort == Netplay.portForwardPort)
                            {
                                Netplay.portForwardOpen = true;
                            }
                        }
                    }

                    if (!Netplay.portForwardOpen)
                    {
                        var terrariaMap = new Mono.Nat.Mapping(Mono.Nat.Protocol.Tcp, Netplay.portForwardPort, Netplay.portForwardPort)
                        {
                            Description = "Terraria Server"
                        };
                        e.Device.CreatePortMap(terrariaMap);
                        Tools.WriteLine("Created a new NAT map record for Terraria Server");
                        Netplay.portForwardOpen = true;
                    }
                    else
                    {
                        Tools.WriteLine("Detected an existing NAT map record for Terraria Server");
                    }
                }
            }
            catch(Exception ex)
            {
                Tools.WriteLine(ex);
            }
            #endif
        }
Example #4
0
        static void NatUtility_DeviceFound(object sender, Mono.Nat.DeviceEventArgs e)
        {
#if ENABLE_NAT
            try
            {
                if (e.Device is Mono.Nat.Upnp.UpnpNatDevice) //TODO, see if Pmp should work as well
                {
                    var current = e.Device.GetAllMappings();
                    if (current != null)
                    {
                        foreach (var map in current)
                        {
                            if (map.Protocol == Mono.Nat.Protocol.Tcp && map.PrivatePort == Netplay.portForwardPort && map.PublicPort == Netplay.portForwardPort)
                            {
                                Netplay.portForwardOpen = true;
                            }
                        }
                    }

                    if (!Netplay.portForwardOpen)
                    {
                        var terrariaMap = new Mono.Nat.Mapping(Mono.Nat.Protocol.Tcp, Netplay.portForwardPort, Netplay.portForwardPort)
                        {
                            Description = "Terraria Server"
                        };
                        e.Device.CreatePortMap(terrariaMap);
                        Tools.WriteLine("Created a new NAT map record for Terraria Server");
                        Netplay.portForwardOpen = true;
                    }
                    else
                    {
                        Tools.WriteLine("Detected an existing NAT map record for Terraria Server");
                    }
                }
            }
            catch (Exception ex)
            {
                Tools.WriteLine(ex);
            }
#endif
        }