You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

138 lines
4.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using SUISS.Cloud.Boomlagoon.JSON;
  4. using SUISS.Storage;
  5. namespace SUISS.Cloud
  6. {
  7. public class ScoreRecord : IStorable, IScoreRecord
  8. {
  9. public string Username { get; set; }
  10. public string Sauid { get; set; }
  11. public string Sagid { get; set; }
  12. public bool IsCheater
  13. {
  14. get
  15. {
  16. return this._isCheater;
  17. }
  18. set
  19. {
  20. this._isCheater = value;
  21. }
  22. }
  23. public string GameUuid { get; set; }
  24. public string CountryCode { get; set; }
  25. public string Signature { get; set; }
  26. public string Data { get; set; }
  27. public int PrimaryScore { get; set; }
  28. public int SecondaryScore { get; set; }
  29. public int TertiaryScore { get; set; }
  30. public int QuaternaryScore { get; set; }
  31. public int RankPage { get; set; }
  32. public int CountryRankPage { get; set; }
  33. public int Rank { get; set; }
  34. public int CountryRank { get; set; }
  35. public int Votes { get; set; }
  36. public bool IslandReady { get; set; }
  37. public static ScoreRecord fromJson(JSONValue json)
  38. {
  39. if (json.Type == JSONValueType.Object)
  40. {
  41. JSONObject obj = json.Obj;
  42. ScoreRecord scoreRecord = new ScoreRecord();
  43. scoreRecord.Sagid = JSONParse.StringField(obj, "sagid", string.Empty);
  44. scoreRecord.Rank = JSONParse.IntField(obj, "gameRank", -1);
  45. scoreRecord.CountryRank = JSONParse.IntField(obj, "countryRank", -1);
  46. scoreRecord.CountryCode = JSONParse.StringField(obj, "countryCode", string.Empty);
  47. scoreRecord.Username = JSONParse.StringField(obj, "username", "UnknownPlayer");
  48. scoreRecord.PrimaryScore = JSONParse.IntField(obj, "primaryScore", -1);
  49. scoreRecord.SecondaryScore = JSONParse.IntField(obj, "secondaryScore", -1);
  50. scoreRecord.TertiaryScore = JSONParse.IntField(obj, "tertiaryScore", -1);
  51. scoreRecord.QuaternaryScore = JSONParse.IntField(obj, "quaternaryScore", -1);
  52. scoreRecord.Votes = JSONParse.IntField(obj, "votes", 0);
  53. scoreRecord.IslandReady = JSONParse.BoolField(obj, "islandReady", scoreRecord.Votes > 0);
  54. scoreRecord.GameUuid = JSONParse.StringField(obj, "gameUuid", string.Empty);
  55. scoreRecord.Signature = JSONParse.StringField(obj, "signature", string.Empty);
  56. scoreRecord.RankPage = JSONParse.IntField(obj, "gameRankPage", 2147483637);
  57. scoreRecord.CountryRankPage = JSONParse.IntField(obj, "countryRankPage", 2147483637);
  58. scoreRecord.IsCheater = JSONParse.BoolField(obj, "isCheater", false);
  59. return scoreRecord;
  60. }
  61. return null;
  62. }
  63. void IStorable.FromStorage(IDictionary<string, object> dict)
  64. {
  65. if (dict.ContainsKey("Username"))
  66. {
  67. this.Username = (string)dict["Username"];
  68. }
  69. if (dict.ContainsKey("PrimaryScore"))
  70. {
  71. this.PrimaryScore = (int)dict["PrimaryScore"];
  72. }
  73. if (dict.ContainsKey("SecondaryScore"))
  74. {
  75. this.SecondaryScore = (int)dict["SecondaryScore"];
  76. }
  77. if (dict.ContainsKey("TertiaryScore"))
  78. {
  79. this.TertiaryScore = (int)dict["TertiaryScore"];
  80. }
  81. if (dict.ContainsKey("QuaternaryScore"))
  82. {
  83. this.QuaternaryScore = (int)dict["QuaternaryScore"];
  84. }
  85. if (dict.ContainsKey("SagId"))
  86. {
  87. this.Sagid = (string)dict["SagId"];
  88. }
  89. }
  90. IDictionary<string, object> IStorable.ToStorage()
  91. {
  92. Dictionary<string, object> dictionary = new Dictionary<string, object>();
  93. dictionary["Username"] = this.Username;
  94. dictionary["PrimaryScore"] = this.PrimaryScore;
  95. dictionary["SecondaryScore"] = this.SecondaryScore;
  96. dictionary["TertiaryScore"] = this.TertiaryScore;
  97. dictionary["QuaternaryScore"] = this.QuaternaryScore;
  98. dictionary["SagId"] = this.Sagid;
  99. return dictionary;
  100. }
  101. private bool _isCheater;
  102. private const string UsernameKey = "Username";
  103. private const string PrimaryScoreKey = "PrimaryScore";
  104. private const string SecondaryScoreKey = "SecondaryScore";
  105. private const string TertiaryScoreKey = "TertiaryScore";
  106. private const string QuaternaryScoreKey = "QuaternaryScore";
  107. private const string SagidKey = "SagId";
  108. }
  109. }