private static void OnSongSuggestionApproved(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongSuggestionApprovalEvent)p_SharkEvent;

            lock (Suggestions)
                Suggestions.Remove(s_Event.SongID);
        }
Example #2
0
        private static void OnChatMessage(SharkEvent p_SharkEvent)
        {
            var s_Event = p_SharkEvent as ChatMessageEvent;

            // Record the last 20 messages in chat history.
            m_ChatHistory.Add(s_Event);

            for (var i = 0; i < m_ChatHistory.Count - 20; ++i)
                m_ChatHistory.RemoveAt(0);

            // Disregard messages that are sent by the bot.
            if (s_Event.UserID == Application.Library.User.Data.UserID)
                return;

            Trace.WriteLine(String.Format("[CHAT] {0}: {1}", s_Event.UserName, s_Event.ChatMessage));

            if (s_Event.ChatMessage.Trim().Length < 2 || s_Event.ChatMessage.Trim()[0] != SettingsManager.CommandPrefix())
                return;

            var s_Parts = s_Event.ChatMessage.Trim().Split(' ');

            var s_Command = s_Parts[0];
            var s_Data = s_Event.ChatMessage.Substring(s_Command.Length).Trim();

            ChatCommand s_ChatCommand;
            if (!m_ChatCommands.TryGetValue(s_Command.Substring(1), out s_ChatCommand))
                return;

            s_ChatCommand.Callback(s_Event, s_Data);
        }
Example #3
0
        private static void OnChatMessage(SharkEvent p_SharkEvent)
        {
            var s_Event = p_SharkEvent as ChatMessageEvent;

            // Record the last 20 messages in chat history.
            m_ChatHistory.Add(s_Event);

            for (var i = 0; i < m_ChatHistory.Count - 20; ++i)
                m_ChatHistory.RemoveAt(0);

            // Disregard messages that are sent by the bot.
            if (s_Event.UserID == Application.Library.User.Data.UserID)
                return;

            Trace.WriteLine(String.Format("[CHAT] {0}: {1}", s_Event.UserName, s_Event.ChatMessage));

            if (s_Event.ChatMessage.Trim().Length < 2 || s_Event.ChatMessage.Trim()[0] != SettingsManager.CommandPrefix())
                return;

            var s_Parts = s_Event.ChatMessage.Trim().Split(' ');

            var s_Command = s_Parts[0];
            var s_Data = s_Event.ChatMessage.Substring(s_Command.Length).Trim();

            ChatCommand s_ChatCommand;
            if (!m_ChatCommands.TryGetValue(s_Command.Substring(1), out s_ChatCommand))
                return;

            s_ChatCommand.Callback(s_Event, s_Data);
        }
Example #4
0
        private void HandleSetResult(SharkEvent p_Event)
        {
            var s_Event = p_Event.As <SetResultEvent>();

            if (s_Event.Blackbox == null || !s_Event.Blackbox.ContainsKey("source"))
            {
                return;
            }
        }
Example #5
0
        private static void OnPlaybackStatusUpdate(SharkEvent p_SharkEvent)
        {
            if (Application.Library.Broadcast.CurrentBroadcastStatus != BroadcastStatus.Broadcasting)
            {
                return;
            }

            var s_Event = (PlaybackStatusUpdateEvent)p_SharkEvent;

            if (s_Event.Status != PlaybackStatus.Completed && s_Event.Status != PlaybackStatus.Paused &&
                s_Event.Status != PlaybackStatus.Suspended)
            {
                return;
            }

            var s_CurrentIndex = QueueManager.GetPlayingSongIndex();

            if (s_CurrentIndex != -1 && s_CurrentIndex < QueueManager.GetCurrentQueue().Count - 2)
            {
                var s_NextSong = QueueManager.GetCurrentQueue()[s_CurrentIndex + 1];
                Application.Library.Broadcast.PlaySong(s_NextSong.SongID, s_NextSong.QueueID);
                return;
            }

            // Allows for custom queuing logic by Modules.
            var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

            if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
            {
                var s_First = s_ModuleSongs.First();
                Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                return;
            }

            // Try to play a new song.
            if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
            {
                var s_SongID = PlaylistManager.DequeueNextSong();
                Application.Library.Broadcast.PlaySong(s_SongID, Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                })[s_SongID]);
                return;
            }

            var s_Random    = new Random();
            var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
            var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

            var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                s_FirstSong
            });

            Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
        }
