Changeset 455 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Jul 31, 2023, 4:06:13 PM (17 months ago)
- Location:
- binary-improvements/7dtd-server-fixes
- Files:
-
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r450 r455 83 83 <ItemGroup> 84 84 <Compile Include="src\AssemblyInfo.cs" /> 85 <Compile Include="src\JSON\JsonManualBuilder.cs" />86 85 <Compile Include="src\LiveData\Animals.cs" /> 87 86 <Compile Include="src\LiveData\Hostiles.cs" /> … … 91 90 <Compile Include="src\PersistentData\Players.cs" /> 92 91 <Compile Include="src\PersistentData\Player.cs" /> 93 <Compile Include="src\JSON\JSONNode.cs" />94 <Compile Include="src\JSON\JSONArray.cs" />95 <Compile Include="src\JSON\JSONObject.cs" />96 <Compile Include="src\JSON\JSONNumber.cs" />97 <Compile Include="src\JSON\JSONString.cs" />98 <Compile Include="src\JSON\JSONBoolean.cs" />99 <Compile Include="src\BlockingQueue.cs" />100 <Compile Include="src\JSON\Parser.cs" />101 <Compile Include="src\JSON\JSONNull.cs" />102 <Compile Include="src\JSON\MalformedJSONException.cs" />103 92 <Compile Include="src\API.cs" /> 104 93 <Compile Include="src\AllocsUtils.cs" /> 105 94 <Compile Include="src\LandClaimList.cs" /> 106 95 <Compile Include="src\PersistentData\Attributes.cs" /> 107 <Compile Include="src\JSON\JSONValue.cs" />108 96 <Compile Include="src\LiveData\EntityFilterList.cs" /> 109 97 </ItemGroup> … … 112 100 <Folder Include="src\" /> 113 101 <Folder Include="src\PersistentData\" /> 114 <Folder Include="src\JSON\Parser\" />115 102 </ItemGroup> 116 103 <ItemGroup> -
binary-improvements/7dtd-server-fixes/ModInfo.xml
r448 r455 5 5 <Description value="Common functions" /> 6 6 <Author value="Christian 'Alloc' Illy" /> 7 <Version value=" 29" />8 <Website value="http ://7dtd.illy.bz" />7 <Version value="30" /> 8 <Website value="https://7dtd.illy.bz" /> 9 9 </ModInfo> 10 10 </xml> -
binary-improvements/7dtd-server-fixes/src/API.cs
r446 r455 1 1 using System.Collections.Generic; 2 2 using AllocsFixes.PersistentData; 3 using JetBrains.Annotations; 3 4 using Platform.Steam; 4 5 5 6 namespace AllocsFixes { 7 [UsedImplicitly] 6 8 public class API : IModApi { 7 9 public void InitMod (Mod _modInstance) { 8 10 ModEvents.GameStartDone.RegisterHandler (GameAwake); 9 ModEvents.GameShutdown.RegisterHandler (GameShutdown);10 11 ModEvents.SavePlayerData.RegisterHandler (SavePlayerData); 11 12 ModEvents.PlayerSpawning.RegisterHandler (PlayerSpawning); … … 15 16 } 16 17 17 p ublic void GameAwake () {18 private static void GameAwake () { 18 19 PersistentContainer.Load (); 19 20 } 20 21 21 public void GameShutdown () { 22 } 23 24 public void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 22 private static void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 25 23 PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).Update (_cInfo, _playerDataFile); 26 24 } 27 25 28 p ublic void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {26 private static void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 29 27 string owner = null; 30 28 if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) { … … 32 30 } 33 31 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 32 Log.Out ( 33 $"Player connected, entityid={_cInfo.entityId}, name={_cInfo.playerName}, pltfmid={_cInfo.PlatformId?.CombinedString ?? "<unknown>"}, crossid={_cInfo.CrossplatformId?.CombinedString ?? "<unknown/none>"}, steamOwner={owner ?? "<unknown/none>"}, ip={_cInfo.ip}" 41 34 ); 42 35 } 43 36 44 p ublic void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {37 private static void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 45 38 Player p = PersistentContainer.Instance.Players.GetByInternalId (_cInfo.InternalId); 46 39 if (p != null) { … … 53 46 } 54 47 55 p ublic void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {48 private static void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) { 56 49 PersistentContainer.Instance.Players.GetOrCreate (_cInfo.InternalId, _cInfo.PlatformId, _cInfo.CrossplatformId).SetOnline (_cInfo); 57 50 PersistentContainer.Instance.Save (); 58 51 } 59 52 60 private const string ANSWER = 61 " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 53 private const string ANSWER = " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 62 54 63 p ublic bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,55 private static bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, 64 56 bool _localizeMain, List<int> _recipientEntityIds) { 65 57 if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) { … … 68 60 69 61 if (_cInfo != null) { 70 Log.Out ( "Sent chat hook reply to {0}", _cInfo.InternalId);62 Log.Out ($"Sent chat hook reply to {_cInfo.InternalId}"); 71 63 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, ANSWER, "", false, null)); 72 64 } else { 73 Log.Error ( "ChatHookExample: Argument _cInfo null on message: {0}", _msg);65 Log.Error ($"ChatHookExample: Argument _cInfo null on message: {_msg}"); 74 66 } 75 67 -
binary-improvements/7dtd-server-fixes/src/AllocsUtils.cs
r325 r455 4 4 public static class AllocsUtils { 5 5 public static string ColorToHex (Color _color) { 6 return string.Format ("{0:X02}{1:X02}{2:X02}", (int) (_color.r * 255), (int) (_color.g * 255), 7 (int) (_color.b * 255)); 6 return $"{(int)(_color.r * 255):X02}{(int)(_color.g * 255):X02}{(int)(_color.b * 255):X02}"; 8 7 } 9 8 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Attributes.cs
r326 r455 8 8 9 9 public bool HideChatCommands { 10 get { return hideChatCommands; }11 set { hideChatCommands = value; }10 get => hideChatCommands; 11 set => hideChatCommands = value; 12 12 } 13 13 14 14 public string HideChatCommandPrefix { 15 get { 16 if (hideChatCommandPrefix == null) { 17 hideChatCommandPrefix = ""; 18 } 19 20 return hideChatCommandPrefix; 21 } 22 set { hideChatCommandPrefix = value; } 15 get => hideChatCommandPrefix ??= ""; 16 set => hideChatCommandPrefix = value; 23 17 } 24 18 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r351 r455 24 24 } 25 25 26 private void ProcessInv ( List<InvItem> _target, ItemStack[]_sourceFields, int _id) {26 private void ProcessInv (ICollection<InvItem> _target, IReadOnlyList<ItemStack> _sourceFields, int _id) { 27 27 _target.Clear (); 28 for (int i = 0; i < _sourceFields. Length; i++) {28 for (int i = 0; i < _sourceFields.Count; i++) { 29 29 InvItem item = CreateInvItem (_sourceFields [i].itemValue, _sourceFields [i].count, _id); 30 30 if (item != null && _sourceFields [i].itemValue.Modifications != null) { … … 43 43 } 44 44 45 private void ProcessParts (I temValue[]_parts, InvItem _item, int _playerId) {46 InvItem[] itemParts = new InvItem[_parts. Length];47 for (int i = 0; i < _parts. Length; i++) {45 private void ProcessParts (IReadOnlyList<ItemValue> _parts, InvItem _item, int _playerId) { 46 InvItem[] itemParts = new InvItem[_parts.Count]; 47 for (int i = 0; i < _parts.Count; i++) { 48 48 InvItem partItem = CreateInvItem (_parts [i], 1, _playerId); 49 49 if (partItem != null && _parts [i].Modifications != null) { … … 67 67 68 68 if (_count > maxAllowed) { 69 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + 70 _count + " > " + maxAllowed + ")"); 69 Log.Out ($"Player with ID {_playerId} has stack for \"{name}\" greater than allowed ({_count} > {maxAllowed})"); 71 70 } 72 71 -
binary-improvements/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r448 r455 12 12 [OptionalField] private Attributes attributes; 13 13 14 public Players Players { 15 get { 16 if (players == null) { 17 players = new Players (); 18 } 14 public Players Players => players ??= new Players (); 19 15 20 return players; 21 } 22 } 23 24 public Attributes Attributes { 25 get { 26 if (attributes == null) { 27 attributes = new Attributes (); 28 } 29 30 return attributes; 31 } 32 } 16 public Attributes Attributes => attributes ??= new Attributes (); 33 17 34 18 private static PersistentContainer instance; 35 19 36 public static PersistentContainer Instance { 37 get { 38 if (instance == null) { 39 instance = new PersistentContainer (); 40 } 41 42 return instance; 43 } 44 } 20 public static PersistentContainer Instance => instance ??= new PersistentContainer (); 45 21 46 22 private PersistentContainer () { … … 49 25 public void Save () { 50 26 lock (fileLockObject) { 51 using Stream stream = File.Open ( GameIO.GetSaveGameDir () + persistentDataFileName, FileMode.Create);27 using Stream stream = File.Open ($"{GameIO.GetSaveGameDir ()}{persistentDataFileName}", FileMode.Create); 52 28 BinaryFormatter bFormatter = new BinaryFormatter (); 53 29 bFormatter.Serialize (stream, this); … … 56 32 57 33 public static bool Load () { 58 if (!File.Exists (GameIO.GetSaveGameDir () + persistentDataFileName)) { 34 var filePath = $"{GameIO.GetSaveGameDir ()}{persistentDataFileName}"; 35 36 if (!File.Exists (filePath)) { 59 37 return false; 60 38 } … … 63 41 PersistentContainer obj; 64 42 lock (fileLockObject) { 65 using Stream stream = File.Open ( GameIO.GetSaveGameDir () + persistentDataFileName, FileMode.Open);43 using Stream stream = File.Open (filePath, FileMode.Open); 66 44 BinaryFormatter bFormatter = new BinaryFormatter (); 67 45 obj = (PersistentContainer)bFormatter.Deserialize (stream); -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r447 r455 124 124 } 125 125 126 Log.Out ( "Player set to offline: " + InternalId);126 Log.Out ($"Player set to offline: {InternalId}"); 127 127 lastOnline = DateTime.Now; 128 128 try { … … 140 140 141 141 public void SetOnline (ClientInfo _ci) { 142 Log.Out ( "Player set to online: " + InternalId);142 Log.Out ($"Player set to online: {InternalId}"); 143 143 clientInfo = _ci; 144 144 entityId = _ci.entityId; -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r446 r455 19 19 } 20 20 21 Log.Out ( "Created new player entry for ID: " + _internalId);21 Log.Out ($"Created new player entry for ID: {_internalId}"); 22 22 Player p = new Player (_internalId, _platformId, _crossPlatformId); 23 23 Dict.Add (_internalId, p);
Note:
See TracChangeset
for help on using the changeset viewer.