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; }
public Server(MsRegisterServerMsgData msg, IPEndPoint externalEndpoint) { InternalEndpoint = Common.CreateEndpointFromString(msg.InternalEndpoint); ExternalEndpoint = externalEndpoint; LastRegisterTime = DateTime.UtcNow.Ticks; Info = new ServerInfo { Id = msg.Id, Cheats = msg.Cheats, 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, Version = msg.ServerVersion, WarpMode = msg.WarpMode }; 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; }
public Server(MsRegisterServerMsgData msg, IPEndPoint externalEndpoint) { Id = msg.Id; ExternalEndpoint = IsLocalIpAddress(externalEndpoint.Address) ? new IPEndPoint(LunaNetUtils.GetOwnExternalIpAddress(), externalEndpoint.Port) : externalEndpoint; Update(msg); }
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, ServerName = msg.ServerName, Description = msg.Description, Country = msg.CountryCode, 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, WarpMode = msg.WarpMode, TerrainQuality = msg.TerrainQuality, }; if (string.IsNullOrEmpty(Info.Country)) { SetCountryFromEndpoint(Info, ExternalEndpoint); } Info.Country = Info.Country.ToUpper(); 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 void Update(MsRegisterServerMsgData msg) { InternalEndpoint = msg.InternalEndpoint; InternalEndpoint6 = msg.InternalEndpoint6; LastRegisterTime = LunaNetworkTime.UtcNow.Ticks; Cheats = msg.Cheats; Password = msg.Password; ServerVersion = msg.ServerVersion; ServerName = msg.ServerName.Length > 30 ? msg.ServerName.Substring(0, 30) : msg.ServerName; Description = msg.Description.Length > 200 ? msg.Description.Substring(0, 200) : msg.Description; if (!string.IsNullOrEmpty(msg.CountryCode) && CountryCodes.Contains(msg.CountryCode.ToUpper())) { Country = msg.CountryCode.ToUpper(); } Website = msg.Website.Length > 60 ? msg.Website.Substring(0, 60) : msg.Website; WebsiteText = msg.WebsiteText.Length > 15 ? msg.WebsiteText.Substring(0, 15) : msg.WebsiteText; RainbowEffect = msg.RainbowEffect; Array.Copy(msg.Color, Color, 3); GameMode = msg.GameMode; MaxPlayers = msg.MaxPlayers; ModControl = msg.ModControl; DedicatedServer = DedicatedServerRetriever.IsDedicatedServer(ExternalEndpoint); PlayerCount = msg.PlayerCount; WarpMode = msg.WarpMode; TerrainQuality = msg.TerrainQuality; if (string.IsNullOrEmpty(Country)) { SetCountryFromEndpoint(this, ExternalEndpoint); } if (!Website.Contains("://")) { Website = "http://" + Website; } if (string.IsNullOrEmpty(WebsiteText) && !string.IsNullOrEmpty(Website)) { WebsiteText = "URL"; } }
public void Update(MsRegisterServerMsgData msg) { InternalEndpoint = Common.CreateEndpointFromString(msg.InternalEndpoint); LastRegisterTime = LunaNetworkTime.UtcNow.Ticks; Info.InternalEndpoint = $"{InternalEndpoint.Address}:{InternalEndpoint.Port}"; Info.Cheats = msg.Cheats; Info.Password = msg.Password; Info.ServerVersion = msg.ServerVersion; Info.Description = msg.Description; Info.Website = msg.Website; Info.WebsiteText = msg.WebsiteText; Info.DropControlOnExit = msg.DropControlOnExit; Info.DropControlOnExitFlight = msg.DropControlOnExitFlight; Info.DropControlOnVesselSwitching = msg.DropControlOnVesselSwitching; Info.GameMode = msg.GameMode; Info.MaxPlayers = msg.MaxPlayers; Info.ModControl = msg.ModControl; Info.PlayerCount = msg.PlayerCount; Info.ServerName = msg.ServerName; Info.WarpMode = msg.WarpMode; Info.TerrainQuality = msg.TerrainQuality; if (string.IsNullOrEmpty(Info.Country)) { 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"; } }
private static void RegisterWithMasterServer(MsRegisterServerMsgData msgData, IPEndPoint masterServer) { var msg = ServerContext.MasterServerMessageFactory.CreateNew <MainMstSrvMsg>(msgData); msg.Data.SentTime = LunaNetworkTime.UtcNow.Ticks; //msg.NetDeliveryMethod = Lidgren.Network.NetDeliveryMethod.Unreliable; var outMsg = LidgrenServer.Server.CreateMessage(msg.GetMessageSize()); msg.Serialize(outMsg); try { LidgrenServer.Server.SendUnconnectedMessage(outMsg, masterServer); //Force send of packets //LidgrenServer.Server.FlushSendQueue(); } catch (Exception) { // ignored } }
private static void RegisterWithMasterServer(MsRegisterServerMsgData msgData, IPEndPoint masterServer) { Task.Run(() => { var msg = ServerContext.MasterServerMessageFactory.CreateNew <MainMstSrvMsg>(msgData); msg.Data.SentTime = LunaTime.UtcNow.Ticks; try { var outMsg = LidgrenServer.Server.CreateMessage(msg.GetMessageSize()); msg.Serialize(outMsg); LidgrenServer.Server.SendUnconnectedMessage(outMsg, masterServer); LidgrenServer.Server.FlushSendQueue(); } catch (Exception) { // ignored } }); }
public void RegisterWithMasterServer() { if (!GeneralSettings.SettingsStore.RegisterWithMasterServer) { return; } var adr = NetUtility.GetMyAddress(out var _); var endpoint = new IPEndPoint(adr, ServerContext.Config.Port); if (MasterServerEndpoints == null || !MasterServerEndpoints.Any()) { MasterServerEndpoints = MasterServerRetriever.RetrieveWorkingMasterServersEndpoints() .Select(Common.CreateEndpointFromString) .ToArray(); } LunaLog.Normal("Registering with master servers..."); while (ServerContext.ServerRunning) { var msgData = new MsRegisterServerMsgData { Id = Server.UniqueIdentifier, Cheats = GeneralSettings.SettingsStore.Cheats, ShowVesselsInThePast = GeneralSettings.SettingsStore.ShowVesselsInThePast, Description = GeneralSettings.SettingsStore.Description, DropControlOnExit = GeneralSettings.SettingsStore.Cheats, DropControlOnExitFlight = GeneralSettings.SettingsStore.Cheats, DropControlOnVesselSwitching = GeneralSettings.SettingsStore.Cheats, GameMode = (int)GeneralSettings.SettingsStore.GameMode, InternalEndpoint = $"{endpoint.Address}:{endpoint.Port}", MaxPlayers = GeneralSettings.SettingsStore.MaxPlayers, ModControl = (int)GeneralSettings.SettingsStore.ModControl, PlayerCount = ServerContext.Clients.Count, ServerName = GeneralSettings.SettingsStore.ServerName, ServerVersion = VersionInfo.VersionNumber, VesselUpdatesSendMsInterval = GeneralSettings.SettingsStore.VesselUpdatesSendMsInterval, SecondaryVesselUpdatesSendMsInterval = GeneralSettings.SettingsStore.SecondaryVesselUpdatesSendMsInterval, WarpMode = (int)GeneralSettings.SettingsStore.WarpMode }; msgData.Description = msgData.Description.Length > 200 ? msgData.Description.Substring(0, 200) : msgData.Description; msgData.ServerName = msgData.ServerName.Length > 30 ? msgData.ServerName.Substring(0, 30) : msgData.ServerName; var msg = ServerContext.MasterServerMessageFactory.CreateNew <MainMstSrvMsg>(msgData); var msgBytes = ServerContext.MasterServerMessageFactory.Serialize(msg); foreach (var masterServer in MasterServerEndpoints) { try { var outMsg = Server.CreateMessage(msgBytes.Length); outMsg.Write(msgBytes); Server.SendUnconnectedMessage(outMsg, masterServer); Server.FlushSendQueue(); } catch (Exception) { // ignored } } Thread.Sleep(MasterServerRegistrationMsInterval); } }