Example #6
0
        private void OnSongVote(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongVoteEvent)p_SharkEvent;

            var s_SongData = CurrentQueue.FirstOrDefault(p_Item => p_Item.QueueID == s_Event.QueueSongID);

            if (s_SongData == null)
            {
                return;
            }

            s_SongData.Votes = s_Event.VoteChange;
        }
Example #7
0
        private static void OnAuthenticated(SharkEvent p_SharkEvent)
        {
            Authenticating       = false;
            AuthenticationResult = AuthenticationResult.Success;

            QueueManager.FetchCollectionSongs();

            if (QueueManager.CollectionSongs.Count < 2)
            {
                return;
            }

            BroadcastManager.CreateBroadcast();
        }
Example #8
0
        internal void DispatchEvent(int p_Event, SharkEvent p_Data)
        {
            List <Action <SharkEvent> > s_Handlers;

            if (!m_EventHandlers.TryGetValue(p_Event, out s_Handlers))
            {
                return;
            }

            foreach (var s_Handler in s_Handlers)
            {
                s_Handler(p_Data);
            }
        }
        private static void OnSongSuggestion(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongSuggestionEvent)p_SharkEvent;

            lock (Suggestions)
            {
                SongSuggestion s_Suggestion;

                // No entry exists for this suggestion yet; create one.
                if (!Suggestions.TryGetValue(s_Event.SongID, out s_Suggestion))
                {
                    s_Suggestion = new SongSuggestion()
                    {
                        SongID     = s_Event.SongID,
                        SongName   = s_Event.SongName,
                        AlbumID    = s_Event.AlbumID,
                        AlbumName  = s_Event.AlbumName,
                        ArtistID   = s_Event.ArtistID,
                        ArtistName = s_Event.ArtistName,
                        Suggester  = new SimpleUser()
                        {
                            UserID         = s_Event.UserID,
                            Name           = s_Event.User.Username,
                            ProfilePicture = s_Event.User.Picture
                        },
                        OtherSuggesters = new List <SimpleUser>()
                    };

                    Suggestions.Add(s_Event.SongID, s_Suggestion);
                    return;
                }

                // This user has already suggested this song; ignore.
                if (s_Suggestion.Suggester.UserID == s_Event.UserID ||
                    s_Suggestion.OtherSuggesters.Any(p_User => p_User.UserID == s_Event.UserID))
                {
                    return;
                }

                s_Suggestion.OtherSuggesters.Add(new SimpleUser()
                {
                    UserID         = s_Event.UserID,
                    Name           = s_Event.User.Username,
                    ProfilePicture = s_Event.User.Picture
                });
            }
        }
