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
|
|
|
}
|
2023-07-01 09:51:13 +00:00
|
|
|
if decodedData.UnpairDeviceData != nil {
|
|
|
|
c.Logger.Warn().Any("data", decodedData).Msg("Unpaired?")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// TODO unpairing
|
2023-06-30 09:54:08 +00:00
|
|
|
c.Logger.Debug().Any("data", decodedData).Msg("Paired device decoded data")
|
2023-07-01 09:51:13 +00:00
|
|
|
if c.pairer != nil {
|
|
|
|
c.pairer.pairCallback(decodedData)
|
|
|
|
} else {
|
|
|
|
c.Logger.Warn().Msg("No pairer to receive callback")
|
|
|
|
}
|
2023-06-30 09:54:08 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|