Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

748 linhas
26 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using CIG;
  6. using CIG.Translation.Native;
  7. using Inno.DLC;
  8. using SUISS.Core;
  9. using SUISS.Scheduling;
  10. using SUISS.Storage;
  11. using SUISSEngine;
  12. using UnityEngine;
  13. [RequireComponent(typeof(Serializing))]
  14. public sealed class CIGWebService : SingletonMonobehaviour<CIGWebService>
  15. {
  16. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  17. public event CIGWebService.PullRequestCompletedHandler PullRequestCompleted;
  18. private void FirePullRequestCompleted()
  19. {
  20. if (this.PullRequestCompleted != null)
  21. {
  22. this.PullRequestCompleted();
  23. }
  24. }
  25. protected override void Awake()
  26. {
  27. base.Awake();
  28. this.UserKey = string.Empty;
  29. this.UpdateAvailable = false;
  30. this.Undelivered = Currencies.Zero;
  31. this.Sale = string.Empty;
  32. this.SaleExpiry = DateTime.MaxValue;
  33. this.UserId = -1L;
  34. this.IslandSyncChangePercent = 5;
  35. this._lastPullRequestTime = -3600L;
  36. this._extraWaitTime = 0L;
  37. this.Multipliers = new Multipliers();
  38. this.VideoSpeedupEnabled = false;
  39. this.VideoSpeedupMaxCurrency = 2;
  40. this.VideoSpeedupMinSeconds = 60;
  41. this.HasPulled = false;
  42. }
  43. private void Start()
  44. {
  45. if (this.serializing == null)
  46. {
  47. UnityEngine.Debug.LogWarning("Web service requires a serializing.");
  48. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._pullRequestRoutine = this.PullRequestRoutine(), base.gameObject);
  49. }
  50. }
  51. protected override void OnDestroy()
  52. {
  53. if (this._pullRequestRoutine != null && SingletonMonobehaviour<Scheduler>.IsAvailable)
  54. {
  55. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._pullRequestRoutine);
  56. this._pullRequestRoutine = null;
  57. }
  58. base.OnDestroy();
  59. }
  60. private void OnSerialize(Dictionary<string, object> values)
  61. {
  62. Dictionary<string, object> root = Storage.Get(StorageLifecycle.Player).Root;
  63. if (string.IsNullOrEmpty(this.UserKey))
  64. {
  65. root.Remove("userKey");
  66. }
  67. else
  68. {
  69. root["userKey"] = this.UserKey;
  70. }
  71. if (this.UserId < 0L)
  72. {
  73. root.Remove("userId");
  74. }
  75. else
  76. {
  77. root["userId"] = this.UserId;
  78. }
  79. values["sessionsPlayed"] = this._sessionsPlayed;
  80. values["undelivered"] = this.Undelivered;
  81. values["allow_iap_deals"] = this.UseIAPDeal;
  82. values["disable_sign_validation"] = this.DisableIAPSignValidation;
  83. values["sale"] = this.Sale;
  84. values["saleExpiry"] = this.SaleExpiry.Ticks;
  85. values["islandSyncChangePercent"] = this.IslandSyncChangePercent;
  86. values["lastRequest"] = this._lastPullRequestTime;
  87. values["lastResponse"] = this._lastResponse;
  88. values["commercialBuildingCostCashMultiplier"] = this.Multipliers.CommercialBuildingCostCashMultiplier;
  89. values["commercialBuildingCostGoldMultiplier"] = this.Multipliers.CommercialBuildingCostGoldMultiplier;
  90. values["communityBuildingCostCashMultiplier"] = this.Multipliers.CommunityBuildingCostCashMultiplier;
  91. values["communityBuildingCostGoldMultiplier"] = this.Multipliers.CommunityBuildingCostGoldMultiplier;
  92. values["residentialBuildingCostCashMultiplier"] = this.Multipliers.ResidentialBuildingCostCashMultiplier;
  93. values["residentialBuildingCostGoldMultiplier"] = this.Multipliers.ResidentialBuildingCostGoldMultiplier;
  94. values["upspeedCostCashMultiplier"] = this.Multipliers.UpspeedCostCashMultiplier;
  95. values["upspeedCostGoldMultiplier"] = this.Multipliers.UpspeedCostGoldMultiplier;
  96. values["commercialBuildingProfitMultiplier"] = this.Multipliers.CommercialBuildingProfitMultiplier;
  97. values["useBadge"] = this.UseBadge;
  98. values["cheater_value"] = this._cheaterType;
  99. values["video_speedup_building_enabled"] = this.VideoSpeedupEnabled;
  100. values["video_speedup_building_max_gold_cost"] = this.VideoSpeedupMaxCurrency;
  101. values["video_speedup_building_min_seconds"] = this.VideoSpeedupMinSeconds;
  102. values["timeDiffWithClientInMinutes"] = this._timeDiffWithClientInMinutes;
  103. }
  104. private void OnDeserialize(Dictionary<string, object> values)
  105. {
  106. Dictionary<string, object> root = Storage.Get(StorageLifecycle.Player).Root;
  107. this.UserKey = root.GetString("userKey", string.Empty);
  108. this.UserId = root.GetLong("userId", values.GetLong("userId", -1L));
  109. object obj;
  110. if (values.TryGetValue("sessionsPlayed", out obj))
  111. {
  112. this._sessionsPlayed = (int)obj;
  113. }
  114. if (values.TryGetValue("undelivered", out obj))
  115. {
  116. this.Undelivered += (Currencies)obj;
  117. }
  118. if (values.TryGetValue("allow_iap_deals", out obj) && obj is bool)
  119. {
  120. this.UseIAPDeal = (bool)obj;
  121. }
  122. if (values.TryGetValue("disable_sign_validation", out obj) && obj is bool)
  123. {
  124. this.DisableIAPSignValidation = (bool)obj;
  125. }
  126. if (values.TryGetValue("sale", out obj))
  127. {
  128. this.Sale = (string)obj;
  129. }
  130. if (values.TryGetValue("saleExpiry", out obj) && obj is long)
  131. {
  132. this.SaleExpiry = new DateTime((long)obj, DateTimeKind.Utc);
  133. }
  134. this.IslandSyncChangePercent = values.GetInt("islandSyncChangePercent", 5);
  135. if (values.TryGetValue("lastRequest", out obj))
  136. {
  137. this._lastPullRequestTime = (long)obj;
  138. }
  139. if (values.TryGetValue("lastResponse", out obj))
  140. {
  141. this._lastResponse = (string)obj;
  142. this._properties = Parser.ParsePropertyFileFormat(this._lastResponse);
  143. }
  144. if (values.TryGetValue("adjust_tokens_seen", out obj))
  145. {
  146. this.MigrateAdjustTokensSeenToSUISSEngineStorage((List<object>)obj);
  147. values.Remove("adjust_tokens_seen");
  148. }
  149. this.UseBadge = values.GetBoolean("useBadge", true);
  150. this._cheaterType = values.GetInt("cheater_value", -1);
  151. this.VideoSpeedupEnabled = values.GetBoolean("video_speedup_building_enabled", false);
  152. this.VideoSpeedupMaxCurrency = values.GetInt("video_speedup_building_max_gold_cost", 2);
  153. this.VideoSpeedupMinSeconds = values.GetInt("video_speedup_building_min_seconds", 60);
  154. this._timeDiffWithClientInMinutes = values.GetLong("timeDiffWithClientInMinutes", 0L);
  155. this.Multipliers.SetStoredData(values);
  156. }
  157. private void MigrateAdjustTokensSeenToSUISSEngineStorage(List<object> adjust_tokens)
  158. {
  159. EdwinServerEventHandler.StorableStringList storableStringList = new EdwinServerEventHandler.StorableStringList();
  160. foreach (object obj in adjust_tokens)
  161. {
  162. storableStringList.Add((string)obj);
  163. }
  164. Dictionary<string, object> dictionary = Storage.Get(StorageLifecycle.Player).GetDictionary("edwinserverEventStorage");
  165. if (dictionary.ContainsKey("adjust_key"))
  166. {
  167. UnityEngine.Debug.LogError("Impossible! Old place still contained edwinserverEventStorage, but new place as well!");
  168. dictionary["adjust_key"] = storableStringList;
  169. }
  170. else
  171. {
  172. dictionary.Add("adjust_key", storableStringList);
  173. }
  174. }
  175. private void OnDeserialized()
  176. {
  177. this._sessionsPlayed++;
  178. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._pullRequestRoutine = this.PullRequestRoutine(), base.gameObject);
  179. }
  180. public void ForcePullRequest()
  181. {
  182. if (this._waitEnumerator != null)
  183. {
  184. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._waitEnumerator);
  185. this._waitEnumerator = null;
  186. }
  187. }
  188. public WWW RedeemCode(string code)
  189. {
  190. WWWForm wwwform = this.GenerateRequestParameters(false);
  191. wwwform.AddField("action", "redeemcode_extended");
  192. wwwform.AddField("code", code);
  193. return new WWW(CIGWebService.APIURL, wwwform);
  194. }
  195. public WWW PurchaseIntent(string item)
  196. {
  197. WWWForm wwwform = this.GenerateRequestParameters(false);
  198. wwwform.AddField("action", "purchase_intent");
  199. wwwform.AddField("item", item);
  200. return new WWW(CIGWebService.APIURL, wwwform);
  201. }
  202. public WWW PurchaseSuccess_OldSchool(string item)
  203. {
  204. WWWForm wwwform = this.GenerateRequestParameters(false);
  205. wwwform.AddField("action", "purchase_success");
  206. wwwform.AddField("item", item);
  207. return new WWW(CIGWebService.APIURL, wwwform);
  208. }
  209. public WWW PricePoints()
  210. {
  211. WWWForm wwwform = this.GenerateRequestParameters(false);
  212. wwwform.AddField("action", "getallpricepoints");
  213. return new WWW(CIGWebService.APIURL, wwwform);
  214. }
  215. public WWW ValidatePurchase(string productID, string receipt, Dictionary<string, string> requestParameters)
  216. {
  217. WWWForm wwwform = this.GenerateUserRequestParameters();
  218. foreach (KeyValuePair<string, string> keyValuePair in requestParameters)
  219. {
  220. wwwform.AddField(keyValuePair.Key, keyValuePair.Value);
  221. }
  222. wwwform.AddField("action", "purchase_receipt");
  223. wwwform.AddField("sku", productID);
  224. wwwform.AddField("receipt", receipt);
  225. return new WWW(CIGWebService.APIURL, wwwform);
  226. }
  227. public Dictionary<string, string> GeneratePurchaseReceiptParameters()
  228. {
  229. Dictionary<string, string> dictionary = new Dictionary<string, string>();
  230. CIGGameState instance = SingletonMonobehaviour<CIGGameState>.Instance;
  231. dictionary.Add("xp", instance.Balance.Round(Currencies.RoundingMethod.Nearest).GetValue("XP").ToString());
  232. dictionary.Add("level", instance.Level.ToString());
  233. dictionary.Add("cash", instance.Balance.Round(Currencies.RoundingMethod.Nearest).GetValue("Cash").ToString());
  234. dictionary.Add("gold", instance.Balance.Round(Currencies.RoundingMethod.Nearest).GetValue("Gold").ToString());
  235. dictionary.Add("cashspent", instance.CurrenciesSpent.Round(Currencies.RoundingMethod.Nearest).GetValue("Cash").ToString());
  236. dictionary.Add("goldspent", instance.CurrenciesSpent.Round(Currencies.RoundingMethod.Nearest).GetValue("Gold").ToString());
  237. dictionary.Add("minutesplayed", instance.TotalMinutesPlayed.ToString());
  238. dictionary.Add("sessions", this._sessionsPlayed.ToString());
  239. dictionary.Add("clientTimestamp", CIGWebService.UnixTimestamp.ToString());
  240. dictionary.Add("timeDiffMinutes", this._timeDiffWithClientInMinutes.ToString());
  241. return dictionary;
  242. }
  243. public Coroutine WWWWithTimeout(WWW www, Action<CIGWebService.WWWResponse> callback, float timeout = 5f)
  244. {
  245. return base.StartCoroutine(this.WWWWithTimeoutRoutine(www, timeout, callback));
  246. }
  247. public WWW RegisterNewsLetter(string email)
  248. {
  249. WWWForm wwwform = this.GenerateRequestParameters(false);
  250. wwwform.AddField("action", "register");
  251. wwwform.AddField("email", email);
  252. return new WWW(CIGWebService.APIURL, wwwform);
  253. }
  254. public static Currencies ParseCurrencies(string str, out int cranes)
  255. {
  256. Currencies currencies = Currencies.Zero;
  257. cranes = 0;
  258. foreach (string text in str.Split(new char[]
  259. {
  260. ','
  261. }))
  262. {
  263. if (text.StartsWith("C"))
  264. {
  265. decimal value;
  266. if (decimal.TryParse(text.Substring(1), out value))
  267. {
  268. currencies += new Currencies("Cash", value);
  269. }
  270. }
  271. else if (text.StartsWith("G"))
  272. {
  273. decimal value2;
  274. if (decimal.TryParse(text.Substring(1), out value2))
  275. {
  276. currencies += new Currencies("Gold", value2);
  277. }
  278. }
  279. else if (text.StartsWith("D"))
  280. {
  281. UnityEngine.Debug.LogWarning("Cannot handle diamonds!");
  282. }
  283. else if (text.StartsWith("XP"))
  284. {
  285. decimal value3;
  286. if (decimal.TryParse(text.Substring(2), out value3))
  287. {
  288. currencies += new Currencies("XP", value3);
  289. }
  290. }
  291. else if (text.StartsWith("B") && !int.TryParse(text.Substring(1), out cranes))
  292. {
  293. UnityEngine.Debug.LogError(string.Format("Unable to parse currencies part '{0}'", text));
  294. }
  295. }
  296. return currencies;
  297. }
  298. public void ClearUndelivered()
  299. {
  300. this.Undelivered = Currencies.Zero;
  301. this.serializing.Serialize();
  302. }
  303. public string GetApiProperty(string key)
  304. {
  305. if (this._properties.ContainsKey(key))
  306. {
  307. return this._properties[key];
  308. }
  309. return string.Empty;
  310. }
  311. public string UserKey { get; private set; }
  312. public long UserId { get; private set; }
  313. public bool UpdateAvailable { get; private set; }
  314. public bool DisableIAPSignValidation { get; private set; }
  315. public Currencies Undelivered { get; private set; }
  316. public bool UseIAPDeal { get; private set; }
  317. public string Sale { get; private set; }
  318. public DateTime SaleExpiry { get; private set; }
  319. public int IslandSyncChangePercent { get; private set; }
  320. public Dictionary<string, string> Properties
  321. {
  322. get
  323. {
  324. return this._properties;
  325. }
  326. }
  327. public bool HasPulled { get; private set; }
  328. public Multipliers Multipliers { get; private set; }
  329. public bool UseBadge { get; private set; }
  330. public bool VideoSpeedupEnabled { get; private set; }
  331. public int VideoSpeedupMaxCurrency { get; private set; }
  332. public int VideoSpeedupMinSeconds { get; private set; }
  333. public static string APIURL
  334. {
  335. get
  336. {
  337. return CIGWebService.APIDomain + "api.php";
  338. }
  339. }
  340. public static string UserPropsURL
  341. {
  342. get
  343. {
  344. return CIGWebService.APIDomain + "userprops.php";
  345. }
  346. }
  347. private static long UnixTimestamp
  348. {
  349. get
  350. {
  351. return (long)(DateTime.UtcNow - CIGWebService.UnixOriginTimestamp).TotalSeconds;
  352. }
  353. }
  354. private static string APIDomain
  355. {
  356. get
  357. {
  358. if (string.IsNullOrEmpty(CIGWebService._apiDomain))
  359. {
  360. CIGWebService.SetupDomains();
  361. }
  362. return CIGWebService._apiDomain;
  363. }
  364. }
  365. public static void SetupDomains()
  366. {
  367. CIGWebService._apiDomain = "https://gamesapi.sparklingsociety.net/cig3-google/";
  368. }
  369. private IEnumerator WaitForPullRequest()
  370. {
  371. long waitTime = this._lastPullRequestTime - (long)Timing.UtcNow + 900L + this._extraWaitTime;
  372. double tfinish = Timing.UtcNow + (double)Math.Max(10L, waitTime);
  373. while (Timing.UtcNow < tfinish)
  374. {
  375. double tleft = tfinish - Timing.UtcNow;
  376. yield return Timing.time + tleft;
  377. }
  378. yield break;
  379. }
  380. private IEnumerator WWWWithTimeoutRoutine(WWW www, float timeout, Action<CIGWebService.WWWResponse> callback)
  381. {
  382. float timeoutAt = Time.realtimeSinceStartup + timeout;
  383. yield return new WaitUntil(() => www.isDone || timeoutAt < Time.realtimeSinceStartup);
  384. if (callback != null)
  385. {
  386. if (www.isDone)
  387. {
  388. callback(new CIGWebService.WWWResponse(false, www.error, www.text));
  389. }
  390. else
  391. {
  392. callback(new CIGWebService.WWWResponse(true, "Request timeout.", string.Empty));
  393. }
  394. }
  395. yield return www;
  396. www.Dispose();
  397. yield break;
  398. }
  399. private IEnumerator PullRequestRoutine()
  400. {
  401. for (;;)
  402. {
  403. yield return this._waitEnumerator = this.WaitForPullRequest();
  404. this._waitEnumerator = null;
  405. WWWForm parameters = this.GenerateRequestParameters(true);
  406. WWW request = new WWW(CIGWebService.UserPropsURL, parameters);
  407. yield return request;
  408. if (request.error != null && request.error.Length > 0)
  409. {
  410. UnityEngine.Debug.LogWarning("Server error: " + request.error);
  411. this._extraWaitTime = Math.Min(600L, Math.Max(60L, 2L * this._extraWaitTime));
  412. }
  413. else
  414. {
  415. this._extraWaitTime = 0L;
  416. this.HandlePullResponse(request.text);
  417. }
  418. }
  419. yield break;
  420. }
  421. private WWWForm GenerateUserRequestParameters()
  422. {
  423. WWWForm wwwform = new WWWForm();
  424. wwwform.AddField("userKey", (this.UserKey != null) ? this.UserKey : string.Empty);
  425. wwwform.AddField("userId", this.UserId.ToString());
  426. wwwform.AddField("game_version", CityIsland.VersionString);
  427. CIGSparkSocServices instance = SingletonMonobehaviour<CIGSparkSocServices>.Instance;
  428. string installUuid = instance.GetInstallUuid();
  429. wwwform.AddField("sagid", (installUuid != null) ? installUuid : string.Empty);
  430. string playerUuid = instance.GetPlayerUuid();
  431. wwwform.AddField("sauid", (playerUuid != null) ? playerUuid : string.Empty);
  432. string playerName = instance.GetPlayerName();
  433. wwwform.AddField("ssuname", (playerName != null) ? playerName : string.Empty);
  434. return wwwform;
  435. }
  436. private WWWForm GenerateRequestParameters(bool extendedInfo)
  437. {
  438. WWWForm wwwform = this.GenerateUserRequestParameters();
  439. if (extendedInfo)
  440. {
  441. string[] defaultLanguages = SystemLocale.DefaultLanguages;
  442. string str;
  443. if (defaultLanguages.Length > 0)
  444. {
  445. str = defaultLanguages[0];
  446. }
  447. else
  448. {
  449. str = Application.systemLanguage.ToString();
  450. }
  451. wwwform.AddField("brand", "Unity");
  452. wwwform.AddField("device", SystemInfo.deviceName);
  453. wwwform.AddField("manufacturer", SystemInfo.graphicsDeviceVendor);
  454. wwwform.AddField("model", SystemInfo.deviceModel);
  455. wwwform.AddField("product", SystemInfo.deviceType.ToString());
  456. wwwform.AddField("island", string.Empty);
  457. wwwform.AddField("gpu_memory", SystemInfo.graphicsMemorySize.ToString());
  458. wwwform.AddField("sys_memory", SystemInfo.systemMemorySize.ToString());
  459. wwwform.AddField("texture_scale", JPEGLoader.TextureScalingFactor.ToString());
  460. CIGGameStats instance = SingletonMonobehaviour<CIGGameStats>.Instance;
  461. wwwform.AddField("gold_CashBuildings", instance.GoldSpent_CashBuildings.ToString());
  462. wwwform.AddField("gold_CashExchange", instance.GoldSpent_CashExchange.ToString());
  463. wwwform.AddField("gold_CraneHire", instance.GoldSpent_CraneHire.ToString());
  464. wwwform.AddField("gold_CranePurchase", instance.GoldSpent_CranePurchase.ToString());
  465. wwwform.AddField("gold_CraneQueue", instance.GoldSpent_CraneQueue.ToString());
  466. wwwform.AddField("gold_Expansions", instance.GoldSpent_Expansions.ToString());
  467. wwwform.AddField("gold_GoldBuildings", instance.GoldSpent_GoldBuildings.ToString());
  468. wwwform.AddField("gold_ImmediateBuild", instance.GoldSpent_ImmediateBuild.ToString());
  469. wwwform.AddField("gold_Speedups", instance.GoldSpent_Speedups.ToString());
  470. wwwform.AddField("cash_BulldozerQueue", instance.CashSpent_BulldozerQueue.ToString());
  471. wwwform.AddField("gold_Ports", instance.GoldEarned_Ports.ToString());
  472. CIGBuilderManager instanceIfAvailable = SingletonMonobehaviour<CIGBuilderManager>.InstanceIfAvailable;
  473. if (instanceIfAvailable != null)
  474. {
  475. wwwform.AddField("cranes", instanceIfAvailable.MaxBuildCount);
  476. }
  477. string value2 = "null";
  478. DLCManager dlcmanager = ServiceLocator.Find<DLCManager>();
  479. if (dlcmanager != null)
  480. {
  481. value2 = ((!dlcmanager.IsEnabled) ? "disabled" : "enabled");
  482. }
  483. wwwform.AddField("dlc_status", value2);
  484. wwwform.AddField("videos_watched", instance.NumberOfVideosWatched.ToString());
  485. wwwform.AddField("total_roads", instance.TotalNumberOfRoads);
  486. wwwform.AddField("total_decorations", instance.TotalNumberOfDecorations);
  487. wwwform.AddField("total_max_level_buildings", instance.TotalNumberOfMaxLevelBuildings);
  488. wwwform.AddField("total_unique_buildings", instance.GetUniqueBuildingTypeCount());
  489. CIGVisitingIslandsManager instance2 = SingletonMonobehaviour<CIGVisitingIslandsManager>.Instance;
  490. wwwform.AddField("total_islands_synced", instance2.SentIslandCount);
  491. }
  492. CIGGameState instance3 = SingletonMonobehaviour<CIGGameState>.Instance;
  493. wwwform.AddField("xp", instance3.Balance.Round(Currencies.RoundingMethod.Nearest).GetValue("XP").ToString());
  494. wwwform.AddField("level", instance3.Level);
  495. wwwform.AddField("islands_unlocked", instance3.GetIslandsUnlockedCount().ToString());
  496. wwwform.AddField("cash", instance3.Balance.Round(Currencies.RoundingMethod.Nearest).GetValue("Cash").ToString());
  497. wwwform.AddField("gold", instance3.Balance.Round(Currencies.RoundingMethod.Nearest).GetValue("Gold").ToString());
  498. wwwform.AddField("cashspent", instance3.CurrenciesSpent.Round(Currencies.RoundingMethod.Nearest).GetValue("Cash").ToString());
  499. wwwform.AddField("goldspent", instance3.CurrenciesSpent.Round(Currencies.RoundingMethod.Nearest).GetValue("Gold").ToString());
  500. wwwform.AddField("minutesplayed", instance3.TotalMinutesPlayed.ToString());
  501. wwwform.AddField("sessions", this._sessionsPlayed.ToString());
  502. return wwwform;
  503. }
  504. private void HandlePullResponse(string response)
  505. {
  506. Dictionary<string, string> dictionary = Parser.ParsePropertyFileFormat(response);
  507. this.UserKey = dictionary.GetString("userKey", string.Empty);
  508. if (!string.IsNullOrEmpty(this.UserKey))
  509. {
  510. }
  511. this.UserId = dictionary.GetLong("userId", -1L);
  512. if (dictionary.ContainsKey("undelivered"))
  513. {
  514. int num;
  515. this.Undelivered += CIGWebService.ParseCurrencies(dictionary["undelivered"], out num);
  516. if (num != 0 && (num < 5 || num > 15))
  517. {
  518. UnityEngine.Debug.LogError(string.Format("B-value from ParseCurrencies is bad ({0}).", num));
  519. }
  520. else
  521. {
  522. CIGBuilderManager instanceIfAvailable = SingletonMonobehaviour<CIGBuilderManager>.InstanceIfAvailable;
  523. if (instanceIfAvailable != null)
  524. {
  525. while (instanceIfAvailable.MaxBuildCount < num)
  526. {
  527. instanceIfAvailable.AddCrane(false);
  528. }
  529. }
  530. else
  531. {
  532. UnityEngine.Debug.LogError(string.Format("Received undelivered B-value of {0}, but we have no Builder Manager.", num));
  533. }
  534. }
  535. }
  536. this.UseIAPDeal = dictionary.GetBoolean("allow_iap_deals", true);
  537. this.DisableIAPSignValidation = dictionary.GetBoolean("disable_sign_validation", false);
  538. this.UpdateAvailable = dictionary.GetBoolean("update_available", false);
  539. this.Sale = dictionary.GetString("saletype", string.Empty);
  540. string s;
  541. double value;
  542. if (dictionary.TryGetValue("saleseconds", out s) && double.TryParse(s, out value))
  543. {
  544. this.SaleExpiry = DateTime.UtcNow.AddSeconds(value);
  545. }
  546. this.IslandSyncChangePercent = dictionary.GetInt("islandSyncChangePercent", 5);
  547. this.UseBadge = dictionary.GetBoolean("use_badge", true);
  548. int @int = dictionary.GetInt("cheater_value", -1);
  549. if (@int != -1 && this._cheaterType != @int)
  550. {
  551. this._cheaterType = @int;
  552. }
  553. this.VideoSpeedupEnabled = dictionary.GetBoolean("video_speedup_building_enabled", false);
  554. this.VideoSpeedupMaxCurrency = dictionary.GetInt("video_speedup_building_max_gold_cost", 2);
  555. this.VideoSpeedupMinSeconds = dictionary.GetInt("video_speedup_building_min_seconds", 60);
  556. this._timeDiffWithClientInMinutes = (CIGWebService.UnixTimestamp - dictionary.GetLong("time", 0L)) / 60L;
  557. string @string = dictionary.GetString("adjust_registered_token", null);
  558. string string2 = dictionary.GetString("adjust_tokens", null);
  559. if (!string.IsNullOrEmpty(string2))
  560. {
  561. EdwinServerEventHandler.HandleAdjust(string2, @string);
  562. }
  563. this._lastResponse = response;
  564. this._properties = dictionary;
  565. this._lastPullRequestTime = (long)Timing.UtcNow;
  566. this.serializing.Serialize();
  567. this.HasPulled = true;
  568. if (this.PullRequestCompleted != null)
  569. {
  570. this.PullRequestCompleted();
  571. }
  572. this.Multipliers.HandlePullResponse(dictionary);
  573. }
  574. public const string AndroidApiDomain = "https://gamesapi.sparklingsociety.net/cig3-google/";
  575. public const string IOSApiDomain = "https://gamesapi.sparklingsociety.net/cig3-ios/";
  576. public const string WindowsApiDomain = "https://gamesapi.sparklingsociety.net/cig3-windows/";
  577. public const string CafeBazaarApiDomain = "https://gamesapi.sparklingsociety.net/cig3-cafebazaar/";
  578. public const string OSXApiDomain = "https://gamesapi.sparklingsociety.net/cig3-osx/";
  579. public const string AmazonApiDomain = "https://gamesapi.sparklingsociety.net/cig3-amazon/";
  580. private const long TimeBetweenPullRequests = 900L;
  581. private const long MinimumWaitTime = 10L;
  582. private const long MinimumExtraWaitTime = 60L;
  583. private const long MaximumExtraWaitTime = 600L;
  584. private const float DefaultWebTimeoutSeconds = 5f;
  585. private static readonly DateTime UnixOriginTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
  586. private const int CheaterTypeNotSet = -1;
  587. private const int DefaultIslandSyncChangePercent = 5;
  588. private const bool DefaultVideoSpeedupEnabled = false;
  589. private const int DefaultVideoSpeedupMaxCurrency = 2;
  590. private const int DefaultVideoSpeedupMinSeconds = 60;
  591. private const string ServerUNIXTimeStampKey = "time";
  592. private const string UpdateAvailableKey = "update_available";
  593. private const string SalesTypeKey = "saletype";
  594. private const string SalesSecondsKey = "saleseconds";
  595. private const string UseBadgeServerKey = "use_badge";
  596. private const string AdjustRegisteredTokenKey = "adjust_registered_token";
  597. private const string AdjustTokensKey = "adjust_tokens";
  598. private const string LastRequestKey = "lastRequest";
  599. private const string LastResponseKey = "lastResponse";
  600. private const string AdjustTokensSeenKey = "adjust_tokens_seen";
  601. private const string TimeDiffWithClientInMinutesKey = "timeDiffWithClientInMinutes";
  602. private const string UserIdKey = "userId";
  603. private const string UserKeyKey = "userKey";
  604. private const string SessionsPlayedKey = "sessionsPlayed";
  605. private const string UndeliveredKey = "undelivered";
  606. private const string SaleKey = "sale";
  607. private const string SaleExpiryKey = "saleExpiry";
  608. private const string IslandSyncChangePercentKey = "islandSyncChangePercent";
  609. private const string UseIAPDealsKey = "allow_iap_deals";
  610. private const string DisableIAPSignValidationKey = "disable_sign_validation";
  611. private const string UseBadgeKey = "useBadge";
  612. private const string CheaterTypeKey = "cheater_value";
  613. private const string VideoSpeedupEnabledKey = "video_speedup_building_enabled";
  614. private const string VideoSpeedupMaxCurrencyKey = "video_speedup_building_max_gold_cost";
  615. private const string VideoSpeedupMinSecondsKey = "video_speedup_building_min_seconds";
  616. [SerializeField]
  617. private Serializing serializing;
  618. private long _timeDiffWithClientInMinutes;
  619. private IEnumerator _pullRequestRoutine;
  620. private IEnumerator _waitEnumerator;
  621. private int _sessionsPlayed;
  622. private long _lastPullRequestTime;
  623. private long _extraWaitTime;
  624. private Dictionary<string, string> _properties = new Dictionary<string, string>();
  625. private string _lastResponse = string.Empty;
  626. private int _cheaterType = -1;
  627. private static string _apiDomain = null;
  628. public delegate void PullRequestCompletedHandler();
  629. public struct WWWResponse
  630. {
  631. public WWWResponse(bool timedout, string error, string text)
  632. {
  633. this.TimedOut = timedout;
  634. this.Error = error;
  635. this.Text = text;
  636. }
  637. public readonly bool TimedOut;
  638. public readonly string Error;
  639. public readonly string Text;
  640. }
  641. }