Example #10
0
        private static void OnSongVote(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongVoteEvent)p_SharkEvent;

            var s_Threshold = SettingsManager.SongVoteThreshold();

            if (s_Threshold == 0)
            {
                return;
            }

            // Automatically skip a song if it reaches a number of negative votes.
            if (s_Event.CurrentVotes <= s_Threshold)
            {
                SkipSong();
            }
        }
        private static void OnSongSuggestion(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongSuggestionEvent) p_SharkEvent;

            lock (Suggestions)
            {
                SongSuggestion s_Suggestion;

                // No entry exists for this suggestion yet; create one.
                if (!Suggestions.TryGetValue(s_Event.SongID, out s_Suggestion))
                {
                    s_Suggestion = new SongSuggestion()
                    {
                        SongID = s_Event.SongID,
                        SongName = s_Event.SongName,
                        AlbumID = s_Event.AlbumID,
                        AlbumName = s_Event.AlbumName,
                        ArtistID = s_Event.ArtistID,
                        ArtistName = s_Event.ArtistName,
                        Suggester = new SimpleUser()
                        {
                            UserID = s_Event.UserID,
                            Name = s_Event.User.Username,
                            ProfilePicture = s_Event.User.Picture
                        },
                        OtherSuggesters = new List<SimpleUser>()
                    };

                    Suggestions.Add(s_Event.SongID, s_Suggestion);
                    return;
                }

                // This user has already suggested this song; ignore.
                if (s_Suggestion.Suggester.UserID == s_Event.UserID ||
                    s_Suggestion.OtherSuggesters.Any(p_User => p_User.UserID == s_Event.UserID))
                    return;

                s_Suggestion.OtherSuggesters.Add(new SimpleUser()
                {
                    UserID = s_Event.UserID,
                    Name = s_Event.User.Username,
                    ProfilePicture = s_Event.User.Picture
                });
            }
        }
        private static void OnSongSuggestionRemoved(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongSuggestionRemovalEvent)p_SharkEvent;

            lock (Suggestions)
            {
                SongSuggestion s_Suggestion;

                // This suggestion doesn't even exist.
                if (!Suggestions.TryGetValue(s_Event.SongID, out s_Suggestion))
                {
                    return;
                }

                // This is the last suggestion; completely remove it.
                if (s_Suggestion.Suggester.UserID == s_Event.UserID &&
                    s_Suggestion.OtherSuggesters.Count == 0)
                {
                    Suggestions.Remove(s_Event.SongID);
                    return;
                }

                // This is an upvote removal on a suggestion by another user.
                var s_Index = CollectionUtils.FindIndex(s_Suggestion.OtherSuggesters,
                                                        p_User => p_User.UserID == s_Event.UserID);

                if (s_Index != -1)
                {
                    s_Suggestion.OtherSuggesters.RemoveAt(s_Index);
                    return;
                }

                // The initial suggester is removing his suggestion. Switch suggesters.
                if (s_Suggestion.Suggester.UserID == s_Event.UserID &&
                    s_Suggestion.OtherSuggesters.Count > 0)
                {
                    s_Suggestion.Suggester = s_Suggestion.OtherSuggesters[0];
                    s_Suggestion.OtherSuggesters.RemoveAt(0);
                }
            }
        }
Example #13
0
        internal void DispatchEvent(ClientEvent p_Event, SharkEvent p_Data)
        {
            List <Action <SharkEvent> > s_Handlers;

            if (!m_EventHandlers.TryGetValue(p_Event, out s_Handlers))
            {
                return;
            }

            foreach (var s_Handler in s_Handlers)
            {
                try
                {
                    s_Handler(p_Data);
                }
                catch (Exception s_Exception)
                {
                    Trace.WriteLine(String.Format("Failed to dispatch event '{0}'. Exception: {1}", p_Event, s_Exception));
                }
            }
        }
Example #14
0
        private static void OnComplianceIssue(SharkEvent p_SharkEvent)
        {
            if (!SettingsManager.MobileCompliance())
            {
                DisableMobileCompliance();
                return;
            }

            // Allows for custom queuing logic by Modules.
            var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

            if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
            {
                var s_First = s_ModuleSongs.First();
                Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                return;
            }

            // Try to play a new song.
            if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
            {
                var s_SongID = PlaylistManager.DequeueNextSong();
                Application.Library.Broadcast.PlaySong(s_SongID, Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                })[s_SongID]);
                return;
            }

            var s_Random    = new Random();
            var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
            var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

            var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                s_FirstSong
            });

            Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
        }
