[253] | 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 | private Dictionary<string, Player> players = new Dictionary<string, Player> ();
|
---|
| 11 |
|
---|
| 12 | public Player this [string steamId, bool create] {
|
---|
| 13 | get {
|
---|
[276] | 14 | if (string.IsNullOrEmpty (steamId)) {
|
---|
| 15 | return null;
|
---|
| 16 | } else if (players.ContainsKey (steamId)) {
|
---|
[253] | 17 | return players [steamId];
|
---|
| 18 | } else {
|
---|
| 19 | if (create && steamId != null && steamId.Length == 17) {
|
---|
| 20 | Log.Out ("Created new player entry for ID: " + steamId);
|
---|
| 21 | Player p = new Player (steamId);
|
---|
| 22 | players.Add (steamId, p);
|
---|
| 23 | return p;
|
---|
| 24 | }
|
---|
| 25 | return null;
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public List<string> SteamIDs {
|
---|
| 31 | get { return new List<string> (players.Keys); }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public int Count {
|
---|
| 35 | get { return players.Count; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | // public Player GetPlayerByNameOrId (string _nameOrId, bool _ignoreColorCodes)
|
---|
| 39 | // {
|
---|
| 40 | // string sid = GetSteamID (_nameOrId, _ignoreColorCodes);
|
---|
| 41 | // if (sid != null)
|
---|
| 42 | // return this [sid];
|
---|
| 43 | // else
|
---|
| 44 | // return null;
|
---|
| 45 | // }
|
---|
| 46 |
|
---|
| 47 | public string GetSteamID (string _nameOrId, bool _ignoreColorCodes) {
|
---|
| 48 | if (_nameOrId == null || _nameOrId.Length == 0) {
|
---|
| 49 | return null;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | long tempLong;
|
---|
| 53 | if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) {
|
---|
| 54 | return _nameOrId;
|
---|
| 55 | } else {
|
---|
| 56 | int entityId = -1;
|
---|
| 57 | if (int.TryParse (_nameOrId, out entityId)) {
|
---|
| 58 | foreach (KeyValuePair<string, Player> kvp in players) {
|
---|
| 59 | if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) {
|
---|
| 60 | return kvp.Key;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | _nameOrId = _nameOrId.ToLower ();
|
---|
| 66 | foreach (KeyValuePair<string, Player> kvp in players) {
|
---|
| 67 | string name = kvp.Value.Name.ToLower ();
|
---|
| 68 | if (_ignoreColorCodes) {
|
---|
| 69 | name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", "");
|
---|
| 70 | }
|
---|
| 71 | if (kvp.Value.IsOnline && name.Equals (_nameOrId)) {
|
---|
| 72 | return kvp.Key;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | return null;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|