Changeset 369
- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- Location:
- binary-improvements
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/API.cs
r354 r369 1 1 using System.Collections.Generic; 2 2 using AllocsFixes.PersistentData; 3 using System;3 using Platform.Steam; 4 4 5 5 namespace AllocsFixes { 6 6 public class API : IModApi { 7 public void InitMod ( ) {7 public void InitMod (Mod _modInstance) { 8 8 ModEvents.GameStartDone.RegisterHandler (GameAwake); 9 9 ModEvents.GameShutdown.RegisterHandler (GameShutdown); … … 16 16 17 17 public void GameAwake () { 18 try { 19 PersistentContainer.Load (); 20 } catch (Exception e) { 21 Log.Out ("Error in StateManager.Awake: " + e); 22 } 18 PersistentContainer.Load (); 23 19 } 24 20 25 21 public void GameShutdown () { 26 try {27 Log.Out ("Server shutting down!");28 PersistentContainer.Instance.Save ();29 } catch (Exception e) {30 Log.Out ("Error in StateManager.Shutdown: " + e);31 }32 22 } 33 23 34 24 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 35 try { 36 PersistentContainer.Instance.Players [_cInfo.playerId, true].Update (_playerDataFile); 37 } catch (Exception e) { 38 Log.Out ("Error in GM_SavePlayerData: " + e); 39 } 25 PersistentContainer.Instance.Players [_cInfo.PlatformId, true].Update (_playerDataFile); 40 26 } 41 27 42 28 public void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 43 try { 44 Log.Out ("Player connected" + 45 ", entityid=" + _cInfo.entityId + 46 ", name=" + _cInfo.playerName + 47 ", steamid=" + _cInfo.playerId + 48 ", steamOwner=" + _cInfo.ownerId + 49 ", ip=" + _cInfo.ip 50 ); 51 } catch (Exception e) { 52 Log.Out ("Error in AllocsLogFunctions.RequestToSpawnPlayer: " + e); 29 string owner = null; 30 if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) { 31 owner = identifierSteam.OwnerId.ToString (); 53 32 } 33 34 Log.Out ("Player connected" + 35 ", entityid=" + _cInfo.entityId + 36 ", name=" + _cInfo.playerName + 37 ", pltfmid=" + (_cInfo.PlatformId?.CombinedString ?? "<unknown>") + 38 ", crossid=" + (_cInfo.CrossplatformId?.CombinedString ?? "<unknown/none>") + 39 ", steamOwner=" + (owner ?? "<unknown/none>") + 40 ", ip=" + _cInfo.ip 41 ); 54 42 } 55 43 56 44 public void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 57 try { 58 Player p = PersistentContainer.Instance.Players [_cInfo.playerId, false]; 59 if (p != null) { 60 p.SetOffline (); 61 } else { 62 Log.Out ("Disconnected player not found in client list..."); 63 } 45 Player p = PersistentContainer.Instance.Players [_cInfo.PlatformId, false]; 46 if (p != null) { 47 p.SetOffline (); 48 } else { 49 Log.Out ("Disconnected player not found in client list..."); 50 } 64 51 65 PersistentContainer.Instance.Save (); 66 } catch (Exception e) { 67 Log.Out ("Error in AllocsLogFunctions.PlayerDisconnected: " + e); 68 } 52 PersistentContainer.Instance.Save (); 69 53 } 70 54 71 55 public void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) { 72 try { 73 PersistentContainer.Instance.Players [_cInfo.playerId, true].SetOnline (_cInfo); 74 PersistentContainer.Instance.Save (); 75 } catch (Exception e) { 76 Log.Out ("Error in AllocsLogFunctions.PlayerSpawnedInWorld: " + e); 77 } 56 PersistentContainer.Instance.Players [_cInfo.PlatformId, true].SetOnline (_cInfo); 57 PersistentContainer.Instance.Save (); 78 58 } 79 59 … … 88 68 89 69 if (_cInfo != null) { 90 Log.Out ("Sent chat hook reply to {0}", _cInfo. playerId);70 Log.Out ("Sent chat hook reply to {0}", _cInfo.InternalId); 91 71 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, ANSWER, "", false, null)); 92 72 } else { -
binary-improvements/7dtd-server-fixes/src/LandClaimList.cs
r351 r369 4 4 5 5 namespace AllocsFixes { 6 public class LandClaimList {6 public static class LandClaimList { 7 7 public delegate bool OwnerFilter (Player _owner); 8 8 … … 41 41 42 42 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 43 Player p = PersistentContainer.Instance.Players [kvp.Key. PlayerId, false];43 Player p = PersistentContainer.Instance.Players [kvp.Key.UserIdentifier, false]; 44 44 if (p == null) { 45 p = new Player (kvp.Key. PlayerId);45 p = new Player (kvp.Key.UserIdentifier); 46 46 } 47 47 … … 67 67 } 68 68 69 public static OwnerFilter SteamIdFilter (string _steamId) {70 return _p => _p. SteamID.Equals (_steamId);69 public static OwnerFilter UserIdFilter (PlatformUserIdentifierAbs _userId) { 70 return _p => _p.PlatformId.Equals (_userId); 71 71 } 72 72 -
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r326 r369 46 46 47 47 public void Save () { 48 Stream stream = File.Open (Game Utils.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Create);48 Stream stream = File.Open (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Create); 49 49 BinaryFormatter bFormatter = new BinaryFormatter (); 50 50 bFormatter.Serialize (stream, this); … … 53 53 54 54 public static bool Load () { 55 if (!File.Exists (Game Utils.GetSaveGameDir () + "/AllocsPeristentData.bin")) {55 if (!File.Exists (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin")) { 56 56 return false; 57 57 } … … 59 59 try { 60 60 PersistentContainer obj; 61 Stream stream = File.Open (Game Utils.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open);61 Stream stream = File.Open (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 62 62 BinaryFormatter bFormatter = new BinaryFormatter (); 63 63 obj = (PersistentContainer) bFormatter.Deserialize (stream); -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r351 r369 1 1 using System; 2 using System.Runtime.Serialization;3 2 using UnityEngine; 4 3 … … 6 5 [Serializable] 7 6 public class Player { 8 private readonly string steamId;7 private readonly PlatformUserIdentifierAbs platformId; 9 8 private int entityId; 10 9 private string name; … … 12 11 private long totalPlayTime; 13 12 14 [OptionalField]private DateTime lastOnline;13 private DateTime lastOnline; 15 14 16 15 private Inventory inventory; 17 16 18 [OptionalField]private int lastPositionX, lastPositionY, lastPositionZ;17 private int lastPositionX, lastPositionY, lastPositionZ; 19 18 20 [OptionalField] [Obsolete ("experience no longer available, use level and expToNextLevel instead")] 21 private uint experience; 22 23 [OptionalField] private bool chatMuted; 24 [OptionalField] private int maxChatLength; 25 [OptionalField] private string chatColor; 26 [OptionalField] private bool chatName; 27 [OptionalField] private uint expToNextLevel; 28 [OptionalField] private int level; 19 private bool chatMuted; 20 private int maxChatLength; 21 private string chatColor; 22 private bool chatName; 23 private uint expToNextLevel; 24 private int level; 29 25 30 26 [NonSerialized] private ClientInfo clientInfo; 31 27 32 public string SteamID { 33 get { return steamId; } 34 } 28 public PlatformUserIdentifierAbs PlatformId => platformId; 35 29 36 public int EntityID { 37 get { return entityId; } 38 } 30 public int EntityID => entityId; 39 31 40 public string Name { 41 get { return name == null ? string.Empty : name; } 42 } 32 public string Name => name ?? string.Empty; 43 33 44 public string IP { 45 get { return ip == null ? string.Empty : ip; } 46 } 34 public string IP => ip ?? string.Empty; 47 35 48 public Inventory Inventory { 49 get { 50 if (inventory == null) { 51 inventory = new Inventory (); 52 } 36 public Inventory Inventory => inventory ?? (inventory = new Inventory ()); 53 37 54 return inventory; 55 } 56 } 38 public bool IsOnline => clientInfo != null; 57 39 58 public bool IsOnline { 59 get { return clientInfo != null; } 60 } 40 public ClientInfo ClientInfo => clientInfo; 61 41 62 public ClientInfo ClientInfo { 63 get { return clientInfo; } 64 } 65 66 public EntityPlayer Entity { 67 get { 68 if (IsOnline) { 69 return GameManager.Instance.World.Players.dict [clientInfo.entityId]; 70 } 71 72 return null; 73 } 74 } 42 public EntityPlayer Entity => IsOnline ? GameManager.Instance.World.Players.dict [clientInfo.entityId] : null; 75 43 76 44 public long TotalPlayTime { … … 84 52 } 85 53 86 public DateTime LastOnline { 87 get { 88 if (IsOnline) { 89 return DateTime.Now; 90 } 54 public DateTime LastOnline => IsOnline ? DateTime.Now : lastOnline; 91 55 92 return lastOnline; 93 } 94 } 56 public Vector3i LastPosition => IsOnline ? new Vector3i (Entity.GetPosition ()) : new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 95 57 96 public Vector3i LastPosition { 97 get { 98 if (IsOnline) { 99 return new Vector3i (Entity.GetPosition ()); 100 } 58 public bool LandProtectionActive => 59 GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 60 .GetPersistentPlayerList ().GetPlayerData (PlatformId)); 101 61 102 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 103 } 104 } 105 106 public bool LandProtectionActive { 107 get { 108 return GameManager.Instance.World.IsLandProtectionValidForPlayer (GameManager.Instance 109 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 110 } 111 } 112 113 public float LandProtectionMultiplier { 114 get { 115 return GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 116 .GetPersistentPlayerList ().GetPlayerData (SteamID)); 117 } 118 } 119 120 121 [Obsolete ("Experience no longer available, use Level instead")] 122 public uint Experience { 123 get { return 0; } 124 } 62 public float LandProtectionMultiplier => 63 GameManager.Instance.World.GetLandProtectionHardnessModifierForPlayer (GameManager.Instance 64 .GetPersistentPlayerList ().GetPlayerData (PlatformId)); 125 65 126 66 public float Level { … … 135 75 136 76 public bool IsChatMuted { 137 get { return chatMuted; }138 set { chatMuted = value; }77 get => chatMuted; 78 set => chatMuted = value; 139 79 } 140 80 … … 147 87 return maxChatLength; 148 88 } 149 set { maxChatLength = value; }89 set => maxChatLength = value; 150 90 } 151 91 152 92 public string ChatColor { 153 93 get { 154 if ( chatColor == null || chatColor == "") {94 if (string.IsNullOrEmpty (chatColor)) { 155 95 chatColor = ""; 156 96 } … … 159 99 } 160 100 161 set { chatColor = value; }101 set => chatColor = value; 162 102 } 163 103 164 104 public bool ChatName { 165 get { return chatName; } 166 167 set { chatName = value; } 105 get => chatName; 106 set => chatName = value; 168 107 } 169 108 170 public Player ( string _steamId) {171 steamId = _steamId;109 public Player (PlatformUserIdentifierAbs _platformId) { 110 platformId = _platformId; 172 111 inventory = new Inventory (); 173 112 } … … 178 117 } 179 118 180 Log.Out ("Player set to offline: " + steamId);119 Log.Out ("Player set to offline: " + platformId); 181 120 lastOnline = DateTime.Now; 182 121 try { … … 194 133 195 134 public void SetOnline (ClientInfo _ci) { 196 Log.Out ("Player set to online: " + steamId);135 Log.Out ("Player set to online: " + platformId); 197 136 clientInfo = _ci; 198 137 entityId = _ci.entityId; … … 222 161 } 223 162 } 163 224 164 } 225 165 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r351 r369 2 2 using System.Collections.Generic; 3 3 using System.Text.RegularExpressions; 4 using Platform.Steam; 4 5 5 6 namespace AllocsFixes.PersistentData { 6 7 [Serializable] 7 8 public class Players { 8 public readonly Dictionary< string, Player> Dict = new Dictionary<string, Player> (StringComparer.OrdinalIgnoreCase);9 public readonly Dictionary<PlatformUserIdentifierAbs, Player> Dict = new Dictionary<PlatformUserIdentifierAbs, Player> (); 9 10 10 public Player this [ string _steamId, bool _create] {11 public Player this [PlatformUserIdentifierAbs _platformId, bool _create] { 11 12 get { 12 if ( string.IsNullOrEmpty (_steamId)) {13 if (_platformId == null) { 13 14 return null; 14 15 } 15 16 16 if (Dict. ContainsKey (_steamId)) {17 return Dict [_steamId];17 if (Dict.TryGetValue (_platformId, out Player pOld)) { 18 return pOld; 18 19 } 19 20 20 if (!_create || _steamId.Length != 17) {21 if (!_create) { 21 22 return null; 22 23 } 23 24 24 Log.Out ("Created new player entry for ID: " + _ steamId);25 Player p = new Player (_ steamId);26 Dict.Add (_ steamId, p);25 Log.Out ("Created new player entry for ID: " + _platformId); 26 Player p = new Player (_platformId); 27 Dict.Add (_platformId, p); 27 28 return p; 28 29 } 29 30 } 30 31 31 public int Count { 32 get { return Dict.Count; } 33 } 32 public int Count => Dict.Count; 34 33 35 // public Player GetPlayerByNameOrId (string _nameOrId, bool _ignoreColorCodes) 36 // { 37 // string sid = GetSteamID (_nameOrId, _ignoreColorCodes); 38 // if (sid != null) 39 // return this [sid]; 40 // else 41 // return null; 42 // } 43 44 public string GetSteamID (string _nameOrId, bool _ignoreColorCodes) { 45 if (_nameOrId == null || _nameOrId.Length == 0) { 34 public PlatformUserIdentifierAbs GetSteamID (string _nameOrId, bool _ignoreColorCodes) { 35 if (string.IsNullOrEmpty (_nameOrId)) { 46 36 return null; 47 37 } 48 38 49 long tempLong; 50 if (_nameOrId.Length == 17 && long.TryParse (_nameOrId, out tempLong)) { 51 return _nameOrId; 39 if (PlatformUserIdentifierAbs.TryFromCombinedString (_nameOrId, out PlatformUserIdentifierAbs userId)) { 40 return userId; 52 41 } 53 42 54 int entityId; 55 if (int.TryParse (_nameOrId, out entityId)) { 56 foreach (KeyValuePair<string, Player> kvp in Dict) { 43 if (int.TryParse (_nameOrId, out int entityId)) { 44 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in Dict) { 57 45 if (kvp.Value.IsOnline && kvp.Value.EntityID == entityId) { 58 46 return kvp.Key; … … 61 49 } 62 50 63 foreach (KeyValuePair< string, Player> kvp in Dict) {51 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in Dict) { 64 52 string name = kvp.Value.Name; 65 53 if (_ignoreColorCodes) { -
binary-improvements/AllocsCommands/API.cs
r328 r369 1 1 namespace AllocsFixes.CustomCommands { 2 2 public class API : IModApi { 3 public void InitMod ( ) {3 public void InitMod (Mod _modInstance) { 4 4 } 5 5 } -
binary-improvements/AllocsCommands/Commands/ListKnownPlayers.cs
r359 r369 1 using System;2 1 using System.Collections.Generic; 3 2 using AllocsFixes.PersistentData; … … 14 13 " 2. listknownplayers -online\n" + 15 14 " 3. listknownplayers -notbanned\n" + 16 " 4. listknownplayers <player name / steamid>\n" +15 " 4. listknownplayers <player name / userid>\n" + 17 16 "1. Lists all players that have ever been online\n" + 18 17 "2. Lists only the players that are currently online\n" + 19 18 "3. Lists only the players that are not banned\n" + 20 "4. Lists all players whose name contains the given string or matches the given SteamID";19 "4. Lists all players whose name contains the given string or matches the given UserID"; 21 20 } 22 21 … … 31 30 bool notBannedOnly = false; 32 31 string nameFilter = string.Empty; 33 bool isSteamId = false;32 PlatformUserIdentifierAbs userIdFilter = null; 34 33 35 34 if (_params.Count == 1) { 36 long steamid;37 35 if (_params [0].EqualsCaseInsensitive ("-online")) { 38 36 onlineOnly = true; 39 37 } else if (_params [0].EqualsCaseInsensitive ("-notbanned")) { 40 38 notBannedOnly = true; 41 } else if ( _params [0].Length == 17 && long.TryParse (_params [0], out steamid)) {42 isSteamId = true;39 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params [0], out userIdFilter)) { 40 // if true nothing to do, set by the out parameter 43 41 } else { 44 42 nameFilter = _params [0]; … … 46 44 } 47 45 48 if ( isSteamId) {49 Player p = PersistentContainer.Instance.Players [ _params [0], false];46 if (userIdFilter != null) { 47 Player p = PersistentContainer.Instance.Players [userIdFilter, false]; 50 48 51 49 if (p != null) { 52 SdtdConsole.Instance.Output (string.Format ( 53 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}", 54 0, p.Name, p.EntityID, _params [0], p.IsOnline, p.IP, 55 p.TotalPlayTime / 60, 56 p.LastOnline.ToString ("yyyy-MM-dd HH:mm")) 50 SdtdConsole.Instance.Output ( 51 $"{0}. {p.Name}, id={p.EntityID}, steamid={_params [0]}, online={p.IsOnline}, ip={p.IP}, playtime={p.TotalPlayTime / 60} m, seen={p.LastOnline:yyyy-MM-dd HH:mm}" 57 52 ); 58 53 } else { 59 SdtdConsole.Instance.Output ( string.Format ("SteamID {0} unknown!", _params [0]));54 SdtdConsole.Instance.Output ($"SteamID {_params [0]} unknown!"); 60 55 } 61 56 } else { 62 57 int num = 0; 63 foreach (KeyValuePair< string, Player> kvp in PersistentContainer.Instance.Players.Dict) {58 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) { 64 59 Player p = kvp.Value; 65 60 66 61 if ( 67 62 (!onlineOnly || p.IsOnline) 68 && (!notBannedOnly || !admTools.IsBanned (kvp.Key ))63 && (!notBannedOnly || !admTools.IsBanned (kvp.Key, out _, out _)) 69 64 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter)) 70 65 ) { 71 SdtdConsole.Instance.Output (string.Format ( 72 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}", 73 ++num, p.Name, p.EntityID, kvp.Key, p.IsOnline, p.IP, 74 p.TotalPlayTime / 60, 75 p.LastOnline.ToString ("yyyy-MM-dd HH:mm")) 66 SdtdConsole.Instance.Output ( 67 $"{++num}. {p.Name}, id={p.EntityID}, steamid={kvp.Key}, online={p.IsOnline}, ip={p.IP}, playtime={p.TotalPlayTime / 60} m, seen={p.LastOnline:yyyy-MM-dd HH:mm}" 76 68 ); 77 69 } 78 70 } 79 71 80 SdtdConsole.Instance.Output ( "Total of " + PersistentContainer.Instance.Players.Count + "known");72 SdtdConsole.Instance.Output ($"Total of {PersistentContainer.Instance.Players.Count} known"); 81 73 } 82 74 } -
binary-improvements/AllocsCommands/Commands/ListLandProtection.cs
r359 r369 12 12 return "Usage:\n" + 13 13 " 1. listlandprotection summary\n" + 14 " 2. listlandprotection < steamid / player name / entity id> [parseable]\n" +14 " 2. listlandprotection <user id / player name / entity id> [parseable]\n" + 15 15 " 3. listlandprotection nearby [length]\n" + 16 16 "1. Lists only players that own claimstones, the number they own and the protection status\n" + 17 "2. Lists only the claims of the player given by his SteamID / entity id / playername, including the individual claim positions.\n" +17 "2. Lists only the claims of the player given by his UserID / entity id / playername, including the individual claim positions.\n" + 18 18 " If \"parseable\" is specified the output of the individual claims will be in a format better suited for programmatical readout.\n" + 19 19 "3. Lists claims in a square with edge length of 64 (or the optionally specified size) around the executing player\n"; … … 25 25 26 26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 27 if (_senderInfo.RemoteClientInfo != null) { 28 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) { 29 _params.Add (_senderInfo.RemoteClientInfo.playerId); 27 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) { 28 if (_senderInfo.RemoteClientInfo != null) { 29 _params.Add (_senderInfo.RemoteClientInfo.entityId.ToString ()); 30 } else if (_senderInfo.IsLocalGame && !GameManager.IsDedicatedServer) { 31 _params.Add (GameManager.Instance.World.GetPrimaryPlayerId ().ToString ()); 30 32 } 31 33 } … … 35 37 36 38 bool summaryOnly = false; 37 string steamIdFilter = string.Empty;39 PlatformUserIdentifierAbs userIdFilter = null; 38 40 Vector3i closeTo = default (Vector3i); 39 41 bool onlyCloseToPlayer = false; … … 47 49 48 50 if (_params.Count == 1) { 49 long tempLong;50 51 51 if (_params [0].EqualsCaseInsensitive ("summary")) { 52 52 summaryOnly = true; 53 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) { 54 steamIdFilter = _params [0]; 53 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params[0], out userIdFilter)) { 55 54 } else { 56 55 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]); 57 56 if (ci != null) { 58 steamIdFilter = ci.playerId;57 userIdFilter = ci.PlatformId; 59 58 } else { 60 59 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found."); … … 74 73 } 75 74 76 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);77 EntityPlayer ep = w.Players.dict [ ci.entityId];75 int entityId = int.Parse (_params [_params.Count - 1]); 76 EntityPlayer ep = w.Players.dict [entityId]; 78 77 closeTo = new Vector3i (ep.GetPosition ()); 79 78 onlyCloseToPlayer = true; … … 91 90 92 91 LandClaimList.OwnerFilter[] ownerFilters = null; 93 if ( !string.IsNullOrEmpty (steamIdFilter)) {94 ownerFilters = new[] {LandClaimList. SteamIdFilter (steamIdFilter)};92 if (userIdFilter != null) { 93 ownerFilters = new[] {LandClaimList.UserIdFilter (userIdFilter)}; 95 94 } 96 95 … … 106 105 "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})", 107 106 kvp.Key.Name, 108 kvp.Key. SteamID,107 kvp.Key.PlatformId, 109 108 kvp.Key.LandProtectionActive, 110 109 kvp.Key.LandProtectionMultiplier, … … 113 112 foreach (Vector3i v in kvp.Value) { 114 113 if (parseableOutput) { 115 SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key. SteamID+114 SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.PlatformId + 116 115 ", playerName=" + kvp.Key.Name + ", location=" + v); 117 116 } else { … … 122 121 } 123 122 124 if ( string.IsNullOrEmpty (steamIdFilter)) {123 if (userIdFilter == null) { 125 124 SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game"); 126 125 } -
binary-improvements/AllocsCommands/Commands/RemoveLandProtection.cs
r359 r369 11 11 public override string GetHelp () { 12 12 return "Usage:" + 13 " 1. removelandprotection < steamid>\n" +13 " 1. removelandprotection <userid>\n" + 14 14 " 2. removelandprotection <x> <y> <z>\n" + 15 15 " 3. removelandprotection nearby [length]\n" + 16 "1. Remove all land claims owned by the user with the given SteamID\n" +16 "1. Remove all land claims owned by the user with the given UserID\n" + 17 17 "2. Remove only the claim block on the exactly given block position\n" + 18 18 "3. Remove all claims in a square with edge length of 64 (or the optionally specified size) around the executing player"; … … 25 25 private void removeById (string _id) { 26 26 try { 27 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList (); 28 29 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) { 27 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_id, out PlatformUserIdentifierAbs userId)) { 30 28 SdtdConsole.Instance.Output ( 31 29 "Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones."); 32 30 return; 33 31 } 32 33 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList (); 34 34 35 if (ppl.Players [ _id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) {35 if (ppl.Players [userId].LPBlocks == null || ppl.Players [userId].LPBlocks.Count == 0) { 36 36 SdtdConsole.Instance.Output ( 37 37 "Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones."); … … 40 40 41 41 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 42 foreach (Vector3i pos in ppl.Players [ _id].LPBlocks) {42 foreach (Vector3i pos in ppl.Players [userId].LPBlocks) { 43 43 BlockChangeInfo bci = new BlockChangeInfo (pos, new BlockValue (0), true, false); 44 44 changes.Add (bci); … … 58 58 59 59 private void removeByPosition (List<string> _coords) { 60 int x, y, z; 61 int.TryParse (_coords [0], out x); 62 int.TryParse (_coords [1], out y); 63 int.TryParse (_coords [2], out z); 60 int.TryParse (_coords [0], out int x); 61 int.TryParse (_coords [1], out int y); 62 int.TryParse (_coords [2], out int z); 64 63 65 64 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { … … 81 80 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); 82 81 83 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 84 changes.Add (bci); 82 List<BlockChangeInfo> changes = new List<BlockChangeInfo> {bci}; 85 83 86 84 GameManager.Instance.SetBlocksRPC (changes); … … 90 88 91 89 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 92 try{90 if (_params.Count > 0 && _params [0].EqualsCaseInsensitive ("nearby")) { 93 91 if (_senderInfo.RemoteClientInfo != null) { 94 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {95 _params.Add (_senderInfo.RemoteClientInfo.playerId);96 }92 _params.Add (_senderInfo.RemoteClientInfo.entityId.ToString ()); 93 } else if (_senderInfo.IsLocalGame && !GameManager.IsDedicatedServer) { 94 _params.Add (GameManager.Instance.World.GetPrimaryPlayerId ().ToString ()); 97 95 } 98 96 99 if (_params.Count > 0 && _params [0].EqualsCaseInsensitive ("nearby")) { 100 try { 101 int closeToDistance = 32; 102 if (_params.Count == 3) { 103 if (!int.TryParse (_params [1], out closeToDistance)) { 104 SdtdConsole.Instance.Output ("Given length is not an integer!"); 105 return; 106 } 107 108 closeToDistance /= 2; 97 try { 98 int closeToDistance = 32; 99 if (_params.Count == 3) { 100 if (!int.TryParse (_params [1], out closeToDistance)) { 101 SdtdConsole.Instance.Output ("Given length is not an integer!"); 102 return; 109 103 } 110 104 111 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]); 112 EntityPlayer ep = GameManager.Instance.World.Players.dict [ci.entityId]; 113 Vector3i closeTo = new Vector3i (ep.GetPosition ()); 114 LandClaimList.PositionFilter[] posFilters = 115 {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)}; 116 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (null, posFilters); 105 closeToDistance /= 2; 106 } 117 107 118 try { 119 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 120 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 121 foreach (Vector3i v in kvp.Value) { 122 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); 123 changes.Add (bci); 124 } 108 int entityId = int.Parse (_params [_params.Count - 1]); 109 EntityPlayer ep = GameManager.Instance.World.Players.dict [entityId]; 110 Vector3i closeTo = new Vector3i (ep.GetPosition ()); 111 LandClaimList.PositionFilter[] posFilters = 112 {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)}; 113 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (null, posFilters); 114 115 try { 116 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 117 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 118 foreach (Vector3i v in kvp.Value) { 119 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); 120 changes.Add (bci); 125 121 } 122 } 126 123 127 GameManager.Instance.SetBlocksRPC (changes); 128 } catch (Exception e) { 129 SdtdConsole.Instance.Output ("Error removing claims"); 130 Log.Out ("Error in RemoveLandProtection.Run: " + e); 131 } 124 GameManager.Instance.SetBlocksRPC (changes); 132 125 } catch (Exception e) { 133 SdtdConsole.Instance.Output ("Error getting current player's position");126 SdtdConsole.Instance.Output ("Error removing claims"); 134 127 Log.Out ("Error in RemoveLandProtection.Run: " + e); 135 128 } 136 } else if (_params.Count == 1) { 137 removeById (_params [0]); 138 } else if (_params.Count == 3) { 139 removeByPosition (_params); 140 } else { 141 SdtdConsole.Instance.Output ("Illegal parameters"); 129 } catch (Exception e) { 130 SdtdConsole.Instance.Output ("Error getting current player's position"); 131 Log.Out ("Error in RemoveLandProtection.Run: " + e); 142 132 } 143 } catch (Exception e) { 144 Log.Out ("Error in RemoveLandProtection.Run: " + e); 133 } else if (_params.Count == 1) { 134 removeById (_params [0]); 135 } else if (_params.Count == 3) { 136 removeByPosition (_params); 137 } else { 138 SdtdConsole.Instance.Output ("Illegal parameters"); 145 139 } 146 140 } -
binary-improvements/AllocsCommands/Commands/ShowInventory.cs
r359 r369 11 11 public override string GetHelp () { 12 12 return "Usage:\n" + 13 " showinventory < steamid / player name / entity id> [tag]\n" +14 "Show the inventory of the player given by his SteamID, player name or\n" +13 " showinventory <user id / player name / entity id> [tag]\n" + 14 "Show the inventory of the player given by his UserID, player name or\n" + 15 15 "entity id (as given by e.g. \"lpi\").\n" + 16 16 "Optionally specify a tag that is included in each line of the output. In\n" + … … 30 30 } 31 31 32 stringsteamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);32 PlatformUserIdentifierAbs steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true); 33 33 if (steamid == null) { 34 34 SdtdConsole.Instance.Output ( -
binary-improvements/AllocsCommands/PrivateMessageConnections.cs
r326 r369 4 4 namespace AllocsFixes.CustomCommands { 5 5 public class PrivateMessageConnections { 6 private static readonly Dictionary< CSteamID, CSteamID> senderOfLastPM = new Dictionary<CSteamID, CSteamID> ();6 private static readonly Dictionary<PlatformUserIdentifierAbs, PlatformUserIdentifierAbs> senderOfLastPM = new Dictionary<PlatformUserIdentifierAbs, PlatformUserIdentifierAbs> (); 7 7 8 8 public static void SetLastPMSender (ClientInfo _sender, ClientInfo _receiver) { 9 senderOfLastPM [_receiver. steamId] = _sender.steamId;9 senderOfLastPM [_receiver.InternalId] = _sender.InternalId; 10 10 } 11 11 12 12 public static ClientInfo GetLastPMSenderForPlayer (ClientInfo _player) { 13 if (!senderOfLastPM. ContainsKey (_player.steamId)) {13 if (!senderOfLastPM.TryGetValue (_player.InternalId, out PlatformUserIdentifierAbs recUserId)) { 14 14 return null; 15 15 } 16 16 17 CSteamID recSteamId = senderOfLastPM [_player.steamId]; 18 ClientInfo recInfo = ConnectionManager.Instance.Clients.ForSteamId (recSteamId); 17 ClientInfo recInfo = ConnectionManager.Instance.Clients.ForUserId (recUserId); 19 18 return recInfo; 20 19 } -
binary-improvements/MapRendering/API.cs
r367 r369 6 6 private Web webInstance; 7 7 8 public void InitMod ( ) {8 public void InitMod (Mod _modInstance) { 9 9 ModEvents.GameStartDone.RegisterHandler (GameStartDone); 10 10 ModEvents.GameShutdown.RegisterHandler (GameShutdown); … … 14 14 private void GameStartDone () { 15 15 // ReSharper disable once ObjectCreationAsStatement 16 if (!ConnectionManager.Instance.IsServer) { 17 return; 18 } 19 16 20 webInstance = new Web (); 17 21 LogBuffer.Init (); … … 23 27 24 28 private void GameShutdown () { 25 webInstance .Shutdown ();29 webInstance?.Shutdown (); 26 30 MapRendering.MapRendering.Shutdown (); 27 31 } -
binary-improvements/MapRendering/MapRendering/MapRendering.cs
r351 r369 26 26 27 27 private MapRendering () { 28 Constants.MAP_DIRECTORY = Game Utils.GetSaveGameDir () + "/map";28 Constants.MAP_DIRECTORY = GameIO.GetSaveGameDir () + "/map"; 29 29 30 30 lock (lockObject) { … … 59 59 60 60 public static void Shutdown () { 61 if (Instance .renderCoroutineRef != null) {61 if (Instance?.renderCoroutineRef != null) { 62 62 ThreadManager.StopCoroutine (Instance.renderCoroutineRef); 63 63 Instance.renderCoroutineRef = null; … … 66 66 67 67 public static void RenderSingleChunk (Chunk _chunk) { 68 if (renderingEnabled ) {68 if (renderingEnabled && Instance != null) { 69 69 // TODO: Replace with regular thread and a blocking queue / set 70 70 ThreadPool.UnsafeQueueUserWorkItem (_o => { … … 101 101 MicroStopwatch microStopwatch = new MicroStopwatch (); 102 102 103 string regionSaveDir = Game Utils.GetSaveGameRegionDir ();103 string regionSaveDir = GameIO.GetSaveGameRegionDir (); 104 104 RegionFileManager rfm = new RegionFileManager (regionSaveDir, regionSaveDir, 0, false); 105 105 Texture2D fullMapTexture = null; -
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r351 r369 8 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 9 int _permissionLevel) { 10 string requestedSteamID = string.Empty; 11 12 if (_req.QueryString ["steamid"] != null) { 13 ulong lViewersSteamID; 14 requestedSteamID = _req.QueryString ["steamid"]; 15 if (requestedSteamID.Length != 17 || !ulong.TryParse (requestedSteamID, out lViewersSteamID)) { 10 PlatformUserIdentifierAbs requestedUserId = null; 11 if (_req.QueryString ["userid"] != null) { 12 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_req.QueryString ["userid"], out requestedUserId)) { 16 13 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 17 Web.SetResponseTextContent (_resp, "Invalid SteamIDgiven");14 Web.SetResponseTextContent (_resp, "Invalid user id given"); 18 15 return; 19 16 } … … 21 18 22 19 // default user, cheap way to avoid 'null reference exception' 23 _user = _user ?? new WebConnection ("", IPAddress.None, 0L);20 PlatformUserIdentifierAbs userId = _user?.UserId; 24 21 25 22 bool bViewAll = WebConnection.CanViewAllClaims (_permissionLevel); … … 32 29 33 30 LandClaimList.OwnerFilter[] ownerFilters = null; 34 if ( !string.IsNullOrEmpty (requestedSteamID)|| !bViewAll) {35 if ( !string.IsNullOrEmpty (requestedSteamID)&& !bViewAll) {31 if (requestedUserId != null || !bViewAll) { 32 if (requestedUserId != null && !bViewAll) { 36 33 ownerFilters = new[] { 37 LandClaimList. SteamIdFilter (_user.SteamID.ToString ()),38 LandClaimList. SteamIdFilter (requestedSteamID)34 LandClaimList.UserIdFilter (userId), 35 LandClaimList.UserIdFilter (requestedUserId) 39 36 }; 40 37 } else if (!bViewAll) { 41 ownerFilters = new[] {LandClaimList. SteamIdFilter (_user.SteamID.ToString ())};38 ownerFilters = new[] {LandClaimList.UserIdFilter (userId)}; 42 39 } else { 43 ownerFilters = new[] {LandClaimList. SteamIdFilter (requestedSteamID)};40 ownerFilters = new[] {LandClaimList.UserIdFilter (requestedUserId)}; 44 41 } 45 42 } … … 50 47 51 48 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 52 // try { 53 JSONObject owner = new JSONObject (); 54 claimOwners.Add (owner); 49 JSONObject owner = new JSONObject (); 50 claimOwners.Add (owner); 55 51 56 owner.Add ("steamid", new JSONString (kvp.Key.SteamID));57 52 owner.Add ("steamid", new JSONString (kvp.Key.PlatformId.CombinedString)); 53 owner.Add ("claimactive", new JSONBoolean (kvp.Key.LandProtectionActive)); 58 54 59 60 61 62 63 55 if (kvp.Key.Name.Length > 0) { 56 owner.Add ("playername", new JSONString (kvp.Key.Name)); 57 } else { 58 owner.Add ("playername", new JSONNull ()); 59 } 64 60 65 66 61 JSONArray claimsJson = new JSONArray (); 62 owner.Add ("claims", claimsJson); 67 63 68 69 70 71 72 64 foreach (Vector3i v in kvp.Value) { 65 JSONObject claim = new JSONObject (); 66 claim.Add ("x", new JSONNumber (v.x)); 67 claim.Add ("y", new JSONNumber (v.y)); 68 claim.Add ("z", new JSONNumber (v.z)); 73 69 74 claimsJson.Add (claim); 75 } 76 // } catch { 77 // } 70 claimsJson.Add (claim); 71 } 78 72 } 79 73 -
binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs
r349 r369 8 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 9 int _permissionLevel) { 10 11 bool showIconColor, showIconName; 12 GetPlayerInventory.GetInventoryArguments (_req, out showIconColor, out showIconName); 10 GetPlayerInventory.GetInventoryArguments (_req, out bool showIconColor, out bool showIconName); 13 11 14 12 JSONArray AllInventoriesResult = new JSONArray (); 15 13 16 foreach (KeyValuePair< string, Player> kvp in PersistentContainer.Instance.Players.Dict) {14 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) { 17 15 Player p = kvp.Value; 18 16 … … 22 20 23 21 if (p.IsOnline) { 24 AllInventoriesResult.Add (GetPlayerInventory.DoPlayer (kvp.Key , p, showIconColor, showIconName));22 AllInventoriesResult.Add (GetPlayerInventory.DoPlayer (kvp.Key.CombinedString, p, showIconColor, showIconName)); 25 23 } 26 24 } -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r348 r369 8 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 9 int _permissionLevel) { 10 if (_req.QueryString [" steamid"] == null) {10 if (_req.QueryString ["userid"] == null) { 11 11 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 12 Web.SetResponseTextContent (_resp, "No SteamIDgiven");12 Web.SetResponseTextContent (_resp, "No user id given"); 13 13 return; 14 14 } 15 15 16 string steamId = _req.QueryString ["steamid"]; 17 18 Player p = PersistentContainer.Instance.Players [steamId, false]; 19 if (p == null) { 20 _resp.StatusCode = (int) HttpStatusCode.NotFound; 21 Web.SetResponseTextContent (_resp, "Invalid or unknown SteamID given"); 16 string userIdString = _req.QueryString ["userid"]; 17 if (!PlatformUserIdentifierAbs.TryFromCombinedString (userIdString, out PlatformUserIdentifierAbs userId)) { 18 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 19 Web.SetResponseTextContent (_resp, "Invalid user id given"); 22 20 return; 23 21 } 24 22 25 bool showIconColor, showIconName; 26 GetInventoryArguments (_req, out showIconColor, out showIconName); 23 Player p = PersistentContainer.Instance.Players [userId, false]; 24 if (p == null) { 25 _resp.StatusCode = (int) HttpStatusCode.NotFound; 26 Web.SetResponseTextContent (_resp, "Unknown user id given"); 27 return; 28 } 27 29 28 JSONObject result = DoPlayer (steamId, p, showIconColor, showIconName); 30 GetInventoryArguments (_req, out bool showIconColor, out bool showIconName); 31 32 JSONObject result = DoPlayer (userIdString, p, showIconColor, showIconName); 29 33 30 34 WriteJSON (_resp, result); … … 49 53 JSONArray belt = new JSONArray (); 50 54 JSONObject equipment = new JSONObject (); 51 result.Add (" steamid", new JSONString (_steamId));55 result.Add ("userid", new JSONString (_steamId)); 52 56 result.Add ("entityid", new JSONNumber (_player.EntityID)); 53 57 result.Add ("playername", new JSONString (_player.Name)); … … 86 90 87 91 for (int i = 0; i < slotindices.Length; i++) { 88 if (_items != null && _items[slotindices [i]] != null) {92 if (_items? [slotindices [i]] != null) { 89 93 InvItem item = _items [slotindices [i]]; 90 94 _eq.Add (_slotname, GetJsonForItem (item, _showIconColor, _showIconName)); -
binary-improvements/MapRendering/Web/API/GetPlayerList.cs
r351 r369 6 6 using AllocsFixes.JSON; 7 7 using AllocsFixes.PersistentData; 8 using UnityEngine.Profiling;9 8 10 9 namespace AllocsFixes.NetConnections.Servers.Web.API { … … 14 13 15 14 #if ENABLE_PROFILER 16 private static readonly CustomSampler jsonSerializeSampler =CustomSampler.Create ("JSON_Build");15 private static readonly UnityEngine.Profiling.CustomSampler jsonSerializeSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_Build"); 17 16 #endif 18 17 … … 20 19 int _permissionLevel) { 21 20 AdminTools admTools = GameManager.Instance.adminTools; 22 _user = _user ?? new WebConnection ("", IPAddress.None, 0L);21 PlatformUserIdentifierAbs userId = _user?.UserId; 23 22 24 23 bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel); … … 47 46 #endif 48 47 49 foreach (KeyValuePair< string, Player> kvp in playersList.Dict) {48 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) { 50 49 Player p = kvp.Value; 51 50 52 ulong player_steam_ID; 53 if (!ulong.TryParse (kvp.Key, out player_steam_ID)) { 54 player_steam_ID = 0L; 55 } 56 57 if (player_steam_ID == _user.SteamID || bViewAll) { 51 if (bViewAll || p.PlatformId.Equals (userId)) { 58 52 JSONObject pos = new JSONObject (); 59 53 pos.Add ("x", new JSONNumber (p.LastPosition.x)); … … 62 56 63 57 JSONObject pJson = new JSONObject (); 64 pJson.Add ("steamid", new JSONString (kvp.Key ));58 pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString)); 65 59 pJson.Add ("entityid", new JSONNumber (p.EntityID)); 66 60 pJson.Add ("ip", new JSONString (p.IP)); … … 74 68 pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 75 69 76 JSONBoolean banned; 77 if (admTools != null) { 78 banned = new JSONBoolean (admTools.IsBanned (kvp.Key)); 79 } else { 80 banned = new JSONBoolean (false); 81 } 70 JSONBoolean banned = admTools != null ? new JSONBoolean (admTools.IsBanned (kvp.Key, out _, out _)) : new JSONBoolean (false); 82 71 83 72 pJson.Add ("banned", banned); -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r351 r369 9 9 int _permissionLevel) { 10 10 AdminTools admTools = GameManager.Instance.adminTools; 11 _user = _user ?? new WebConnection ("", IPAddress.None, 0L);11 PlatformUserIdentifierAbs userId = _user?.UserId; 12 12 13 13 bool listOffline = false; … … 22 22 Players playersList = PersistentContainer.Instance.Players; 23 23 24 foreach (KeyValuePair< string, Player> kvp in playersList.Dict) {24 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) { 25 25 if (admTools != null) { 26 if (admTools.IsBanned (kvp.Key )) {26 if (admTools.IsBanned (kvp.Key, out _, out _)) { 27 27 continue; 28 28 } … … 32 32 33 33 if (listOffline || p.IsOnline) { 34 ulong player_steam_ID; 35 if (!ulong.TryParse (kvp.Key, out player_steam_ID)) { 36 player_steam_ID = 0L; 37 } 38 39 if (player_steam_ID == _user.SteamID || bViewAll) { 34 if (bViewAll || p.PlatformId.Equals (userId)) { 40 35 JSONObject pos = new JSONObject (); 41 36 pos.Add ("x", new JSONNumber (p.LastPosition.x)); … … 44 39 45 40 JSONObject pJson = new JSONObject (); 46 pJson.Add ("steamid", new JSONString (kvp.Key ));41 pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString)); 47 42 48 43 // pJson.Add("entityid", new JSONNumber (p.EntityID)); -
binary-improvements/MapRendering/Web/API/GetPlayersOnline.cs
r351 r369 13 13 foreach (KeyValuePair<int, EntityPlayer> current in w.Players.dict) { 14 14 ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (current.Key); 15 Player player = PersistentContainer.Instance.Players [ci. playerId, false];15 Player player = PersistentContainer.Instance.Players [ci.PlatformId, false]; 16 16 17 17 JSONObject pos = new JSONObject (); … … 21 21 22 22 JSONObject p = new JSONObject (); 23 p.Add ("steamid", new JSONString (ci. playerId));23 p.Add ("steamid", new JSONString (ci.PlatformId.CombinedString)); 24 24 p.Add ("entityid", new JSONNumber (ci.entityId)); 25 25 p.Add ("ip", new JSONString (ci.ip)); … … 28 28 p.Add ("position", pos); 29 29 30 // Deprecated! 31 p.Add ("experience", new JSONNumber (-1)); 32 33 p.Add ("level", new JSONNumber (player != null ? player.Level : -1)); 30 p.Add ("level", new JSONNumber (player?.Level ?? -1)); 34 31 p.Add ("health", new JSONNumber (current.Value.Health)); 35 32 p.Add ("stamina", new JSONNumber (current.Value.Stamina)); … … 39 36 p.Add ("score", new JSONNumber (current.Value.Score)); 40 37 41 p.Add ("totalplaytime", new JSONNumber (player != null ? player.TotalPlayTime :-1));38 p.Add ("totalplaytime", new JSONNumber (player?.TotalPlayTime ?? -1)); 42 39 p.Add ("lastonline", new JSONString (player != null ? player.LastOnline.ToString ("s") : string.Empty)); 43 40 p.Add ("ping", new JSONNumber (ci.ping)); -
binary-improvements/MapRendering/Web/ConnectionHandler.cs
r351 r369 2 2 using System.Collections.Generic; 3 3 using System.Net; 4 using Platform.Steam; 4 5 5 6 namespace AllocsFixes.NetConnections.Servers.Web { … … 36 37 public WebConnection LogIn (ulong _steamId, IPAddress _ip) { 37 38 string sessionId = Guid.NewGuid ().ToString (); 38 WebConnection con = new WebConnection (sessionId, _ip, _steamId); 39 PlatformUserIdentifierAbs userId = new UserIdentifierSteam (_steamId); 40 WebConnection con = new WebConnection (sessionId, _ip, userId); 39 41 connections.Add (sessionId, con); 40 42 return con; -
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r367 r369 77 77 78 78 try { 79 loadIconsFromFolder ( Utils.GetGameDir ("Data/ItemIcons"), tintedIcons);79 loadIconsFromFolder (GameIO.GetGameDir ("Data/ItemIcons"), tintedIcons); 80 80 } catch (Exception e) { 81 81 Log.Error ("Failed loading icons from base game"); -
binary-improvements/MapRendering/Web/Handlers/UserStatusHandler.cs
r351 r369 13 13 14 14 result.Add ("loggedin", new JSONBoolean (_user != null)); 15 result.Add ("username", new JSONString (_user != null ? _user. SteamID.ToString () : string.Empty));15 result.Add ("username", new JSONString (_user != null ? _user.UserId.ToString () : string.Empty)); 16 16 17 17 JSONArray perms = new JSONArray (); -
binary-improvements/MapRendering/Web/LogBuffer.cs
r350 r369 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Text.RegularExpressions;4 3 using UnityEngine; 5 4 … … 8 7 private const int MAX_ENTRIES = 3000; 9 8 private static LogBuffer instance; 10 11 private static readonly Regex logMessageMatcher =12 new Regex (@"^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2}) ([0-9]+[,.][0-9]+) [A-Z]+ (.*)$");13 9 14 10 private readonly List<LogEntry> logEntries = new List<LogEntry> (); … … 23 19 24 20 private LogBuffer () { 25 Log ger.Main.LogCallbacks+= LogCallback;21 Log.LogCallbacksExtended += LogCallback; 26 22 } 27 23 … … 72 68 } 73 69 74 private void LogCallback (string _ msg, string _trace, LogType _type) {70 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 75 71 LogEntry le = new LogEntry (); 76 72 77 Match match = logMessageMatcher.Match (_msg); 78 if (match.Success) { 79 le.date = match.Groups [1].Value; 80 le.time = match.Groups [2].Value; 81 le.uptime = match.Groups [3].Value; 82 le.message = match.Groups [4].Value; 83 } else { 84 DateTime dt = DateTime.Now; 85 le.date = string.Format ("{0:0000}-{1:00}-{2:00}", dt.Year, dt.Month, dt.Day); 86 le.time = string.Format ("{0:00}:{1:00}:{2:00}", dt.Hour, dt.Minute, dt.Second); 87 le.uptime = ""; 88 le.message = _msg; 89 } 90 73 le.date = $"{_timestamp.Year:0000}-{_timestamp.Month:00}-{_timestamp.Day:00}"; 74 le.time = $"{_timestamp.Hour:00}:{_timestamp.Minute:00}:{_timestamp.Second:00}"; 75 le.uptime = _uptime.ToString (); 76 le.message = _plainMsg; 91 77 le.trace = _trace; 92 78 le.type = _type; -
binary-improvements/MapRendering/Web/SSE/EventLog.cs
r367 r369 1 1 using System; 2 using System.Net;3 using System.Text;4 using System.Text.RegularExpressions;5 2 using AllocsFixes.JSON; 6 3 using UnityEngine; … … 8 5 namespace AllocsFixes.NetConnections.Servers.Web.SSE { 9 6 public class EventLog : EventBase { 10 private static readonly Regex logMessageMatcher =11 new Regex (@"^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}:[0-9]{2}) ([0-9]+[,.][0-9]+) [A-Z]+ (.*)$");12 13 7 public EventLog (SseHandler _parent) : base (_parent, _name: "log") { 14 Log ger.Main.LogCallbacks+= LogCallback;8 Log.LogCallbacksExtended += LogCallback; 15 9 } 16 10 17 18 private void LogCallback (string _msg, string _trace, LogType _type) { 19 Match match = logMessageMatcher.Match (_msg); 20 21 string date; 22 string time; 23 string uptime; 24 string message; 25 if (match.Success) { 26 date = match.Groups [1].Value; 27 time = match.Groups [2].Value; 28 uptime = match.Groups [3].Value; 29 message = match.Groups [4].Value; 30 } else { 31 DateTime dt = DateTime.Now; 32 date = $"{dt.Year:0000}-{dt.Month:00}-{dt.Day:00}"; 33 time = $"{dt.Hour:00}:{dt.Minute:00}:{dt.Second:00}"; 34 uptime = ""; 35 message = _msg; 36 } 11 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 12 string date = $"{_timestamp.Year:0000}-{_timestamp.Month:00}-{_timestamp.Day:00}"; 13 string time = $"{_timestamp.Hour:00}:{_timestamp.Minute:00}:{_timestamp.Second:00}"; 14 string uptime = _uptime.ToString (); 15 string message = _plainMsg; 37 16 38 17 JSONObject data = new JSONObject (); … … 46 25 SendData ("logLine", data); 47 26 } 48 49 27 } 50 28 } -
binary-improvements/MapRendering/Web/Web.cs
r367 r369 59 59 RegisterPathHandler ("/itemicons/", new ItemIconHandler (true)); 60 60 RegisterPathHandler ("/map/", new StaticHandler ( 61 Game Utils.GetSaveGameDir () + "/map",61 GameIO.GetSaveGameDir () + "/map", 62 62 MapRendering.MapRendering.GetTileCache (), 63 63 false, … … 111 111 } 112 112 113 public void SendLog (string _ text, string _trace, LogType _type) {113 public void SendLog (string _formattedMessage, string _plainMessage, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 114 114 // Do nothing, handled by LogBuffer internally 115 115 } … … 248 248 if (con != null) { 249 249 _con = con; 250 return GameManager.Instance.adminTools.GetUserPermissionLevel (_con. SteamID.ToString ());250 return GameManager.Instance.adminTools.GetUserPermissionLevel (_con.UserId); 251 251 } 252 252 } … … 270 270 WebConnection con = connectionHandler.LogIn (id, _req.RemoteEndPoint.Address); 271 271 _con = con; 272 int level = GameManager.Instance.adminTools.GetUserPermissionLevel ( id.ToString ());272 int level = GameManager.Instance.adminTools.GetUserPermissionLevel (con.UserId); 273 273 Log.Out ("Steam OpenID login from {0} with ID {1}, permission level {2}", 274 remoteEndpointString, con. SteamID, level);274 remoteEndpointString, con.UserId, level); 275 275 return level; 276 276 } -
binary-improvements/MapRendering/Web/WebCommandResult.cs
r332 r369 95 95 } 96 96 97 public void SendLog (string _ msg, string _trace, LogType _type) {97 public void SendLog (string _formattedMessage, string _plainMessage, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 98 98 //throw new NotImplementedException (); 99 99 } -
binary-improvements/MapRendering/Web/WebConnection.cs
r332 r369 11 11 private readonly string conDescription; 12 12 13 public WebConnection (string _sessionId, IPAddress _endpoint, ulong _steamId) {13 public WebConnection (string _sessionId, IPAddress _endpoint, PlatformUserIdentifierAbs _userId) { 14 14 SessionID = _sessionId; 15 15 Endpoint = _endpoint; 16 SteamID = _steamId;16 UserId = _userId; 17 17 login = DateTime.Now; 18 18 lastAction = login; … … 20 20 } 21 21 22 public string SessionID { get; private set;}22 public string SessionID { get; } 23 23 24 public IPAddress Endpoint { get; private set;}24 public IPAddress Endpoint { get; } 25 25 26 public ulong SteamID { get; private set; }26 public PlatformUserIdentifierAbs UserId { get; } 27 27 28 public TimeSpan Age { 29 get { return DateTime.Now - lastAction; } 30 } 28 public TimeSpan Age => DateTime.Now - lastAction; 31 29 32 30 public static bool CanViewAllPlayers (int _permissionLevel) { … … 54 52 } 55 53 56 public override void SendLog (string _ msg, string _trace, LogType _type) {54 public override void SendLog (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 57 55 // Do nothing, handled by LogBuffer 58 56 } -
binary-improvements/MapRendering/Web/WebPermissions.cs
r351 r369 191 191 modules.Clear (); 192 192 193 if (! Utils.FileExists (GetFullPath ())) {193 if (!File.Exists (GetFullPath ())) { 194 194 Log.Out (string.Format ("Permissions file '{0}' not found, creating.", GetFileName ())); 195 195 Save (); -
binary-improvements/MapRendering/WebAndMapRendering.csproj
r367 r369 31 31 </PropertyGroup> 32 32 <ItemGroup> 33 <Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> 34 <HintPath>..\7dtd-binaries\Assembly-CSharp-firstpass.dll</HintPath> 35 <Private>False</Private> 36 </Reference> 33 37 <Reference Include="LogLibrary"> 34 38 <HintPath>..\7dtd-binaries\LogLibrary.dll</HintPath> -
binary-improvements/webserver/index.html
r297 r369 159 159 <div id="playerInventoryDialog" title="Player inventory"> 160 160 Player: <span id="invPlayerName"></span><br/> 161 SteamID: <span id="invSteamId"></span><br/>161 UserID: <span id="invSteamId"></span><br/> 162 162 <br/> 163 163 <table> -
binary-improvements/webserver/js/inventory_dialog.js
r361 r369 44 44 // } 45 45 46 $.getJSON( "../api/getplayerinventory", { steamid: steamid })46 $.getJSON( "../api/getplayerinventory", { userid: steamid }) 47 47 .done(function(data) { 48 48 $("#invPlayerName").text(data.playername); -
binary-improvements/webserver/js/players.js
r320 r369 24 24 // Define columns to be shown 25 25 var columns = [ 26 [ "steamid", " SteamID" ],26 [ "steamid", "UserID" ], 27 27 [ "entityid", "EntityID" ], 28 28 [ "ip", "IP" ],
Note:
See TracChangeset
for help on using the changeset viewer.