Changeset 459 for TFP-WebServer/MarkersMod/src/Markers.cs
- Timestamp:
- Aug 9, 2023, 9:41:32 PM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TFP-WebServer/MarkersMod/src/Markers.cs
r434 r459 21 21 22 22 for (int i = 0; i < numRandomMarkers; i++) { 23 int lat= random.RandomRange (-1000, 1001);24 int lng= random.RandomRange (-1000, 1001);23 int x = random.RandomRange (-1000, 1001); 24 int y = random.RandomRange (-1000, 1001); 25 25 26 markers.Add (WebUtils.GenerateGuid (), ( lat, lng, null));26 markers.Add (WebUtils.GenerateGuid (), (x, y, null)); 27 27 } 28 28 … … 31 31 32 32 private static readonly byte[] jsonKeyId = JsonWriter.GetEncodedPropertyNameWithBeginObject ("id"); 33 private static readonly byte[] jsonKey Lat = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("lat");34 private static readonly byte[] jsonKey Lng = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("lng");33 private static readonly byte[] jsonKeyX = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("x"); 34 private static readonly byte[] jsonKeyY = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("y"); 35 35 private static readonly byte[] jsonKeyIcon = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("icon"); 36 36 … … 78 78 _writer.WriteRaw (jsonKeyId); 79 79 _writer.WriteString (_markerId); 80 _writer.WriteRaw (jsonKey Lat);81 (int lat, int lng, string icon) = _properties;82 _writer.WriteInt32 ( lat);83 _writer.WriteRaw (jsonKey Lng);84 _writer.WriteInt32 ( lng);80 _writer.WriteRaw (jsonKeyX); 81 (int x, int y, string icon) = _properties; 82 _writer.WriteInt32 (x); 83 _writer.WriteRaw (jsonKeyY); 84 _writer.WriteInt32 (y); 85 85 _writer.WriteRaw (jsonKeyIcon); 86 86 _writer.WriteString (icon ?? defaultIcon); … … 89 89 90 90 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 91 if (!JsonCommons.TryGetJsonField (_jsonInput, " lat", out int lat)) {92 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_ LAT");91 if (!JsonCommons.TryGetJsonField (_jsonInput, "x", out int x)) { 92 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_X"); 93 93 return; 94 94 } 95 95 96 if (!JsonCommons.TryGetJsonField (_jsonInput, " lng", out int lng)) {97 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_ LNG");96 if (!JsonCommons.TryGetJsonField (_jsonInput, "y", out int y)) { 97 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_Y"); 98 98 return; 99 99 } … … 105 105 106 106 string newId = WebUtils.GenerateGuid (); 107 markers.Add (newId, ( lat, lng, icon));107 markers.Add (newId, (x, y, icon)); 108 108 109 109 PrepareEnvelopedResult (out JsonWriter writer); … … 113 113 114 114 protected override void HandleRestPut (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 115 if (!JsonCommons.TryGetJsonField (_jsonInput, " lat", out int lat)) {116 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_ LAT");115 if (!JsonCommons.TryGetJsonField (_jsonInput, "x", out int x)) { 116 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_X"); 117 117 return; 118 118 } 119 119 120 if (!JsonCommons.TryGetJsonField (_jsonInput, " lng", out int lng)) {121 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_ LNG");120 if (!JsonCommons.TryGetJsonField (_jsonInput, "y", out int y)) { 121 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_Y"); 122 122 return; 123 123 } … … 139 139 icon = properties.Item3; 140 140 } 141 markers [id] = ( lat, lng, icon);141 markers [id] = (x, y, icon); 142 142 143 143 PrepareEnvelopedResult (out JsonWriter writer); 144 144 writer.WriteRaw (jsonKeyId); 145 145 writer.WriteString (id); 146 writer.WriteRaw (jsonKey Lat);147 writer.WriteInt32 ( lat);148 writer.WriteRaw (jsonKey Lng);149 writer.WriteInt32 ( lng);146 writer.WriteRaw (jsonKeyX); 147 writer.WriteInt32 (x); 148 writer.WriteRaw (jsonKeyY); 149 writer.WriteInt32 (y); 150 150 writer.WriteRaw (jsonKeyIcon); 151 151 writer.WriteString (icon);
Note:
See TracChangeset
for help on using the changeset viewer.