@@ -83,6 +83,8 @@ public partial class CoveServer
8383
8484 public List < string > WantedTags = new ( ) ;
8585
86+ public List < PreviousPlayer > PreviousPlayers = new ( ) ;
87+
8688 public void Init ( )
8789 {
8890 cbThread = new ( runSteamworksUpdate ) ;
@@ -347,6 +349,7 @@ public void Init()
347349 CSteamID userMakingChange = new CSteamID ( param . m_ulSteamIDMakingChange ) ;
348350
349351 EChatMemberStateChange stateChange = ( EChatMemberStateChange ) param . m_rgfChatMemberStateChange ;
352+ // Player joined the lobby
350353 if ( stateChange . HasFlag ( EChatMemberStateChange . k_EChatMemberStateChangeEntered ) )
351354 {
352355 string Username = SteamFriends . GetFriendPersonaName ( userChanged ) ;
@@ -357,6 +360,7 @@ public void Init()
357360 connectionsQueued . Add ( userChanged ) ;
358361 }
359362
363+ // Player left the lobby
360364 if ( stateChange . HasFlag ( EChatMemberStateChange . k_EChatMemberStateChangeLeft ) || stateChange . HasFlag ( EChatMemberStateChange . k_EChatMemberStateChangeDisconnected ) )
361365 {
362366 string Username = SteamFriends . GetFriendPersonaName ( userChanged ) ;
@@ -368,7 +372,7 @@ public void Init()
368372 // if player is in AllPlayers, remove them
369373 if ( ! connectionsQueued . Contains ( userChanged ) )
370374 {
371- WFPlayer player = AllPlayers . Find ( p => p . SteamId == userChanged ) ;
375+ var player = AllPlayers . Find ( p => p . SteamId == userChanged ) ;
372376 if ( player != null )
373377 {
374378 AllPlayers . Remove ( player ) ;
@@ -386,6 +390,21 @@ public void Init()
386390 // tell all plugins that the player left
387391 loadedPlugins . ForEach ( plugin => plugin . plugin . onPlayerLeave ( player ) ) ;
388392
393+ // find the previous player and update their state
394+ var previousPlayer = PreviousPlayers . Find ( p => p . SteamId == player . SteamId ) ;
395+ if ( previousPlayer != null )
396+ {
397+ previousPlayer . leftTimestamp = ( uint ) DateTimeOffset . UtcNow . ToUnixTimeSeconds ( ) ;
398+ previousPlayer . State = PlayerState . Left ;
399+ }
400+ else
401+ {
402+ // if the player is not in the previous players list, add them
403+ var p = PreviousPlayer . FromWFPlayer ( player ) ;
404+ PreviousPlayers . Add ( p ) ;
405+ p . leftTimestamp = ( uint ) DateTimeOffset . UtcNow . ToUnixTimeSeconds ( ) ;
406+ p . State = PlayerState . Left ;
407+ }
389408 }
390409 }
391410 }
@@ -468,6 +487,21 @@ out chatEntryType
468487 // make the player a wfplayer
469488 WFPlayer player = new WFPlayer ( userId , SteamFriends . GetFriendPersonaName ( userId ) , new SteamNetworkingIdentity ( ) ) ;
470489 AllPlayers . Add ( player ) ;
490+
491+ // if there is already a player with the same FisherID, remove them from the previous players list to prevent duplicates
492+ var sharedIDPrev = PreviousPlayers . Find ( p => p . FisherID == player . FisherID ) ;
493+ if ( sharedIDPrev != null )
494+ {
495+ PreviousPlayers . Remove ( sharedIDPrev ) ; // remove the previous player with the same FisherID
496+ }
497+
498+ var prev = PreviousPlayers . Find ( p => p . SteamId == userId ) ;
499+ if ( prev != null )
500+ {
501+ PreviousPlayers . Remove ( prev ) ; // remove the previous player if they are already in the list
502+ }
503+
504+ PreviousPlayers . Add ( PreviousPlayer . FromWFPlayer ( player ) ) ; // add the player to the previous players list
471505
472506 Dictionary < string , object > joinedPacket = new ( ) ;
473507 joinedPacket [ "type" ] = "user_joined_weblobby" ;
0 commit comments