Infinidoge / nix-minecraft

An attempt to better support Minecraft-related content for the Nix ecosystem
MIT License
172 stars 18 forks source link

Allow duplicate ports when using multiple IP addresses #77

Open brianmay opened 1 week ago

brianmay commented 1 week ago

I see the code:

        {
          assertion =
            let
              serverPorts = mapAttrsToList
                (name: conf: conf.serverProperties.server-port or 25565)
                (filterAttrs (_: cfg: cfg.openFirewall) servers);

              counts = map (port: count (x: x == port) serverPorts) (unique serverPorts);
            in
            lib.all (x: x == 1) counts;
          message = "Multiple servers are set to use the same port. Change one to use a different port.";
        }

I haven't tested it, but this looks very much like you can't have multiple servers using the same server-port even if they have different server-ip values.

Or Maybe it just means you can't use openFirewall with such configs. Still trying to understand this logic.

Infinidoge commented 1 week ago

This is indeed an oversight. The general logic is that it catches trivial mistakes for the general case of non-differentiated IPs, which prevents starting servers in a situation that would cause them to conflict. Shouldn't be too difficult to make it check both server ip and port to make sure those combinations are unique. openFirewall isn't much of an issue since it should(?, not actually sure) have it open for all IP addresses, so just filtering out duplicate ports would be fine.