Example #15
0
        private static void OnPendingDestruction(SharkEvent p_SharkEvent)
        {
            if (Application.Library.Broadcast.CurrentBroadcastStatus != BroadcastStatus.Broadcasting)
            {
                return;
            }

            // Allows for custom queuing logic by Modules.
            var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

            if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
            {
                var s_First = s_ModuleSongs.First();
                Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                return;
            }

            if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
            {
                var s_SongID = PlaylistManager.DequeueNextSong();
                Application.Library.Broadcast.PlaySong(s_SongID, Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_SongID
                })[s_SongID]);
                return;
            }

            // Broadcast ran out of songs somehow; add and play a random song.
            var s_Random    = new Random();
            var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
            var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

            var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                s_FirstSong
            });

            Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
        }
Example #16
0
 private static void OnBroadcastCreationFailed(SharkEvent p_SharkEvent)
 {
     CreatingBroadcast = false;
 }
Example #17
0
 private static void OnSongVote(SharkEvent p_SharkEvent)
 {
     lock (m_PendingSongVoteEvents)
         m_PendingSongVoteEvents.Enqueue((SongVoteEvent)p_SharkEvent);
 }
Example #18
0
 private static void OnUserJoinedBroadcast(SharkEvent p_SharkEvent)
 {
     lock (m_PendingUserJoinEvents)
         m_PendingUserJoinEvents.Enqueue((UserJoinedBroadcastEvent)p_SharkEvent);
 }
Example #19
0
 private static void OnUserLeftBroadcast(SharkEvent p_SharkEvent)
 {
     lock (m_PendingUserLeaveEvents)
         m_PendingUserLeaveEvents.Enqueue((UserLeftBroadcastEvent)p_SharkEvent);
 }
Example #20
0
        private void HandleSubUpdate(SharkEvent p_Event)
        {
            var s_Event = p_Event.As <SubUpdateEvent>();

            if (s_Event.Sub != Library.Chat.GetChatChannel(ActiveBroadcastID) &&
                s_Event.Sub != Library.Chat.GetChatChannel(ActiveBroadcastID, true))
            {
                if (s_Event.Type == "publish")
                {
                    Library.Remora.HandlePublish(s_Event);
                }

                if (s_Event.Type == "subinfo_change")
                {
                    Library.Remora.HandleSubInfoChange(s_Event);
                }

                return;
            }

            if (s_Event.Sub == Library.Chat.GetChatChannel(ActiveBroadcastID))
            {
                if (s_Event.Params != null && s_Event.Params.ContainsKey("s"))
                {
                    var s_Data = s_Event.Params["s"].ToObject <PlaybackStatusData>();
                    HandlePlaybackStatusUpdate(s_Data);
                    return;
                }

                if (s_Event.Value != null && s_Event.Value.ContainsKey("type"))
                {
                    if (s_Event.Value["type"].Value <String>() == "vipRequest")
                    {
                        HandleVIPRequest(s_Event.Value["data"], s_Event);
                        return;
                    }

                    if (s_Event.Value["type"].Value <String>() == "broadcastOwnerEnded")
                    {
                        Library.Chat.DisconnectSilent();
                        return;
                    }
                }
            }

            if (s_Event.Sub == Library.Chat.GetChatChannel(ActiveBroadcastID, true))
            {
                if (s_Event.Value != null && s_Event.Value.ContainsKey("type"))
                {
                    if (s_Event.Value["type"].Value <String>() == "activeSongVote")
                    {
                        var s_Vote        = s_Event.Value["data"]["vote"].Value <int>();
                        var s_QueueSongID = s_Event.Value["data"]["queueSongID"].Value <Int64>();

                        var s_Index = Library.Queue.GetInternalIndexForSong(s_QueueSongID);

                        if (s_Index != -1)
                        {
                            Library.Queue.CurrentQueue[s_Index].Votes += s_Vote;
                        }

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

                        Library.DispatchEvent(ClientEvent.SongVote, new SongVoteEvent()
                        {
                            VoteChange   = s_Vote,
                            QueueSongID  = s_QueueSongID,
                            CurrentVotes = s_Index != -1 ? Library.Queue.CurrentQueue[s_Index].Votes : 0,
                            User         = s_UserData,
                            UserID       = s_UserID
                        });

                        return;
                    }

                    if (s_Event.Value["type"].Value <String>() == "suggestion" && s_Event.Value.ContainsKey("data"))
                    {
                        var s_Data = s_Event.Value["data"].ToObject <Dictionary <String, JToken> >();

                        var s_SongData = s_Data["song"].ToObject <PlaybackStatusData.ActiveBroadcastData>();

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

                        var s_SongEvent = new SongSuggestionEvent()
                        {
                            SongID     = s_SongData.Data.SongID,
                            SongName   = s_SongData.Data.SongName,
                            ArtistID   = s_SongData.Data.ArtistID,
                            ArtistName = s_SongData.Data.ArtistName,
                            AlbumID    = s_SongData.Data.AlbumID,
                            AlbumName  = s_SongData.Data.AlbumName,
                            User       = s_UserData,
                            UserID     = s_UserID
                        };

                        Library.DispatchEvent(ClientEvent.SongSuggestion, s_SongEvent);
                        return;
                    }

                    if (s_Event.Value["type"].Value <String>() == "suggestionRemove" && s_Event.Value.ContainsKey("data"))
                    {
                        var s_Data = s_Event.Value["data"].ToObject <Dictionary <String, JToken> >();

                        var s_SongID = s_Data["songID"].Value <Int64>();

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

                        var s_SongEvent = new SongSuggestionRemovalEvent()
                        {
                            SongID = s_SongID,
                            User   = s_UserData,
                            UserID = s_UserID
                        };

                        Library.DispatchEvent(ClientEvent.SongSuggestionRemoved, s_SongEvent);
                        return;
                    }
                }
            }

            // TODO: Implement
        }
