Skip to content

Commit 76bda75

Browse files
committed
Fleetcarrier end point appears synced with fleetcarrier json
1 parent 7f78d5b commit 76bda75

File tree

6 files changed

+485
-217
lines changed

6 files changed

+485
-217
lines changed

BaseUtilities/BaseUtilities/Misc.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Globalization;
33
using System.IO;
4+
using System.Linq;
45
using System.Text;
56

67
namespace BaseUtils
@@ -56,6 +57,46 @@ static public long InvariantParseLong(this string s, long def)
5657
else
5758
return null;
5859
}
60+
61+
static public int? ToHex(this char c)
62+
{
63+
if (char.IsDigit(c))
64+
return c - '0';
65+
else if ("ABCDEF".Contains(c))
66+
return c - 'A' + 10;
67+
else if ("abcdef".Contains(c))
68+
return c - 'a' + 10;
69+
else
70+
return null;
71+
}
72+
73+
static public int? ToHex(this string s, int p)
74+
{
75+
if ( s.Length>p+1)
76+
{
77+
int? top = ToHex(s[p]);
78+
int? bot = ToHex(s[p+1]);
79+
if (top.HasValue && bot.HasValue)
80+
return (top << 4) | bot;
81+
}
82+
return null;
83+
}
84+
85+
static public string FromHexString(this string ascii)
86+
{
87+
string s = "";
88+
for( int i = 0; i < ascii.Length; i += 2)
89+
{
90+
int? v = ascii.ToHex(i);
91+
if (v.HasValue)
92+
s += Convert.ToChar(v.Value);
93+
else
94+
return null;
95+
}
96+
97+
return s;
98+
}
99+
59100
}
60101
}
61102

CAPI/EndPointBaseClass.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* EDDiscovery is not affiliated with Frontier Developments plc.
1515
*/
1616

17+
using BaseUtils;
1718
using QuickJSON;
1819
using System;
1920
using System.Collections.Generic;
@@ -100,7 +101,7 @@ public class Ship
100101

101102
protected List<OrdersCommoditySales> GetOrdersCommoditiesSales(JArray clist) // may return null. Returns name, locName, price, stock
102103
{
103-
if (clist != null)
104+
if (clist != null && clist.Count > 0)
104105
{
105106
var list = new List<OrdersCommoditySales>();
106107
foreach (var kvp in clist)
@@ -118,7 +119,7 @@ public class Ship
118119

119120
protected List<OrdersCommodityPurchases> GetOrdersCommoditiesPurchases(JArray clist) // may return null. Returns name, locName, price, stock
120121
{
121-
if (clist != null)
122+
if (clist != null && clist.Count > 0)
122123
{
123124
var list = new List<OrdersCommodityPurchases>();
124125
foreach (var kvp in clist)
@@ -135,7 +136,7 @@ public class Ship
135136
}
136137
protected List<OrdersMRSales> GetOrdersMicroresourcesSales(JObject clist) // may return null. Returns name, locName, price, stock
137138
{
138-
if (clist != null)
139+
if (clist != null && clist.Count > 0)
139140
{
140141
var list = new List<OrdersMRSales>();
141142
foreach (var kvp in clist)
@@ -152,7 +153,7 @@ public class Ship
152153
}
153154
protected List<OrdersMRPurchases> GetOrdersMicroresourcesPurchases(JArray clist) // may return null. Returns name, locName, price, stock
154155
{
155-
if (clist != null)
156+
if (clist != null && clist.Count > 0)
156157
{
157158
var list = new List<OrdersMRPurchases>();
158159
foreach (var kvp in clist)
@@ -175,8 +176,8 @@ private OrdersCommoditySales OrdersCommoditySalesFromJSON(JObject data)
175176
var m = new OrdersCommoditySales()
176177
{
177178
Name = data["name"].Str(),
178-
Stock = data["stock"].Long(),
179-
Price = data["price"].Long(),
179+
Stock = data["stock"].Str("0").InvariantParseLong(0),
180+
Price = data["price"].Str("0").InvariantParseLong(0),
180181
Blackmarket = data["blackmarket"].Bool()
181182
};
182183

@@ -228,7 +229,7 @@ private OrdersMRSales OrdersMRSalesFromJSON(JObject data)
228229
{
229230
var m = new OrdersMRSales()
230231
{
231-
ID = data["ID"].Long(),
232+
ID = data["id"].Long(),
232233
Name = data["name"].Str(),
233234
LocName = data["locName"].Str(),
234235
Price = data["price"].Long(),
@@ -243,7 +244,7 @@ private OrdersMRSales OrdersMRSalesFromJSON(JObject data)
243244

244245
protected List<Commodity> GetCommodityList(JArray clist)
245246
{
246-
if (clist != null)
247+
if (clist != null && clist.Count>0)
247248
{
248249
List<Commodity> list = new List<Commodity>();
249250
foreach (var entry in clist)
@@ -288,7 +289,7 @@ private Commodity CommodityFromJSON(JObject data)
288289
protected Dictionary<string, double> GetEconomies(JObject data)
289290
{
290291
var list = new Dictionary<string, double>();
291-
if (data != null)
292+
if (data != null && data.Count>0)
292293
{
293294
foreach (var e in data)
294295
list.Add(e.Value["name"].Str("Unknown"), e.Value["proportion"].Double() * 100.0);
@@ -298,7 +299,7 @@ protected Dictionary<string, double> GetEconomies(JObject data)
298299
}
299300
protected List<Module> GetModules(JObject moduleslist) // may be null if no shipyard
300301
{
301-
if (moduleslist != null)
302+
if (moduleslist != null && moduleslist.Count>0)
302303
{
303304
List<Module> list = new List<Module>();
304305
foreach (var kvp in moduleslist)
@@ -327,7 +328,7 @@ protected Dictionary<string, double> GetEconomies(JObject data)
327328

328329
protected List<Ship> GetShips(JObject shiplist) // may be null if no shipyard
329330
{
330-
if (shiplist != null)
331+
if (shiplist != null && shiplist.Count > 0)
331332
{
332333
List<Ship> list = new List<Ship>();
333334
foreach (var kvp in shiplist)

0 commit comments

Comments
 (0)