using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace AllocsFixes.PersistentData { [Serializable] public class Players { public readonly Dictionary Dict = new Dictionary (StringComparer.OrdinalIgnoreCase); public Player this [string steamId, bool create] { get { if (string.IsNullOrEmpty (steamId)) { return null; } if (Dict.ContainsKey (steamId)) { return Dict [steamId]; } if (!create || steamId.Length != 17) { return null; } Log.Out ("Created new player entry for ID: " + steamId); Player p = new Player (steamId); Dict.Add (steamId, p); return p; } } public int Count { get { return Dict.Count; } } // public Player GetPlayerByNameOrId (string _nameOrId, bool _ignoreColorCodes) // { // string sid = GetSteamID (_nameOrId, _ignoreColorCodes); // if (sid != null) // return this [sid]; // else // return null; // } public string GetSteamID (string _nameOrId, bool _ignoreColorCodes) { if (_nameOrId == null || _nameOrId.Length == 0) { return null; } long tempLong; if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { return _nameOrId; } int entityId; if (int.TryParse (_nameOrId, out entityId)) { foreach (KeyValuePair kvp in Dict) { if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { return kvp.Key; } } } foreach (KeyValuePair kvp in Dict) { string name = kvp.Value.Name; if (_ignoreColorCodes) { name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); } if (kvp.Value.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) { return kvp.Key; } } return null; } } }