Пример #1
0
        void ProcessCommandQueue()
        {
            if (m_state != e_RPCState.Connected)
            {
                return;
            }

            bool     write   = m_commandQueue.Count > 0;
            ICommand command = null;

            while (write && m_internalClient.IsConnected)
            {
                command = m_commandQueue.Peek();

                if (command is CloseCommand)
                {
                    m_state = e_RPCState.Disconnected;

                    if (!WriteFrame(new Frame(Frame.e_OpCode.Close, new Handshake()
                    {
                        Version = m_version, ClientID = m_clientID
                    })))
                    {
                        InternalConsole.Error("Discord Client: Handwave Failed");
                    }

                    return;
                }
                else
                {
                    IPayload payload = command.PreparePayload(m_nounce++);

                    Frame frame = new Frame();

                    if (!m_shutdown)
                    {
                        frame.OpCode = Frame.e_OpCode.Frame;
                        frame.SetObject(payload);

                        WriteFrame(frame);
                    }
                }

                m_commandQueue.Dequeue();
                write = m_commandQueue.Count > 0;
            }
        }
Пример #2
0
        void ProcessEvent(EventPayload a_event)
        {
            if (a_event.Event.HasValue && a_event.Event == EventPayload.e_ServerEvent.Error)
            {
                ErrorMessage error = a_event.GetObject <ErrorMessage>();

                InternalConsole.Error(string.Format("Discord responded with error: ({0}) {1}", error.ErrorCode, error.Message));

                EnqueueMessage(error);
            }

            if (m_state == e_RPCState.Connecting)
            {
                if (a_event.Command == e_Command.Dispatch && a_event.Event.HasValue && a_event.Event.Value == EventPayload.e_ServerEvent.Ready)
                {
                    m_state = e_RPCState.Connected;

                    ReadyMessage ready = a_event.GetObject <ReadyMessage>();

                    m_config = ready.Configuration;

                    User user = ready.User;

                    user.Configuration = ready.Configuration;

                    ready.User = user;
                    m_user     = user;

                    EnqueueMessage(ready);

                    return;
                }
            }

            // TODO: Implement Connected Commands
            if (m_state == e_RPCState.Connected)
            {
                switch (a_event.Command)
                {
                case e_Command.Dispatch:
                {
                    break;
                }
                }
            }
        }
Пример #3
0
        void Handshake()
        {
            InternalConsole.AddMessage("Attempting Discord Handshake");

            if (m_state != e_RPCState.Disconnected)
            {
                InternalConsole.Warning("Discord Client: State must be disconnected to handshake");

                return;
            }

            if (WriteFrame(new Frame(Frame.e_OpCode.Handshake, new Handshake()
            {
                Version = m_version, ClientID = m_clientID
            })))
            {
                m_state = e_RPCState.Connecting;
            }
        }
Пример #4
0
        public DiscordClient()
        {
            m_processID = Process.GetCurrentProcess().Id;

            m_frameQueue   = new Queue <Frame>();
            m_messageQueue = new Queue <IMessage>();
            m_commandQueue = new Queue <ICommand>();

            m_state = e_RPCState.Disconnected;

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Unix:
            {
                m_internalClient = new UnixClient(this);

                break;
            }

            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
            {
                m_internalClient = new WindowsClient(this);

                break;
            }

            default:
            {
                Debug.Assert(false);

                break;
            }
            }

            m_nounce = 0;
        }