-
Notifications
You must be signed in to change notification settings - Fork 89
/
net_messages.go
71 lines (58 loc) · 1.86 KB
/
net_messages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package demoinfocs
import (
"bytes"
bit "github.com/markus-wa/demoinfocs-golang/v2/internal/bitread"
events "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/events"
msg "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/msg"
)
const entitySentinel = 9999
func (p *parser) handlePacketEntities(pe *msg.CSVCMsg_PacketEntities) {
defer func() {
p.setError(recoverFromUnexpectedEOF(recover()))
}()
r := bit.NewSmallBitReader(bytes.NewReader(pe.EntityData))
currentEntity := -1
for i := 0; i < int(pe.UpdatedEntries); i++ {
currentEntity += 1 + int(r.ReadUBitInt())
if currentEntity > entitySentinel {
break
}
if r.ReadBit() {
// Leave PVS
if entity := p.gameState.entities[currentEntity]; entity != nil {
entity.Destroy()
delete(p.gameState.entities, currentEntity)
}
// 'Force Delete' flag, not exactly sure what it's supposed to do
r.ReadBit()
} else if r.ReadBit() {
// Enter PVS
if existing := p.gameState.entities[currentEntity]; existing != nil {
// Sometimes entities don't get destroyed when they should be
// For instance when a player is replaced by a BOT
existing.Destroy()
}
p.gameState.entities[currentEntity] = p.stParser.ReadEnterPVS(r, currentEntity)
} else { //nolint:gocritic
// Delta Update
if entity := p.gameState.entities[currentEntity]; entity != nil {
entity.ApplyUpdate(r)
}
}
}
r.Pool()
}
func (p *parser) handleSetConVar(setConVar *msg.CNETMsg_SetConVar) {
updated := make(map[string]string)
for _, cvar := range setConVar.Convars.Cvars {
updated[cvar.Name] = cvar.Value
p.gameState.conVars[cvar.Name] = cvar.Value
}
p.eventDispatcher.Dispatch(events.ConVarsUpdated{
UpdatedConVars: updated,
})
}
func (p *parser) handleServerInfo(srvInfo *msg.CSVCMsg_ServerInfo) {
// srvInfo.MapCrc might be interesting as well
p.tickInterval = srvInfo.TickInterval
}