Browse Source

pull in screenname from request

Mike 3 năm trước cách đây
mục cha
commit
48f2cbbcde
3 tập tin đã thay đổi với 21 bổ sung1 xóa
  1. 8 1
      oscar/bucp.go
  2. 4 0
      oscar/locate.go
  3. 9 0
      oscar/protocol.go

+ 8 - 1
oscar/bucp.go

@@ -3,6 +3,7 @@ package oscar
 import (
 	"bytes"
 	"encoding/binary"
+	"errors"
 	"fmt"
 	"io"
 	"reflect"
@@ -151,12 +152,18 @@ func ReceiveAndSendBUCPLoginRequest(r io.Reader, w io.Writer, sequence *uint32)
 		foodGroup: 0x17,
 		subGroup:  0x03,
 	}
+
+	screenName, found := snacPayload.getString(0x01)
+	if !found {
+		return errors.New("unable to find screen name tlv")
+	}
+
 	snacPayloadOut := &snacBUCPLoginRequest{
 		TLVPayload: TLVPayload{
 			TLVs: []*TLV{
 				{
 					tType: 0x01,
-					val:   "myscreenname",
+					val:   screenName,
 				},
 				{
 					tType: 0x08,

+ 4 - 0
oscar/locate.go

@@ -130,6 +130,7 @@ func ReceiveSetInfo(flap *flapFrame, snac *snacFrame, r io.Reader, w io.Writer,
 	lookup := map[uint16]reflect.Kind{
 		0x01: reflect.String,
 		0x02: reflect.Slice,
+		0x03: reflect.Slice,
 		0x04: reflect.Slice,
 		0x05: reflect.Slice,
 		0x06: reflect.Slice,
@@ -138,6 +139,9 @@ func ReceiveSetInfo(flap *flapFrame, snac *snacFrame, r io.Reader, w io.Writer,
 		return err
 	}
 
+	for _, tlv := range snacPayload.TLVs {
+		fmt.Printf("set info: %v\n", tlv.val)
+	}
 	fmt.Printf("ReceiveSetInfo read SNAC: %+v\n", snacPayload)
 
 	return nil

+ 9 - 0
oscar/protocol.go

@@ -111,6 +111,15 @@ func (s *TLVPayload) write(w io.Writer) error {
 	return nil
 }
 
+func (s *TLVPayload) getString(tType uint16) (string, bool) {
+	for _, tlv := range s.TLVs {
+		if tType == tlv.tType {
+			return tlv.val.(string), true
+		}
+	}
+	return "", false
+}
+
 type TLV struct {
 	tType uint16
 	val   any