Untitled


SUBMITTED BY: moudixblack

DATE: Aug. 5, 2017, 12:40 a.m.

FORMAT: Text only

SIZE: 2.6 kB

HITS: 621

  1. using ProtoBuf;
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Collections.Concurrent;
  8. using System.Text;
  9. using LordsRoad;
  10. using LordsRoad.Database;
  11. using System.Threading.Tasks;
  12. namespace LordsRoad.Network.GamePackets
  13. {
  14. public class MsgGlobalLotteryRankList
  15. {
  16. public MsgGlobalLotteryRankList() { }
  17. public MsgGlobalLotteryRankListProto Info;
  18. [ProtoContract]
  19. public class MsgGlobalLotteryRankListProto
  20. {
  21. [ProtoMember(1, IsRequired = true)]
  22. public uint Page;
  23. [ProtoMember(2, IsRequired = true)]
  24. public uint CountinPage;
  25. [ProtoMember(3, IsRequired = true)]
  26. public uint AllCount;
  27. [ProtoMember(4, IsRequired = true)]
  28. public Picker[] Pickers;
  29. }
  30. [ProtoContract]
  31. public class Picker
  32. {
  33. [ProtoMember(1, IsRequired = true)]
  34. public uint PickItem;
  35. [ProtoMember(2, IsRequired = true)]
  36. public string Name;
  37. }
  38. public bool Read(byte[] packet)
  39. {
  40. using (var memoryStream = new MemoryStream(packet))
  41. {
  42. Info = Serializer.DeserializeWithLengthPrefix<MsgGlobalLotteryRankListProto>(memoryStream, PrefixStyle.Fixed32);
  43. }
  44. return true;
  45. }
  46. public void Handle(Client.GameClient client)
  47. {
  48. switch (Info.Page)
  49. {
  50. default:// Page
  51. {
  52. var proto = new MsgGlobalLotteryRankListProto();
  53. proto.CountinPage = Math.Min((uint)MsgGlobalLottery.Ranking.Count, (uint)10);
  54. proto.AllCount = Math.Min((uint)MsgGlobalLottery.Ranking.Count, (uint)2500);
  55. proto.Pickers = new Picker[Math.Min((uint)MsgGlobalLottery.Ranking.Count, (uint)2500)];
  56. var array = MsgGlobalLottery.Ranking.ToArray();
  57. for (int i = 0; i < proto.Pickers.Length; i++)
  58. {
  59. proto.Pickers[i] = new Picker();
  60. proto.Pickers[i].Name = array[i].Key;
  61. proto.Pickers[i].PickItem = array[i].Value;
  62. }
  63. client.Send(Kernel.FinalizeProtoBuf(proto, 3283));
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. }

comments powered by Disqus