-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDracoClient.cs
More file actions
255 lines (222 loc) · 9.05 KB
/
DracoClient.cs
File metadata and controls
255 lines (222 loc) · 9.05 KB
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
246
247
248
249
250
251
252
253
254
255
using FantaziumGo.Command;
using FantaziumGo.Serializer;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace DracoApi.Net
{
public class DracoClient
{
public FClientInfo ClientInfo { get; set; }
public UserInfo User { get; set; }
private SerializerContext serializer;
private RestClient client;
public DracoClient() : this("iOS 10.3.3", "iPhone8,1", DracoUtils.GenerateDeviceId())
{
}
public DracoClient(string platformVersion, string deviceModel, string deviceid)
{
this.User = new UserInfo();
this.User.DeviceId = deviceid;
this.User.DeviceAdId = DracoUtils.GenerateDeviceId();
ClientInfo = new FClientInfo()
{
platform = "IPhonePlayer",
platformVersion = platformVersion,
revision = "6935",
deviceModel = deviceModel,
screenWidth = 750,
screenHeight = 1334,
language = "English",
iOsAdvertisingIdentifier = this.User.DeviceAdId,
iOsAdvertisingTrackingEnabled = true,
iOsVendorIdentifier = this.User.DeviceId,
googleAdvertisingId = null,
googleTrackingEnabled = false
};
this.serializer = new SerializerContext("portal", Gen.FGameObjects.CLASSES, 839333433u);
this.client = new RestClient("https://us.draconiusgo.com");
this.client.ClearHandlers();
this.client.UserAgent = "DraconiusGO/6935 CFNetwork/811.5.4 Darwin/16.7.0";
this.client.AddDefaultHeader("Accept", "*/*");
this.client.AddDefaultHeader("Accept-Language", "en-us");
this.client.AddDefaultHeader("X-Unity-Version", "2017.1.0f3");
this.client.CookieContainer = new CookieContainer();
}
public void SetProxy(string proxy)
{
if (proxy != null)
{
this.client.Proxy = new WebProxy(proxy);
}
else
{
this.client.Proxy = null;
}
}
public bool Ping()
{
var request = new RestRequest("ping", Method.POST);
request.AddHeader("Content-Type", "application /x-www-form-urlencoded");
var response = client.Execute(request);
this.client.AddDefaultParameter("Path", "/", ParameterType.Cookie);
this.client.AddDefaultParameter("path", "/", ParameterType.Cookie);
this.client.AddDefaultParameter("domain", ".draconiusgo.com", ParameterType.Cookie);
return response.StatusCode == HttpStatusCode.OK;
}
public object ServiceCall(string service, string method, object body)
{
var rawbody = serializer.Serialize(body);
var request = new RestRequest("serviceCall", Method.POST);
request.AddHeader("Protocol-Version", serializer.protocolVersion.ToString());
if (this.User.PortalId != null)
{
request.AddHeader("dcportal", this.User.PortalId);
}
request.AddParameter("service", service);
request.AddParameter("method", method);
request.AddFile("args", rawbody, "args.dat", "application/octet-stream");
var response = client.Execute(request);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception("Invalid status received: " + response.StatusDescription);
}
var protocolVersion = response.Headers.ToList().Find(x => x.Name == "Protocol-Version" || x.Name == "protocol-version").Value.ToString();
var dcportal = response.Headers.ToList().Find(x => x.Name == "dcportal").Value.ToString();
if (dcportal != null) this.User.PortalId = dcportal;
if (protocolVersion != serializer.protocolVersion.ToString())
{
throw new Exception("Incorrect protocol version received: " + protocolVersion);
}
var data = serializer.Deserialize(response.RawBytes);
(data ?? "").ToString();
return data;
}
public void Event(string name, string value1 = null, string value2 = null)
{
this.ServiceCall("ClientEventService", "onEvent", new object[]
{
name,
this.User.UserId,
this.ClientInfo,
value1,
value2,
null,
null,
null
});
}
public void Boot()
{
this.Event("LoadingScreenPercent", "100");
this.Event("Initialized");
}
public FAuthData TrySignIn()
{
this.Event("TrySingIn", "DEVICE");
var data = this.ServiceCall("AuthService", "trySingIn", new object[]
{
new AuthData() { authType = Gen.AuthType.DEVICE, profileId = this.User.DeviceId },
this.ClientInfo,
new FRegistrationInfo() { age = "", email = "", gender = "", regType = "dv", socialId = "" },
}) as FAuthData;
if (data != null)
{
this.User.UserId = data.info.userId;
this.User.Avatar = data.info.avatarAppearanceDetails;
}
return data;
}
public string ValidateNickName(string nickname, bool takeSuggested = true)
{
this.Event("ValidateNickname", nickname);
var result = this.ServiceCall("AuthService", "validateNickname", new object[] { nickname }) as FNicknameValidationResult;
if (result == null) return nickname;
else if (result.error == Gen.FNicknameValidationError.DUPLICATE)
{
this.Event("ValidateNicknameError", "DUPLICATE");
if (takeSuggested) return ValidateNickName(result.suggestedNickname, true);
else return null;
}
else
{
return null;
}
}
public void AcceptToS()
{
this.Event("LicenceShown");
this.Event("LicenceAccepted");
}
public FAuthData Register(string nickname)
{
this.Event("Register", "DEVICE", nickname);
var data = this.ServiceCall("AuthService", "register", new object[]
{
new AuthData() { authType = Gen.AuthType.DEVICE, profileId = this.User.DeviceId },
nickname,
this.ClientInfo,
new FRegistrationInfo() { age = "", email = "", gender = "", regType = "dv", socialId = "" },
}) as FAuthData;
this.User.UserId = data.info.userId;
this.Event("ServerAuthSuccess", this.User.UserId);
return data;
}
public void SetAvatar()
{
this.Event("AvatarPlayerGenderRace", "1", "1");
this.Event("AvatarPlayerSubmit", "271891");
this.ServiceCall("PlayerService", "saveUserSettings", new object[] { this.User.Avatar });
}
public void Init()
{
this.Event("LoadingScreenPercent", "100");
this.Event("CreateAvatarByType", "MageMale");
this.Event("LoadingScreenPercent", "100");
this.Event("AvatarUpdateView", this.User.Avatar.ToString());
this.Event("InitPushNotifications", "True");
}
public FBagUpdate GetUserItems()
{
var data = this.ServiceCall("ItemService", "getUserItems", null) as FBagUpdate;
return data;
}
public FCreadex GetCreadex()
{
var data = this.ServiceCall("UserCreatureService", "getCreadex", new object[] { }) as FCreadex;
return data;
}
public FUserCreaturesList GetUserCreatures()
{
var data = this.ServiceCall("UserCreatureService", "getUserCreatures", new object[] { }) as FUserCreaturesList;
return data;
}
public FUpdate GetMapUpdate(float latitude, float longitude)
{
var data = this.ServiceCall("MapService", "getUpdate", new object[] {
new FUpdateRequest()
{
clientRequest = new FClientRequest()
{
time = 0,
currentUtcOffsetSeconds = 7200,
coords = new GeoCoords()
{
latitude = latitude,
longitude = longitude,
horizontalAccuracy = 20,
},
},
clientPlatform = Gen.ClientPlatform.IOS,
tilesCache = new Dictionary<FTile, long>(),
}
}) as FUpdate;
return data;
}
}
}