Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a new server manager.
        /// </summary>
        /// <param name="serverSettings">The server's main configuration.</param>
        /// <param name="serverRegistrySettings">The server's registry configuration.</param>
        /// <param name="clusterSpawnData">The cluster configuration</param>
        /// <param name="networkListenerManager">The server's network listener manager.</param>
        /// <param name="threadHelper">The server's thread helper.</param>
        /// <param name="serverRegistryConnectorManager">The server's registry connector manager.</param>
        /// <param name="logManager">The server's log manager.</param>
        /// <param name="logger">The logger to use.</param>
        /// <param name="metricsManager">The server's metrics manager.</param>
        internal RemoteServerManager(ServerSpawnData.ServerSettings serverSettings, ServerSpawnData.ServerRegistrySettings serverRegistrySettings, ClusterSpawnData clusterSpawnData, NetworkListenerManager networkListenerManager, DarkRiftThreadHelper threadHelper, ServerRegistryConnectorManager serverRegistryConnectorManager, LogManager logManager, Logger logger, MetricsManager metricsManager)
        {
            this.AdvertisedHost = serverRegistrySettings.AdvertisedHost;
            this.AdvertisedPort = serverRegistrySettings.AdvertisedPort;


            this.networkListenerManager         = networkListenerManager;
            this.serverRegistryConnectorManager = serverRegistryConnectorManager;
            this.logger = logger;
            this.Group  = serverSettings.ServerGroup;

            if (!string.IsNullOrEmpty(serverSettings.ServerGroup))
            {
                if (serverRegistrySettings.AdvertisedHost == null || serverRegistrySettings.AdvertisedPort == 0)
                {
                    throw new ArgumentException("Cannot start server clustering without an advertised host and port. Consider setting the 'advertisedHost' and 'advertisedPort' properties in configuration.");
                }

                // Find our group
                ClusterSpawnData.GroupsSettings.GroupSettings ourGroup = null;
                foreach (ClusterSpawnData.GroupsSettings.GroupSettings groupSettings in clusterSpawnData.Groups.Groups)
                {
                    if (groupSettings.Name == serverSettings.ServerGroup)
                    {
                        ourGroup = groupSettings;
                        break;
                    }
                }

                if (ourGroup == null)
                {
                    throw new ArgumentException($"The group specified to own this server '{serverSettings.ServerGroup}' is not present in the cluster configuration. Consider adding this group to the cluster configuration or moving the server to an existing group.");
                }

                this.Visibility = ourGroup.Visibility;

                // Build relationships to other groups
                foreach (ClusterSpawnData.GroupsSettings.GroupSettings groupSettings in clusterSpawnData.Groups.Groups)
                {
                    ClusterSpawnData.GroupsSettings.GroupSettings.ConnectsToSettings ourGroupConnectsTo = ourGroup.ConnectsTo.FirstOrDefault(c => c.Name == groupSettings.Name);
                    ClusterSpawnData.GroupsSettings.GroupSettings.ConnectsToSettings connectsToOurGroup = groupSettings.ConnectsTo.FirstOrDefault(c => c.Name == ourGroup.Name);

                    IModifiableServerGroup serverGroup;
                    if (ourGroupConnectsTo != null)
                    {
                        serverGroup = new UpstreamServerGroup(groupSettings.Name, groupSettings.Visibility, threadHelper, serverRegistryConnectorManager, this, serverSettings.ReconnectAttempts, logManager.GetLoggerFor(nameof(UpstreamServerGroup)), logManager.GetLoggerFor(nameof(UpstreamRemoteServer)), metricsManager.GetMetricsCollectorFor(nameof(UpstreamServerGroup)), metricsManager.GetMetricsCollectorFor(nameof(UpstreamRemoteServer)));
                    }
                    else if (connectsToOurGroup != null)
                    {
                        serverGroup = new DownstreamServerGroup(groupSettings.Name, groupSettings.Visibility, threadHelper, logManager.GetLoggerFor(nameof(DownstreamServerGroup)), logManager.GetLoggerFor(nameof(DownstreamRemoteServer)), metricsManager.GetMetricsCollectorFor(nameof(DownstreamServerGroup)), metricsManager.GetMetricsCollectorFor(nameof(DownstreamRemoteServer)));
                    }
                    else
                    {
                        continue;
                    }

                    groups.Add(groupSettings.Name, serverGroup);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates a new client manager.
        /// </summary>
        /// <param name="settings">The settings for this client manager.</param>
        /// <param name="networkListenerManager">The server's network listener manager.</param>
        /// <param name="threadHelper">The thread helper the client manager will use.</param>
        /// <param name="logger">The logger this client manager will use.</param>
        /// <param name="clientLogger">The logger clients will use.</param>
        internal ClientManager(ServerSpawnData.ServerSettings settings, NetworkListenerManager networkListenerManager, DarkRiftThreadHelper threadHelper, Logger logger, Logger clientLogger)
#endif
        {
            this.MaxStrikes             = settings.MaxStrikes;
            this.networkListenerManager = networkListenerManager;
            this.threadHelper           = threadHelper;
            this.logger       = logger;
            this.clientLogger = clientLogger;
#if PRO
            this.clientMetricsCollector = clientMetricsCollector;

            clientsConnectedGauge                  = metricsCollector.Gauge("clients_connected", "The number of clients connected to the server.");
            clientConnectedEventTimeHistogram      = metricsCollector.Histogram("client_connected_event_time", "The time taken to execute the ClientConnected event.");
            clientDisconnectedEventTimeHistogram   = metricsCollector.Histogram("client_disconnected_event_time", "The time taken to execute the ClientDisconnected event.");
            clientConnectedEventFailuresCounter    = metricsCollector.Counter("client_connected_event_failures", "The number of failures executing the ClientConnected event.");
            clientDisconnectedEventFailuresCounter = metricsCollector.Counter("client_disconnected_event_failures", "The number of failures executing the ClientDisconnected event.");
#endif
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Creates a new client manager.
 /// </summary>
 /// <param name="settings">The settings for this client manager.</param>
 /// <param name="networkListenerManager">The server's network listener manager. Used to implement obsolete functionality.</param>
 /// <param name="threadHelper">The thread helper the client manager will use.</param>
 /// <param name="logger">The logger this client manager will use.</param>
 /// <param name="clientLogger">The logger clients will use.</param>
 /// <param name="metricsCollector">The metrics collector to use.</param>
 /// <param name="clientMetricsCollector">The metrics collector clients will use.</param>
 internal ClientManager(ServerSpawnData.ServerSettings settings, NetworkListenerManager networkListenerManager, DarkRiftThreadHelper threadHelper, Logger logger, Logger clientLogger, MetricsCollector metricsCollector, MetricsCollector clientMetricsCollector)