-
Notifications
You must be signed in to change notification settings - Fork 1
/
LobBrowser.cs
245 lines (177 loc) · 8.28 KB
/
LobBrowser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
namespace DEBoarded
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class LobBrowser
{
[JsonProperty("match_id", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(ParseStringConverter))]
public long? MatchId { get; set; }
[JsonProperty("lobby_id", NullValueHandling = NullValueHandling.Ignore)]
public string LobbyId { get; set; }
[JsonProperty("match_uuid", NullValueHandling = NullValueHandling.Ignore)]
public Guid? MatchUuid { get; set; }
[JsonProperty("version")]
[JsonConverter(typeof(ParseStringConverter))]
public long? Version { get; set; }
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
public string Name { get; set; }
[JsonProperty("num_players", NullValueHandling = NullValueHandling.Ignore)]
public long? NumPlayers { get; set; }
[JsonProperty("num_slots", NullValueHandling = NullValueHandling.Ignore)]
public long? NumSlots { get; set; }
[JsonProperty("average_rating")]
public long? AverageRating { get; set; }
[JsonProperty("cheats", NullValueHandling = NullValueHandling.Ignore)]
public bool? Cheats { get; set; }
[JsonProperty("full_tech_tree", NullValueHandling = NullValueHandling.Ignore)]
public bool? FullTechTree { get; set; }
[JsonProperty("ending_age", NullValueHandling = NullValueHandling.Ignore)]
public long? EndingAge { get; set; }
[JsonProperty("expansion")]
public object Expansion { get; set; }
[JsonProperty("game_type", NullValueHandling = NullValueHandling.Ignore)]
public long? GameType { get; set; }
[JsonProperty("has_custom_content")]
public object HasCustomContent { get; set; }
[JsonProperty("has_password", NullValueHandling = NullValueHandling.Ignore)]
public bool? HasPassword { get; set; }
[JsonProperty("lock_speed", NullValueHandling = NullValueHandling.Ignore)]
public bool? LockSpeed { get; set; }
[JsonProperty("lock_teams", NullValueHandling = NullValueHandling.Ignore)]
public bool? LockTeams { get; set; }
[JsonProperty("map_size", NullValueHandling = NullValueHandling.Ignore)]
public long? MapSize { get; set; }
[JsonProperty("map_type", NullValueHandling = NullValueHandling.Ignore)]
public long? MapType { get; set; }
[JsonProperty("pop", NullValueHandling = NullValueHandling.Ignore)]
public long? Pop { get; set; }
[JsonProperty("ranked")]
public object Ranked { get; set; }
[JsonProperty("leaderboard_id")]
public object LeaderboardId { get; set; }
[JsonProperty("rating_type", NullValueHandling = NullValueHandling.Ignore)]
public long? RatingType { get; set; }
[JsonProperty("resources", NullValueHandling = NullValueHandling.Ignore)]
public long? Resources { get; set; }
[JsonProperty("rms")]
public string Rms { get; set; }
[JsonProperty("scenario")]
public string Scenario { get; set; }
//[JsonProperty("server", NullValueHandling = NullValueHandling.Ignore)]
//public Server? Server { get; set; }
[JsonProperty("shared_exploration", NullValueHandling = NullValueHandling.Ignore)]
public bool? SharedExploration { get; set; }
[JsonProperty("speed", NullValueHandling = NullValueHandling.Ignore)]
public long? Speed { get; set; }
[JsonProperty("starting_age", NullValueHandling = NullValueHandling.Ignore)]
public long? StartingAge { get; set; }
[JsonProperty("team_together", NullValueHandling = NullValueHandling.Ignore)]
public bool? TeamTogether { get; set; }
[JsonProperty("team_positions", NullValueHandling = NullValueHandling.Ignore)]
public bool? TeamPositions { get; set; }
[JsonProperty("treaty_length", NullValueHandling = NullValueHandling.Ignore)]
public long? TreatyLength { get; set; }
[JsonProperty("turbo", NullValueHandling = NullValueHandling.Ignore)]
public bool? Turbo { get; set; }
[JsonProperty("victory", NullValueHandling = NullValueHandling.Ignore)]
public long? Victory { get; set; }
[JsonProperty("victory_time", NullValueHandling = NullValueHandling.Ignore)]
public long? VictoryTime { get; set; }
[JsonProperty("visibility", NullValueHandling = NullValueHandling.Ignore)]
public long? Visibility { get; set; }
[JsonProperty("opened", NullValueHandling = NullValueHandling.Ignore)]
public long? Opened { get; set; }
[JsonProperty("started")]
public object Started { get; set; }
[JsonProperty("finished")]
public object Finished { get; set; }
[JsonProperty("players", NullValueHandling = NullValueHandling.Ignore)]
public Player[] Players { get; set; }
}
public partial class Player
{
[JsonProperty("profile_id")]
public long? ProfileId { get; set; }
[JsonProperty("steam_id")]
public string SteamId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("clan")]
public string Clan { get; set; }
[JsonProperty("country")]
public object Country { get; set; }
[JsonProperty("slot", NullValueHandling = NullValueHandling.Ignore)]
public long? Slot { get; set; }
[JsonProperty("slot_type", NullValueHandling = NullValueHandling.Ignore)]
public long? SlotType { get; set; }
[JsonProperty("rating")]
public long? Rating { get; set; }
[JsonProperty("games")]
public long? Games { get; set; }
[JsonProperty("wins")]
public long? Wins { get; set; }
[JsonProperty("streak")]
public long? Streak { get; set; }
[JsonProperty("drops")]
public long? Drops { get; set; }
[JsonProperty("color")]
public object Color { get; set; }
[JsonProperty("team")]
public object Team { get; set; }
[JsonProperty("civ")]
public object Civ { get; set; }
}
//public enum Server { Australiasoutheast, Brazilsouth, Eastus, Southeastasia, Ukwest, Westeurope, Westindia, Westus2 };
public partial class LobBrowser
{
public static LobBrowser[] FromJson(string json) => JsonConvert.DeserializeObject<LobBrowser[]>(json, Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this LobBrowser[] self) => JsonConvert.SerializeObject(self, Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
//ServerConverter.Singleton,
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString());
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}