Example #21
0
        private static void OnSongVote(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongVoteEvent) p_SharkEvent;

            var s_Threshold = SettingsManager.SongVoteThreshold();

            if (s_Threshold == 0)
                return;

            // Automatically skip a song if it reaches a number of negative votes.
            if (s_Event.CurrentVotes <= s_Threshold)
                SkipSong();
        }
Example #22
0
        private static void OnSongPlaying(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongPlayingEvent)p_SharkEvent;

            Trace.WriteLine(String.Format("Currently playing song: {0} ({1})", s_Event.SongName, s_Event.SongID));

            if (s_Event.SongID == 0)
            {
                // We stopped playing, how did this happen?
                // Quickly! Add two to the queue!

                // Allows for custom queuing logic by Modules.
                var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(2);

                if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
                {
                    var s_First = s_ModuleSongs.First();
                    Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                    return;
                }

                if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
                {
                    var s_SongID = PlaylistManager.DequeueNextSong();
                    var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List<Int64> { s_SongID });
                    Application.Library.Broadcast.PlaySong(s_SongID, s_QueueIDs[s_SongID]);
                    return;
                }

                var s_Random = new Random();
                var s_FirstSongIndex = s_Random.Next(0, CollectionSongs.Count);
                var s_SecondSongIndex = s_Random.Next(0, CollectionSongs.Count);

                var s_FirstSong = CollectionSongs[s_FirstSongIndex];
                var s_SecondSong = CollectionSongs[s_SecondSongIndex];

                while (s_SecondSong == s_FirstSong)
                {
                    s_SecondSongIndex = s_Random.Next(0, CollectionSongs.Count);
                    s_SecondSong = CollectionSongs[s_SecondSongIndex];
                }

                var s_Songs = Application.Library.Broadcast.AddSongs(new List<Int64> { s_FirstSong, s_SecondSong });
                Application.Library.Broadcast.PlaySong(s_FirstSong, s_Songs[s_FirstSong]);
                return;
            }

            PlayedSongs.Add(s_Event.SongID);

            // Clear songs from history (if needed).
            for (var i = 0; i < PlayedSongs.Count - SettingsManager.MaxHistorySongs(); ++i)
                PlayedSongs.RemoveAt(0);

            UpdateQueue();
        }
