示例#1
0
 internal PresenceMessage(RichPresenceResponse rpr)
 {
     if (rpr == null)
     {
         this.Presence      = (RichPresence)null;
         this.Name          = "No Rich Presence";
         this.ApplicationID = "";
     }
     else
     {
         this.Presence      = (RichPresence)rpr;
         this.Name          = rpr.Name;
         this.ApplicationID = rpr.ClientID;
     }
 }
示例#2
0
 internal PresenceMessage(RichPresenceResponse rpr)
 {
     if (rpr == null)
     {
         Presence      = null;
         Name          = "No Rich Presence";
         ApplicationID = "";
     }
     else
     {
         Presence      = (RichPresence)rpr;
         Name          = rpr.Name;
         ApplicationID = rpr.ClientID;
     }
 }
        /// <summary>Handles the response from the pipe and calls appropriate events and changes states.</summary>
        /// <param name="response">The response received by the server.</param>
        private void ProcessFrame(EventPayload response)
        {
            Logger.Info("Handling Response. Cmd: {0}, Event: {1}", response.Command, response.Event);

            //Check if it is an error
            if (response.Event.HasValue && response.Event.Value == ServerEvent.Error)
            {
                //We have an error
                Logger.Error("Error received from the RPC");

                //Create the event objetc and push it to the queue
                ErrorMessage err = response.GetObject <ErrorMessage>();
                Logger.Error("Server responded with an error message: ({0}) {1}", err.Code.ToString(), err.Message);

                //Enqueue the messsage and then end
                EnqueueMessage(err);
                return;
            }

            //Check if its a handshake
            if (State == RpcState.Connecting)
            {
                if (response.Command == Command.Dispatch && response.Event.HasValue && response.Event.Value == ServerEvent.Ready)
                {
                    Logger.Info("Connection established with the RPC");
                    SetConnectionState(RpcState.Connected);
                    delay.Reset();

                    //Prepare the object
                    ReadyMessage ready = response.GetObject <ReadyMessage>();
                    lock (l_config)
                    {
                        _configuration = ready.Configuration;
                        ready.User.SetConfiguration(_configuration);
                    }

                    //Enqueue the message
                    EnqueueMessage(ready);
                    return;
                }
            }

            if (State == RpcState.Connected)
            {
                switch (response.Command)
                {
                //We were sent a dispatch, better process it
                case Command.Dispatch:
                    ProcessDispatch(response);
                    break;

                //We were sent a Activity Update, better enqueue it
                case Command.SetActivity:
                    if (response.Data == null)
                    {
                        EnqueueMessage(new PresenceMessage());
                    }
                    else
                    {
                        RichPresenceResponse rp = response.GetObject <RichPresenceResponse>();
                        EnqueueMessage(new PresenceMessage(rp));
                    }
                    break;

                case Command.Unsubscribe:
                case Command.Subscribe:

                    //Prepare a serializer that can account for snake_case enums.
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Converters.Add(new Converters.EnumSnakeCaseConverter());

                    //Go through the data, looking for the evt property, casting it to a server event
                    var evt = response.GetObject <EventPayload>().Event.Value;

                    //Enqueue the appropriate message.
                    if (response.Command == Command.Subscribe)
                    {
                        EnqueueMessage(new SubscribeMessage(evt));
                    }
                    else
                    {
                        EnqueueMessage(new UnsubscribeMessage(evt));
                    }

                    break;


                case Command.SendActivityJoinInvite:
                    Logger.Info("Got invite response ack.");
                    break;

                case Command.CloseActivityJoinRequest:
                    Logger.Info("Got invite response reject ack.");
                    break;

                //we have no idea what we were sent
                default:
                    Logger.Error("Unkown frame was received! {0}", response.Command);
                    return;
                }
                return;
            }

            Logger.Info("Received a frame while we are disconnected. Ignoring. Cmd: {0}, Event: {1}", response.Command, response.Event);
        }
示例#4
0
        /// <summary>Handles the response from the pipe and calls appropriate events and changes states.</summary>
        /// <param name="response">The response received by the server.</param>
        private void ProcessFrame(EventPayload response)
        {
            Console.WriteLine($"Handling Response. Cmd: {response.Command}, Event: {response.Event}");

            //Check if it is an error
            if (response.Event.HasValue && response.Event.Value == ServerEvent.Error)
            {
                //We have an error
                Console.WriteLine("Error received from the RPC");

                //Create the event objetc and push it to the queue
                ErrorMessage err = response.GetObject <ErrorMessage>();
                Console.WriteLine($"Server responded with an error message: ({err.Code.ToString()}) {err.Message}");

                //Enqueue the messsage and then end
                EnqueueMessage(err);
                return;
            }

            //Check if its a handshake
            if (State == RpcState.Connecting)
            {
                if (response.Command == Command.Dispatch && response.Event.HasValue && response.Event.Value == ServerEvent.Ready)
                {
                    Console.WriteLine("Connection established with the RPC");
                    SetConnectionState(RpcState.Connected);
                    delay.Reset();

                    //Prepare the object
                    ReadyMessage ready = response.GetObject <ReadyMessage>();
                    lock (l_config)
                    {
                        _configuration = ready.Configuration;
                        ready.User.SetConfiguration(_configuration);
                    }

                    //Enqueue the message
                    EnqueueMessage(ready);
                    return;
                }
            }

            if (State == RpcState.Connected)
            {
                switch (response.Command)
                {
                //We were sent a Activity Update, better enqueue it
                case Command.SetActivity:
                    if (response.Data == null)
                    {
                        EnqueueMessage(new PresenceMessage());
                    }
                    else
                    {
                        RichPresenceResponse rp = response.GetObject <RichPresenceResponse>();
                        EnqueueMessage(new PresenceMessage(rp));
                    }
                    break;


                //we have no idea what we were sent
                default:
                    Console.WriteLine($"Unkown frame was received! {response.Command}");
                    return;
                }
                return;
            }

            Console.WriteLine($"Received a frame while we are disconnected. Ignoring. Cmd: {response.Command}, Event: {response.Event}");
        }