public static void RefreshMasterServersList()
        {
            SystemBase.TaskFactory.StartNew(() =>
            {
                foreach (var masterServer in MasterServerRetriever.RetrieveWorkingMasterServersEndpoints())
                {
                    var endpoint = Common.CreateEndpointFromString(masterServer);

                    var netClient = new NetClient(Config);
                    netClient.Start();

                    netClient.Connect(endpoint);
                    netClient.FlushSendQueue();

                    var connectionTrials = 0;
                    while (netClient.ConnectionStatus != NetConnectionStatus.Connected && connectionTrials < 3)
                    {
                        connectionTrials++;
                        Thread.Sleep(1000);
                    }

                    if (netClient.ConnectionStatus == NetConnectionStatus.Connected)
                    {
                        MasterServerEndpoints.TryAdd(endpoint, netClient);
                        RequestServerList(netClient);
                        netClient.RegisterReceivedCallback(GotMessage);
                    }
                }
            });
        }
예제 #2
0
        private static void CheckMasterServerListed()
        {
            var servers     = MasterServerRetriever.RetrieveWorkingMasterServersEndpoints();
            var ownEndpoint = GetOwnIpAddress() + ":" + Port;

            Form.WriteLine(!servers.Contains(ownEndpoint)
                ? "CAUTION! This server is not listed in the master-servers URL " +
                           $"({MasterServerRetriever.MasterServersListShortUrl}) Clients/Servers will not see you"
                : $"Own ip correctly listed in master-servers URL ({MasterServerRetriever.MasterServersListShortUrl})");
        }
 /// <summary>
 /// Refreshes the list of master servers
 /// </summary>
 public static void RefreshMasterServers()
 {
     if (!MasterServers.Any())
     {
         var servers = MasterServerRetriever.RetrieveWorkingMasterServersEndpoints();
         foreach (var server in servers)
         {
             MasterServers.Add(Common.CreateEndpointFromString(server));
         }
     }
 }
예제 #4
0
        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");
            }
        }
예제 #5
0
        public static async void RefreshMasterServersList()
        {
            if (!GeneralSettings.SettingsStore.RegisterWithMasterServer)
            {
                return;
            }

            while (ServerContext.ServerRunning)
            {
                lock (MasterServerEndpoints)
                {
                    MasterServerEndpoints.Clear();
                    MasterServerEndpoints.AddRange(MasterServerRetriever.RetrieveWorkingMasterServersEndpoints()
                                                   .Select(Common.CreateEndpointFromString));
                }

                await Task.Delay((int)TimeSpan.FromMinutes(10).TotalMilliseconds);
            }
        }
예제 #6
0
        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);
            }
        }