@@ -82,6 +82,8 @@ public partial class CoveServer
8282
8383 public List < string > WantedTags = new ( ) ;
8484
85+ public List < PreviousPlayer > PreviousPlayers = new ( ) ;
86+
8587 public void Init ( )
8688 {
8789 cbThread = new ( runSteamworksUpdate ) ;
@@ -346,6 +348,7 @@ public void Init()
346348 CSteamID userMakingChange = new CSteamID ( param . m_ulSteamIDMakingChange ) ;
347349
348350 EChatMemberStateChange stateChange = ( EChatMemberStateChange ) param . m_rgfChatMemberStateChange ;
351+ // Player joined the lobby
349352 if ( stateChange . HasFlag ( EChatMemberStateChange . k_EChatMemberStateChangeEntered ) )
350353 {
351354 string Username = SteamFriends . GetFriendPersonaName ( userChanged ) ;
@@ -356,6 +359,7 @@ public void Init()
356359 connectionsQueued . Add ( userChanged ) ;
357360 }
358361
362+ // Player left the lobby
359363 if ( stateChange . HasFlag ( EChatMemberStateChange . k_EChatMemberStateChangeLeft ) || stateChange . HasFlag ( EChatMemberStateChange . k_EChatMemberStateChangeDisconnected ) )
360364 {
361365 string Username = SteamFriends . GetFriendPersonaName ( userChanged ) ;
@@ -367,7 +371,7 @@ public void Init()
367371 // if player is in AllPlayers, remove them
368372 if ( ! connectionsQueued . Contains ( userChanged ) )
369373 {
370- WFPlayer player = AllPlayers . Find ( p => p . SteamId == userChanged ) ;
374+ var player = AllPlayers . Find ( p => p . SteamId == userChanged ) ;
371375 if ( player != null )
372376 {
373377 AllPlayers . Remove ( player ) ;
@@ -385,6 +389,21 @@ public void Init()
385389 // tell all plugins that the player left
386390 loadedPlugins . ForEach ( plugin => plugin . plugin . onPlayerLeave ( player ) ) ;
387391
392+ // find the previous player and update their state
393+ var previousPlayer = PreviousPlayers . Find ( p => p . SteamId == player . SteamId ) ;
394+ if ( previousPlayer != null )
395+ {
396+ previousPlayer . leftTimestamp = ( uint ) DateTimeOffset . UtcNow . ToUnixTimeSeconds ( ) ;
397+ previousPlayer . State = PlayerState . Left ;
398+ }
399+ else
400+ {
401+ // if the player is not in the previous players list, add them
402+ var p = PreviousPlayer . FromWFPlayer ( player ) ;
403+ PreviousPlayers . Add ( p ) ;
404+ p . leftTimestamp = ( uint ) DateTimeOffset . UtcNow . ToUnixTimeSeconds ( ) ;
405+ p . State = PlayerState . Left ;
406+ }
388407 }
389408 }
390409 }
@@ -467,6 +486,21 @@ out chatEntryType
467486 // make the player a wfplayer
468487 WFPlayer player = new WFPlayer ( userId , SteamFriends . GetFriendPersonaName ( userId ) , new SteamNetworkingIdentity ( ) ) ;
469488 AllPlayers . Add ( player ) ;
489+
490+ // if there is already a player with the same FisherID, remove them from the previous players list to prevent duplicates
491+ var sharedIDPrev = PreviousPlayers . Find ( p => p . FisherID == player . FisherID ) ;
492+ if ( sharedIDPrev != null )
493+ {
494+ PreviousPlayers . Remove ( sharedIDPrev ) ; // remove the previous player with the same FisherID
495+ }
496+
497+ var prev = PreviousPlayers . Find ( p => p . SteamId == userId ) ;
498+ if ( prev != null )
499+ {
500+ PreviousPlayers . Remove ( prev ) ; // remove the previous player if they are already in the list
501+ }
502+
503+ PreviousPlayers . Add ( PreviousPlayer . FromWFPlayer ( player ) ) ; // add the player to the previous players list
470504
471505 Dictionary < string , object > joinedPacket = new ( ) ;
472506 joinedPacket [ "type" ] = "user_joined_weblobby" ;
0 commit comments