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

Last change on this file since 158 was 156, checked in by alloc, 10 years ago

fixes

File size: 1.8 KB
RevLine 
[144]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 {
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
[146]33 public int Count {
34 get { return players.Count; }
35 }
36
[156]37 public Player GetPlayerByClientId (int _clientid)
38 {
39 foreach (Player p in players.Values) {
40 if (p.ClientInfo.clientId == _clientid) {
41 return p;
42 }
43 }
44 return null;
45 }
46
[144]47 public string GetSteamID (string _nameOrId, bool _ignoreColorCodes)
48 {
49 if (_nameOrId == null || _nameOrId.Length == 0)
50 return null;
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 }
[145]63 }
[144]64
[145]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}\\]", "");
[144]70 }
[145]71 if (kvp.Value.IsOnline && name.Equals (_nameOrId)) {
72 return kvp.Key;
73 }
[144]74 }
75 }
76 return null;
77 }
78 }
79}
80
Note: See TracBrowser for help on using the repository browser.