Changeset 369 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 5 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) {
Note:
See TracChangeset
for help on using the changeset viewer.