25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

868 lines
31 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Text;
  6. using SUISS.Cloud.Boomlagoon.JSON;
  7. using SUISS.Cloud.Crypto;
  8. using SUISS.Storage;
  9. using UnityEngine;
  10. namespace SUISS.Cloud
  11. {
  12. public class LeaderboardController : ILeaderboardController
  13. {
  14. public LeaderboardController(IPlayernameController playernames, string boardName, string countryCode, int leaderboardTopSize, int syncLeaderboardsEverySeconds, string sparkSocGameId, int buildVersion)
  15. {
  16. this._leaderboardTopSize = leaderboardTopSize;
  17. this._refreshCacheEvery = syncLeaderboardsEverySeconds;
  18. this._sparkSocGameId = sparkSocGameId;
  19. this._buildVersion = buildVersion;
  20. this._boardName = boardName;
  21. this._countryCode = countryCode;
  22. this._playernames = playernames;
  23. this._serverUrl = "https://leaderboards.sparklingsociety.net";
  24. this._loginUrl = "https://usernames.sparklingsociety.net/login/leaderboards";
  25. }
  26. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames for all login features.")]
  27. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  28. public event Action LoginLostEvent;
  29. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames for all login features.")]
  30. private void FireLoginLostEvent()
  31. {
  32. if (this.LoginLostEvent != null)
  33. {
  34. this.LoginLostEvent();
  35. }
  36. }
  37. private Dictionary<string, object> storage
  38. {
  39. get
  40. {
  41. return SUISS.Storage.Storage.Get(StorageLifecycle.Game).GetDictionary("leaderboardController");
  42. }
  43. }
  44. private LeaderboardController.Leaderboards GlobalBoardsCache
  45. {
  46. get
  47. {
  48. if (!this.storage.ContainsKey("leaderboardpages1") || !(this.storage["leaderboardpages1"] is LeaderboardController.Leaderboards))
  49. {
  50. this.storage["leaderboardpages1"] = new LeaderboardController.Leaderboards();
  51. }
  52. return (LeaderboardController.Leaderboards)this.storage["leaderboardpages1"];
  53. }
  54. set
  55. {
  56. this.storage["leaderboardpages1"] = value;
  57. }
  58. }
  59. private int Page
  60. {
  61. get
  62. {
  63. if (this.storage.ContainsKey("LeaderboardPage1"))
  64. {
  65. return (int)this.storage["LeaderboardPage1"];
  66. }
  67. return -1;
  68. }
  69. set
  70. {
  71. this.storage["LeaderboardPage1"] = value;
  72. }
  73. }
  74. private bool HasAccessToken
  75. {
  76. get
  77. {
  78. return this._accessToken != null && !this._accessToken.HasExpired && !string.IsNullOrEmpty(this._accessToken.Token);
  79. }
  80. }
  81. private int LeaderboardTopPages
  82. {
  83. get
  84. {
  85. return (this._leaderboardTopSize + this._pageSize - 1) / this._pageSize;
  86. }
  87. }
  88. [Obsolete("Currently not used.")]
  89. public DateTime VotesResetAt
  90. {
  91. get
  92. {
  93. if (this.storage.ContainsKey("VotesResetAt"))
  94. {
  95. return (DateTime)this.storage["VotesResetAt"];
  96. }
  97. return DateTime.UtcNow;
  98. }
  99. private set
  100. {
  101. this.storage["LeaderboardPage1"] = value;
  102. }
  103. }
  104. [Obsolete("Currently not used.")]
  105. public int VotesLeft
  106. {
  107. get
  108. {
  109. if (this.storage.ContainsKey("VotesLeft"))
  110. {
  111. return (int)this.storage["VotesLeft"];
  112. }
  113. return -1;
  114. }
  115. private set
  116. {
  117. this.storage["LeaderboardPage1"] = value;
  118. }
  119. }
  120. private LeaderboardController.Leaderboards CountryBoardsCache
  121. {
  122. get
  123. {
  124. if (!this.storage.ContainsKey("CountryBoardsCache1") || !(this.storage["CountryBoardsCache1"] is LeaderboardController.Leaderboards))
  125. {
  126. this.storage["CountryBoardsCache1"] = new LeaderboardController.Leaderboards();
  127. }
  128. return (LeaderboardController.Leaderboards)this.storage["CountryBoardsCache1"];
  129. }
  130. set
  131. {
  132. this.storage["CountryBoardsCache1"] = value;
  133. }
  134. }
  135. private int CountryPage
  136. {
  137. get
  138. {
  139. if (this.storage.ContainsKey("CountryPage1"))
  140. {
  141. return (int)this.storage["CountryPage1"];
  142. }
  143. return -1;
  144. }
  145. set
  146. {
  147. this.storage["CountryPage1"] = value;
  148. }
  149. }
  150. [Obsolete]
  151. private string InstallUuid
  152. {
  153. get
  154. {
  155. if (!this.storage.ContainsKey("installUuid"))
  156. {
  157. this.storage["installUuid"] = string.Empty;
  158. }
  159. return (string)this.storage["installUuid"];
  160. }
  161. set
  162. {
  163. this.storage["installUuid"] = value;
  164. }
  165. }
  166. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames, and shouldn't need Refreshtokens")]
  167. private string RefreshToken
  168. {
  169. get
  170. {
  171. if (!this.storage.ContainsKey("refreshToken2"))
  172. {
  173. this.storage["refreshToken2"] = string.Empty;
  174. }
  175. return (string)this.storage["refreshToken2"];
  176. }
  177. set
  178. {
  179. this.storage["refreshToken2"] = value;
  180. }
  181. }
  182. [Obsolete]
  183. private string Scope
  184. {
  185. get
  186. {
  187. if (!this.storage.ContainsKey("oauthScope"))
  188. {
  189. this.storage["oauthScope"] = string.Empty;
  190. }
  191. return (string)this.storage["oauthScope"];
  192. }
  193. set
  194. {
  195. this.storage["oauthScope"] = value;
  196. }
  197. }
  198. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames for all login features.")]
  199. public bool IsLoggedIn
  200. {
  201. get
  202. {
  203. return !string.IsNullOrEmpty(this.RefreshToken);
  204. }
  205. }
  206. public bool InCountryTop
  207. {
  208. get
  209. {
  210. return this.CountryRank >= 0 && this.CountryRank <= this._leaderboardTopSize;
  211. }
  212. }
  213. public bool InGlobalTop
  214. {
  215. get
  216. {
  217. return this.GlobalRank >= 0 && this.GlobalRank <= this._leaderboardTopSize;
  218. }
  219. }
  220. public int GlobalRank
  221. {
  222. get
  223. {
  224. if (this.storage.ContainsKey("GobalRank"))
  225. {
  226. return (int)this.storage["GobalRank"];
  227. }
  228. return -1;
  229. }
  230. private set
  231. {
  232. this.storage["GobalRank"] = value;
  233. }
  234. }
  235. public int CountryRank
  236. {
  237. get
  238. {
  239. if (this.storage.ContainsKey("CountryRank"))
  240. {
  241. return (int)this.storage["CountryRank"];
  242. }
  243. return -1;
  244. }
  245. private set
  246. {
  247. this.storage["CountryRank"] = value;
  248. }
  249. }
  250. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames to get access tokens.")]
  251. public CloudRequest<LeaderboardErrors?> Login(string username, string password, string installUuid)
  252. {
  253. return new CloudRequest<LeaderboardErrors?>(this.CoLogin(username, password, installUuid));
  254. }
  255. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames to get access tokens.")]
  256. public void LogOut()
  257. {
  258. this._accessToken = new AccessToken();
  259. this.RefreshToken = string.Empty;
  260. this.InstallUuid = string.Empty;
  261. this.Scope = string.Empty;
  262. this.Page = -1;
  263. this.CountryPage = -1;
  264. }
  265. public Leaderboard GetGlobalLocal()
  266. {
  267. if (this._playernames.IsPlayerLoggedIn && !this.InGlobalTop)
  268. {
  269. return this.CollectAndCreateBoard(60, this.GlobalBoardsCache, this.GlobalLocalPages());
  270. }
  271. return new Leaderboard();
  272. }
  273. public Leaderboard GetCountryLocal()
  274. {
  275. if (this.HasAccessToken && !this.InCountryTop)
  276. {
  277. return this.CollectAndCreateBoard(60, this.CountryBoardsCache, this.CountyLocalPages());
  278. }
  279. return new Leaderboard();
  280. }
  281. public Leaderboard GetGlobalTop()
  282. {
  283. return this.CollectAndCreateBoard(this._leaderboardTopSize, this.GlobalBoardsCache, this.TopPages());
  284. }
  285. public Leaderboard GetCountryTop()
  286. {
  287. return this.CollectAndCreateBoard(this._leaderboardTopSize, this.CountryBoardsCache, this.TopPages());
  288. }
  289. public CustomYieldInstruction UpdateLeaderboards()
  290. {
  291. return CloudRequestRunner.StartCoroutine(this.CoUpdateLeaderboards());
  292. }
  293. public void StartLeaderboardSync()
  294. {
  295. CloudRequestRunner.StartCoroutine(this.periodicUpdate());
  296. }
  297. public CustomYieldInstruction UpdateScore(IScoreRecord record)
  298. {
  299. return CloudRequestRunner.StartCoroutine(this.CoUpdateLeaderboardScore(record));
  300. }
  301. public string SignRecord(IScoreRecord record, string leaderboardSecret)
  302. {
  303. string message = string.Concat(new string[]
  304. {
  305. record.PrimaryScore.ToString(),
  306. record.SecondaryScore.ToString(),
  307. record.TertiaryScore.ToString(),
  308. record.QuaternaryScore.ToString(),
  309. record.CountryCode,
  310. record.GameUuid,
  311. record.Sagid,
  312. "2"
  313. });
  314. return this.CreateToken(message, leaderboardSecret);
  315. }
  316. public CloudRequest<LeaderboardErrors?> Vote(string installUuid, bool upVote)
  317. {
  318. return new CloudRequest<LeaderboardErrors?>(this.CoVote(installUuid, upVote));
  319. }
  320. public IEnumerator CoVote(string installUuid, bool upVote)
  321. {
  322. if (!this.HasAccessToken)
  323. {
  324. CloudRequest<LeaderboardErrors?> loginRequest = this.Login();
  325. yield return loginRequest;
  326. if (loginRequest.Error != null)
  327. {
  328. yield return new YieldError<LeaderboardErrors?>(loginRequest.Error);
  329. }
  330. }
  331. string call = string.Format("{0}/leaderboards/vote/{1}?access_token={2}&voteUp={3}", new object[]
  332. {
  333. this._serverUrl,
  334. this._playernames.InstallUuid,
  335. this._accessToken.Token,
  336. (!upVote) ? "false" : "true"
  337. });
  338. ApiRequest request = ApiRequest.Post(call, new JSONObject
  339. {
  340. {
  341. "installUuid",
  342. installUuid
  343. }
  344. }, this._buildVersion.ToString(), this._sparkSocGameId);
  345. yield return request;
  346. if (request.Result != null)
  347. {
  348. JSONValue data = request.Result.Data;
  349. UnityEngine.Debug.LogWarning("TODO: save votes left: " + data.ToString());
  350. }
  351. else if (request.Error != null)
  352. {
  353. if (request.Error.Status == 0)
  354. {
  355. UnityEngine.Debug.Log("Failed to update leaderboard record. Message:" + request.Error.Error);
  356. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.NoInternet));
  357. }
  358. else
  359. {
  360. UnityEngine.Debug.LogError(string.Concat(new object[]
  361. {
  362. "Post record (",
  363. request.Error.Status,
  364. "): ",
  365. request.Error.Error
  366. }));
  367. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.GeneralError));
  368. }
  369. }
  370. yield break;
  371. }
  372. private CloudRequest<LeaderboardErrors?> Login()
  373. {
  374. return new CloudRequest<LeaderboardErrors?>(this.CoLogin());
  375. }
  376. private IEnumerator CoLogin()
  377. {
  378. if (!this.HasAccessToken)
  379. {
  380. CloudRequest<IAccessToken, PlayernameErrors?> login = this._playernames.RequestPlayerAccessToken("leaderboards");
  381. yield return login;
  382. if (login.Result != null)
  383. {
  384. this._accessToken = login.Result;
  385. if (!this.HasAccessToken)
  386. {
  387. UnityEngine.Debug.LogError("Leaderboards received invalid access token from _playernames.");
  388. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.GeneralError));
  389. }
  390. }
  391. else
  392. {
  393. PlayernameErrors value = login.Error.Value;
  394. if (value != PlayernameErrors.NoInternet)
  395. {
  396. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.GeneralError));
  397. }
  398. else
  399. {
  400. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.NoInternet));
  401. }
  402. }
  403. }
  404. yield break;
  405. }
  406. [Obsolete("No longer needed! Leaderboard Controller now uses IPlayernames for all login features.")]
  407. private IEnumerator CoLogin(string username, string password, string installUuid)
  408. {
  409. if (!this.HasAccessToken)
  410. {
  411. string scope = "read-write:" + installUuid;
  412. OAuthRequest request = OAuthRequest.LoginPassword(this._loginUrl, username, password, scope);
  413. yield return request;
  414. if (request.Result != null)
  415. {
  416. this._accessToken = request.Result.AccessToken;
  417. this.RefreshToken = request.Result.RefreshToken;
  418. this.InstallUuid = installUuid;
  419. this.Scope = request.Result.Scope;
  420. }
  421. else
  422. {
  423. this._accessToken = new AccessToken();
  424. if (request.Error.NoInternet)
  425. {
  426. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.NoInternet));
  427. }
  428. else
  429. {
  430. this.RefreshToken = string.Empty;
  431. this.InstallUuid = string.Empty;
  432. this.Scope = string.Empty;
  433. yield return new YieldError<LeaderboardErrors?>(new LeaderboardErrors?(LeaderboardErrors.GeneralError));
  434. }
  435. }
  436. }
  437. yield break;
  438. }
  439. private IEnumerator CoFetchLeaderboard(string boardName, int page)
  440. {
  441. string call = string.Format("{0}/leaderboards/{1}/{2}/{3}", new object[]
  442. {
  443. this._serverUrl,
  444. boardName,
  445. this._sparkSocGameId,
  446. page
  447. });
  448. ApiRequest request = ApiRequest.Get(call, this._buildVersion.ToString(), this._sparkSocGameId);
  449. yield return request;
  450. if (request.Result != null)
  451. {
  452. JSONValue data = request.Result.Data;
  453. List<ScoreRecord> list = this.parseRecords(data);
  454. if (list.Count > 0)
  455. {
  456. int rank = list[0].Rank;
  457. List<LeaderboardEntry> list2 = new List<LeaderboardEntry>();
  458. foreach (ScoreRecord scoreRecord in list)
  459. {
  460. list2.Add(new LeaderboardEntry(scoreRecord.Sagid, scoreRecord.Username, scoreRecord.PrimaryScore, scoreRecord.SecondaryScore, scoreRecord.TertiaryScore, scoreRecord.QuaternaryScore, scoreRecord.Votes, scoreRecord.IslandReady));
  461. }
  462. this.GlobalBoardsCache[page.ToString()] = new Leaderboard(this._pageSize, rank, list2);
  463. }
  464. else
  465. {
  466. this.GlobalBoardsCache[page.ToString()] = new Leaderboard();
  467. }
  468. }
  469. else if (request.Error.NoInternet)
  470. {
  471. UnityEngine.Debug.Log("Failed to update leaderboards. (No internet) Message:" + request.Error.Error);
  472. }
  473. else
  474. {
  475. UnityEngine.Debug.LogError(string.Concat(new object[]
  476. {
  477. "Get leaderboard (",
  478. request.Error.Status,
  479. "): ",
  480. request.Error.Error
  481. }));
  482. }
  483. yield break;
  484. }
  485. private CustomYieldInstruction FetchLeaderboard(string boardName, int page)
  486. {
  487. return CloudRequestRunner.StartCoroutine(this.CoFetchLeaderboard(boardName, page));
  488. }
  489. private IEnumerator CoFetchCountryLeaderboard(string boardName, int page, string countryCode)
  490. {
  491. string call = string.Format("{0}/leaderboards/{1}/{2}/{3}/{4}", new object[]
  492. {
  493. this._serverUrl,
  494. boardName,
  495. this._sparkSocGameId,
  496. countryCode,
  497. page
  498. });
  499. ApiRequest request = ApiRequest.Get(call, this._buildVersion.ToString(), this._sparkSocGameId);
  500. yield return request;
  501. if (request.Result != null)
  502. {
  503. JSONValue data = request.Result.Data;
  504. List<ScoreRecord> list = this.parseRecords(data);
  505. if (list.Count > 0)
  506. {
  507. int countryRank = list[0].CountryRank;
  508. List<LeaderboardEntry> list2 = new List<LeaderboardEntry>();
  509. foreach (ScoreRecord scoreRecord in list)
  510. {
  511. list2.Add(new LeaderboardEntry(scoreRecord.Sagid, scoreRecord.Username, scoreRecord.PrimaryScore, scoreRecord.SecondaryScore, scoreRecord.TertiaryScore, scoreRecord.QuaternaryScore, scoreRecord.Votes, scoreRecord.IslandReady));
  512. }
  513. this.CountryBoardsCache[page.ToString()] = new Leaderboard(this._pageSize, countryRank, list2);
  514. }
  515. else
  516. {
  517. this.CountryBoardsCache[page.ToString()] = new Leaderboard();
  518. }
  519. }
  520. else if (request.Error.Status == 0)
  521. {
  522. UnityEngine.Debug.Log("Failed to update leaderboards. (No internet) Message:" + request.Error.Error);
  523. }
  524. else
  525. {
  526. UnityEngine.Debug.LogError(string.Concat(new object[]
  527. {
  528. "Get leaderboard (",
  529. request.Error.Status,
  530. "): ",
  531. request.Error.Error
  532. }));
  533. }
  534. yield break;
  535. }
  536. private CustomYieldInstruction FetchCountryLeaderboard(string boardName, int page, string countryCode)
  537. {
  538. return CloudRequestRunner.StartCoroutine(this.CoFetchCountryLeaderboard(boardName, page, countryCode));
  539. }
  540. private IEnumerator CoUpdateLeaderboardScore(IScoreRecord record)
  541. {
  542. if (!this.HasAccessToken)
  543. {
  544. CloudRequest<LeaderboardErrors?> loginRequest = this.Login();
  545. yield return loginRequest;
  546. if (loginRequest.Error != null)
  547. {
  548. UnityEngine.Debug.LogError("Failed to update leaderboards: " + loginRequest.Error);
  549. yield break;
  550. }
  551. }
  552. string call = string.Format("{0}/leaderboards/records?access_token={1}", this._serverUrl, this._accessToken.Token);
  553. JSONValue jsonValue = new JSONValue(new JSONObject
  554. {
  555. {
  556. "username",
  557. new JSONValue(record.Username)
  558. },
  559. {
  560. "sauid",
  561. new JSONValue(record.Sauid)
  562. },
  563. {
  564. "sagid",
  565. new JSONValue(record.Sagid)
  566. },
  567. {
  568. "gameUuid",
  569. new JSONValue(record.GameUuid)
  570. },
  571. {
  572. "countryCode",
  573. new JSONValue(record.CountryCode)
  574. },
  575. {
  576. "signature",
  577. new JSONValue(record.Signature)
  578. },
  579. {
  580. "data",
  581. new JSONValue(record.Data)
  582. },
  583. {
  584. "primaryScore",
  585. new JSONValue((double)record.PrimaryScore)
  586. },
  587. {
  588. "secondaryScore",
  589. new JSONValue((double)record.SecondaryScore)
  590. },
  591. {
  592. "tertiaryScore",
  593. new JSONValue((double)record.TertiaryScore)
  594. },
  595. {
  596. "quaternaryScore",
  597. new JSONValue((double)record.QuaternaryScore)
  598. },
  599. {
  600. "isCheater",
  601. new JSONValue(record.IsCheater)
  602. },
  603. {
  604. "islandReady",
  605. new JSONValue(record.IslandReady)
  606. }
  607. });
  608. ApiRequest request = ApiRequest.Post(call, jsonValue, this._buildVersion.ToString(), this._sparkSocGameId);
  609. yield return request;
  610. if (request.Result != null)
  611. {
  612. JSONValue data = request.Result.Data;
  613. ScoreRecord scoreRecord = ScoreRecord.fromJson(data);
  614. this.Page = scoreRecord.RankPage;
  615. this.CountryPage = scoreRecord.CountryRankPage;
  616. this.GlobalRank = scoreRecord.Rank;
  617. this.CountryRank = scoreRecord.CountryRank;
  618. }
  619. else if (request.Error != null)
  620. {
  621. if (request.Error.Status == 0)
  622. {
  623. UnityEngine.Debug.Log("Failed to update leaderboard record. Message:" + request.Error.Error);
  624. }
  625. else
  626. {
  627. UnityEngine.Debug.LogError(string.Concat(new object[]
  628. {
  629. "Post record (",
  630. request.Error.Status,
  631. "): ",
  632. request.Error.Error
  633. }));
  634. }
  635. }
  636. yield break;
  637. }
  638. private Leaderboard CollectAndCreateBoard(int size, LeaderboardController.Leaderboards fromCache, HashSet<int> pages)
  639. {
  640. List<LeaderboardEntry> list = new List<LeaderboardEntry>();
  641. int num = int.MaxValue;
  642. foreach (int num2 in pages)
  643. {
  644. if (fromCache.ContainsKey(num2.ToString()))
  645. {
  646. num = Math.Min(num, fromCache[num2.ToString()].FirstRank);
  647. foreach (LeaderboardEntry item in fromCache[num2.ToString()].Records)
  648. {
  649. list.Add(item);
  650. }
  651. }
  652. }
  653. if (list.Count > size)
  654. {
  655. list = list.GetRange(0, size);
  656. }
  657. return new Leaderboard(size, num, list);
  658. }
  659. private string CreateToken(string message, string secret)
  660. {
  661. secret = (secret ?? string.Empty);
  662. ASCIIEncoding asciiencoding = new ASCIIEncoding();
  663. byte[] bytes = asciiencoding.GetBytes(secret);
  664. byte[] bytes2 = asciiencoding.GetBytes(message);
  665. HmacSha256 hmacSha = new HmacSha256(bytes);
  666. byte[] inArray = hmacSha.ComputeHash(bytes2);
  667. return Convert.ToBase64String(inArray);
  668. }
  669. private List<ScoreRecord> parseRecords(JSONValue json)
  670. {
  671. if (json.Type != JSONValueType.Array)
  672. {
  673. UnityEngine.Debug.LogError("Exprected leaderboards json to be an array. But got " + json.Type.ToString());
  674. }
  675. JSONArray array = json.Array;
  676. List<ScoreRecord> list = new List<ScoreRecord>();
  677. foreach (JSONValue json2 in array)
  678. {
  679. ScoreRecord item = ScoreRecord.fromJson(json2);
  680. list.Add(item);
  681. }
  682. return list;
  683. }
  684. private IEnumerator periodicUpdate()
  685. {
  686. for (; ; )
  687. {
  688. HashSet<int> globalPages = this.TopPages();
  689. HashSet<int> countryPages = this.TopPages();
  690. globalPages.UnionWith(this.GlobalLocalPages());
  691. countryPages.UnionWith(this.CountyLocalPages());
  692. foreach (int page in globalPages)
  693. {
  694. this.FetchLeaderboard(this._boardName, page);
  695. }
  696. foreach (int page2 in globalPages)
  697. {
  698. this.FetchCountryLeaderboard(this._boardName, page2, this._countryCode);
  699. }
  700. yield return new WaitForSeconds((float)this._refreshCacheEvery);
  701. }
  702. yield break;
  703. }
  704. private IEnumerator CoUpdateLeaderboards()
  705. {
  706. HashSet<int> globalPages = this.TopPages();
  707. HashSet<int> countryPages = this.TopPages();
  708. globalPages.UnionWith(this.GlobalLocalPages());
  709. countryPages.UnionWith(this.CountyLocalPages());
  710. foreach (int p in globalPages)
  711. {
  712. yield return this.FetchLeaderboard(this._boardName, p);
  713. }
  714. foreach (int p2 in globalPages)
  715. {
  716. yield return this.FetchCountryLeaderboard(this._boardName, p2, this._countryCode);
  717. }
  718. yield break;
  719. }
  720. private HashSet<int> TopPages()
  721. {
  722. int leaderboardTopPages = this.LeaderboardTopPages;
  723. HashSet<int> hashSet = new HashSet<int>();
  724. for (int i = 1; i <= leaderboardTopPages; i++)
  725. {
  726. hashSet.Add(i);
  727. }
  728. return hashSet;
  729. }
  730. private HashSet<int> CountyLocalPages()
  731. {
  732. HashSet<int> hashSet = new HashSet<int>();
  733. if (this.CountryPage == -1 || this.InCountryTop)
  734. {
  735. return hashSet;
  736. }
  737. hashSet.Add(this.CountryPage - 1);
  738. hashSet.Add(this.CountryPage);
  739. hashSet.Add(this.CountryPage + 1);
  740. return hashSet;
  741. }
  742. private HashSet<int> GlobalLocalPages()
  743. {
  744. HashSet<int> hashSet = new HashSet<int>();
  745. if (this.Page == -1 || this.InGlobalTop)
  746. {
  747. return hashSet;
  748. }
  749. hashSet.Add(this.Page - 1);
  750. hashSet.Add(this.Page);
  751. hashSet.Add(this.Page + 1);
  752. return hashSet;
  753. }
  754. public const string StorageKey = "leaderboardController";
  755. [Obsolete]
  756. public const string RefreshTokenKey = "refreshToken2";
  757. [Obsolete]
  758. public const string InstallUuidKey = "installUuid";
  759. [Obsolete]
  760. public const string AccessTokenKey = "accessToken";
  761. [Obsolete]
  762. public const string ScopeKey = "oauthScope";
  763. public const string LeaderboardsKey = "leaderboardpages1";
  764. public const string LeaderboardPageKey = "LeaderboardPage1";
  765. public const string GobalRankKey = "GobalRank";
  766. public const string CountryRankKey = "CountryRank";
  767. public const string CountryBoardsCacheKey = "CountryBoardsCache1";
  768. public const string CountryPageKey = "CountryPage1";
  769. public const string VotesResetAtKey = "VotesResetAt";
  770. public const string VotesLeftKey = "VotesLeft";
  771. private const string GetLeaderboardsCall = "{0}/leaderboards/{1}/{2}/{3}";
  772. private const string GetCountryLeaderboardsCall = "{0}/leaderboards/{1}/{2}/{3}/{4}";
  773. private const string StoreLeaderboardsCall = "{0}/leaderboards/records?access_token={1}";
  774. private const string VoteCall = "{0}/leaderboards/vote/{1}?access_token={2}&voteUp={3}";
  775. private string _serverUrl;
  776. private string _loginUrl;
  777. private IPlayernameController _playernames;
  778. private string _sparkSocGameId = "a5a5a4f8-2d69-4cab-ab38-3d98b346e4ba";
  779. private int _buildVersion;
  780. private int _pageSize = 20;
  781. private int _leaderboardTopSize = 100;
  782. private int _refreshCacheEvery;
  783. private string _boardName = "boards";
  784. private string _countryCode = "xx";
  785. private IAccessToken _accessToken = new AccessToken();
  786. private class Leaderboards : StorableDictionary<Leaderboard>
  787. {
  788. }
  789. }
  790. }