diff --git a/machine/action/action_server.go b/machine/action/action_server.go index 373f439..68ad3b6 100644 --- a/machine/action/action_server.go +++ b/machine/action/action_server.go @@ -3,6 +3,7 @@ package action import ( "bytes" "fmt" + "math" "mongo.games.com/game/machine/machinedoll" "mongo.games.com/game/protocol/machine" "mongo.games.com/goserver/core/logger" @@ -169,7 +170,7 @@ func SMDollMachineGrabHandler(session *netlib.Session, packetId int, data interf // 监听抓取结果返回 func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid, id int32) { - num := 1 + num := int64(1) for { // 读取数据 fmt.Println("监听抓取结果返回!") @@ -179,12 +180,6 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid fmt.Println("Failed to read response from client:", err) return } - if n != 0 && num == 1 { - num += 1 - fmt.Println("清除脏数据!!!!!!!!!!!!!buf = ", buf[:n]) - continue - } - num++ // 将读取到的数据按照 221 进行分割 parts := bytes.Split(buf[:n], []byte{221}) fmt.Println("获取到的返回值:", parts) @@ -195,7 +190,7 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid if len(part) > 0 { part = part[:len(part)-1] // 去除最后一个字节,该字节为分隔符 fmt.Println("比较返回结果 part = ", part) - if bytes.Contains(part, instruction) { + if bytes.Contains(part, instruction) && num != 1 { fmt.Printf("Part %d: %s\n", i+1, part) //回应数据 _, err = conn.Write([]byte{0xAA, 0x04, 0x01, 0x50, 0x09, 0x5c, 0xdd}) @@ -213,7 +208,7 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid conn.SetDeadline(time.Time{}) return } - if bytes.Contains(part, instruction1) { + if bytes.Contains(part, instruction1) && num != 1 { fmt.Printf("Part %d: %s\n", i+1, part) //回应数据 _, err = conn.Write([]byte{0xAA, 0x04, 0x01, 0x50, 0x09, 0x5c, 0xdd}) @@ -257,6 +252,10 @@ func DollMachineGrabResult(session *netlib.Session, conn *machinedoll.Conn, snid } } } + num++ + if num >= math.MaxInt64 { + num = 2 + } } }