示例#1
0
        /// <summary>
        /// Used to spawn specific shards only
        /// </summary>
        /// <param name="properties">general gateway properties</param>
        /// <param name="shards">Which shards should this cluster spawn</param>
        public GatewayCluster(GatewayProperties properties, IEnumerable <int> shards)
        {
            if (shards == null)
            {
                throw new ArgumentException("shards cannot be null.");
            }

            messageSubject = new Subject <GatewayMessage>();

            foreach (var i in shards)
            {
                var shardProperties = new GatewayProperties
                {
                    Encoding               = properties.Encoding,
                    Compressed             = properties.Compressed,
                    Ratelimiter            = properties.Ratelimiter,
                    ShardCount             = properties.ShardCount,
                    ShardId                = i,
                    Token                  = properties.Token,
                    Version                = properties.Version,
                    Intents                = properties.Intents,
                    AllowNonDispatchEvents = properties.AllowNonDispatchEvents,
                    GatewayFactory         = properties.GatewayFactory,
                    SerializerOptions      = properties.SerializerOptions,
                    UseGatewayEvents       = false
                };

                var shard = properties.GatewayFactory(shardProperties);
                Shards.Add(i, shard);
                shard.PacketReceived.Subscribe(messageSubject.OnNext);
            }

            Events = new GatewayEventHandler(messageSubject, properties.SerializerOptions);
        }
示例#2
0
        public GatewayShard(GatewayProperties configuration)
        {
            tokenSource = new CancellationTokenSource();
            connection  = new GatewayConnection(configuration);

            if (configuration.UseGatewayEvents)
            {
                eventHandler = new GatewayEventHandler(
                    PacketReceived, configuration.SerializerOptions);
            }
        }