gmessages/libgm/opcode_handler.go

40 lines
1 KiB
Go
Raw Normal View History

2023-06-30 09:54:08 +00:00
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)
}
}
}