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

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