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

Last change on this file since 379 was 369, checked in by alloc, 3 years ago

Preparations for A20 release
Changes usage of "SteamID" to "UserID" in console commands
Also changes a bunch of the WebAPI stuff to show / use UserIDs

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