|
|
@ -7,8 +7,8 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/golang/snappy"
|
|
|
|
"github.com/golang/snappy"
|
|
|
|
// "github.com/jordanorelli/hyperstone/bit"
|
|
|
|
"github.com/jordanorelli/hyperstone/bit"
|
|
|
|
// "github.com/jordanorelli/hyperstone/dota"
|
|
|
|
"github.com/jordanorelli/hyperstone/dota"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type parser struct {
|
|
|
|
type parser struct {
|
|
|
@ -28,7 +28,7 @@ func newParser(r io.Reader) *parser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (p *parser) run(out chan proto.Message) {
|
|
|
|
func (p *parser) run(out chan maybe) {
|
|
|
|
defer close(out)
|
|
|
|
defer close(out)
|
|
|
|
ok, err := p.checkHeader()
|
|
|
|
ok, err := p.checkHeader()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -51,37 +51,44 @@ func (p *parser) run(out chan proto.Message) {
|
|
|
|
p.err = wrap(err, "open packet error in run loop")
|
|
|
|
p.err = wrap(err, "open packet error in run loop")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out <- msg
|
|
|
|
|
|
|
|
|
|
|
|
switch m := msg.(type) {
|
|
|
|
|
|
|
|
case *dota.CDemoPacket:
|
|
|
|
|
|
|
|
p.emitChildren(m, out)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out <- maybe{Message: msg}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
func (p *parser) emitChildren(pkt *dota.CDemoPacket, c chan maybe) {
|
|
|
|
// func (p *parser) handleDemoPacket(packet *dota.CDemoPacket) error {
|
|
|
|
br := bit.NewBytesReader(pkt.GetData())
|
|
|
|
// br := bit.NewBytesReader(packet.GetData())
|
|
|
|
for {
|
|
|
|
// for {
|
|
|
|
t := entityType(br.ReadUBitVar())
|
|
|
|
// t := entityType(br.ReadUBitVar())
|
|
|
|
s := br.ReadVarInt()
|
|
|
|
// s := br.ReadVarInt()
|
|
|
|
b := p.scratch[:s]
|
|
|
|
// b := p.scratch[:s]
|
|
|
|
br.Read(b)
|
|
|
|
// br.Read(b)
|
|
|
|
p.pbuf.SetBuf(b)
|
|
|
|
// p.pbuf.SetBuf(b)
|
|
|
|
switch err := br.Err(); err {
|
|
|
|
// switch err := br.Err(); err {
|
|
|
|
case nil:
|
|
|
|
// case nil:
|
|
|
|
break
|
|
|
|
// break
|
|
|
|
case io.EOF:
|
|
|
|
// case io.EOF:
|
|
|
|
return
|
|
|
|
// return nil
|
|
|
|
default:
|
|
|
|
// default:
|
|
|
|
c <- maybe{error: err}
|
|
|
|
// return err
|
|
|
|
return
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// e, err := messages.BuildEntity(t)
|
|
|
|
e, err := messages.BuildEntity(t)
|
|
|
|
// if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
// fmt.Printf("\tskipping entity of size %d, type %s: %v\n", len(b), t, err)
|
|
|
|
c <- maybe{error: wrap(err, "skipping entity of size %d, type %s", len(b), t)}
|
|
|
|
// continue
|
|
|
|
continue
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// if err := p.pbuf.Unmarshal(e); err != nil {
|
|
|
|
if err := p.pbuf.Unmarshal(e); err != nil {
|
|
|
|
// fmt.Printf("entity unmarshal error: %v\n", err)
|
|
|
|
c <- maybe{error: wrap(err, "entity unmarshal error")}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
c <- maybe{Message: e}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DecodeVarint reads a varint-encoded integer from the source reader.
|
|
|
|
// DecodeVarint reads a varint-encoded integer from the source reader.
|
|
|
|
// It returns the value as a uin64 and any errors encountered. The reader will
|
|
|
|
// It returns the value as a uin64 and any errors encountered. The reader will
|
|
|
|