- Timestamp:
- Jun 12, 2023, 3:21:34 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.