- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r276 r325 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Runtime.Serialization;4 3 using System.Text.RegularExpressions; 5 4 6 namespace AllocsFixes.PersistentData 7 { 5 namespace AllocsFixes.PersistentData { 8 6 [Serializable] 9 7 public class Players { 10 private Dictionary<string, Player> players = new Dictionary<string, Player> ();8 private readonly Dictionary<string, Player> players = new Dictionary<string, Player> (); 11 9 12 10 public Player this [string steamId, bool create] { … … 14 12 if (string.IsNullOrEmpty (steamId)) { 15 13 return null; 16 } else if (players.ContainsKey (steamId)) { 14 } 15 16 if (players.ContainsKey (steamId)) { 17 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 18 } 19 20 if (create && steamId != null && steamId.Length == 17) { 21 Log.Out ("Created new player entry for ID: " + steamId); 22 Player p = new Player (steamId); 23 players.Add (steamId, p); 24 return p; 25 } 26 27 return null; 27 28 } 28 29 } … … 53 54 if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { 54 55 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 } 56 } 64 57 65 _nameOrId = _nameOrId.ToLower (); 58 int entityId = -1; 59 if (int.TryParse (_nameOrId, out entityId)) { 66 60 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)) { 61 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { 72 62 return kvp.Key; 73 63 } 74 64 } 75 65 } 66 67 _nameOrId = _nameOrId.ToLower (); 68 foreach (KeyValuePair<string, Player> kvp in players) { 69 string name = kvp.Value.Name.ToLower (); 70 if (_ignoreColorCodes) { 71 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 72 } 73 74 if (kvp.Value.IsOnline && name.Equals (_nameOrId)) { 75 return kvp.Key; 76 } 77 } 78 76 79 return null; 77 80 } 78 81 } 79 82 } 80
Note:
See TracChangeset
for help on using the changeset viewer.