diff --git a/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt b/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt index 0b8f46588..a9ec016af 100644 --- a/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt +++ b/LavalinkServer/src/main/java/lavalink/server/io/WebSocketHandler.kt @@ -84,7 +84,9 @@ class WebSocketHandler( } val track = decodeTrack(context.audioPlayerManager, json.getString("track")) - + if(!track){ + return + } if (json.has("startTime")) { track.position = json.getLong("startTime") } diff --git a/LavalinkServer/src/main/java/lavalink/server/player/AudioLoaderRestHandler.kt b/LavalinkServer/src/main/java/lavalink/server/player/AudioLoaderRestHandler.kt index 0b164d505..b1cc164c2 100644 --- a/LavalinkServer/src/main/java/lavalink/server/player/AudioLoaderRestHandler.kt +++ b/LavalinkServer/src/main/java/lavalink/server/player/AudioLoaderRestHandler.kt @@ -76,8 +76,10 @@ class AudioLoaderRestHandler( HttpStatus.BAD_REQUEST, "No track to decode provided" ) - val decodedTrack = decodeTrack(audioPlayerManager, trackToDecode).toTrack(trackToDecode) - return ResponseEntity.ok(DecodedTrack(decodedTrack.encoded, decodedTrack.info, decodedTrack.info)) + val decodedTrack = decodeTrack(audioPlayerManager, trackToDecode) + if(!decodedTrack) return + val rightOne = decodedTrack.toTrack(trackToDecode) + return ResponseEntity.ok(DecodedTrack(rightOne.encoded, rightOne.info, rightOne.info)) } @PostMapping(value = ["/decodetracks", "/v3/decodetracks"]) @@ -86,7 +88,9 @@ class AudioLoaderRestHandler( throw ResponseStatusException(HttpStatus.BAD_REQUEST, "No tracks to decode provided") } return ResponseEntity.ok(encodedTracks.map { - decodeTrack(audioPlayerManager, it).toTrack(it) + val trackE = decodeTrack(audioPlayerManager, it) + if(!trackE) return + val track = trackE.toTrack(it) }) } diff --git a/protocol/src/main/java/dev/arbjerg/lavalink/protocol/v3/util.kt b/protocol/src/main/java/dev/arbjerg/lavalink/protocol/v3/util.kt index 5216e4145..8efa32cb5 100644 --- a/protocol/src/main/java/dev/arbjerg/lavalink/protocol/v3/util.kt +++ b/protocol/src/main/java/dev/arbjerg/lavalink/protocol/v3/util.kt @@ -7,17 +7,22 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack import org.apache.commons.codec.binary.Base64 import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream +import org.slf4j.LoggerFactory + companion object { + private val log = LoggerFactory.getLogger(EventEmitter::class.java) + } + class TrackDecodingException(message: String) : Exception(message) -fun decodeTrack(audioPlayerManager: AudioPlayerManager, message: String): AudioTrack { +fun decodeTrack(audioPlayerManager: AudioPlayerManager, message: String): AudioTrack? { val bais = ByteArrayInputStream(Base64.decodeBase64(message)) return try { audioPlayerManager.decodeTrack(MessageInput(bais)).decodedTrack - ?: throw TrackDecodingException("Failed to decode track") + ?: log.info("Hye bit") } catch (e: IllegalStateException) { // Handle the exception here - throw TrackDecodingException("An error occurred while decoding track: ${e.message}") + log.info("Hye bit") } } fun encodeTrack(audioPlayerManager: AudioPlayerManager, track: AudioTrack): String {