aboutsummaryrefslogtreecommitdiff
path: root/pkg/types
diff options
context:
space:
mode:
authorArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2024-06-15 13:58:30 +0300
committerGitHub <noreply@github.com>2024-06-15 13:58:30 +0300
commit77e4b066cb8d506b4bc944ab4eb2d6e4679e2202 (patch)
tree1d549eca619ed36cb881e487cb054c4643ac8376 /pkg/types
parentchange project name to sdp.go (diff)
downloadsdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.tar.gz
sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.tar.bz2
sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.zip
enable multithreading with goroutines (#20)
Diffstat (limited to 'pkg/types')
-rw-r--r--pkg/types/gameevent.go80
-rw-r--r--pkg/types/types.go71
2 files changed, 151 insertions, 0 deletions
diff --git a/pkg/types/gameevent.go b/pkg/types/gameevent.go
new file mode 100644
index 0000000..4f00bc0
--- /dev/null
+++ b/pkg/types/gameevent.go
@@ -0,0 +1,80 @@
1package types
2
3import (
4 "fmt"
5
6 "github.com/pektezol/bitreader"
7)
8
9type SvcGameEventList struct {
10 Events int16 `json:"events"`
11 Length int32 `json:"length"`
12 GameEventDescriptor []GameEventDescriptor `json:"game_event_descriptor"`
13}
14
15type GameEventDescriptor struct {
16 EventID uint32 `json:"event_id"`
17 Name string `json:"name"`
18 Keys []GameEventDescriptorKey `json:"keys"`
19}
20
21type GameEventDescriptorKey struct {
22 Name string `json:"name"`
23 Type EventDescriptor `json:"type"`
24}
25
26type EventDescriptor uint8
27
28func (svcGameEventList *SvcGameEventList) ParseGameEventDescriptor(reader *bitreader.Reader, demo *Demo) {
29 svcGameEventList.GameEventDescriptor = make([]GameEventDescriptor, svcGameEventList.Events)
30 for event := 0; event < int(svcGameEventList.Events); event++ {
31 svcGameEventList.GameEventDescriptor[event] = GameEventDescriptor{
32 EventID: uint32(reader.TryReadBits(9)),
33 Name: reader.TryReadString(),
34 }
35 demo.Writer.TempAppendLine("\t\t\t%d: %s", svcGameEventList.GameEventDescriptor[event].EventID, svcGameEventList.GameEventDescriptor[event].Name)
36 for {
37 descriptorType := reader.TryReadBits(3)
38 if descriptorType == 0 {
39 break
40 }
41 KeyName := reader.TryReadString()
42 svcGameEventList.GameEventDescriptor[event].Keys = append(svcGameEventList.GameEventDescriptor[event].Keys, GameEventDescriptorKey{
43 Name: KeyName,
44 Type: EventDescriptor(descriptorType),
45 })
46 }
47 demo.Writer.TempAppendLine("\t\t\t\tKeys: %v", svcGameEventList.GameEventDescriptor[event].Keys)
48 }
49}
50
51const (
52 EventDescriptorString EventDescriptor = iota + 1
53 EventDescriptorFloat
54 EventDescriptorInt32
55 EventDescriptorInt16
56 EventDescriptorInt8
57 EventDescriptorBool
58 EventDescriptorUInt64
59)
60
61func (eventDescriptor EventDescriptor) String() string {
62 switch eventDescriptor {
63 case EventDescriptorString:
64 return "String"
65 case EventDescriptorFloat:
66 return "Float"
67 case EventDescriptorInt32:
68 return "Int32"
69 case EventDescriptorInt16:
70 return "Int16"
71 case EventDescriptorInt8:
72 return "Int8"
73 case EventDescriptorBool:
74 return "Bool"
75 case EventDescriptorUInt64:
76 return "UInt64"
77 default:
78 return fmt.Sprintf("%d", eventDescriptor)
79 }
80}
diff --git a/pkg/types/types.go b/pkg/types/types.go
new file mode 100644
index 0000000..341e875
--- /dev/null
+++ b/pkg/types/types.go
@@ -0,0 +1,71 @@
1package types
2
3import (
4 "github.com/pektezol/sdp.go/pkg/writer"
5)
6
7type Demo struct {
8 Headers Headers `json:"headers"`
9 Messages []Message `json:"messages"`
10 Writer *writer.Writer `json:"-"`
11 GameEventList *SvcGameEventList `json:"-"`
12}
13
14type Headers struct {
15 DemoFileStamp string `json:"demo_file_stamp"`
16 DemoProtocol int32 `json:"demo_protocol"`
17 NetworkProtocol int32 `json:"network_protocol"`
18 ServerName string `json:"server_name"`
19 ClientName string `json:"client_name"`
20 MapName string `json:"map_name"`
21 GameDirectory string `json:"game_directory"`
22 PlaybackTime float32 `json:"playback_time"`
23 PlaybackTicks int32 `json:"playback_ticks"`
24 PlaybackFrames int32 `json:"playback_frames"`
25 SignOnLength int32 `json:"sign_on_length"`
26}
27
28type Message struct {
29 PacketType MessageType `json:"packet_type"`
30 TickNumber int32 `json:"tick_number"`
31 SlotNumber uint8 `json:"slot_number"`
32 Data any `json:"data"`
33}
34
35type MessageType uint8
36
37const (
38 SignOn MessageType = iota + 1
39 Packet
40 SyncTick
41 ConsoleCmd
42 UserCmd
43 DataTables
44 Stop
45 CustomData
46 StringTables
47)
48
49func (t MessageType) String() string {
50 switch t {
51 case SignOn:
52 return "SIGNON"
53 case Packet:
54 return "PACKET"
55 case SyncTick:
56 return "SYNCTICK"
57 case ConsoleCmd:
58 return "CONSOLECMD"
59 case UserCmd:
60 return "USERCMD"
61 case DataTables:
62 return "DATATABLES"
63 case Stop:
64 return "STOP"
65 case CustomData:
66 return "CUSTOMDATA"
67 case StringTables:
68 return "STRINGTABLES"
69 }
70 return "INVALID"
71}