Changeset 391 for binary-improvements2/7dtd-server-fixes/src
- Timestamp:
- Aug 7, 2022, 3:02:24 PM (2 years ago)
- Location:
- binary-improvements2/7dtd-server-fixes/src
- Files:
-
- 1 deleted
- 20 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/7dtd-server-fixes/src/AllocsUtils.cs
r325 r391 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-improvements2/7dtd-server-fixes/src/AssemblyInfo.cs
r325 r391 7 7 [assembly: AssemblyDescription ("")] 8 8 [assembly: AssemblyConfiguration ("")] 9 [assembly: AssemblyCompany (" ")]9 [assembly: AssemblyCompany ("The Fun Pimps LLC")] 10 10 [assembly: AssemblyProduct ("")] 11 [assembly: AssemblyCopyright (" Alloc")]11 [assembly: AssemblyCopyright ("The Fun Pimps LLC")] 12 12 [assembly: AssemblyTrademark ("")] 13 13 [assembly: AssemblyCulture ("")] -
binary-improvements2/7dtd-server-fixes/src/FileCache/DirectAccess.cs
r351 r391 7 7 public override byte[] GetFileContent (string _filename) { 8 8 try { 9 if (!File.Exists (_filename)) { 10 return null; 11 } 12 13 return File.ReadAllBytes (_filename); 9 return File.Exists (_filename) ? File.ReadAllBytes (_filename) : null; 14 10 } catch (Exception e) { 15 11 Log.Out ("Error in DirectAccess.GetFileContent: " + e); -
binary-improvements2/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r351 r391 36 36 lock (cache) { 37 37 CurrentZoomFile cacheEntry = cache [_zoomlevel]; 38 39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals (_filename)) {40 cacheEntry.filename = _filename;41 38 42 if (!File.Exists (_filename)) { 43 cacheEntry.pngData = null; 44 return null; 45 } 39 if (cacheEntry.filename != null && cacheEntry.filename.Equals (_filename)) { 40 return cacheEntry.pngData; 41 } 46 42 47 Profiler.BeginSample ("ReadPng"); 48 cacheEntry.pngData = ReadAllBytes (_filename); 49 Profiler.EndSample (); 43 cacheEntry.filename = _filename; 44 45 if (!File.Exists (_filename)) { 46 cacheEntry.pngData = null; 47 return null; 50 48 } 49 50 Profiler.BeginSample ("ReadPng"); 51 cacheEntry.pngData = ReadAllBytes (_filename); 52 Profiler.EndSample (); 51 53 52 54 return cacheEntry.pngData; … … 103 105 } 104 106 105 if (!File.Exists (_filename)) { 106 return transparentTile; 107 } 108 109 return ReadAllBytes (_filename); 107 return !File.Exists (_filename) ? transparentTile : ReadAllBytes (_filename); 110 108 } 111 109 } catch (Exception e) { -
binary-improvements2/7dtd-server-fixes/src/FileCache/SimpleCache.cs
r351 r391 11 11 try { 12 12 lock (fileCache) { 13 if (!fileCache.ContainsKey (_filename)) { 14 if (!File.Exists (_filename)) { 15 return null; 16 } 13 if (fileCache.ContainsKey (_filename)) { 14 return fileCache [_filename]; 15 } 17 16 18 fileCache.Add (_filename, File.ReadAllBytes (_filename)); 17 if (!File.Exists (_filename)) { 18 return null; 19 19 } 20 21 fileCache.Add (_filename, File.ReadAllBytes (_filename)); 20 22 21 23 return fileCache [_filename]; -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONArray.cs
r351 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONArray : JSONNode {6 private readonly List<J SONNode> nodes = new List<JSONNode> ();5 public class JsonArray : JsonNode { 6 private readonly List<JsonNode> nodes = new List<JsonNode> (); 7 7 8 public J SONNode this [int _index] {9 get { return nodes [_index]; }10 set { nodes [_index] = value; }8 public JsonNode this [int _index] { 9 get => nodes [_index]; 10 set => nodes [_index] = value; 11 11 } 12 12 13 public int Count { 14 get { return nodes.Count; } 15 } 13 public int Count => nodes.Count; 16 14 17 public void Add (J SONNode _node) {15 public void Add (JsonNode _node) { 18 16 nodes.Add (_node); 19 17 } … … 25 23 } 26 24 27 foreach (J SONNode n in nodes) {25 foreach (JsonNode n in nodes) { 28 26 if (_prettyPrint) { 29 27 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); … … 48 46 } 49 47 50 public static J SONArray Parse (string _json, ref int _offset) {48 public static JsonArray Parse (string _json, ref int _offset) { 51 49 //Log.Out ("ParseArray enter (" + offset + ")"); 52 J SONArray arr = new JSONArray ();50 JsonArray arr = new JsonArray (); 53 51 54 52 bool nextElemAllowed = true; … … 63 61 _offset++; 64 62 } else { 65 throw new MalformedJ SONException (63 throw new MalformedJsonException ( 66 64 "Could not parse array, found a comma without a value first"); 67 65 } -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONBoolean.cs
r389 r391 2 2 3 3 namespace AllocsFixes.JSON { 4 public class J SONBoolean : JSONValue {4 public class JsonBoolean : JsonValue { 5 5 private readonly bool value; 6 6 7 public J SONBoolean (bool _value) {7 public JsonBoolean (bool _value) { 8 8 value = _value; 9 9 } … … 17 17 } 18 18 19 public static J SONBoolean Parse (string _json, ref int _offset) {19 public static JsonBoolean Parse (string _json, ref int _offset) { 20 20 //Log.Out ("ParseBool enter (" + offset + ")"); 21 21 … … 23 23 //Log.Out ("JSON:Parsed Bool: true"); 24 24 _offset += 4; 25 return new J SONBoolean (true);25 return new JsonBoolean (true); 26 26 } 27 27 … … 29 29 //Log.Out ("JSON:Parsed Bool: false"); 30 30 _offset += 5; 31 return new J SONBoolean (false);31 return new JsonBoolean (false); 32 32 } 33 33 34 throw new MalformedJ SONException ("No valid boolean found");34 throw new MalformedJsonException ("No valid boolean found"); 35 35 } 36 36 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONNode.cs
r351 r391 2 2 3 3 namespace AllocsFixes.JSON { 4 public abstract class J SONNode {4 public abstract class JsonNode { 5 5 public abstract void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0); 6 6 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONNull.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONNull : JSONValue {5 public class JsonNull : JsonValue { 6 6 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 7 7 _stringBuilder.Append ("null"); 8 8 } 9 9 10 public static J SONNull Parse (string _json, ref int _offset) {10 public static JsonNull Parse (string _json, ref int _offset) { 11 11 //Log.Out ("ParseNull enter (" + offset + ")"); 12 12 13 13 if (!_json.Substring (_offset, 4).Equals ("null")) { 14 throw new MalformedJ SONException ("No valid null value found");14 throw new MalformedJsonException ("No valid null value found"); 15 15 } 16 16 17 17 //Log.Out ("JSON:Parsed Null"); 18 18 _offset += 4; 19 return new J SONNull ();19 return new JsonNull (); 20 20 } 21 21 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONNumber.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONNumber : JSONValue {5 public class JsonNumber : JsonValue { 6 6 private readonly double value; 7 7 8 public J SONNumber (double _value) {8 public JsonNumber (double _value) { 9 9 value = _value; 10 10 } … … 22 22 } 23 23 24 public static J SONNumber Parse (string _json, ref int _offset) {24 public static JsonNumber Parse (string _json, ref int _offset) { 25 25 //Log.Out ("ParseNumber enter (" + offset + ")"); 26 26 StringBuilder sbNum = new StringBuilder (); … … 37 37 } else if (_json [_offset] == '.') { 38 38 if (hasExp) { 39 throw new MalformedJ SONException ("Decimal separator in exponent");39 throw new MalformedJsonException ("Decimal separator in exponent"); 40 40 } 41 41 42 42 if (hasDec) { 43 throw new MalformedJ SONException ("Multiple decimal separators in number found");43 throw new MalformedJsonException ("Multiple decimal separators in number found"); 44 44 } 45 45 46 46 if (sbNum.Length == 0) { 47 throw new MalformedJ SONException ("No leading digits before decimal separator found");47 throw new MalformedJsonException ("No leading digits before decimal separator found"); 48 48 } 49 49 … … 53 53 if (hasExp) { 54 54 if (sbExp.Length > 0) { 55 throw new MalformedJ SONException ("Negative sign in exponent after digits");55 throw new MalformedJsonException ("Negative sign in exponent after digits"); 56 56 } 57 57 … … 59 59 } else { 60 60 if (sbNum.Length > 0) { 61 throw new MalformedJ SONException ("Negative sign in mantissa after digits");61 throw new MalformedJsonException ("Negative sign in mantissa after digits"); 62 62 } 63 63 … … 66 66 } else if (_json [_offset] == 'e' || _json [_offset] == 'E') { 67 67 if (hasExp) { 68 throw new MalformedJ SONException ("Multiple exponential markers in number found");68 throw new MalformedJsonException ("Multiple exponential markers in number found"); 69 69 } 70 70 71 71 if (sbNum.Length == 0) { 72 throw new MalformedJ SONException ("No leading digits before exponential marker found");72 throw new MalformedJsonException ("No leading digits before exponential marker found"); 73 73 } 74 74 … … 78 78 if (hasExp) { 79 79 if (sbExp.Length > 0) { 80 throw new MalformedJ SONException ("Positive sign in exponent after digits");80 throw new MalformedJsonException ("Positive sign in exponent after digits"); 81 81 } 82 82 83 83 sbExp.Append (_json [_offset]); 84 84 } else { 85 throw new MalformedJ SONException ("Positive sign in mantissa found");85 throw new MalformedJsonException ("Positive sign in mantissa found"); 86 86 } 87 87 } else { 88 double number; 89 if (!StringParsers.TryParseDouble (sbNum.ToString (), out number)) { 90 throw new MalformedJSONException ("Mantissa is not a valid decimal (\"" + sbNum + "\")"); 88 if (!StringParsers.TryParseDouble (sbNum.ToString (), out double number)) { 89 throw new MalformedJsonException ("Mantissa is not a valid decimal (\"" + sbNum + "\")"); 91 90 } 92 91 93 92 if (hasExp) { 94 int exp; 95 if (!int.TryParse (sbExp.ToString (), out exp)) { 96 throw new MalformedJSONException ("Exponent is not a valid integer (\"" + sbExp + "\")"); 93 if (!int.TryParse (sbExp.ToString (), out int exp)) { 94 throw new MalformedJsonException ("Exponent is not a valid integer (\"" + sbExp + "\")"); 97 95 } 98 96 99 number = number *Math.Pow (10, exp);97 number *= Math.Pow (10, exp); 100 98 } 101 99 102 100 //Log.Out ("JSON:Parsed Number: " + number.ToString ()); 103 return new J SONNumber (number);101 return new JsonNumber (number); 104 102 } 105 103 … … 107 105 } 108 106 109 throw new MalformedJ SONException ("End of JSON reached before parsing number finished");107 throw new MalformedJsonException ("End of JSON reached before parsing number finished"); 110 108 } 111 109 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONObject.cs
r389 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class J SONObject : JSONNode {6 private readonly Dictionary<string, J SONNode> nodes = new Dictionary<string, JSONNode> ();5 public class JsonObject : JsonNode { 6 private readonly Dictionary<string, JsonNode> nodes = new Dictionary<string, JsonNode> (); 7 7 8 public J SONNode this [string _name] {8 public JsonNode this [string _name] { 9 9 get => nodes [_name]; 10 10 set => nodes [_name] = value; … … 19 19 } 20 20 21 public bool TryGetValue (string _name, out J SONNode _node) {21 public bool TryGetValue (string _name, out JsonNode _node) { 22 22 return nodes.TryGetValue (_name, out _node); 23 23 } 24 24 25 public void Add (string _name, J SONNode _node) {25 public void Add (string _name, JsonNode _node) { 26 26 nodes.Add (_name, _node); 27 27 } … … 33 33 } 34 34 35 foreach ( KeyValuePair<string, JSONNode> kvpin nodes) {35 foreach ((string key, JsonNode value) in nodes) { 36 36 if (_prettyPrint) { 37 37 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); 38 38 } 39 39 40 _stringBuilder.Append ( string.Format ("\"{0}\":", kvp.Key));40 _stringBuilder.Append ($"\"{key}\":"); 41 41 if (_prettyPrint) { 42 42 _stringBuilder.Append (" "); 43 43 } 44 44 45 kvp.Value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1);45 value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1); 46 46 _stringBuilder.Append (","); 47 47 if (_prettyPrint) { … … 61 61 } 62 62 63 public static J SONObject Parse (string _json, ref int _offset) {63 public static JsonObject Parse (string _json, ref int _offset) { 64 64 //Log.Out ("ParseObject enter (" + offset + ")"); 65 J SONObject obj = new JSONObject ();65 JsonObject obj = new JsonObject (); 66 66 67 67 bool nextElemAllowed = true; … … 72 72 case '"': 73 73 if (nextElemAllowed) { 74 J SONString key = JSONString.Parse (_json, ref _offset);74 JsonString key = JsonString.Parse (_json, ref _offset); 75 75 Parser.SkipWhitespace (_json, ref _offset); 76 76 if (_json [_offset] != ':') { 77 throw new MalformedJ SONException (77 throw new MalformedJsonException ( 78 78 "Could not parse object, missing colon (\":\") after key"); 79 79 } 80 80 81 81 _offset++; 82 J SONNode val = Parser.ParseInternal (_json, ref _offset);82 JsonNode val = Parser.ParseInternal (_json, ref _offset); 83 83 obj.Add (key.GetString (), val); 84 84 nextElemAllowed = false; 85 85 } else { 86 throw new MalformedJ SONException (86 throw new MalformedJsonException ( 87 87 "Could not parse object, found new key without a separating comma"); 88 88 } … … 94 94 _offset++; 95 95 } else { 96 throw new MalformedJ SONException (96 throw new MalformedJsonException ( 97 97 "Could not parse object, found a comma without a key/value pair first"); 98 98 } -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONString.cs
r389 r391 2 2 3 3 namespace AllocsFixes.JSON { 4 public class J SONString : JSONValue {4 public class JsonString : JsonValue { 5 5 private readonly string value; 6 6 7 public J SONString (string _value) {7 public JsonString (string _value) { 8 8 value = _value; 9 9 } … … 14 14 15 15 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 16 if ( value == null || value.Length == 0) {16 if (string.IsNullOrEmpty (value)) { 17 17 _stringBuilder.Append ("\"\""); 18 18 return; … … 64 64 } 65 65 66 public static J SONString Parse (string _json, ref int _offset) {66 public static JsonString Parse (string _json, ref int _offset) { 67 67 //Log.Out ("ParseString enter (" + offset + ")"); 68 68 StringBuilder sb = new StringBuilder (); … … 104 104 105 105 //Log.Out ("JSON:Parsed String: " + sb.ToString ()); 106 return new J SONString (sb.ToString ());106 return new JsonString (sb.ToString ()); 107 107 default: 108 108 sb.Append (_json [_offset]); … … 112 112 } 113 113 114 throw new MalformedJ SONException ("End of JSON reached before parsing string finished");114 throw new MalformedJsonException ("End of JSON reached before parsing string finished"); 115 115 } 116 116 -
binary-improvements2/7dtd-server-fixes/src/JSON/JSONValue.cs
r389 r391 1 1 namespace AllocsFixes.JSON { 2 public abstract class J SONValue : JSONNode {2 public abstract class JsonValue : JsonNode { 3 3 public abstract string AsString { get; } 4 4 public abstract int AsInt { get; } -
binary-improvements2/7dtd-server-fixes/src/JSON/JsonManualBuilder.cs
r354 r391 9 9 NonEmpty = 1, 10 10 Object = 2, 11 Array = 4 ,11 Array = 4 12 12 } 13 13 … … 20 20 private int currentLevelNumber; 21 21 22 private ELevelInfo CurrentLevelInfo { 23 get { return (ELevelInfo) (currentLevelType & levelBitsMask); } 24 } 25 26 private bool CurrentLevelIsNonEmpty { 27 get { return (CurrentLevelInfo & ELevelInfo.NonEmpty) == ELevelInfo.NonEmpty; } 28 } 29 30 private bool CurrentLevelIsArray { 31 get { return (CurrentLevelInfo & ELevelInfo.Array) != ELevelInfo.Array; } 32 } 33 34 private bool CurrentLevelIsObject { 35 get { return (CurrentLevelInfo & ELevelInfo.Object) != ELevelInfo.Object; } 36 } 37 22 private ELevelInfo CurrentLevelInfo => (ELevelInfo) (currentLevelType & levelBitsMask); 23 24 private bool CurrentLevelIsNonEmpty => (CurrentLevelInfo & ELevelInfo.NonEmpty) == ELevelInfo.NonEmpty; 25 26 private bool CurrentLevelIsArray => (CurrentLevelInfo & ELevelInfo.Array) != ELevelInfo.Array; 27 28 private bool CurrentLevelIsObject => (CurrentLevelInfo & ELevelInfo.Object) != ELevelInfo.Object; 29 38 30 public JsonManualBuilder (bool _prettyPrint) { 39 31 prettyPrint = _prettyPrint; … … 54 46 } 55 47 56 currentLevelType = currentLevelType |(long) ELevelInfo.NonEmpty;48 currentLevelType |= (long) ELevelInfo.NonEmpty; 57 49 } 58 50 … … 210 202 211 203 currentLevelNumber--; 212 currentLevelType = currentLevelType >>levelTypeBits;204 currentLevelType >>= levelTypeBits; 213 205 214 206 if (prettyPrint) { -
binary-improvements2/7dtd-server-fixes/src/JSON/MalformedJSONException.cs
r351 r391 3 3 4 4 namespace AllocsFixes.JSON { 5 public class MalformedJ SONException : ApplicationException {6 public MalformedJ SONException () {5 public class MalformedJsonException : ApplicationException { 6 public MalformedJsonException () { 7 7 } 8 8 9 public MalformedJ SONException (string _message) : base (_message) {9 public MalformedJsonException (string _message) : base (_message) { 10 10 } 11 11 12 public MalformedJ SONException (string _message, Exception _inner) : base (_message, _inner) {12 public MalformedJsonException (string _message, Exception _inner) : base (_message, _inner) { 13 13 } 14 14 15 protected MalformedJ SONException (SerializationInfo _info, StreamingContext _context) : base (_info, _context) {15 protected MalformedJsonException (SerializationInfo _info, StreamingContext _context) : base (_info, _context) { 16 16 } 17 17 } -
binary-improvements2/7dtd-server-fixes/src/JSON/Parser.cs
r351 r391 1 1 namespace AllocsFixes.JSON { 2 public class Parser {3 public static J SONNode Parse (string _json) {2 public static class Parser { 3 public static JsonNode Parse (string _json) { 4 4 int offset = 0; 5 5 return ParseInternal (_json, ref offset); 6 6 } 7 7 8 public static J SONNode ParseInternal (string _json, ref int _offset) {8 public static JsonNode ParseInternal (string _json, ref int _offset) { 9 9 SkipWhitespace (_json, ref _offset); 10 10 … … 12 12 switch (_json [_offset]) { 13 13 case '[': 14 return J SONArray.Parse (_json, ref _offset);14 return JsonArray.Parse (_json, ref _offset); 15 15 case '{': 16 return J SONObject.Parse (_json, ref _offset);16 return JsonObject.Parse (_json, ref _offset); 17 17 case '"': 18 return J SONString.Parse (_json, ref _offset);18 return JsonString.Parse (_json, ref _offset); 19 19 case 't': 20 20 case 'f': 21 return J SONBoolean.Parse (_json, ref _offset);21 return JsonBoolean.Parse (_json, ref _offset); 22 22 case 'n': 23 return J SONNull.Parse (_json, ref _offset);23 return JsonNull.Parse (_json, ref _offset); 24 24 default: 25 return J SONNumber.Parse (_json, ref _offset);25 return JsonNumber.Parse (_json, ref _offset); 26 26 } 27 27 } … … 42 42 } 43 43 44 throw new MalformedJ SONException ("End of JSON reached before parsing finished");44 throw new MalformedJsonException ("End of JSON reached before parsing finished"); 45 45 } 46 46 } -
binary-improvements2/7dtd-server-fixes/src/LandClaimList.cs
r369 r391 20 20 Dictionary<PersistentPlayerData, List<Vector3i>> owners = 21 21 new Dictionary<PersistentPlayerData, List<Vector3i>> (); 22 foreach ( KeyValuePair<Vector3i, PersistentPlayerData> kvpin d) {22 foreach ((Vector3i claimPos, PersistentPlayerData owner) in d) { 23 23 bool allowed = true; 24 24 if (_positionFilters != null) { 25 25 foreach (PositionFilter pf in _positionFilters) { 26 if (!pf (kvp.Key)) { 27 allowed = false; 28 break; 26 if (pf (claimPos)) { 27 continue; 29 28 } 29 30 allowed = false; 31 break; 30 32 } 31 33 } 32 34 33 if (allowed) { 34 if (!owners.ContainsKey (kvp.Value)) { 35 owners.Add (kvp.Value, new List<Vector3i> ()); 36 } 35 if (!allowed) { 36 continue; 37 } 37 38 38 owners [kvp.Value].Add (kvp.Key); 39 if (!owners.ContainsKey (owner)) { 40 owners.Add (owner, new List<Vector3i> ()); 39 41 } 42 43 owners [owner].Add (claimPos); 40 44 } 41 45 42 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) { 43 Player p = PersistentContainer.Instance.Players [kvp.Key.UserIdentifier, false]; 44 if (p == null) { 45 p = new Player (kvp.Key.UserIdentifier); 46 } 46 foreach ((PersistentPlayerData owner, List<Vector3i> claimPositions) in owners) { 47 Player p = PersistentContainer.Instance.Players [owner.UserIdentifier, false] ?? new Player (owner.UserIdentifier); 47 48 48 49 bool allowed = true; 49 50 if (_ownerFilters != null) { 50 51 foreach (OwnerFilter of in _ownerFilters) { 51 if (!of (p)) { 52 allowed = false; 53 break; 52 if (of (p)) { 53 continue; 54 54 } 55 56 allowed = false; 57 break; 55 58 } 56 59 } 57 60 58 if (allowed) { 59 result.Add (p, new List<Vector3i> ()); 60 foreach (Vector3i v in kvp.Value) { 61 result [p].Add (v); 62 } 61 if (!allowed) { 62 continue; 63 } 64 65 result.Add (p, new List<Vector3i> ()); 66 foreach (Vector3i v in claimPositions) { 67 result [p].Add (v); 63 68 } 64 69 } -
binary-improvements2/7dtd-server-fixes/src/ModApi.cs
r390 r391 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 { 6 public class API : IModApi { 7 [UsedImplicitly] 8 public class ModApi : 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 ublicvoid GameAwake () {18 private 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 void SavePlayerData (ClientInfo _cInfo, PlayerDataFile _playerDataFile) { 25 23 PersistentContainer.Instance.Players [_cInfo.InternalId, true].Update (_playerDataFile); 26 24 } 27 25 28 p ublicvoid PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) {26 private void PlayerSpawning (ClientInfo _cInfo, int _chunkViewDim, PlayerProfile _playerProfile) { 29 27 string owner = null; 30 28 if (_cInfo.PlatformId is UserIdentifierSteam identifierSteam) { … … 42 40 } 43 41 44 p ublicvoid PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) {42 private void PlayerDisconnected (ClientInfo _cInfo, bool _bShutdown) { 45 43 Player p = PersistentContainer.Instance.Players [_cInfo.InternalId, false]; 46 44 if (p != null) { … … 53 51 } 54 52 55 p ublicvoid PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) {53 private void PlayerSpawned (ClientInfo _cInfo, RespawnType _respawnReason, Vector3i _spawnPos) { 56 54 PersistentContainer.Instance.Players [_cInfo.InternalId, true].SetOnline (_cInfo); 57 55 PersistentContainer.Instance.Save (); 58 56 } 59 57 60 private const string ANSWER=58 private const string testChatAnswer = 61 59 " [ff0000]I[-] [ff7f00]W[-][ffff00]A[-][80ff00]S[-] [00ffff]H[-][0080ff]E[-][0000ff]R[-][8b00ff]E[-]"; 62 60 63 p ublicbool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName,61 private bool ChatMessage (ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, 64 62 bool _localizeMain, List<int> _recipientEntityIds) { 65 63 if (string.IsNullOrEmpty (_msg) || !_msg.EqualsCaseInsensitive ("/alloc")) { … … 69 67 if (_cInfo != null) { 70 68 Log.Out ("Sent chat hook reply to {0}", _cInfo.InternalId); 71 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, ANSWER, "", false, null));69 _cInfo.SendPackage (NetPackageManager.GetPackage<NetPackageChat> ().Setup (EChatType.Whisper, -1, testChatAnswer, "", false, null)); 72 70 } else { 73 71 Log.Error ("ChatHookExample: Argument _cInfo null on message: {0}", _msg); -
binary-improvements2/7dtd-server-fixes/src/PersistentData/Attributes.cs
r326 r391 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 ?? (hideChatCommandPrefix = ""); 16 set => hideChatCommandPrefix = value; 23 17 } 24 18 } -
binary-improvements2/7dtd-server-fixes/src/PersistentData/PersistentContainer.cs
r369 r391 10 10 [OptionalField] private Attributes attributes; 11 11 12 public Players Players { 13 get { 14 if (players == null) { 15 players = new Players (); 16 } 12 public Players Players => players ?? (players = new Players ()); 17 13 18 return players; 19 } 20 } 21 22 public Attributes Attributes { 23 get { 24 if (attributes == null) { 25 attributes = new Attributes (); 26 } 27 28 return attributes; 29 } 30 } 14 public Attributes Attributes => attributes ?? (attributes = new Attributes ()); 31 15 32 16 private static PersistentContainer instance; 33 17 34 public static PersistentContainer Instance { 35 get { 36 if (instance == null) { 37 instance = new PersistentContainer (); 38 } 39 40 return instance; 41 } 42 } 18 public static PersistentContainer Instance => instance ?? (instance = new PersistentContainer ()); 43 19 44 20 private PersistentContainer () { … … 58 34 59 35 try { 60 PersistentContainer obj;61 36 Stream stream = File.Open (GameIO.GetSaveGameDir () + "/AllocsPeristentData.bin", FileMode.Open); 62 37 BinaryFormatter bFormatter = new BinaryFormatter (); 63 obj = (PersistentContainer) bFormatter.Deserialize (stream);38 PersistentContainer obj = (PersistentContainer) bFormatter.Deserialize (stream); 64 39 stream.Close (); 65 40 instance = obj; -
binary-improvements2/7dtd-server-fixes/src/PersistentData/Players.cs
r383 r391 41 41 42 42 if (int.TryParse (_nameOrId, out int entityId)) { 43 foreach ( KeyValuePair<PlatformUserIdentifierAbs, Player> kvpin Dict) {44 if ( kvp.Value.IsOnline && kvp.Value.EntityID == entityId) {45 return kvp.Key;43 foreach ((PlatformUserIdentifierAbs iUserId, Player player) in Dict) { 44 if (player.IsOnline && player.EntityID == entityId) { 45 return iUserId; 46 46 } 47 47 } 48 48 } 49 49 50 foreach ( KeyValuePair<PlatformUserIdentifierAbs, Player> kvpin Dict) {51 string name = kvp.Value.Name;50 foreach ((PlatformUserIdentifierAbs iUserId, Player player) in Dict) { 51 string name = player.Name; 52 52 if (_ignoreColorCodes) { 53 53 name = Regex.Replace (name, "\\[[0-9a-fA-F]{6}\\]", ""); 54 54 } 55 55 56 if ( kvp.Value.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) {57 return kvp.Key;56 if (player.IsOnline && name.EqualsCaseInsensitive (_nameOrId)) { 57 return iUserId; 58 58 } 59 59 }
Note:
See TracChangeset
for help on using the changeset viewer.