- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r351 r369 2 2 using System.Collections.Generic; 3 3 using System.Text.RegularExpressions; 4 using Platform.Steam; 4 5 5 6 namespace AllocsFixes.PersistentData { 6 7 [Serializable] 7 8 public class Players { 8 public readonly Dictionary< string, Player> Dict = new Dictionary<string, Player> (StringComparer.OrdinalIgnoreCase);9 public readonly Dictionary<PlatformUserIdentifierAbs, Player> Dict = new Dictionary<PlatformUserIdentifierAbs, Player> (); 9 10 10 public Player this [ string _steamId, bool _create] {11 public Player this [PlatformUserIdentifierAbs _platformId, bool _create] { 11 12 get { 12 if ( string.IsNullOrEmpty (_steamId)) {13 if (_platformId == null) { 13 14 return null; 14 15 } 15 16 16 if (Dict. ContainsKey (_steamId)) {17 return Dict [_steamId];17 if (Dict.TryGetValue (_platformId, out Player pOld)) { 18 return pOld; 18 19 } 19 20 20 if (!_create || _steamId.Length != 17) {21 if (!_create) { 21 22 return null; 22 23 } 23 24 24 Log.Out ("Created new player entry for ID: " + _ steamId);25 Player p = new Player (_ steamId);26 Dict.Add (_ steamId, p);25 Log.Out ("Created new player entry for ID: " + _platformId); 26 Player p = new Player (_platformId); 27 Dict.Add (_platformId, p); 27 28 return p; 28 29 } 29 30 } 30 31 31 public int Count { 32 get { return Dict.Count; } 33 } 32 public int Count => Dict.Count; 34 33 35 // public Player GetPlayerByNameOrId (string _nameOrId, bool _ignoreColorCodes) 36 // { 37 // string sid = GetSteamID (_nameOrId, _ignoreColorCodes); 38 // if (sid != null) 39 // return this [sid]; 40 // else 41 // return null; 42 // } 43 44 public string GetSteamID (string _nameOrId, bool _ignoreColorCodes) { 45 if (_nameOrId == null || _nameOrId.Length == 0) { 34 public PlatformUserIdentifierAbs GetSteamID (string _nameOrId, bool _ignoreColorCodes) { 35 if (string.IsNullOrEmpty (_nameOrId)) { 46 36 return null; 47 37 } 48 38 49 long tempLong; 50 if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { 51 return _nameOrId; 39 if (PlatformUserIdentifierAbs.TryFromCombinedString (_nameOrId, out PlatformUserIdentifierAbs userId)) { 40 return userId; 52 41 } 53 42 54 int entityId; 55 if (int.TryParse (_nameOrId, out entityId)) { 56 foreach (KeyValuePair<string, Player> kvp in Dict) { 43 if (int.TryParse (_nameOrId, out int entityId)) { 44 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in Dict) { 57 45 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { 58 46 return kvp.Key; … … 61 49 } 62 50 63 foreach (KeyValuePair< string, Player> kvp in Dict) {51 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in Dict) { 64 52 string name = kvp.Value.Name; 65 53 if (_ignoreColorCodes) {
Note:
See TracChangeset
for help on using the changeset viewer.