SubnauticaNitrox / Nitrox

An open-source, multiplayer modification for the game Subnautica.
GNU General Public License v3.0
1.72k stars 1.04k forks source link

Support online port checkers #2160

Open Measurity opened 1 month ago

Measurity commented 1 month ago

Describe the issue

Users want to verify they port forwarded correctly by using port checkers. Currently, the server doesn't respond to just any UDP message. Update to latest LiteNetLib version so that PacketLayer can be used to intercept messages and send a response.

After implementation, verify by using some port checkers like:

For port checkers to work, use your public IP: https://ipv4.icanhazip.com/

Proof of concept

Following code should show Open status in port checkers for port 11000 UDP.

using UdpClient client = new(new IPEndPoint(IPAddress.Any, 11000));
Console.WriteLine("Ready to receive stuff!");
while (true)
{
    var result = await client.ReceiveAsync();
    Console.WriteLine($"{result.RemoteEndPoint} - {result.Buffer.Length} bytes: {BitConverter.ToString(result.Buffer).Replace('-', '\0')}");
    await client.SendAsync(result.Buffer, result.Buffer.Length, result.RemoteEndPoint);
}