source: binary-improvements2/7dtd-server-fixes/src/PersistentData/Players.cs@ 383

Last change on this file since 383 was 383, checked in by alloc, 2 years ago

Fixed a bunch of warnings

File size: 1.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text.RegularExpressions;
4
5namespace AllocsFixes.PersistentData {
6 [Serializable]
7 public class Players {
8 public readonly Dictionary<PlatformUserIdentifierAbs, Player> Dict = new Dictionary<PlatformUserIdentifierAbs, Player> ();
9
10 public Player this [PlatformUserIdentifierAbs _platformId, bool _create] {
11 get {
12 if (_platformId == null) {
13 return null;
14 }
15
16 if (Dict.TryGetValue (_platformId, out Player pOld)) {
17 return pOld;
18 }
19
20 if (!_create) {
21 return null;
22 }
23
24 Log.Out ("Created new player entry for ID: " + _platformId);
25 Player p = new Player (_platformId);
26 Dict.Add (_platformId, p);
27 return p;
28 }
29 }
30
31 public int Count => Dict.Count;
32
33 public PlatformUserIdentifierAbs GetSteamID (string _nameOrId, bool _ignoreColorCodes) {
34 if (string.IsNullOrEmpty (_nameOrId)) {
35 return null;
36 }
37
38 if (PlatformUserIdentifierAbs.TryFromCombinedString (_nameOrId, out PlatformUserIdentifierAbs userId)) {
39 return userId;
40 }
41
42 if (int.TryParse (_nameOrId, out int entityId)) {
43 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in Dict) {
44 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) {
45 return kvp.Key;
46 }
47 }
48 }
49
50 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in Dict) {
51 string name = kvp.Value.Name;
52 if (_ignoreColorCodes) {
53 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", "");
54 }
55
56 if (kvp.Value.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) {
57 return kvp.Key;
58 }
59 }
60
61 return null;
62 }
63 }
64}
Note: See TracBrowser for help on using the repository browser.