Changeset 351 for binary-improvements/7dtd-server-fixes
- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/BlockingQueue.cs
r325 r351 7 7 private bool closing; 8 8 9 public void Enqueue (T item) {9 public void Enqueue (T _item) { 10 10 lock (queue) { 11 queue.Enqueue ( item);11 queue.Enqueue (_item); 12 12 Monitor.PulseAll (queue); 13 13 } -
binary-improvements/7dtd-server-fixes/src/FileCache/AbstractCache.cs
r325 r351 1 1 namespace AllocsFixes.FileCache { 2 2 public abstract class AbstractCache { 3 public abstract byte[] GetFileContent (string filename);3 public abstract byte[] GetFileContent (string _filename); 4 4 } 5 5 } -
binary-improvements/7dtd-server-fixes/src/FileCache/DirectAccess.cs
r325 r351 5 5 // Not caching at all, simply reading from disk on each request 6 6 public class DirectAccess : AbstractCache { 7 public override byte[] GetFileContent (string filename) {7 public override byte[] GetFileContent (string _filename) { 8 8 try { 9 if (!File.Exists ( filename)) {9 if (!File.Exists (_filename)) { 10 10 return null; 11 11 } 12 12 13 return File.ReadAllBytes ( filename);13 return File.ReadAllBytes (_filename); 14 14 } catch (Exception e) { 15 15 Log.Out ("Error in DirectAccess.GetFileContent: " + e); -
binary-improvements/7dtd-server-fixes/src/FileCache/MapTileCache.cs
r346 r351 25 25 } 26 26 27 public void SetZoomCount (int count) {28 cache = new CurrentZoomFile[ count];27 public void SetZoomCount (int _count) { 28 cache = new CurrentZoomFile[_count]; 29 29 for (int i = 0; i < cache.Length; i++) { 30 30 cache [i] = new CurrentZoomFile (); … … 32 32 } 33 33 34 public byte[] LoadTile (int zoomlevel, stringfilename) {34 public byte[] LoadTile (int _zoomlevel, string _filename) { 35 35 try { 36 36 lock (cache) { 37 CurrentZoomFile cacheEntry = cache [ zoomlevel];37 CurrentZoomFile cacheEntry = cache [_zoomlevel]; 38 38 39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals ( filename)) {40 cacheEntry.filename = filename;39 if (cacheEntry.filename == null || !cacheEntry.filename.Equals (_filename)) { 40 cacheEntry.filename = _filename; 41 41 42 if (!File.Exists ( filename)) {42 if (!File.Exists (_filename)) { 43 43 cacheEntry.pngData = null; 44 44 return null; … … 46 46 47 47 Profiler.BeginSample ("ReadPng"); 48 cacheEntry.pngData = ReadAllBytes ( filename);48 cacheEntry.pngData = ReadAllBytes (_filename); 49 49 Profiler.EndSample (); 50 50 } … … 59 59 } 60 60 61 public void SaveTile (int zoomlevel, byte[]contentPng) {61 public void SaveTile (int _zoomlevel, byte[] _contentPng) { 62 62 try { 63 63 lock (cache) { 64 CurrentZoomFile cacheEntry = cache [ zoomlevel];64 CurrentZoomFile cacheEntry = cache [_zoomlevel]; 65 65 66 66 string file = cacheEntry.filename; … … 69 69 } 70 70 71 cacheEntry.pngData = contentPng;71 cacheEntry.pngData = _contentPng; 72 72 73 73 Profiler.BeginSample ("WritePng"); 74 74 using (Stream stream = new FileStream (file, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 75 75 4096)) { 76 stream.Write ( contentPng, 0,contentPng.Length);76 stream.Write (_contentPng, 0, _contentPng.Length); 77 77 } 78 78 Profiler.EndSample (); … … 83 83 } 84 84 85 public void ResetTile (int zoomlevel) {85 public void ResetTile (int _zoomlevel) { 86 86 try { 87 87 lock (cache) { 88 cache [ zoomlevel].filename = null;89 cache [ zoomlevel].pngData = null;88 cache [_zoomlevel].filename = null; 89 cache [_zoomlevel].pngData = null; 90 90 } 91 91 } catch (Exception e) { … … 94 94 } 95 95 96 public override byte[] GetFileContent (string filename) {96 public override byte[] GetFileContent (string _filename) { 97 97 try { 98 98 lock (cache) { 99 99 foreach (CurrentZoomFile czf in cache) { 100 if (czf.filename != null && czf.filename.Equals ( filename)) {100 if (czf.filename != null && czf.filename.Equals (_filename)) { 101 101 return czf.pngData; 102 102 } 103 103 } 104 104 105 if (!File.Exists ( filename)) {105 if (!File.Exists (_filename)) { 106 106 return transparentTile; 107 107 } 108 108 109 return ReadAllBytes ( filename);109 return ReadAllBytes (_filename); 110 110 } 111 111 } catch (Exception e) { -
binary-improvements/7dtd-server-fixes/src/FileCache/SimpleCache.cs
r325 r351 8 8 private readonly Dictionary<string, byte[]> fileCache = new Dictionary<string, byte[]> (); 9 9 10 public override byte[] GetFileContent (string filename) {10 public override byte[] GetFileContent (string _filename) { 11 11 try { 12 12 lock (fileCache) { 13 if (!fileCache.ContainsKey ( filename)) {14 if (!File.Exists ( filename)) {13 if (!fileCache.ContainsKey (_filename)) { 14 if (!File.Exists (_filename)) { 15 15 return null; 16 16 } 17 17 18 fileCache.Add ( filename, File.ReadAllBytes (filename));18 fileCache.Add (_filename, File.ReadAllBytes (_filename)); 19 19 } 20 20 21 return fileCache [ filename];21 return fileCache [_filename]; 22 22 } 23 23 } catch (Exception e) { -
binary-improvements/7dtd-server-fixes/src/JSON/JSONArray.cs
r325 r351 6 6 private readonly List<JSONNode> nodes = new List<JSONNode> (); 7 7 8 public JSONNode this [int index] {9 get { return nodes [ index]; }10 set { nodes [ index] = value; }8 public JSONNode this [int _index] { 9 get { return nodes [_index]; } 10 set { nodes [_index] = value; } 11 11 } 12 12 … … 15 15 } 16 16 17 public void Add (JSONNode node) {18 nodes.Add ( node);17 public void Add (JSONNode _node) { 18 nodes.Add (_node); 19 19 } 20 20 21 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {22 stringBuilder.Append ("[");23 if ( prettyPrint) {24 stringBuilder.Append ('\n');21 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 22 _stringBuilder.Append ("["); 23 if (_prettyPrint) { 24 _stringBuilder.Append ('\n'); 25 25 } 26 26 27 27 foreach (JSONNode n in nodes) { 28 if ( prettyPrint) {29 stringBuilder.Append (new string ('\t',currentLevel + 1));28 if (_prettyPrint) { 29 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); 30 30 } 31 31 32 n.ToString ( stringBuilder, prettyPrint,currentLevel + 1);33 stringBuilder.Append (",");34 if ( prettyPrint) {35 stringBuilder.Append ('\n');32 n.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1); 33 _stringBuilder.Append (","); 34 if (_prettyPrint) { 35 _stringBuilder.Append ('\n'); 36 36 } 37 37 } 38 38 39 39 if (nodes.Count > 0) { 40 stringBuilder.Remove (stringBuilder.Length - (prettyPrint ? 2 : 1), 1);40 _stringBuilder.Remove (_stringBuilder.Length - (_prettyPrint ? 2 : 1), 1); 41 41 } 42 42 43 if ( prettyPrint) {44 stringBuilder.Append (new string ('\t',currentLevel));43 if (_prettyPrint) { 44 _stringBuilder.Append (new string ('\t', _currentLevel)); 45 45 } 46 46 47 stringBuilder.Append ("]");47 _stringBuilder.Append ("]"); 48 48 } 49 49 50 public static JSONArray Parse (string json, ref intoffset) {50 public static JSONArray Parse (string _json, ref int _offset) { 51 51 //Log.Out ("ParseArray enter (" + offset + ")"); 52 52 JSONArray arr = new JSONArray (); 53 53 54 54 bool nextElemAllowed = true; 55 offset++;55 _offset++; 56 56 while (true) { 57 Parser.SkipWhitespace ( json, refoffset);57 Parser.SkipWhitespace (_json, ref _offset); 58 58 59 switch ( json [offset]) {59 switch (_json [_offset]) { 60 60 case ',': 61 61 if (!nextElemAllowed) { 62 62 nextElemAllowed = true; 63 offset++;63 _offset++; 64 64 } else { 65 65 throw new MalformedJSONException ( … … 69 69 break; 70 70 case ']': 71 offset++;71 _offset++; 72 72 73 73 //Log.Out ("JSON:Parsed Array: " + arr.ToString ()); 74 74 return arr; 75 75 default: 76 arr.Add (Parser.ParseInternal ( json, refoffset));76 arr.Add (Parser.ParseInternal (_json, ref _offset)); 77 77 nextElemAllowed = false; 78 78 break; -
binary-improvements/7dtd-server-fixes/src/JSON/JSONBoolean.cs
r325 r351 5 5 private readonly bool value; 6 6 7 public JSONBoolean (bool value) {8 this.value =value;7 public JSONBoolean (bool _value) { 8 value = _value; 9 9 } 10 10 … … 13 13 } 14 14 15 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {16 stringBuilder.Append (value ? "true" : "false");15 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 16 _stringBuilder.Append (value ? "true" : "false"); 17 17 } 18 18 19 public static JSONBoolean Parse (string json, ref intoffset) {19 public static JSONBoolean Parse (string _json, ref int _offset) { 20 20 //Log.Out ("ParseBool enter (" + offset + ")"); 21 21 22 if ( json.Substring (offset, 4).Equals ("true")) {22 if (_json.Substring (_offset, 4).Equals ("true")) { 23 23 //Log.Out ("JSON:Parsed Bool: true"); 24 offset += 4;24 _offset += 4; 25 25 return new JSONBoolean (true); 26 26 } 27 27 28 if ( json.Substring (offset, 5).Equals ("false")) {28 if (_json.Substring (_offset, 5).Equals ("false")) { 29 29 //Log.Out ("JSON:Parsed Bool: false"); 30 offset += 5;30 _offset += 5; 31 31 return new JSONBoolean (false); 32 32 } -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNode.cs
r325 r351 3 3 namespace AllocsFixes.JSON { 4 4 public abstract class JSONNode { 5 public abstract void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0);5 public abstract void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0); 6 6 7 7 public override string ToString () { -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNull.cs
r326 r351 3 3 namespace AllocsFixes.JSON { 4 4 public class JSONNull : JSONValue { 5 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {6 stringBuilder.Append ("null");5 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 6 _stringBuilder.Append ("null"); 7 7 } 8 8 9 public static JSONNull Parse (string json, ref intoffset) {9 public static JSONNull Parse (string _json, ref int _offset) { 10 10 //Log.Out ("ParseNull enter (" + offset + ")"); 11 11 12 if (! json.Substring (offset, 4).Equals ("null")) {12 if (!_json.Substring (_offset, 4).Equals ("null")) { 13 13 throw new MalformedJSONException ("No valid null value found"); 14 14 } 15 15 16 16 //Log.Out ("JSON:Parsed Null"); 17 offset += 4;17 _offset += 4; 18 18 return new JSONNull (); 19 19 } -
binary-improvements/7dtd-server-fixes/src/JSON/JSONNumber.cs
r325 r351 6 6 private readonly double value; 7 7 8 public JSONNumber (double value) {9 this.value =value;8 public JSONNumber (double _value) { 9 value = _value; 10 10 } 11 11 … … 18 18 } 19 19 20 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {21 stringBuilder.Append (value.ToCultureInvariantString ());20 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 21 _stringBuilder.Append (value.ToCultureInvariantString ()); 22 22 } 23 23 24 public static JSONNumber Parse (string json, ref intoffset) {24 public static JSONNumber Parse (string _json, ref int _offset) { 25 25 //Log.Out ("ParseNumber enter (" + offset + ")"); 26 26 StringBuilder sbNum = new StringBuilder (); … … 28 28 bool hasDec = false; 29 29 bool hasExp = false; 30 while ( offset <json.Length) {31 if ( json [offset] >= '0' && json [offset] <= '9') {30 while (_offset < _json.Length) { 31 if (_json [_offset] >= '0' && _json [_offset] <= '9') { 32 32 if (hasExp) { 33 sbExp.Append ( json [offset]);33 sbExp.Append (_json [_offset]); 34 34 } else { 35 sbNum.Append ( json [offset]);35 sbNum.Append (_json [_offset]); 36 36 } 37 } else if ( json [offset] == '.') {37 } else if (_json [_offset] == '.') { 38 38 if (hasExp) { 39 39 throw new MalformedJSONException ("Decimal separator in exponent"); … … 50 50 sbNum.Append ('.'); 51 51 hasDec = true; 52 } else if ( json [offset] == '-') {52 } else if (_json [_offset] == '-') { 53 53 if (hasExp) { 54 54 if (sbExp.Length > 0) { … … 56 56 } 57 57 58 sbExp.Append ( json [offset]);58 sbExp.Append (_json [_offset]); 59 59 } else { 60 60 if (sbNum.Length > 0) { … … 62 62 } 63 63 64 sbNum.Append ( json [offset]);64 sbNum.Append (_json [_offset]); 65 65 } 66 } else if ( json [offset] == 'e' || json [offset] == 'E') {66 } else if (_json [_offset] == 'e' || _json [_offset] == 'E') { 67 67 if (hasExp) { 68 68 throw new MalformedJSONException ("Multiple exponential markers in number found"); … … 75 75 sbExp = new StringBuilder (); 76 76 hasExp = true; 77 } else if ( json [offset] == '+') {77 } else if (_json [_offset] == '+') { 78 78 if (hasExp) { 79 79 if (sbExp.Length > 0) { … … 81 81 } 82 82 83 sbExp.Append ( json [offset]);83 sbExp.Append (_json [_offset]); 84 84 } else { 85 85 throw new MalformedJSONException ("Positive sign in mantissa found"); … … 104 104 } 105 105 106 offset++;106 _offset++; 107 107 } 108 108 -
binary-improvements/7dtd-server-fixes/src/JSON/JSONObject.cs
r326 r351 6 6 private readonly Dictionary<string, JSONNode> nodes = new Dictionary<string, JSONNode> (); 7 7 8 public JSONNode this [string name] {9 get { return nodes [ name]; }10 set { nodes [ name] = value; }8 public JSONNode this [string _name] { 9 get { return nodes [_name]; } 10 set { nodes [_name] = value; } 11 11 } 12 12 … … 19 19 } 20 20 21 public bool ContainsKey (string name) {22 return nodes.ContainsKey ( name);21 public bool ContainsKey (string _name) { 22 return nodes.ContainsKey (_name); 23 23 } 24 24 25 public void Add (string name, JSONNodenode) {26 nodes.Add ( name,node);25 public void Add (string _name, JSONNode _node) { 26 nodes.Add (_name, _node); 27 27 } 28 28 29 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {30 stringBuilder.Append ("{");31 if ( prettyPrint) {32 stringBuilder.Append ('\n');29 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 30 _stringBuilder.Append ("{"); 31 if (_prettyPrint) { 32 _stringBuilder.Append ('\n'); 33 33 } 34 34 35 35 foreach (KeyValuePair<string, JSONNode> kvp in nodes) { 36 if ( prettyPrint) {37 stringBuilder.Append (new string ('\t',currentLevel + 1));36 if (_prettyPrint) { 37 _stringBuilder.Append (new string ('\t', _currentLevel + 1)); 38 38 } 39 39 40 stringBuilder.Append (string.Format ("\"{0}\":", kvp.Key));41 if ( prettyPrint) {42 stringBuilder.Append (" ");40 _stringBuilder.Append (string.Format ("\"{0}\":", kvp.Key)); 41 if (_prettyPrint) { 42 _stringBuilder.Append (" "); 43 43 } 44 44 45 kvp.Value.ToString ( stringBuilder, prettyPrint,currentLevel + 1);46 stringBuilder.Append (",");47 if ( prettyPrint) {48 stringBuilder.Append ('\n');45 kvp.Value.ToString (_stringBuilder, _prettyPrint, _currentLevel + 1); 46 _stringBuilder.Append (","); 47 if (_prettyPrint) { 48 _stringBuilder.Append ('\n'); 49 49 } 50 50 } 51 51 52 52 if (nodes.Count > 0) { 53 stringBuilder.Remove (stringBuilder.Length - (prettyPrint ? 2 : 1), 1);53 _stringBuilder.Remove (_stringBuilder.Length - (_prettyPrint ? 2 : 1), 1); 54 54 } 55 55 56 if ( prettyPrint) {57 stringBuilder.Append (new string ('\t',currentLevel));56 if (_prettyPrint) { 57 _stringBuilder.Append (new string ('\t', _currentLevel)); 58 58 } 59 59 60 stringBuilder.Append ("}");60 _stringBuilder.Append ("}"); 61 61 } 62 62 63 public static JSONObject Parse (string json, ref intoffset) {63 public static JSONObject Parse (string _json, ref int _offset) { 64 64 //Log.Out ("ParseObject enter (" + offset + ")"); 65 65 JSONObject obj = new JSONObject (); 66 66 67 67 bool nextElemAllowed = true; 68 offset++;68 _offset++; 69 69 while (true) { 70 Parser.SkipWhitespace ( json, refoffset);71 switch ( json [offset]) {70 Parser.SkipWhitespace (_json, ref _offset); 71 switch (_json [_offset]) { 72 72 case '"': 73 73 if (nextElemAllowed) { 74 JSONString key = JSONString.Parse ( json, refoffset);75 Parser.SkipWhitespace ( json, refoffset);76 if ( json [offset] != ':') {74 JSONString key = JSONString.Parse (_json, ref _offset); 75 Parser.SkipWhitespace (_json, ref _offset); 76 if (_json [_offset] != ':') { 77 77 throw new MalformedJSONException ( 78 78 "Could not parse object, missing colon (\":\") after key"); 79 79 } 80 80 81 offset++;82 JSONNode val = Parser.ParseInternal ( json, refoffset);81 _offset++; 82 JSONNode val = Parser.ParseInternal (_json, ref _offset); 83 83 obj.Add (key.GetString (), val); 84 84 nextElemAllowed = false; … … 92 92 if (!nextElemAllowed) { 93 93 nextElemAllowed = true; 94 offset++;94 _offset++; 95 95 } else { 96 96 throw new MalformedJSONException ( … … 100 100 break; 101 101 case '}': 102 offset++;102 _offset++; 103 103 104 104 //Log.Out ("JSON:Parsed Object: " + obj.ToString ()); -
binary-improvements/7dtd-server-fixes/src/JSON/JSONString.cs
r325 r351 5 5 private readonly string value; 6 6 7 public JSONString (string value) {8 this.value =value;7 public JSONString (string _value) { 8 value = _value; 9 9 } 10 10 … … 13 13 } 14 14 15 public override void ToString (StringBuilder stringBuilder, bool prettyPrint = false, intcurrentLevel = 0) {15 public override void ToString (StringBuilder _stringBuilder, bool _prettyPrint = false, int _currentLevel = 0) { 16 16 if (value == null || value.Length == 0) { 17 stringBuilder.Append ("\"\"");17 _stringBuilder.Append ("\"\""); 18 18 return; 19 19 } … … 21 21 int len = value.Length; 22 22 23 stringBuilder.EnsureCapacity (stringBuilder.Length + 2 * len);23 _stringBuilder.EnsureCapacity (_stringBuilder.Length + 2 * len); 24 24 25 stringBuilder.Append ('"');25 _stringBuilder.Append ('"'); 26 26 27 27 foreach (char c in value) { … … 31 31 32 32 // case '/': 33 stringBuilder.Append ('\\');34 stringBuilder.Append (c);33 _stringBuilder.Append ('\\'); 34 _stringBuilder.Append (c); 35 35 break; 36 36 case '\b': 37 stringBuilder.Append ("\\b");37 _stringBuilder.Append ("\\b"); 38 38 break; 39 39 case '\t': 40 stringBuilder.Append ("\\t");40 _stringBuilder.Append ("\\t"); 41 41 break; 42 42 case '\n': 43 stringBuilder.Append ("\\n");43 _stringBuilder.Append ("\\n"); 44 44 break; 45 45 case '\f': 46 stringBuilder.Append ("\\f");46 _stringBuilder.Append ("\\f"); 47 47 break; 48 48 case '\r': 49 stringBuilder.Append ("\\r");49 _stringBuilder.Append ("\\r"); 50 50 break; 51 51 default: 52 52 if (c < ' ') { 53 stringBuilder.Append ("\\u");54 stringBuilder.Append (((int) c).ToString ("X4"));53 _stringBuilder.Append ("\\u"); 54 _stringBuilder.Append (((int) c).ToString ("X4")); 55 55 } else { 56 stringBuilder.Append (c);56 _stringBuilder.Append (c); 57 57 } 58 58 … … 61 61 } 62 62 63 stringBuilder.Append ('"');63 _stringBuilder.Append ('"'); 64 64 } 65 65 66 public static JSONString Parse (string json, ref intoffset) {66 public static JSONString Parse (string _json, ref int _offset) { 67 67 //Log.Out ("ParseString enter (" + offset + ")"); 68 68 StringBuilder sb = new StringBuilder (); 69 offset++;70 while ( offset <json.Length) {71 switch ( json [offset]) {69 _offset++; 70 while (_offset < _json.Length) { 71 switch (_json [_offset]) { 72 72 case '\\': 73 offset++;74 switch ( json [offset]) {73 _offset++; 74 switch (_json [_offset]) { 75 75 case '\\': 76 76 case '"': 77 77 case '/': 78 sb.Append ( json [offset]);78 sb.Append (_json [_offset]); 79 79 break; 80 80 case 'b': … … 94 94 break; 95 95 default: 96 sb.Append ( json [offset]);96 sb.Append (_json [_offset]); 97 97 break; 98 98 } 99 99 100 offset++;100 _offset++; 101 101 break; 102 102 case '"': 103 offset++;103 _offset++; 104 104 105 105 //Log.Out ("JSON:Parsed String: " + sb.ToString ()); 106 106 return new JSONString (sb.ToString ()); 107 107 default: 108 sb.Append ( json [offset]);109 offset++;108 sb.Append (_json [_offset]); 109 _offset++; 110 110 break; 111 111 } -
binary-improvements/7dtd-server-fixes/src/JSON/MalformedJSONException.cs
r325 r351 7 7 } 8 8 9 public MalformedJSONException (string message) : base (message) {9 public MalformedJSONException (string _message) : base (_message) { 10 10 } 11 11 12 public MalformedJSONException (string message, Exception inner) : base (message,inner) {12 public MalformedJSONException (string _message, Exception _inner) : base (_message, _inner) { 13 13 } 14 14 15 protected MalformedJSONException (SerializationInfo info, StreamingContext context) : base (info,context) {15 protected MalformedJSONException (SerializationInfo _info, StreamingContext _context) : base (_info, _context) { 16 16 } 17 17 } -
binary-improvements/7dtd-server-fixes/src/JSON/Parser.cs
r325 r351 1 1 namespace AllocsFixes.JSON { 2 2 public class Parser { 3 public static JSONNode Parse (string json) {3 public static JSONNode Parse (string _json) { 4 4 int offset = 0; 5 return ParseInternal ( json, ref offset);5 return ParseInternal (_json, ref offset); 6 6 } 7 7 8 public static JSONNode ParseInternal (string json, ref intoffset) {9 SkipWhitespace ( json, refoffset);8 public static JSONNode ParseInternal (string _json, ref int _offset) { 9 SkipWhitespace (_json, ref _offset); 10 10 11 11 //Log.Out ("ParseInternal (" + offset + "): Decide on: '" + json [offset] + "'"); 12 switch ( json [offset]) {12 switch (_json [_offset]) { 13 13 case '[': 14 return JSONArray.Parse ( json, refoffset);14 return JSONArray.Parse (_json, ref _offset); 15 15 case '{': 16 return JSONObject.Parse ( json, refoffset);16 return JSONObject.Parse (_json, ref _offset); 17 17 case '"': 18 return JSONString.Parse ( json, refoffset);18 return JSONString.Parse (_json, ref _offset); 19 19 case 't': 20 20 case 'f': 21 return JSONBoolean.Parse ( json, refoffset);21 return JSONBoolean.Parse (_json, ref _offset); 22 22 case 'n': 23 return JSONNull.Parse ( json, refoffset);23 return JSONNull.Parse (_json, ref _offset); 24 24 default: 25 return JSONNumber.Parse ( json, refoffset);25 return JSONNumber.Parse (_json, ref _offset); 26 26 } 27 27 } 28 28 29 public static void SkipWhitespace (string json, ref intoffset) {29 public static void SkipWhitespace (string _json, ref int _offset) { 30 30 //Log.Out ("SkipWhitespace (" + offset + "): '" + json [offset] + "'"); 31 while ( offset <json.Length) {32 switch ( json [offset]) {31 while (_offset < _json.Length) { 32 switch (_json [_offset]) { 33 33 case ' ': 34 34 case '\t': 35 35 case '\r': 36 36 case '\n': 37 offset++;37 _offset++; 38 38 break; 39 39 default: -
binary-improvements/7dtd-server-fixes/src/LandClaimList.cs
r326 r351 5 5 namespace AllocsFixes { 6 6 public class LandClaimList { 7 public delegate bool OwnerFilter (Player owner);7 public delegate bool OwnerFilter (Player _owner); 8 8 9 public delegate bool PositionFilter (Vector3i position);9 public delegate bool PositionFilter (Vector3i _position); 10 10 11 11 public static Dictionary<Player, List<Vector3i>> GetLandClaims (OwnerFilter[] _ownerFilters, … … 68 68 69 69 public static OwnerFilter SteamIdFilter (string _steamId) { 70 return p =>p.SteamID.Equals (_steamId);70 return _p => _p.SteamID.Equals (_steamId); 71 71 } 72 72 73 73 public static PositionFilter CloseToFilter2dRect (Vector3i _position, int _maxDistance) { 74 return v => Math.Abs (v.x - _position.x) <= _maxDistance && Math.Abs (v.z - _position.z) <= _maxDistance;74 return _v => Math.Abs (_v.x - _position.x) <= _maxDistance && Math.Abs (_v.z - _position.z) <= _maxDistance; 75 75 } 76 76 77 77 public static OwnerFilter OrOwnerFilter (OwnerFilter _f1, OwnerFilter _f2) { 78 return p => _f1 (p) || _f2 (p);78 return _p => _f1 (_p) || _f2 (_p); 79 79 } 80 80 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/InvItem.cs
r325 r351 16 16 public int useTimes; 17 17 18 public InvItem (string itemName, int count, int quality, int maxUseTimes, intmaxUse) {19 this.itemName =itemName;20 this.count =count;21 this.quality =quality;22 this.maxUseTimes =maxUseTimes;23 this.useTimes =maxUse;18 public InvItem (string _itemName, int _count, int _quality, int _maxUseTimes, int _maxUse) { 19 itemName = _itemName; 20 count = _count; 21 quality = _quality; 22 maxUseTimes = _maxUseTimes; 23 useTimes = _maxUse; 24 24 } 25 25 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs
r326 r351 15 15 } 16 16 17 public void Update (PlayerDataFile pdf) {17 public void Update (PlayerDataFile _pdf) { 18 18 lock (this) { 19 19 //Log.Out ("Updating player inventory - player id: " + pdf.id); 20 ProcessInv (bag, pdf.bag,pdf.id);21 ProcessInv (belt, pdf.inventory,pdf.id);22 ProcessEqu ( pdf.equipment,pdf.id);20 ProcessInv (bag, _pdf.bag, _pdf.id); 21 ProcessInv (belt, _pdf.inventory, _pdf.id); 22 ProcessEqu (_pdf.equipment, _pdf.id); 23 23 } 24 24 } 25 25 26 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, intid) {27 target.Clear ();28 for (int i = 0; i < sourceFields.Length; i++) {29 InvItem item = CreateInvItem ( sourceFields [i].itemValue, sourceFields [i].count,id);30 if (item != null && sourceFields [i].itemValue.Modifications != null) {31 ProcessParts ( sourceFields [i].itemValue.Modifications, item,id);26 private void ProcessInv (List<InvItem> _target, ItemStack[] _sourceFields, int _id) { 27 _target.Clear (); 28 for (int i = 0; i < _sourceFields.Length; i++) { 29 InvItem item = CreateInvItem (_sourceFields [i].itemValue, _sourceFields [i].count, _id); 30 if (item != null && _sourceFields [i].itemValue.Modifications != null) { 31 ProcessParts (_sourceFields [i].itemValue.Modifications, item, _id); 32 32 } 33 33 34 target.Add (item);34 _target.Add (item); 35 35 } 36 36 } 37 37 38 private void ProcessEqu (Equipment sourceEquipment, int _playerId) {39 equipment = new InvItem[ sourceEquipment.GetSlotCount ()];40 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) {41 equipment [i] = CreateInvItem ( sourceEquipment.GetSlotItem (i), 1, _playerId);38 private void ProcessEqu (Equipment _sourceEquipment, int _playerId) { 39 equipment = new InvItem[_sourceEquipment.GetSlotCount ()]; 40 for (int i = 0; i < _sourceEquipment.GetSlotCount (); i++) { 41 equipment [i] = CreateInvItem (_sourceEquipment.GetSlotItem (i), 1, _playerId); 42 42 } 43 43 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r333 r351 168 168 } 169 169 170 public Player (string steamId) {171 this.steamId =steamId;170 public Player (string _steamId) { 171 steamId = _steamId; 172 172 inventory = new Inventory (); 173 173 } … … 193 193 } 194 194 195 public void SetOnline (ClientInfo ci) {195 public void SetOnline (ClientInfo _ci) { 196 196 Log.Out ("Player set to online: " + steamId); 197 clientInfo = ci;198 entityId = ci.entityId;199 name = ci.playerName;200 ip = ci.ip;197 clientInfo = _ci; 198 entityId = _ci.entityId; 199 name = _ci.playerName; 200 ip = _ci.ip; 201 201 lastOnline = DateTime.Now; 202 202 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Players.cs
r332 r351 8 8 public readonly Dictionary<string, Player> Dict = new Dictionary<string, Player> (StringComparer.OrdinalIgnoreCase); 9 9 10 public Player this [string steamId, boolcreate] {10 public Player this [string _steamId, bool _create] { 11 11 get { 12 if (string.IsNullOrEmpty ( steamId)) {12 if (string.IsNullOrEmpty (_steamId)) { 13 13 return null; 14 14 } 15 15 16 if (Dict.ContainsKey ( steamId)) {17 return Dict [ steamId];16 if (Dict.ContainsKey (_steamId)) { 17 return Dict [_steamId]; 18 18 } 19 19 20 if (! create ||steamId.Length != 17) {20 if (!_create || _steamId.Length != 17) { 21 21 return null; 22 22 } 23 23 24 Log.Out ("Created new player entry for ID: " + steamId);25 Player p = new Player ( steamId);26 Dict.Add ( steamId, p);24 Log.Out ("Created new player entry for ID: " + _steamId); 25 Player p = new Player (_steamId); 26 Dict.Add (_steamId, p); 27 27 return p; 28 28 }
Note:
See TracChangeset
for help on using the changeset viewer.