disgoorg / disgolink

A Golang Lavalink Client
Apache License 2.0
25 stars 4 forks source link

Voice Server Updates sent to Lavalink #31

Closed fiwippi closed 2 years ago

fiwippi commented 2 years ago

Hi, I changed a little bit of code in lavalink.go

1   player := l.ExistingPlayer(voiceServerUpdate.GuildID)
2   if player == nil {
3       return
4   }

Changes:

  1. I stopped checking for if the player was nil and then checking for its session ID because that causes a nil-pointer error
  2. U used the ExistingPlayer() func to access the players since it already uses mutexes to access it
  3. I removed checking for the last session ID since you may be on a new session etc. and you will want to change to that. My current code does not play to voice if it performs the check for last session.

If there's anything I didn't understand from your code feel free to let me know.

topi314 commented 2 years ago

the mutex is a good catch 👀

fiwippi commented 2 years ago

I've reintroduced the check for the session as

if player == nil || player.LastSessionID() == nil {
    return
}

This ensures that we must have a valid player and a valid session ID. The previous check is liable to panic consistently because it's checking if player is nil and then trying to access it using player.LastSessionID() which will cause a NPE. And this is better than the old check because it takes session ID into account.