40 lines
1 KiB
Go
40 lines
1 KiB
Go
|
package textgapi
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
|
||
|
"go.mau.fi/mautrix-gmessages/libgm/binary"
|
||
|
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
||
|
)
|
||
|
|
||
|
func (c *Client) handleSeperateOpCode(msgData *binary.MessageData) {
|
||
|
decodedBytes, err := crypto.Base64DecodeStandard(msgData.EncodedData)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
switch msgData.RoutingOpCode {
|
||
|
case 14: // paired successful
|
||
|
decodedData := &binary.Container{}
|
||
|
err = binary.DecodeProtoMessage(decodedBytes, decodedData)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
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 {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
if (decodedData.Sub && decodedData.Third != 0) && decodedData.EncryptedData != nil {
|
||
|
bugleData := &binary.BugleBackendService{}
|
||
|
err = c.cryptor.DecryptAndDecodeData(decodedData.EncryptedData, bugleData)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
c.handleBugleOpCode(bugleData)
|
||
|
}
|
||
|
}
|
||
|
}
|