2023-06-30 11:05:33 +00:00
|
|
|
package libgm
|
2023-06-30 09:54:08 +00:00
|
|
|
|
|
|
|
import (
|
2023-06-30 10:48:52 +00:00
|
|
|
"encoding/base64"
|
2023-06-30 09:54:08 +00:00
|
|
|
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Client) handleSeperateOpCode(msgData *binary.MessageData) {
|
2023-06-30 10:48:52 +00:00
|
|
|
decodedBytes, err := base64.StdEncoding.DecodeString(msgData.EncodedData)
|
2023-06-30 09:54:08 +00:00
|
|
|
if err != nil {
|
2023-06-30 11:48:50 +00:00
|
|
|
panic(err)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
switch msgData.RoutingOpCode {
|
|
|
|
case 14: // paired successful
|
|
|
|
decodedData := &binary.Container{}
|
|
|
|
err = binary.DecodeProtoMessage(decodedBytes, decodedData)
|
|
|
|
if err != nil {
|
2023-06-30 11:48:50 +00:00
|
|
|
panic(err)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
c.Logger.Debug().Any("data", decodedData).Msg("Paired device decoded data")
|
|
|
|
c.pairer.pairCallback(decodedData)
|
|
|
|
default:
|
|
|
|
decodedData := &binary.EncodedResponse{}
|
|
|
|
err = binary.DecodeProtoMessage(decodedBytes, decodedData)
|
|
|
|
if err != nil {
|
2023-06-30 11:48:50 +00:00
|
|
|
panic(err)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
if (decodedData.Sub && decodedData.Third != 0) && decodedData.EncryptedData != nil {
|
|
|
|
bugleData := &binary.BugleBackendService{}
|
|
|
|
err = c.cryptor.DecryptAndDecodeData(decodedData.EncryptedData, bugleData)
|
|
|
|
if err != nil {
|
2023-06-30 11:48:50 +00:00
|
|
|
panic(err)
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
c.handleBugleOpCode(bugleData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|