Example #23
0
 private static void OnQueueUpdated(SharkEvent p_SharkEvent)
 {
     UpdateQueue();
 }
Example #24
0
        private static void OnSongPlaying(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongPlayingEvent)p_SharkEvent;

            Trace.WriteLine(String.Format("Currently playing song: {0} ({1})", s_Event.SongName, s_Event.SongID));

            if (s_Event.SongID == 0)
            {
                // We stopped playing, how did this happen?
                // Quickly! Add two to the queue!

                // Allows for custom queuing logic by Modules.
                var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(2);

                if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
                {
                    var s_First = s_ModuleSongs.First();
                    Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                    return;
                }

                if (PlaylistManager.PlaylistActive && PlaylistManager.HasNextSong())
                {
                    var s_SongID   = PlaylistManager.DequeueNextSong();
                    var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                        s_SongID
                    });
                    Application.Library.Broadcast.PlaySong(s_SongID, s_QueueIDs[s_SongID]);
                    return;
                }

                var s_Random          = new Random();
                var s_FirstSongIndex  = s_Random.Next(0, CollectionSongs.Count);
                var s_SecondSongIndex = s_Random.Next(0, CollectionSongs.Count);

                var s_FirstSong  = CollectionSongs[s_FirstSongIndex];
                var s_SecondSong = CollectionSongs[s_SecondSongIndex];

                while (s_SecondSong == s_FirstSong)
                {
                    s_SecondSongIndex = s_Random.Next(0, CollectionSongs.Count);
                    s_SecondSong      = CollectionSongs[s_SecondSongIndex];
                }

                var s_Songs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_FirstSong, s_SecondSong
                });
                Application.Library.Broadcast.PlaySong(s_FirstSong, s_Songs[s_FirstSong]);
                return;
            }

            PlayedSongs.Add(s_Event.SongID);

            // Clear songs from history (if needed).
            for (var i = 0; i < PlayedSongs.Count - SettingsManager.MaxHistorySongs(); ++i)
            {
                PlayedSongs.RemoveAt(0);
            }

            UpdateQueue();
        }
Example #25
0
 private static void OnAuthenticationFailed(SharkEvent p_SharkEvent)
 {
     Authenticating = false;
     AuthenticationResult = AuthenticationResult.InternalError;
 }
Example #26
0
        private static void OnAuthenticated(SharkEvent p_SharkEvent)
        {
            Authenticating = false;
            AuthenticationResult = AuthenticationResult.Success;

            QueueManager.FetchCollectionSongs();

            if (QueueManager.CollectionSongs.Count < 2)
                return;

            BroadcastManager.CreateBroadcast();
        }
 private static void OnUserLeftBroadcast(SharkEvent p_SharkEvent)
 {
     lock (m_PendingUserLeaveEvents)
         m_PendingUserLeaveEvents.Enqueue((UserLeftBroadcastEvent) p_SharkEvent);
 }
