diff --git a/voice.go b/voice.go index aedb87904..a4c3bf558 100644 --- a/voice.go +++ b/voice.go @@ -120,9 +120,9 @@ func (v *VoiceConnection) ChangeChannel(channelID string, mute, deaf bool) (err v.log(LogInformational, "called") data := voiceChannelJoinOp{4, voiceChannelJoinData{&v.GuildID, &channelID, mute, deaf}} - v.wsMutex.Lock() + v.session.wsMutex.Lock() err = v.session.wsConn.WriteJSON(data) - v.wsMutex.Unlock() + v.session.wsMutex.Unlock() if err != nil { return } @@ -323,7 +323,9 @@ func (v *VoiceConnection) open() (err error) { } data := voiceHandshakeOp{0, voiceHandshakeData{v.GuildID, v.UserID, v.sessionID, v.token}} + v.wsMutex.Lock() err = v.wsConn.WriteJSON(data) + v.wsMutex.Unlock() if err != nil { v.log(LogWarning, "error sending init packet, %s", err) return @@ -829,7 +831,12 @@ func (v *VoiceConnection) opusReceiver(udpConn *net.UDPConn, close <-chan struct p.SSRC = binary.BigEndian.Uint32(recvbuf[8:12]) // decrypt opus data copy(nonce[:], recvbuf[0:12]) - p.Opus, _ = secretbox.Open(nil, recvbuf[12:rlen], &nonce, &v.op4.SecretKey) + + if opus, ok := secretbox.Open(nil, recvbuf[12:rlen], &nonce, &v.op4.SecretKey); ok { + p.Opus = opus + } else { + return + } // extension bit set, and not a RTCP packet if ((recvbuf[0] & 0x10) == 0x10) && ((recvbuf[1] & 0x80) == 0) { @@ -870,7 +877,11 @@ func (v *VoiceConnection) reconnect() { v.reconnecting = true v.Unlock() - defer func() { v.reconnecting = false }() + defer func() { + v.Lock() + v.reconnecting = false + v.Unlock() + }() // Close any currently open connections v.Close()