Ejemplo n.º 1
0
        public GatewaySocket(string loggingName, int sequence,
                             GatewayRateLimiter outboundPayloadRateLimiter, GatewayRateLimiter gameStatusUpdateRateLimiter,
                             GatewayRateLimiter identifyRateLimiter)
            : base(loggingName)
        {
            this.sequence = sequence;
            this.outboundPayloadRateLimiter  = outboundPayloadRateLimiter;
            this.gameStatusUpdateRateLimiter = gameStatusUpdateRateLimiter;
            this.identifyRateLimiter         = identifyRateLimiter;

            log = new DiscoreLogger(loggingName);

            InitializePayloadHandlers();
        }
Ejemplo n.º 2
0
        internal Gateway(string botToken, Shard shard, int totalShards)
        {
            this.botToken    = botToken;
            this.shard       = shard;
            this.totalShards = totalShards;

            http = new DiscordHttpClient(botToken);

            cache = shard.Cache;

            log   = new DiscoreLogger($"Gateway#{shard.Id}");
            state = GatewayState.Disconnected;

            handshakeCompleteEvent = new AsyncManualResetEvent();
            handshakeCompleteCancellationSource = new CancellationTokenSource();

            // Up-to-date rate limit parameters: https://discord.com/developers/docs/topics/gateway#rate-limiting
            identifyRateLimiter         = new GatewayRateLimiter(5, 1);    // 1 IDENTIFY per 5 seconds
            outboundPayloadRateLimiter  = new GatewayRateLimiter(60, 120); // 120 outbound payloads every 60 seconds
            gameStatusUpdateRateLimiter = new GatewayRateLimiter(60, 5);   // 5 status updates per minute

            InitializeDispatchHandlers();
        }