AttorneyOnline / tsuserver3

An Attorney Online server.
GNU Affero General Public License v3.0
25 stars 51 forks source link

Jukebox functionality is broken #165

Open in1tiate opened 3 years ago

in1tiate commented 3 years ago

When an area is in jukebox mode, playing a song is supposed to add it to the queue. This does not work, the server instead reports "You removed your song from the jukebox" even if the jukebox queue is empty. Newbie Hole has been unable to play music for who knows how long.

caleb-mabry commented 3 years ago

The offending code is

        def add_jukebox_vote(self, client: ClientManager.Client, music_name: str, length: int = -1, showname: str = ''):
            """Cast a vote on the jukebox.
            Args:
                client (ClientManager.Client): Client that is requesting
                music_name (str): track name
                length (int, optional): length of track. Defaults to -1.
                showname (str, optional): showname of voter. Defaults to ''.
            """

            if not self.jukebox:
                return
            if length <= 0:
                self.remove_jukebox_vote(client, False)
            else:
                self.remove_jukebox_vote(client, True)
                self.jukebox_votes.append(
                    self.JukeboxVote(client, music_name, length, showname))
                client.send_ooc('Your song was added to the jukebox.')
                if len(self.jukebox_votes) == 1:
                    self.start_jukebox()

Now, I'm not quite sure what the -1 is used for; however, there's some kind of trap happening here. The parameter length is generated through:

    def get_song_data(self, music_list, music):
        """
        Get information about a track, if exists.
        :param music_list: music list to search
        :param music: track name
        :returns: tuple (name, length or -1)
        :raises: ServerError if track not found
        """
        for item in music_list:
            if 'category' not in item: #skip settings n stuff
                continue
            if item['category'] == music:
                return item['category'], -1
            for song in item['songs']:
                if song['name'] == music:
                    try:
                        return song['name'], song['length']
                    except KeyError:
                        return song['name'], -1

It looks like the config defaults to -1.

If your music.yaml doesn't have the length attribute as something other than -1, it won't allow you to play it on the Jukebox. I brought this up in the development channel in the Discord and I'll wait to do something until I get feedback there.