| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Runtime.Serialization;
|
|---|
| 4 | using System.Text.RegularExpressions;
|
|---|
| 5 |
|
|---|
| 6 | namespace AllocsFixes.PersistentData
|
|---|
| 7 | {
|
|---|
| 8 | [Serializable]
|
|---|
| 9 | public class Players
|
|---|
| 10 | {
|
|---|
| 11 | private Dictionary<string, Player> players = new Dictionary<string, Player> ();
|
|---|
| 12 |
|
|---|
| 13 | public Player this [string steamId] {
|
|---|
| 14 | get {
|
|---|
| 15 | if (players.ContainsKey (steamId))
|
|---|
| 16 | return players [steamId];
|
|---|
| 17 | else {
|
|---|
| 18 | if (steamId != null && steamId.Length == 17) {
|
|---|
| 19 | Log.Out ("Created new player entry for ID: " + steamId);
|
|---|
| 20 | Player p = new Player (steamId);
|
|---|
| 21 | players.Add (steamId, p);
|
|---|
| 22 | return p;
|
|---|
| 23 | }
|
|---|
| 24 | return null;
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | public List<string> SteamIDs {
|
|---|
| 30 | get { return new List<string> (players.Keys); }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | public int Count {
|
|---|
| 34 | get { return players.Count; }
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | public string GetSteamID (string _nameOrId, bool _ignoreColorCodes)
|
|---|
| 38 | {
|
|---|
| 39 | if (_nameOrId == null || _nameOrId.Length == 0)
|
|---|
| 40 | return null;
|
|---|
| 41 |
|
|---|
| 42 | long tempLong;
|
|---|
| 43 | if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) {
|
|---|
| 44 | return _nameOrId;
|
|---|
| 45 | } else {
|
|---|
| 46 | int entityId = -1;
|
|---|
| 47 | if (int.TryParse (_nameOrId, out entityId)) {
|
|---|
| 48 | foreach (KeyValuePair<string, Player> kvp in players) {
|
|---|
| 49 | if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) {
|
|---|
| 50 | return kvp.Key;
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | _nameOrId = _nameOrId.ToLower ();
|
|---|
| 56 | foreach (KeyValuePair<string, Player> kvp in players) {
|
|---|
| 57 | string name = kvp.Value.Name.ToLower ();
|
|---|
| 58 | if (_ignoreColorCodes) {
|
|---|
| 59 | name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", "");
|
|---|
| 60 | }
|
|---|
| 61 | if (kvp.Value.IsOnline && name.Equals (_nameOrId)) {
|
|---|
| 62 | return kvp.Key;
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | return null;
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|