/// <summary> /// Returns true if the server is running in a local LAN /// </summary> private static bool ServerIsInLocalLan(IPEndPoint serverEndPoint) { var ownNetwork = LunaNetUtils.GetOwnInternalIPv6Network(); if (ownNetwork != null && serverEndPoint.AddressFamily == AddressFamily.InterNetworkV6) { // For IPv6, we strip both addresses down to the subnet portion (likely the first 64 bits) and compare them. // Because we only receive Global Unique Addresses from GetOwnInternalIPv6Network() (which are globally // unique, as the name suggests and the RFCs define), those being equal should mean both are on the same network. var ownBytes = ownNetwork.Address.GetAddressBytes(); var serverBytes = serverEndPoint.Address.GetAddressBytes(); // TODO IPv6: We currently assume an on-link prefix length of 64 bits, which is the most common case // and standardized as per the RFCs. UnicastIPAddressInformation.PrefixLength is not implemented yet, // and also wouldn't be reliable (hosts often assign their address as /128). A possible solution could be // checking whether serverEndPoint matches any configured on-link/no-gateway route. Array.Resize(ref ownBytes, 8); Array.Resize(ref serverBytes, 8); if (ownBytes == serverBytes) { return(true); } } return(Equals(LunaNetUtils.GetOwnExternalIpAddress(), serverEndPoint.Address)); }
public Server(MsRegisterServerMsgData msg, IPEndPoint externalEndpoint) { Id = msg.Id; ExternalEndpoint = IsLocalIpAddress(externalEndpoint.Address) ? new IPEndPoint(LunaNetUtils.GetOwnExternalIpAddress(), externalEndpoint.Port) : externalEndpoint; Update(msg); }
private static void CheckMasterServerListed() { var ownEndpoint = new IPEndPoint(LunaNetUtils.GetOwnExternalIpAddress(), Port); if (!MasterServerRetriever.MasterServers.Contains(ownEndpoint)) { LunaLog.Error($"You're not in the master-servers URL ({RepoConstants.MasterServersListShortUrl}) Clients/Servers won't see you"); } else { LunaLog.Normal("Own ip correctly listed in master - servers URL"); } }
private static void CheckMasterServerListed() { var servers = MasterServerRetriever.RetrieveWorkingMasterServersEndpoints(); var ownEndpoint = $"{LunaNetUtils.GetOwnExternalIpAddress()}:{Port}"; if (!servers.Contains(ownEndpoint)) { ConsoleLogger.Log(LogLevels.Error, $"You're not in the master-servers URL ({RepoConstants.MasterServersListShortUrl}) " + "Clients/Servers won't see you"); } else { ConsoleLogger.Log(LogLevels.Normal, "Own ip correctly listed in master - servers URL"); } }
private static void CheckMasterServerListed() { var ownAddress = LunaNetUtils.GetOwnExternalIpAddress(); if (ownAddress != null) { var ownEndpoint = new IPEndPoint(ownAddress, Port); if (!MasterServerRetriever.MasterServers.Contains(ownEndpoint)) { LunaLog.Error($"You're not listed in the master servers list ({RepoConstants.MasterServersListShortUrl}). Clients/Servers won't see you"); } else { LunaLog.Normal("You're correctly listed in the master servers list"); } } else { LunaLog.Error("Could not retrieve own external IP address, master server likely won't function properly"); } }
/// <summary> /// Returns true if the server is running in a local LAN /// </summary> private static bool ServerIsInLocalLan(IPEndPoint serverEndPoint) { return(LunaNetUtils.GetOwnExternalIpAddress() == serverEndPoint.Address.ToString()); }
/// <summary> /// Returns true if the server is running in a local LAN /// </summary> private static bool ServerIsInLocalLan(IPEndPoint serverEndPoint) { return(Equals(LunaNetUtils.GetOwnExternalIpAddress(), serverEndPoint.Address)); }
public Server(MsRegisterServerMsgData msg, IPEndPoint externalEndpoint) { ExternalEndpoint = IsLocalIpAddress(externalEndpoint.Address) ? new IPEndPoint(IPAddress.Parse(LunaNetUtils.GetOwnExternalIpAddress()), externalEndpoint.Port) : externalEndpoint; InternalEndpoint = Common.CreateEndpointFromString(msg.InternalEndpoint); LastRegisterTime = LunaNetworkTime.UtcNow.Ticks; Info = new ServerInfo { Id = msg.Id, ExternalEndpoint = $"{ExternalEndpoint.Address}:{ExternalEndpoint.Port}", InternalEndpoint = $"{InternalEndpoint.Address}:{InternalEndpoint.Port}", Cheats = msg.Cheats, Password = msg.Password, ServerVersion = msg.ServerVersion, Description = msg.Description, Website = msg.Website, WebsiteText = msg.WebsiteText, DropControlOnExit = msg.DropControlOnExit, DropControlOnExitFlight = msg.DropControlOnExitFlight, DropControlOnVesselSwitching = msg.DropControlOnVesselSwitching, GameMode = msg.GameMode, MaxPlayers = msg.MaxPlayers, ModControl = msg.ModControl, PlayerCount = msg.PlayerCount, ServerName = msg.ServerName, WarpMode = msg.WarpMode, TerrainQuality = msg.TerrainQuality, }; SetCountryFromEndpoint(Info, ExternalEndpoint); Info.ServerName = Info.ServerName.Length > 30 ? Info.ServerName.Substring(0, 30) : Info.ServerName; Info.Description = Info.Description.Length > 200 ? Info.Description.Substring(0, 200) : Info.Description; Info.Website = Info.Website.Length > 60 ? Info.Website.Substring(0, 60) : Info.Website; Info.WebsiteText = Info.WebsiteText.Length > 15 ? Info.WebsiteText.Substring(0, 15) : Info.WebsiteText; if (!string.IsNullOrEmpty(Info.Website) && !Info.Website.Contains("://")) { Info.Website = "http://" + Info.Website; } if (string.IsNullOrEmpty(Info.WebsiteText) && !string.IsNullOrEmpty(Info.Website)) { Info.WebsiteText = "URL"; } }
public Server(MsRegisterServerMsgData msg, IPEndPoint externalEndpoint) { ExternalEndpoint = IsLocalIpAddress(externalEndpoint.Address) ? new IPEndPoint(IPAddress.Parse(LunaNetUtils.GetOwnExternalIpAddress()), externalEndpoint.Port) : externalEndpoint; InternalEndpoint = Common.CreateEndpointFromString(msg.InternalEndpoint); LastRegisterTime = LunaTime.UtcNow.Ticks; Info = new ServerInfo { Id = msg.Id, ExternalEndpoint = $"{ExternalEndpoint.Address}:{ExternalEndpoint.Port}", InternalEndpoint = $"{InternalEndpoint.Address}:{InternalEndpoint.Port}", Cheats = msg.Cheats, Password = msg.Password, ServerVersion = msg.ServerVersion, ShowVesselsInThePast = msg.ShowVesselsInThePast, Description = msg.Description, DropControlOnExit = msg.DropControlOnExit, DropControlOnExitFlight = msg.DropControlOnExitFlight, DropControlOnVesselSwitching = msg.DropControlOnVesselSwitching, GameMode = msg.GameMode, MaxPlayers = msg.MaxPlayers, ModControl = msg.ModControl, PlayerCount = msg.PlayerCount, ServerName = msg.ServerName, WarpMode = msg.WarpMode, TerrainQuality = msg.TerrainQuality }; Info.ServerName = Info.ServerName.Length > 30 ? Info.ServerName.Substring(0, 30) : Info.ServerName; Info.Description = Info.Description.Length > 200 ? Info.Description.Substring(0, 200) : Info.Description; }