Changeset 446 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Jun 12, 2023, 3:21:34 PM (17 months ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/API.cs
r443 r446 23 23 24 24 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 25 PersistentContainer.Instance.Players [_cInfo.InternalId, true].Update (_cInfo, _playerDataFile);25 PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).Update (_cInfo, _playerDataFile); 26 26 } 27 27 … … 43 43 44 44 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 45 Player p = PersistentContainer.Instance.Players [_cInfo.InternalId, false];45 Player p = PersistentContainer.Instance.Players.GetByInternalId (_cInfo.InternalId); 46 46 if (p != null) { 47 47 p.SetOffline (); … … 54 54 55 55 public void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) { 56 PersistentContainer.Instance.Players [_cInfo.InternalId, true].SetOnline (_cInfo);56 PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).SetOnline (_cInfo); 57 57 PersistentContainer.Instance.Save (); 58 58 } -
binary-improvements/7dtd-server-fixes/src/LandClaimList.cs
r369 r446 41 41 42 42 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 43 Player p = PersistentContainer.Instance.Players [kvp.Key.UserIdentifier, false];43 Player p = PersistentContainer.Instance.Players.GetByInternalId (kvp.Key.UserIdentifier); 44 44 if (p == null) { 45 p = new Player (kvp.Key.UserIdentifier); 45 PlatformUserIdentifierAbs platformId = kvp.Key.PlatformUserIdentifier; 46 PlatformUserIdentifierAbs internalId = kvp.Key.UserIdentifier; 47 PlatformUserIdentifierAbs crossPlatformId = platformId.Equals (internalId) ? null : internalId; 48 p = new Player (internalId, platformId, crossPlatformId); 46 49 } 47 50 … … 68 71 69 72 public static OwnerFilter UserIdFilter (PlatformUserIdentifierAbs _userId) { 70 return _p => _p. PlatformId.Equals (_userId);73 return _p => _p.InternalId.Equals (_userId); 71 74 } 72 75 -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r443 r446 5 5 [Serializable] 6 6 public class Player { 7 private readonly PlatformUserIdentifierAbs platformId;8 7 private int entityId; 9 8 private string name; … … 26 25 [NonSerialized] private ClientInfo clientInfo; 27 26 28 public PlatformUserIdentifierAbs PlatformId => platformId; 27 public PlatformUserIdentifierAbs InternalId { get; } 28 public PlatformUserIdentifierAbs PlatformId { get; } 29 public PlatformUserIdentifierAbs CrossPlatformId { get; } 29 30 30 31 public int EntityID => entityId; … … 34 35 public string IP => ip ?? string.Empty; 35 36 36 public Inventory Inventory => inventory ?? (inventory = new Inventory ());37 public Inventory Inventory => inventory ??= new Inventory (); 37 38 38 39 public bool IsOnline => clientInfo != null; … … 58 59 public bool LandProtectionActive => 59 60 GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 60 .GetPersistentPlayerList ().GetPlayerData ( PlatformId));61 .GetPersistentPlayerList ().GetPlayerData (InternalId)); 61 62 62 63 public float LandProtectionMultiplier => 63 64 GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 64 .GetPersistentPlayerList ().GetPlayerData ( PlatformId));65 .GetPersistentPlayerList ().GetPlayerData (InternalId)); 65 66 66 67 public float Level { … … 107 108 } 108 109 109 public Player (PlatformUserIdentifierAbs _platformId) { 110 platformId = _platformId; 110 public Player (PlatformUserIdentifierAbs _internalId, PlatformUserIdentifierAbs _platformId, PlatformUserIdentifierAbs _crossPlatformId) { 111 InternalId = _internalId; 112 PlatformId = _platformId; 113 CrossPlatformId = _crossPlatformId; 111 114 inventory = new Inventory (); 112 115 } … … 117 120 } 118 121 119 Log.Out ("Player set to offline: " + platformId);122 Log.Out ("Player set to offline: " + InternalId); 120 123 lastOnline = DateTime.Now; 121 124 try { … … 133 136 134 137 public void SetOnline (ClientInfo _ci) { 135 Log.Out ("Player set to online: " + platformId);138 Log.Out ("Player set to online: " + InternalId); 136 139 clientInfo = _ci; 137 140 entityId = _ci.entityId; -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r369 r446 2 2 using System.Collections.Generic; 3 3 using System.Text.RegularExpressions; 4 using Platform.Steam;5 4 6 5 namespace AllocsFixes.PersistentData { … … 9 8 public readonly Dictionary<PlatformUserIdentifierAbs, Player> Dict = new Dictionary<PlatformUserIdentifierAbs, Player> (); 10 9 11 public Player this [PlatformUserIdentifierAbs _platformId, bool _create] { 12 get { 13 if (_platformId == null) { 14 return null; 15 } 10 public int Count => Dict.Count; 16 11 17 if (Dict.TryGetValue (_platformId, out Player pOld)) { 18 return pOld; 19 } 12 public Player GetOrCreate (PlatformUserIdentifierAbs _internalId, PlatformUserIdentifierAbs _platformId, PlatformUserIdentifierAbs _crossPlatformId) { 13 if (_internalId == null) { 14 return null; 15 } 20 16 21 if (!_create) {22 return null;23 17 if (Dict.TryGetValue (_internalId, out Player pOld)) { 18 return pOld; 19 } 24 20 25 Log.Out ("Created new player entry for ID: " + _platformId); 26 Player p = new Player (_platformId); 27 Dict.Add (_platformId, p); 28 return p; 29 } 21 Log.Out ("Created new player entry for ID: " + _internalId); 22 Player p = new Player (_internalId, _platformId, _crossPlatformId); 23 Dict.Add (_internalId, p); 24 return p; 30 25 } 31 26 32 public int Count => Dict.Count; 27 public Player GetByInternalId (PlatformUserIdentifierAbs _internalId) { 28 if (_internalId == null) { 29 return null; 30 } 33 31 34 public PlatformUserIdentifierAbs GetSteamID (string _nameOrId, bool _ignoreColorCodes) { 32 return Dict.TryGetValue (_internalId, out Player pOld) ? pOld : null; 33 } 34 35 public Player GetByUserId (PlatformUserIdentifierAbs _userId) { 36 foreach ((_, Player p) in Dict) { 37 if (p.PlatformId.Equals (_userId) || p.CrossPlatformId.Equals (_userId)) { 38 return p; 39 } 40 } 41 42 return null; 43 } 44 45 public Player GetByString (string _nameOrId, bool _ignoreColorCodes) { 35 46 if (string.IsNullOrEmpty (_nameOrId)) { 36 47 return null; … … 38 49 39 50 if (PlatformUserIdentifierAbs.TryFromCombinedString (_nameOrId, out PlatformUserIdentifierAbs userId)) { 40 return userId;51 return GetByUserId (userId); 41 52 } 42 53 43 54 if (int.TryParse (_nameOrId, out int entityId)) { 44 foreach ( KeyValuePair<PlatformUserIdentifierAbs, Player> kvpin Dict) {45 if ( kvp.Value.IsOnline && kvp.Value.EntityID == entityId) {46 return kvp.Key;55 foreach ((_, Player p) in Dict) { 56 if (p.IsOnline && p.EntityID == entityId) { 57 return p; 47 58 } 48 59 } 49 60 } 50 61 51 foreach ( KeyValuePair<PlatformUserIdentifierAbs, Player> kvpin Dict) {52 string name = kvp.Value.Name;62 foreach ((_, Player p) in Dict) { 63 string name = p.Name; 53 64 if (_ignoreColorCodes) { 54 65 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 55 66 } 56 67 57 if ( kvp.Value.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) {58 return kvp.Key;68 if (p.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) { 69 return p; 59 70 } 60 71 }
Note:
See TracChangeset
for help on using the changeset viewer.