private static bool CheckPort() { if (LunaNetUtils.IsUdpPortInUse(Lidgren.MasterServer.Port)) { LunaLog.Fatal($"Port {Lidgren.MasterServer.Port} is already in use!"); return(false); } return(true); }
public static void SetupLidgrenServer() { if (!IPAddress.TryParse(ConnectionSettings.SettingsStore.ListenAddress, out var listenAddress)) { LunaLog.Warning("Could not parse ListenAddress, falling back to 0.0.0.0"); listenAddress = IPAddress.Any; } ; ServerContext.Config.LocalAddress = listenAddress; // Listen on dual-stack for the unspecified address in IPv6 format ([::]). if (ServerContext.Config.LocalAddress.Equals(IPAddress.IPv6Any)) { ServerContext.Config.DualStack = true; } ServerContext.Config.Port = ConnectionSettings.SettingsStore.Port; ServerContext.Config.AutoExpandMTU = ConnectionSettings.SettingsStore.AutoExpandMtu; ServerContext.Config.MaximumTransmissionUnit = ConnectionSettings.SettingsStore.MaximumTransmissionUnit; ServerContext.Config.MaximumConnections = GeneralSettings.SettingsStore.MaxPlayers; ServerContext.Config.PingInterval = (float)TimeSpan.FromMilliseconds(ConnectionSettings.SettingsStore.HearbeatMsInterval).TotalSeconds; ServerContext.Config.ConnectionTimeout = (float)TimeSpan.FromMilliseconds(ConnectionSettings.SettingsStore.ConnectionMsTimeout).TotalSeconds; if (LunaNetUtils.IsUdpPortInUse(ServerContext.Config.Port)) { throw new HandledException($"Port {ServerContext.Config.Port} is already in use"); } ServerContext.Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); ServerContext.Config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); if (LogSettings.SettingsStore.LogLevel >= LogLevels.NetworkDebug) { ServerContext.Config.EnableMessageType(NetIncomingMessageType.DebugMessage); } if (LogSettings.SettingsStore.LogLevel >= LogLevels.VerboseNetworkDebug) { ServerContext.Config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); } #if DEBUG if (DebugSettings.SettingsStore?.SimulatedLossChance < 100 && DebugSettings.SettingsStore?.SimulatedLossChance > 0) { ServerContext.Config.SimulatedLoss = DebugSettings.SettingsStore.SimulatedLossChance / 100f; } if (DebugSettings.SettingsStore?.SimulatedDuplicatesChance < 100 && DebugSettings.SettingsStore?.SimulatedLossChance > 0) { ServerContext.Config.SimulatedDuplicatesChance = DebugSettings.SettingsStore.SimulatedDuplicatesChance / 100f; } ServerContext.Config.SimulatedRandomLatency = (float)TimeSpan.FromMilliseconds((double)DebugSettings.SettingsStore?.MaxSimulatedRandomLatencyMs).TotalSeconds; ServerContext.Config.SimulatedMinimumLatency = (float)TimeSpan.FromMilliseconds((double)DebugSettings.SettingsStore?.MinSimulatedLatencyMs).TotalSeconds; #endif Server = new NetServer(ServerContext.Config); Server.Start(); ServerContext.ServerStarting = false; }
public static void SetupLidgrenServer() { ServerContext.Config.Port = ConnectionSettings.SettingsStore.Port; ServerContext.Config.AutoExpandMTU = ConnectionSettings.SettingsStore.AutoExpandMtu; ServerContext.Config.MaximumTransmissionUnit = ConnectionSettings.SettingsStore.MaximumTransmissionUnit; ServerContext.Config.MaximumConnections = GeneralSettings.SettingsStore.MaxPlayers; ServerContext.Config.PingInterval = (float)TimeSpan.FromMilliseconds(ConnectionSettings.SettingsStore.HearbeatMsInterval).TotalSeconds; ServerContext.Config.ConnectionTimeout = (float)TimeSpan.FromMilliseconds(ConnectionSettings.SettingsStore.ConnectionMsTimeout).TotalSeconds; if (LunaNetUtils.IsUdpPortInUse(ServerContext.Config.Port)) { throw new HandledException($"Port {ServerContext.Config.Port} is already in use"); } ServerContext.Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval); ServerContext.Config.EnableMessageType(NetIncomingMessageType.NatIntroductionSuccess); if (LogSettings.SettingsStore.LogLevel >= LogLevels.NetworkDebug) { ServerContext.Config.EnableMessageType(NetIncomingMessageType.DebugMessage); } if (LogSettings.SettingsStore.LogLevel >= LogLevels.VerboseNetworkDebug) { ServerContext.Config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage); } #if DEBUG if (DebugSettings.SettingsStore?.SimulatedLossChance < 100 && DebugSettings.SettingsStore?.SimulatedLossChance > 0) { ServerContext.Config.SimulatedLoss = DebugSettings.SettingsStore.SimulatedLossChance / 100f; } if (DebugSettings.SettingsStore?.SimulatedDuplicatesChance < 100 && DebugSettings.SettingsStore?.SimulatedLossChance > 0) { ServerContext.Config.SimulatedDuplicatesChance = DebugSettings.SettingsStore.SimulatedDuplicatesChance / 100f; } ServerContext.Config.SimulatedRandomLatency = (float)TimeSpan.FromMilliseconds((double)DebugSettings.SettingsStore?.MaxSimulatedRandomLatencyMs).TotalSeconds; ServerContext.Config.SimulatedMinimumLatency = (float)TimeSpan.FromMilliseconds((double)DebugSettings.SettingsStore?.MinSimulatedLatencyMs).TotalSeconds; #endif Server = new NetServer(ServerContext.Config); Server.Start(); ServerContext.ServerStarting = false; }