Ejemplo n.º 1
0
        private void HandleVIPRequest(JToken p_Request, SubUpdateEvent p_Event)
        {
            var s_Action = p_Request["action"].Value <String>();

            if (s_Action == "approveSuggestion")
            {
                var s_SongID = p_Request["songID"].Value <Int64>();

                var s_UserData = p_Event.ID["app_data"].ToObject <ChatUserData>();
                var s_UserID   = Int64.Parse(p_Event.ID["userid"].Value <String>());

                var s_QueueIDs = AddSongs(new List <Int64>()
                {
                    s_SongID
                });

                if (PlayingSongID == 0)
                {
                    PlaySong(s_SongID, s_QueueIDs[s_SongID]);
                }

                Library.DispatchEvent(ClientEvent.SongSuggestionApproved, new SongSuggestionApprovalEvent()
                {
                    SongID = s_SongID,
                    User   = s_UserData,
                    UserID = s_UserID
                });

                return;
            }
        }
Ejemplo n.º 2
0
 internal void HandleSubInfoChange(SubUpdateEvent p_Event)
 {
 }
Ejemplo n.º 3
0
        internal bool HandlePublish(SubUpdateEvent p_Event)
        {
            if (p_Event.Sub != ControlChannel)
            {
                return(false);
            }

            if (p_Event.Value == null)
            {
                return(true);
            }

            if (!m_Created && !m_PendingCreation)
            {
                if (p_Event.ID.ContainsKey("sudo") && (bool)p_Event.ID["sudo"] &&
                    p_Event.Value.ContainsKey("available"))
                {
                    m_PendingCreation = true;

                    var s_Params = Library.Broadcast.GetParamsForRemora();
                    s_Params.Add("queueChannel", ControlChannel);

                    Library.Chat.PublishToChannels(new List <string>()
                    {
                        Channel
                    }, new Dictionary <String, Object>()
                    {
                        { "setupQueue", ControlChannel },
                        { "ownerID", p_Event.Value["available"] },
                        { "queue", s_Params }
                    });
                }

                return(true);
            }

            if (m_PendingCreation)
            {
                if (p_Event.Value.ContainsKey("blackbox") && !p_Event.Value.ContainsKey("action"))
                {
                    var s_Blackbox = p_Event.Value["blackbox"].ToObject <Dictionary <String, JToken> >();

                    if (s_Blackbox.ContainsKey("getFullQueue") && s_Blackbox["getFullQueue"].Value <bool>())
                    {
                        if (m_ResumeTimeout != null)
                        {
                            m_ResumeTimeout.Dispose();
                        }

                        // Queue takeover failed.
                        if (!p_Event.Value.ContainsKey("response") || !p_Event.Value.ContainsKey("success") ||
                            !p_Event.Value["success"].Value <bool>())
                        {
                            m_Created         = false;
                            m_PendingCreation = false;

                            // Destroy queue and proceed with channel creation.
                            Library.Remora.DestroyQueue();
                            Library.Remora.JoinControlChannels();
                            return(true);
                        }

                        var s_Response = p_Event.Value["response"].ToObject <Dictionary <String, JToken> >();

                        Library.Queue.CurrentQueue.Clear();

                        if (s_Response.ContainsKey("songs"))
                        {
                            var s_Songs = s_Response["songs"].ToObject <JArray>();

                            foreach (var s_Song in s_Songs)
                            {
                                var s_SongData = s_Song.ToObject <PlaybackStatusData.ActiveBroadcastData>();
                                Library.Queue.AddToQueue(s_SongData.Data.SongID, s_SongData.QueueSongID,
                                                         s_SongData.Data.SongName, s_SongData.Data.ArtistID, s_SongData.Data.ArtistName,
                                                         s_SongData.Data.AlbumID, s_SongData.Data.AlbumName);
                            }
                        }

                        Library.Broadcast.CurrentBroadcastStatus = BroadcastStatus.Broadcasting;

                        m_Created         = true;
                        m_PendingCreation = false;

                        while (m_QueuedMessages.Count > 0)
                        {
                            Library.Chat.PublishToChannels(new List <string>()
                            {
                                ControlChannel
                            }, m_QueuedMessages.Dequeue());
                        }

                        Library.Chat.UpdateCurrentStatus();
                        Library.Chat.SubscribeToBroadcastStatuses();

                        Library.DispatchEvent(ClientEvent.QueueUpdated, null);

                        return(true);
                    }
                }
            }

            if (!p_Event.Value.ContainsKey("action"))
            {
                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "rejectSuggestion")
            {
                var s_SongID = p_Event.Value["songID"].Value <Int64>();

                var s_UserData = p_Event.ID["app_data"].ToObject <ChatUserData>();
                var s_UserID   = Int64.Parse(p_Event.ID["userid"].Value <String>());

                var s_Event = new SongSuggestionRejectionEvent()
                {
                    SongID = s_SongID,
                    User   = s_UserData,
                    UserID = s_UserID
                };

                Library.DispatchEvent(ClientEvent.SongSuggestionRejected, s_Event);
                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "approveSuggestion")
            {
                var s_SongID = p_Event.Value["songID"].Value <Int64>();

                var s_UserData = p_Event.ID["app_data"].ToObject <ChatUserData>();
                var s_UserID   = Int64.Parse(p_Event.ID["userid"].Value <String>());

                var s_Event = new SongSuggestionApprovalEvent()
                {
                    SongID = s_SongID,
                    User   = s_UserData,
                    UserID = s_UserID
                };

                Library.DispatchEvent(ClientEvent.SongSuggestionApproved, s_Event);
                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "setupQueueFailed")
            {
                m_PendingCreation = false;
                m_Created         = false;

                Library.Broadcast.CurrentBroadcastStatus = BroadcastStatus.Idle;
                Library.Broadcast.ActiveBroadcastID      = null;

                Library.DispatchEvent(ClientEvent.BroadcastCreationFailed, null);
                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "setupQueueSuccess")
            {
                if (!p_Event.Value.ContainsKey("broadcast") || p_Event.Value["broadcast"] == null)
                {
                    return(true);
                }

                m_Created         = true;
                m_PendingCreation = false;

                var s_Broadcast = p_Event.Value["broadcast"];

                Library.Broadcast.ActiveBroadcastID      = s_Broadcast["BroadcastID"].Value <String>();
                Library.Broadcast.CurrentBroadcastName   = s_Broadcast["Name"].Value <String>();
                Library.Broadcast.CurrentBroadcastStatus = BroadcastStatus.Broadcasting;

                while (m_QueuedMessages.Count > 0)
                {
                    Library.Chat.PublishToChannels(new List <string>()
                    {
                        ControlChannel
                    }, m_QueuedMessages.Dequeue());
                }

                Library.Chat.UpdateCurrentStatus();

                Library.Chat.SubscribeToBroadcastStatuses();

                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "queueUpdate")
            {
                HandleQueueUpdate(p_Event.Value);
                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "queueReset")
            {
                HandleQueueReset(p_Event.Value);
                return(true);
            }


            if (p_Event.Value["action"].Value <String>() == "complianceIssue")
            {
                var s_Event = new ComplianceIssueEvent()
                {
                    Issue  = p_Event.Value.ContainsKey("issue") ? p_Event.Value["issue"].Value <String>() : "",
                    Reason = p_Event.Value.ContainsKey("reason") ? p_Event.Value["reason"].Value <String>() : ""
                };

                Library.DispatchEvent(ClientEvent.ComplianceIssue, s_Event);

                return(true);
            }

            if (p_Event.Value["action"].Value <String>() == "pendingDestruction")
            {
                var s_Event = new PendingDestructionEvent()
                {
                    TimeLeft = p_Event.Value.ContainsKey("timeLeft") ? p_Event.Value["timeLeft"].Value <Int64>() : 600000
                };

                Library.DispatchEvent(ClientEvent.PendingDestruction, s_Event);

                return(true);
            }

            return(true);
        }