namespace Supercell.Laser.Logic.Message.Ranking { using Supercell.Laser.Logic.Avatar; using Supercell.Laser.Logic.Home; using Supercell.Laser.Logic.Club; using Supercell.Laser.Logic.Helper; public class LeaderboardMessage : GameMessage { public int LeaderboardType { get; set; } public int CharachterId { get; set; } public int SeasonId { get; set; } // echoed back into the header flag position public List> Avatars; public Dictionary Brawlers; public List AllianceList; public long OwnAvatarId; public string Region { get; set; } public LeaderboardMessage() : base() { Avatars = new List>(); AllianceList = new List(); LeaderboardType = 1; } /* public override void Encode() { base.Encode(); ByteStream.WriteBoolean(true); ByteStream.WriteVInt(0); ByteStream.WriteVInt(0); ByteStream.WriteString("RU"); if (_leaderboard == null || _leaderboard.Count == 0) { ByteStream.WriteVInt(2); for (int i = 0; i < 2; i++) { ByteStream.WriteVInt(0); ByteStream.WriteVInt(1); ByteStream.WriteVInt(1); ByteStream.WriteVInt(0); ByteStream.WriteVInt(1); ByteStream.WriteString("тестнет"); ByteStream.WriteString(i == 0 ? "Жалко, но тут ничего нет" : "It's a pity, but there's nothing here"); ByteStream.WriteVInt(0); ByteStream.WriteVInt(28000069); ByteStream.WriteVInt(43000005); ByteStream.WriteVInt(46000005); ByteStream.WriteVInt(0); } } else { ByteStream.WriteVInt(_leaderboard.Count); for (int i = 0; i < _leaderboard.Count; i++) { var account = _leaderboard[i]; ByteStream.WriteVInt(0); ByteStream.WriteVInt((int)account.GetAccountId()); ByteStream.WriteVInt(i + 1); ByteStream.WriteVInt((int)account.GetFieldValueByAccountStructureParameterFromAccountModel(AccountStructure.Trophies)); ByteStream.WriteVInt(1); ByteStream.WriteString(account.GetFieldValueByAccountStructureParameterFromAccountModel(AccountStructure.AvatarName).ToString()); ByteStream.WriteString(account.GetFieldValueByAccountStructureParameterFromAccountModel(AccountStructure.AvatarName).ToString()); ByteStream.WriteVInt(0); ByteStream.WriteVInt((int)account.GetFieldValueByAccountStructureParameterFromAccountModel(AccountStructure.PlayerThumbnailGlobalId)); ByteStream.WriteVInt((int)account.GetFieldValueByAccountStructureParameterFromAccountModel(AccountStructure.NameColorGlobalId)); ByteStream.WriteVInt(0); ByteStream.WriteVInt(0); } } ByteStream.WriteVInt(0); ByteStream.WriteVInt(1); ByteStream.WriteVInt(0); ByteStream.WriteVInt(0); ByteStream.WriteString("RU"); } */ public override void Encode() { int playerIndex = 0; Stream.WriteVInt(LeaderboardType); Stream.WriteVInt(SeasonId); // must echo the request's season id, or the client silently discards the whole message ByteStreamHelper.WriteDataReference(Stream, CharachterId); Stream.WriteString(Region); // Region // Confirmed wire format (from client decompile of RankingEntry / PlayerRankingData / // PlayerDisplayData / AllianceRankingData): // // RankingEntry: // WriteVLong id // WriteVInt field2 (constant 1, not used to gate anything) // WriteVInt field3 (score: Trophies / RankedRank) // WriteBoolean hasPlayerData // if true -> PlayerRankingData: // WriteString allianceName // PlayerDisplayData: // WriteString name // WriteVInt level // WriteVInt thumbnailId (raw GlobalID, single VInt - NOT DataReference) // WriteVInt nameColorId (raw GlobalID, single VInt - NOT DataReference) // WriteVInt extra (override color GlobalID, or 0/-1) // WriteBoolean hasAllianceData // if true -> AllianceRankingData: // WriteString name // WriteVInt memberCount // WriteDataReference badgeId (this one really IS a DataReference) if (LeaderboardType == 1) { Stream.WriteVInt(Avatars.Count); foreach (var pair in Avatars) { var home = pair.Key; var avatar = pair.Value; if (avatar.AccountId == OwnAvatarId) { playerIndex = Avatars.IndexOf(pair) + 1; } WritePlayerEntry(home, avatar, avatar.Trophies); } } else if (LeaderboardType == 2) { Stream.WriteVInt(AllianceList.Count); foreach (var alliance in AllianceList) { WriteAllianceEntry(alliance); } } else if (LeaderboardType == 0) { Stream.WriteVInt(Brawlers.Count); foreach (KeyValuePair pair in Brawlers) { var home = pair.Key; var avatar = pair.Value; if (avatar.AccountId == OwnAvatarId) { playerIndex = Avatars.IndexOf(pair) + 1; } WritePlayerEntry(home, avatar, avatar.GetHero(CharachterId).Trophies); } } else if (LeaderboardType == 3) { Stream.WriteVInt(Avatars.Count); foreach (var pair in Avatars) { var home = pair.Key; var avatar = pair.Value; if (avatar.AccountId == OwnAvatarId) { playerIndex = Avatars.IndexOf(pair) + 1; } WritePlayerEntry(home, avatar, avatar.RankedRank); } } else if (LeaderboardType == 4 || LeaderboardType == 5) { Stream.WriteVInt(Avatars.Count); foreach (var pair in Avatars) { var home = pair.Key; var avatar = pair.Value; if (avatar.AccountId == OwnAvatarId) { playerIndex = Avatars.IndexOf(pair) + 1; } WritePlayerEntry(home, avatar, avatar.RankedRank); } } else { Stream.WriteVInt(0); } Stream.WriteVInt(0); Stream.WriteVInt(playerIndex); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteString("RU"); } private void WritePlayerEntry(ClientHome home, ClientAvatar avatar, int score) { Stream.WriteVLong(avatar.AccountId); Stream.WriteVInt(1); Stream.WriteVInt(score); Stream.WriteBoolean(true); // hasPlayerData Stream.WriteString(avatar.AllianceName); // PlayerRankingData.allianceName Stream.WriteString(avatar.Name ?? "Brawler"); // PlayerDisplayData.name Stream.WriteVInt(100); // PlayerDisplayData.level Stream.WriteVInt(home.ThumbnailId); // PlayerDisplayData.thumbnailId (raw GlobalID) Stream.WriteVInt(home.NameColorId); // PlayerDisplayData.nameColorId (raw GlobalID) if (avatar.Name != null && avatar.Name.StartsWith("