Exemplo n.º 1
0
        private bool OnReady(GatewaySocketFrame <Ready> frame)
        {
            var ready = frame.Payload;

            _sessionId = ready.SessionId;
            return(FireEvent(frame, Ready));
        }
Exemplo n.º 2
0
        private static bool FireEvent <T>(GatewaySocketFrame frame, Action <T> eventHandler)
        {
            var eventArgs = ((GatewaySocketFrame <T>)frame).Payload;

            eventHandler(eventArgs);
            return(true);
        }
Exemplo n.º 3
0
        private void HandleMessage(GatewaySocketFrame frame)
        {
            if (frame.SequenceNumber.HasValue)
            {
                _lastEventSequenceNumber = frame.SequenceNumber.Value;
            }

            ProcessEvents(frame);
        }
Exemplo n.º 4
0
        private async Task SendMessageAsync <T>(GatewayOperation op, GatewayEvent?e, T payload)
        {
            var frame = new GatewaySocketFrame <T>
            {
                Operation = op,
                Event     = e,
                Payload   = payload,
            };

            await _socket !.SendMessageAsync(frame);
        }
Exemplo n.º 5
0
        private bool OnInvalidSession(GatewaySocketFrame frame)
        {
            switch (GatewayStatus)
            {
            case GatewayStatus.InvalidSession:
                _ = ReconnectAsync();
                break;

            case GatewayStatus.Reconnecting:
                FireEvent(frame, InvalidSession);
                break;
            }

            return(true);
        }
Exemplo n.º 6
0
 private bool OnHelloReceived(GatewaySocketFrame <Hello> frame)
 {
     _ = SetupGateway(frame.Payload.HeartbeatInterval);
     return(true);
 }
Exemplo n.º 7
0
        protected void ProcessEvents(GatewaySocketFrame frame)
        {
            bool succeeded = frame switch
            {
                UnknownOperationGatewaySocketFrame osf => FireEvent(osf.Operation, UnknownOperationEncountered),
                UnknownEventGatewaySocketFrame osf => FireEvent(osf.Event, UnknownEventEncountered),
                _ => frame.Operation switch
                {
                    GatewayOperation.Hello => OnHelloReceived((GatewaySocketFrame <Hello>)frame),
                    GatewayOperation.InvalidSession => OnInvalidSession(frame),
                    GatewayOperation.HeartbeatAck => OnHeartbeatAck(),
                    GatewayOperation.Dispatch => FireEvent(frame.Event !.Value, KnownEventEncountered) && frame.Event switch
                    {
                        GatewayEvent.READY => OnReady((GatewaySocketFrame <Ready>)frame),
                        GatewayEvent.RESUMED => FireEvent(frame, Resumed),

                        GatewayEvent.GUILD_CREATE => FireEvent(frame, GuildCreated),
                        GatewayEvent.GUILD_UPDATE => FireEvent(frame, GuildUpdated),
                        GatewayEvent.GUILD_DELETE => FireEvent(frame, GuildDeleted),

                        GatewayEvent.GUILD_BAN_ADD => FireEvent(frame, GuildBanAdded),
                        GatewayEvent.GUILD_BAN_REMOVE => FireEvent(frame, GuildBanRemoved),

                        GatewayEvent.CHANNEL_CREATE => FireEvent(frame, ChannelCreated),
                        GatewayEvent.CHANNEL_UPDATE => FireEvent(frame, ChannelUpdated),
                        GatewayEvent.CHANNEL_DELETE => FireEvent(frame, ChannelDeleted),

                        GatewayEvent.CHANNEL_RECIPIENT_ADD => FireEvent(frame, ChannelRecipientAdded),
                        GatewayEvent.CHANNEL_RECIPIENT_REMOVE => FireEvent(frame, ChannelRecipientRemoved),

                        GatewayEvent.MESSAGE_ACK => FireEvent(frame, MessageAck),
                        GatewayEvent.MESSAGE_CREATE => FireEvent(frame, MessageCreated),
                        GatewayEvent.MESSAGE_UPDATE => FireEvent(frame, MessageUpdated),
                        GatewayEvent.MESSAGE_DELETE => FireEvent(frame, MessageDeleted),

                        GatewayEvent.MESSAGE_REACTION_ADD => FireEvent(frame, MessageReactionAdded),
                        GatewayEvent.MESSAGE_REACTION_REMOVE => FireEvent(frame, MessageReactionRemoved),
                        GatewayEvent.MESSAGE_REACTION_REMOVE_ALL => FireEvent(frame, MessageReactionRemovedAll),

                        GatewayEvent.GUILD_MEMBER_ADD => FireEvent(frame, GuildMemberAdded),
                        GatewayEvent.GUILD_MEMBER_UPDATE => FireEvent(frame, GuildMemberUpdated),
                        GatewayEvent.GUILD_MEMBER_REMOVE => FireEvent(frame, GuildMemberRemoved),
                        GatewayEvent.GUILD_MEMBER_LIST_UPDATE => FireEvent(frame, GuildMemberListUpdated),
                        GatewayEvent.GUILD_MEMBERS_CHUNK => FireEvent(frame, GuildMembersChunk),

                        GatewayEvent.RELATIONSHIP_ADD => FireEvent(frame, RelationshipAdded),
                        GatewayEvent.RELATIONSHIP_UPDATE => FireEvent(frame, RelationshipUpdated),
                        GatewayEvent.RELATIONSHIP_REMOVE => FireEvent(frame, RelationshipRemoved),

                        GatewayEvent.TYPING_START => FireEvent(frame, TypingStarted),
                        GatewayEvent.PRESENCE_UPDATE => FireEvent(frame, PresenceUpdated),

                        GatewayEvent.USER_NOTE_UPDATE => FireEvent(frame, UserNoteUpdated),
                        GatewayEvent.USER_SETTINGS_UPDATE => FireEvent(frame, UserSettingsUpdated),
                        GatewayEvent.USER_GUILD_SETTINGS_UPDATE => FireEvent(frame, UserGuildSettingsUpdated),

                        GatewayEvent.VOICE_STATE_UPDATE => FireEvent(frame, VoiceStateUpdated),
                        GatewayEvent.VOICE_SERVER_UPDATE => FireEvent(frame, VoiceServerUpdated),

                        GatewayEvent.STREAM_CREATE => FireEvent(frame, StreamCreate),
                        GatewayEvent.STREAM_SERVER_UPDATE => FireEvent(frame, StreamServerUpdate),
                        // GatewayEvent.STREAM_UPDATE => FireEvent(frame, StreamCreate),

                        GatewayEvent.SESSIONS_REPLACE => FireEvent(frame, SessionReplaced),

                        _ => FireEvent(frame.Event !.Value, UnhandledEventEncountered),
                    },