source: binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs@ 304

Last change on this file since 304 was 276, checked in by alloc, 9 years ago

fixes 8_11_13_1

File size: 2.0 KB
RevLine 
[253]1using System;
2using System.Collections.Generic;
3using System.Runtime.Serialization;
4using System.Text.RegularExpressions;
5
6namespace 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
Note: See TracBrowser for help on using the repository browser.