manage state transitions in print_replay tool
This commit is contained in:
@@ -19,6 +19,8 @@ var (
|
|||||||
ProtocolVersion = cmd.Int("protocol", -1, "The protocol version")
|
ProtocolVersion = cmd.Int("protocol", -1, "The protocol version")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var state = proto_base.Login
|
||||||
|
|
||||||
func UnpackPacket(r io.Reader) (packet proto_base.EncodeDecodeAble, err error) {
|
func UnpackPacket(r io.Reader) (packet proto_base.EncodeDecodeAble, err error) {
|
||||||
var timestamp, length uint32
|
var timestamp, length uint32
|
||||||
err = binary.Read(r, binary.BigEndian, ×tamp)
|
err = binary.Read(r, binary.BigEndian, ×tamp)
|
||||||
@@ -40,7 +42,7 @@ func UnpackPacket(r io.Reader) (packet proto_base.EncodeDecodeAble, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
i, ok := proto.LookUpTypeByPacketInfo(proto_base.ToClient, proto_base.Login, packetId, int32(*ProtocolVersion))
|
i, ok := proto.LookUpTypeByPacketInfo(proto_base.ToClient, state, packetId, int32(*ProtocolVersion))
|
||||||
if !ok {
|
if !ok {
|
||||||
packet = &proto.UnCodablePacket{Err: proto.BadPacketIdErr, Data: b.Bytes(), Direction: proto_base.ToClient}
|
packet = &proto.UnCodablePacket{Err: proto.BadPacketIdErr, Data: b.Bytes(), Direction: proto_base.ToClient}
|
||||||
return
|
return
|
||||||
@@ -51,6 +53,12 @@ func UnpackPacket(r io.Reader) (packet proto_base.EncodeDecodeAble, err error) {
|
|||||||
packet = &proto.UnCodablePacket{Err: err, Data: b.Bytes(), Direction: proto_base.ToClient}
|
packet = &proto.UnCodablePacket{Err: err, Data: b.Bytes(), Direction: proto_base.ToClient}
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
switch i.Name {
|
||||||
|
case "success":
|
||||||
|
state = proto_base.Configuration
|
||||||
|
case "finish_configuration":
|
||||||
|
state = proto_base.Play
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +86,5 @@ func Run(args []string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("Packet: %#v\n", packet)
|
fmt.Printf("Packet: %#v\n", packet)
|
||||||
fmt.Printf("Packet lllll: %v\n", packet)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user