diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-12 20:53:09 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:42 +0300 |
| commit | 82871ba1bac1d62f69e1933b66659e62d2e5e063 (patch) | |
| tree | a906310fba89b670bcfda9625a6d776553d482f6 /pkg/packets/headers.go | |
| parent | net/svc messages finally getting parsed correctly (diff) | |
| download | sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.gz sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.bz2 sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.zip | |
another rewrite, v1.0.0
Diffstat (limited to 'pkg/packets/headers.go')
| -rw-r--r-- | pkg/packets/headers.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pkg/packets/headers.go b/pkg/packets/headers.go new file mode 100644 index 0000000..543476b --- /dev/null +++ b/pkg/packets/headers.go | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | package packets | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type Headers struct { | ||
| 10 | DemoFileStamp string | ||
| 11 | DemoProtocol int32 | ||
| 12 | NetworkProtocol int32 | ||
| 13 | ServerName string | ||
| 14 | ClientName string | ||
| 15 | MapName string | ||
| 16 | GameDirectory string | ||
| 17 | PlaybackTime float32 | ||
| 18 | PlaybackTicks int32 | ||
| 19 | PlaybackFrames int32 | ||
| 20 | SignOnLength int32 | ||
| 21 | } | ||
| 22 | |||
| 23 | func ParseHeaders(reader *bitreader.ReaderType) Headers { | ||
| 24 | headers := Headers{ | ||
| 25 | DemoFileStamp: reader.TryReadString(), | ||
| 26 | DemoProtocol: int32(reader.TryReadInt32()), | ||
| 27 | NetworkProtocol: int32(reader.TryReadInt32()), | ||
| 28 | ServerName: reader.TryReadStringLen(260), | ||
| 29 | ClientName: reader.TryReadStringLen(260), | ||
| 30 | MapName: reader.TryReadStringLen(260), | ||
| 31 | GameDirectory: reader.TryReadStringLen(260), | ||
| 32 | PlaybackTime: reader.TryReadFloat32(), | ||
| 33 | PlaybackTicks: int32(reader.TryReadInt32()), | ||
| 34 | PlaybackFrames: int32(reader.TryReadInt32()), | ||
| 35 | SignOnLength: int32(reader.TryReadInt32()), | ||
| 36 | } | ||
| 37 | if headers.DemoFileStamp != "HL2DEMO" { | ||
| 38 | panic("invalid demo file stamp") | ||
| 39 | } | ||
| 40 | if headers.DemoProtocol != 4 { | ||
| 41 | panic("this parser only supports demos from new engine") | ||
| 42 | } | ||
| 43 | if headers.NetworkProtocol != 2001 { | ||
| 44 | panic("this parser only supports demos from portal 2") | ||
| 45 | } | ||
| 46 | fmt.Printf("Headers: %+v\n", headers) | ||
| 47 | return headers | ||
| 48 | } | ||