Exemplo n.º 1
0
        /// <summary>
        /// Send a request to the master server to introduce us and do the nat punchtrough to the selected server
        /// </summary>
        public static void IntroduceToServer(long serverId)
        {
            if (Servers.TryGetValue(serverId, out var serverInfo))
            {
                var serverEndpoint = Common.CreateEndpointFromString(serverInfo.ExternalEndpoint);
                if (ServerIsInLocalLan(serverEndpoint))
                {
                    LunaLog.Log("Server is in LAN. Skipping NAT punch");
                    NetworkConnection.ConnectToServer(serverEndpoint.Address.ToString(), serverEndpoint.Port, Password);
                }
                else
                {
                    try
                    {
                        var token       = RandomString(10);
                        var ownEndpoint = new IPEndPoint(LunaNetUtils.GetMyAddress(), NetworkMain.Config.Port);

                        var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <MsIntroductionMsgData>();
                        msgData.Id               = serverId;
                        msgData.Token            = token;
                        msgData.InternalEndpoint = Common.StringFromEndpoint(ownEndpoint);

                        var introduceMsg = NetworkMain.MstSrvMsgFactory.CreateNew <MainMstSrvMsg>(msgData);

                        LunaLog.Log($"[LMP]: Sending NAT introduction to server. Token: {token}");
                        NetworkSender.QueueOutgoingMessage(introduceMsg);
                    }
                    catch (Exception e)
                    {
                        LunaLog.LogError($"[LMP]: Error connecting to server: {e}");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static async void RegisterWithMasterServer()
        {
            if (!GeneralSettings.SettingsStore.RegisterWithMasterServer)
            {
                return;
            }

            LunaLog.Normal("Registering with master servers...");

            var adr = LunaNetUtils.GetMyAddress();

            if (adr == null)
            {
                return;
            }

            var endpoint = new IPEndPoint(adr, ServerContext.Config.Port);

            while (ServerContext.ServerRunning)
            {
                var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <MsRegisterServerMsgData>();
                msgData.Id                                   = LidgrenServer.Server.UniqueIdentifier;
                msgData.Password                             = !string.IsNullOrEmpty(GeneralSettings.SettingsStore.Password);
                msgData.Cheats                               = GeneralSettings.SettingsStore.Cheats;
                msgData.ShowVesselsInThePast                 = GeneralSettings.SettingsStore.ShowVesselsInThePast;
                msgData.Description                          = GeneralSettings.SettingsStore.Description;
                msgData.DropControlOnExit                    = GeneralSettings.SettingsStore.Cheats;
                msgData.DropControlOnExitFlight              = GeneralSettings.SettingsStore.Cheats;
                msgData.DropControlOnVesselSwitching         = GeneralSettings.SettingsStore.Cheats;
                msgData.GameMode                             = (int)GeneralSettings.SettingsStore.GameMode;
                msgData.InternalEndpoint                     = $"{endpoint.Address}:{endpoint.Port}";
                msgData.MaxPlayers                           = GeneralSettings.SettingsStore.MaxPlayers;
                msgData.ModControl                           = (int)GeneralSettings.SettingsStore.ModControl;
                msgData.PlayerCount                          = ServerContext.Clients.Count;
                msgData.ServerName                           = GeneralSettings.SettingsStore.ServerName;
                msgData.ServerVersion                        = LmpVersioning.CurrentVersion;
                msgData.VesselUpdatesSendMsInterval          = GeneralSettings.SettingsStore.VesselUpdatesSendMsInterval;
                msgData.SecondaryVesselUpdatesSendMsInterval = GeneralSettings.SettingsStore.SecondaryVesselUpdatesSendMsInterval;
                msgData.WarpMode                             = (int)GeneralSettings.SettingsStore.WarpMode;
                msgData.TerrainQuality                       = (int)GeneralSettings.SettingsStore.TerrainQuality;

                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;

                lock (MasterServerEndpoints)
                {
                    foreach (var masterServer in MasterServerEndpoints)
                    {
                        RegisterWithMasterServer(msgData, masterServer);
                    }
                }

                await Task.Delay(MasterServerRegistrationMsInterval);
            }
        }
        public static void IntroduceToServer(long currentEntryId)
        {
            var token       = RandomString(10);
            var ownEndpoint = new IPEndPoint(LunaNetUtils.GetMyAddress(), NetworkMain.Config.Port);

            LunaLog.Log($"[LMP]: Sending NAT introduction to server. Token: {token}");

            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <MsIntroductionMsgData>();

            msgData.Id               = currentEntryId;
            msgData.Token            = token;
            msgData.InternalEndpoint = Common.StringFromEndpoint(ownEndpoint);
            var introduceMsg = MstSrvMsgFactory.CreateNew <MainMstSrvMsg>(msgData);

            foreach (var masterServer in MasterServerEndpoints.Values.ToArray())
            {
                try
                {
                    var lidgrenMsg = masterServer.CreateMessage((int)introduceMsg.GetMessageSize());
                    introduceMsg.Serialize(lidgrenMsg);

                    masterServer.SendMessage(lidgrenMsg, introduceMsg.NetDeliveryMethod);
                    masterServer.FlushSendQueue();
                }
                catch (Exception e)
                {
                    LunaLog.LogError($"[LMP]: Error connecting to server: {e}");
                }
            }

            introduceMsg.Recycle();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Send a request to the master server to introduce us and do the nat punchtrough to the selected server
        /// </summary>
        public static void IntroduceToServer(long currentEntryId)
        {
            try
            {
                var token       = RandomString(10);
                var ownEndpoint = new IPEndPoint(LunaNetUtils.GetMyAddress(), NetworkMain.Config.Port);

                var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <MsIntroductionMsgData>();
                msgData.Id               = currentEntryId;
                msgData.Token            = token;
                msgData.InternalEndpoint = Common.StringFromEndpoint(ownEndpoint);

                var introduceMsg = NetworkMain.MstSrvMsgFactory.CreateNew <MainMstSrvMsg>(msgData);

                LunaLog.Log($"[LMP]: Sending NAT introduction to server. Token: {token}");
                NetworkSender.QueueOutgoingMessage(introduceMsg);
            }
            catch (Exception e)
            {
                LunaLog.LogError($"[LMP]: Error connecting to server: {e}");
            }
        }