Skip to content

Commit

Permalink
fix: upload new image & optimize ip parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 9, 2024
1 parent beb6239 commit 38317db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/highway.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (c *QQClient) SendUpBlockAsync(block UpBlock, server string) bool {
MsgLoginSigHead: loginHead,
}
isEnd := block.Offset+uint64(len(block.Block)) == block.FileSize
packet := &binary.Builder{}
packet := binary.NewBuilder(nil)
packet.WriteBytes(block.Block, false)
payload, err := SendPacketAsync(highwayHead, packet, server, isEnd)
if err != nil {
Expand Down
29 changes: 13 additions & 16 deletions client/richmedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package client

import (
"bytes"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"io"
"net"
"net/netip"

"github.com/LagrangeDev/LagrangeGo/message"
"github.com/LagrangeDev/LagrangeGo/packets/oidb"
Expand All @@ -16,27 +16,24 @@ import (
"github.com/LagrangeDev/LagrangeGo/utils/proto"
)

func ConvertIP(raw uint32) string {
ip := make(net.IP, 4)
ip[0] = byte(raw & 0xFF)
ip[1] = byte((raw >> 8) & 0xFF)
ip[2] = byte((raw >> 16) & 0xFF)
ip[3] = byte((raw >> 24) & 0xFF)
return fmt.Sprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3])
func le32toipstr(raw uint32) string {
var buf [4]byte
binary.LittleEndian.PutUint32(buf[:], raw)
return netip.AddrFrom4(buf).String()
}

func ConvertNTHighwayNetWork(ipv4s []*oidb2.IPv4) []*highway.NTHighwayIPv4 {
var IPv4s []*highway.NTHighwayIPv4
for _, ipv4 := range ipv4s {
IPv4s = append(IPv4s, &highway.NTHighwayIPv4{
hwipv4s := make([]*highway.NTHighwayIPv4, len(ipv4s))
for i, ip := range ipv4s {
hwipv4s[i] = &highway.NTHighwayIPv4{
Domain: &highway.NTHighwayDomain{
IsEnable: true,
IP: ConvertIP(ipv4.OutIP),
IP: le32toipstr(ip.OutIP),
},
Port: ipv4.OutPort,
})
Port: ip.OutPort,
}
}
return IPv4s
return hwipv4s
}

func (c *QQClient) ImageUploadPrivate(targetUid string, element message.IMessageElement) (*message.FriendImageElement, error) {
Expand Down

0 comments on commit 38317db

Please sign in to comment.