Example #28
0
        private static void OnBroadcastCreated(SharkEvent p_SharkEvent)
        {
            CreatingBroadcast = false;

            QueueManager.FetchCollectionSongs();
            QueueManager.ClearHistory();

            // Add two random songs to the collection.
            if (Application.Library.Queue.CurrentQueue.Count < 2)
            {
                var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(2);

                if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
                {
                    var s_First = s_ModuleSongs.First();
                    Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                    return;
                }

                var s_Random          = new Random();
                var s_FirstSongIndex  = s_Random.Next(0, QueueManager.CollectionSongs.Count);
                var s_SecondSongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);

                var s_FirstSong  = QueueManager.CollectionSongs[s_FirstSongIndex];
                var s_SecondSong = QueueManager.CollectionSongs[s_SecondSongIndex];

                while (s_SecondSong == s_FirstSong)
                {
                    s_SecondSongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
                    s_SecondSong      = QueueManager.CollectionSongs[s_SecondSongIndex];
                }

                var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_FirstSong, s_SecondSong
                });

                if (Application.Library.Broadcast.PlayingSongID == 0)
                {
                    Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
                }
            }
            else if (Application.Library.Broadcast.PlayingSongID == 0)
            {
                var s_ModuleSongs = ModuleManager.OnFetchingNextSongs(1);

                if (s_ModuleSongs != null && s_ModuleSongs.Count > 0)
                {
                    var s_First = s_ModuleSongs.First();
                    Application.Library.Broadcast.PlaySong(s_First.Key, s_First.Value);
                    return;
                }

                var s_Random    = new Random();
                var s_SongIndex = s_Random.Next(0, QueueManager.CollectionSongs.Count);
                var s_FirstSong = QueueManager.CollectionSongs[s_SongIndex];

                var s_QueueIDs = Application.Library.Broadcast.AddSongs(new List <Int64> {
                    s_FirstSong
                });

                Application.Library.Broadcast.PlaySong(s_FirstSong, s_QueueIDs[s_FirstSong]);
            }
            else if (Application.Library.Broadcast.PlayingSongID != 0)
            {
                QueueManager.UpdateQueue();
            }

            // Disable mobile compliance if needed.
            if (!SettingsManager.MobileCompliance())
            {
                DisableMobileCompliance();
            }
        }
Example #29
0
 private static void OnAuthenticationFailed(SharkEvent p_SharkEvent)
 {
     Authenticating       = false;
     AuthenticationResult = AuthenticationResult.InternalError;
 }
Example #30
0
 private static void OnQueueUpdated(SharkEvent p_SharkEvent)
 {
     UpdateQueue();
 }
        private static void OnSongSuggestionRemoved(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongSuggestionRemovalEvent) p_SharkEvent;

            lock (Suggestions)
            {
                SongSuggestion s_Suggestion;

                // This suggestion doesn't even exist.
                if (!Suggestions.TryGetValue(s_Event.SongID, out s_Suggestion))
                    return;

                // This is the last suggestion; completely remove it.
                if (s_Suggestion.Suggester.UserID == s_Event.UserID &&
                    s_Suggestion.OtherSuggesters.Count == 0)
                {
                    Suggestions.Remove(s_Event.SongID);
                    return;
                }

                // This is an upvote removal on a suggestion by another user.
                var s_Index = CollectionUtils.FindIndex(s_Suggestion.OtherSuggesters,
                    p_User => p_User.UserID == s_Event.UserID);

                if (s_Index != -1)
                {
                    s_Suggestion.OtherSuggesters.RemoveAt(s_Index);
                    return;
                }

                // The initial suggester is removing his suggestion. Switch suggesters.
                if (s_Suggestion.Suggester.UserID == s_Event.UserID &&
                    s_Suggestion.OtherSuggesters.Count > 0)
                {
                    s_Suggestion.Suggester = s_Suggestion.OtherSuggesters[0];
                    s_Suggestion.OtherSuggesters.RemoveAt(0);
                }
            }
        }
 private static void OnSongVote(SharkEvent p_SharkEvent)
 {
     lock (m_PendingSongVoteEvents)
         m_PendingSongVoteEvents.Enqueue((SongVoteEvent) p_SharkEvent);
 }
        private static void OnSongSuggestionApproved(SharkEvent p_SharkEvent)
        {
            var s_Event = (SongSuggestionApprovalEvent) p_SharkEvent;

            lock (Suggestions)
                Suggestions.Remove(s_Event.SongID);
        }
 private static void OnUserJoinedBroadcast(SharkEvent p_SharkEvent)
 {
     lock (m_PendingUserJoinEvents)
         m_PendingUserJoinEvents.Enqueue((UserJoinedBroadcastEvent) p_SharkEvent);
 }