Skip to content

Commit 4f7fd79

Browse files
committed
fix: players missing from teams
- Players were seen as disconnected and so not returned by some participants functions - Rely on m_iConnected to detect players connection/disconnection - Disable player_connect and player_disconnect game events for CS2 demos - Dispatch events from prop updates ref #494 #492
1 parent 06fee1c commit 4f7fd79

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,32 @@ func (p *parser) getOrCreatePlayerFromControllerEntity(controllerEntity st.Entit
514514
func (p *parser) bindNewPlayerControllerS2(controllerEntity st.Entity) {
515515
pl := p.getOrCreatePlayerFromControllerEntity(controllerEntity)
516516

517-
controllerEntity.Property("m_hPawn").OnUpdate(func(val st.PropertyValue) {
518-
if val.Handle() == constants.InvalidEntityHandleSource2 {
519-
pl.IsConnected = false
517+
controllerEntity.Property("m_iConnected").OnUpdate(func(val st.PropertyValue) {
518+
state := val.S2UInt32()
519+
wasConnected := pl.IsConnected
520+
pl.IsConnected = state == 0
521+
522+
isDisconnection := state == 8
523+
if isDisconnection {
524+
for k, v := range p.rawPlayers {
525+
if v.XUID == pl.SteamID64 {
526+
delete(p.rawPlayers, k)
527+
}
528+
}
529+
p.gameEventHandler.dispatch(events.PlayerDisconnected{
530+
Player: pl,
531+
})
532+
533+
return
534+
}
535+
536+
isConnection := !wasConnected && pl.IsConnected
537+
if isConnection {
538+
if pl.SteamID64 != 0 {
539+
p.eventDispatcher.Dispatch(events.PlayerConnect{Player: pl})
540+
} else {
541+
p.eventDispatcher.Dispatch(events.BotConnect{Player: pl})
542+
}
520543
}
521544
})
522545

@@ -557,15 +580,6 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
557580
pl := p.getOrCreatePlayerFromControllerEntity(controllerEntity)
558581

559582
p.bindPlayerWeaponsS2(pawnEntity, pl)
560-
561-
if !pl.IsConnected {
562-
pl.IsConnected = true
563-
if pl.SteamID64 != 0 {
564-
p.eventDispatcher.Dispatch(events.PlayerConnect{Player: pl})
565-
} else {
566-
p.eventDispatcher.Dispatch(events.BotConnect{Player: pl})
567-
}
568-
}
569583
})
570584

571585
// Position
@@ -632,14 +646,6 @@ func (p *parser) bindNewPlayerPawnS2(pawnEntity st.Entity) {
632646
spottedByMaskProp.OnUpdate(spottersChanged)
633647
pawnEntity.Property("m_bSpottedByMask.0001").OnUpdate(spottersChanged)
634648
}
635-
636-
pawnEntity.OnDestroy(func() {
637-
pl := getPlayerFromPawnEntity(pawnEntity)
638-
if pl == nil {
639-
return
640-
}
641-
pl.IsConnected = false
642-
})
643649
}
644650

645651
const maxWeapons = 64

pkg/demoinfocs/game_events.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ func (geh gameEventHandler) HostageRescuedAll(map[string]*msg.CSVCMsg_GameEventK
620620
}
621621

622622
func (geh gameEventHandler) playerConnect(data map[string]*msg.CSVCMsg_GameEventKeyT) {
623+
if geh.parser.isSource2() {
624+
return
625+
}
626+
623627
pl := common.PlayerInfo{
624628
UserID: int(data["userid"].GetValShort()),
625629
Name: data["name"].GetValString(),
@@ -637,12 +641,14 @@ func (geh gameEventHandler) playerConnect(data map[string]*msg.CSVCMsg_GameEvent
637641
}
638642
}
639643

640-
if !geh.parser.isSource2() {
641-
geh.parser.setRawPlayer(int(data["index"].GetValByte()), pl)
642-
}
644+
geh.parser.setRawPlayer(int(data["index"].GetValByte()), pl)
643645
}
644646

645647
func (geh gameEventHandler) playerDisconnect(data map[string]*msg.CSVCMsg_GameEventKeyT) {
648+
if geh.parser.isSource2() {
649+
return
650+
}
651+
646652
uid := int(data["userid"].GetValShort())
647653

648654
for k, v := range geh.parser.rawPlayers {
@@ -658,7 +664,7 @@ func (geh gameEventHandler) playerDisconnect(data map[string]*msg.CSVCMsg_GameEv
658664
Player: pl,
659665
})
660666

661-
geh.playerByUserID(uid).IsConnected = false
667+
pl.IsConnected = false
662668
}
663669
}
664670

0 commit comments

Comments
 (0)