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