@@ -179,26 +179,42 @@ func (p *Parser) bindPlayers() {
179179}
180180
181181func (p * Parser ) bindNewPlayer (playerEntity * st.Entity ) {
182- var pl * common.Player
183- playerIndex := playerEntity .ID ()
184- if p .gameState .playersByEntityID [playerIndex ] != nil {
185- pl = p .gameState .playersByEntityID [playerIndex ]
186- } else {
187- pl = common .NewPlayer ()
188- p .gameState .playersByEntityID [playerIndex ] = pl
189- pl .SteamID = - 1
190- pl .Name = "unconnected"
182+ entityID := playerEntity .ID ()
183+ rp := p .rawPlayers [entityID - 1 ]
184+
185+ isNew := false
186+ pl := p .gameState .playersByEntityID [entityID ]
187+ if pl == nil {
188+ pl = p .gameState .playersByUserID [rp .userID ]
189+
190+ if pl == nil {
191+ isNew = true
192+
193+ pl = common .NewPlayer ()
194+ pl .Name = rp .name
195+ pl .SteamID = rp .xuid
196+ pl .IsBot = rp .isFakePlayer
197+ pl .UserID = rp .userID
198+ }
191199 }
200+ p .gameState .playersByEntityID [entityID ] = pl
201+ p .gameState .playersByUserID [rp .userID ] = pl
192202
193- pl .EntityID = playerEntity . ID ()
203+ pl .EntityID = entityID
194204 pl .Entity = playerEntity
205+ pl .AdditionalPlayerInformation = & p .additionalPlayerInfo [entityID ]
195206
196207 playerEntity .OnDestroy (func () {
197- delete (p .gameState .playersByEntityID , pl . EntityID )
208+ delete (p .gameState .playersByEntityID , entityID )
198209 })
199210
200211 // Position
201- playerEntity .BindPosition (& pl .Position )
212+ playerEntity .OnPositionUpdate (func (pos r3.Vector ) {
213+ pl .Position = pos
214+ if pl .IsAlive () {
215+ pl .LastAlivePosition = pos
216+ }
217+ })
202218
203219 // General info
204220 playerEntity .FindProperty ("m_iTeamNum" ).OnUpdate (func (val st.PropertyValue ) {
@@ -279,6 +295,10 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
279295 }
280296 pl .IsDefusing = val .IntVal != 0
281297 })
298+
299+ if isNew && pl .SteamID != 0 {
300+ p .eventDispatcher .Dispatch (events.PlayerConnect {Player : pl })
301+ }
282302}
283303
284304func (p * Parser ) bindWeapons () {
0 commit comments