Skip to content

Commit

Permalink
Fix ipv4 mapped ipv6 addresses not triggering IP connection spam bloc…
Browse files Browse the repository at this point in the history
…king

Since MCGalaxy only supports ipv4 connections by default this won't affect majority of servers
  • Loading branch information
UnknownShadow200 committed May 20, 2022
1 parent da78b98 commit f2b8ef5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 8 additions & 2 deletions MCGalaxy/Network/Utils/Utils.cs
Expand Up @@ -47,7 +47,8 @@ public static class IPUtil

// IPv4 mapped addresses have the format
// 0000:0000:0000:0000:0000:FFFF:[ipv4 address]
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++)
{
if (addr[i] != 0) return false;
}
return addr[10] == 0xFF && addr[11] == 0xFF;
Expand All @@ -69,7 +70,12 @@ public static class SocketUtil
{
/// <summary> Retrieves the remote IP address associated with the given socket </summary>
public static IPAddress GetIP(Socket s) {
return ((IPEndPoint)s.RemoteEndPoint).Address;
IPAddress addr = ((IPEndPoint)s.RemoteEndPoint).Address;

// Convert IPv4 mapped addresses to IPv4 addresses for consistency
// (e.g. so IPv4 mapped LAN IPs are treated as LAN IPs)
if (IPUtil.IsIPv4Mapped(addr)) addr = IPUtil.MapToIPV4(addr);
return addr;
}
}
}
4 changes: 0 additions & 4 deletions MCGalaxy/Player/Player.cs
Expand Up @@ -180,10 +180,6 @@ public partial class Player : Entity, IDisposable {
}

public void SetIP(IPAddress addr) {
// Convert IPv4 mapped addresses to IPv4 addresses for consistency
// (e.g. so IPv4 mapped LAN IPs are treated as LAN IPs)
if (IPUtil.IsIPv4Mapped(addr)) addr = IPUtil.MapToIPV4(addr);

IP = addr;
ip = addr.ToString();
}
Expand Down

0 comments on commit f2b8ef5

Please sign in to comment.