private static void HandleRequestLeaderboardData(RequestLeaderboardData request) { if (request == null) { throw new WrongPacketTypeException(); } LeaderboardDataEntry[] playerData = World.Instance.GetPlayers() .Select(item => new LeaderboardDataEntry { Name = item.UserID, Score = item.Score }) .OrderByDescending(item => item.Score).ToArray(); int rank = 1; foreach (LeaderboardDataEntry entry in playerData) { entry.Type = LeaderboardDataType.Player; entry.Rank = rank++; Socket.Instance.SendPacket(entry, Packets.LeaderboardData, request.UserID); } LeaderboardDataEntry[] teamData = TeamManager.Instance.GetTeams() .Select(item => new LeaderboardDataEntry { Name = item.Name, Score = item.Score }) .OrderByDescending(item => item.Score).ToArray(); rank = 1; foreach (LeaderboardDataEntry entry in teamData) { entry.Type = LeaderboardDataType.Team; entry.Rank = rank++; Socket.Instance.SendPacket(entry, Packets.LeaderboardData, request.UserID); } Socket.Instance.SendPacket(new EndLeaderboardResponse(), Packets.EndLeaderboardResponse, request.UserID); }
public void RequestLeaderboardUpdate() { _playerLeaderboard.Clear(); _teamLeaderboard.Clear(); RequestLeaderboardData request = new RequestLeaderboardData { UserID = ConnectionManager.Instance.UserID, }; Socket.Instance.SendPacket(request, Packets.RequestLeaderboardData); }