Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.54 KB | None | 0 0
  1. public class MsgRankMemberShow
  2.     {
  3.         public MsgRankMemberShow() { }
  4.         public MsgRankMemberShowProto Info;
  5.         [ProtoContract]
  6.         public class MsgRankMemberShowProto
  7.         {
  8.             [ProtoMember(1, IsRequired = true)]
  9.             public uint ActionId;
  10.             [ProtoMember(2, IsRequired = true)]
  11.             public MsgRankMemberShowProtoSer proto;
  12.         }
  13.         [ProtoContract]
  14.         public class MsgRankMemberShowProtoSer
  15.         {
  16.             [ProtoMember(1, IsRequired = true)]
  17.             public uint dwParam;
  18.             [ProtoMember(2, IsRequired = true)]
  19.             public uint Count;
  20.             [ProtoMember(3, IsRequired = true)]
  21.             public uint UID;
  22.             [ProtoMember(4, IsRequired = true)]
  23.             public string Name = "";
  24.             [ProtoMember(5, IsRequired = true)]
  25.             public string Guild = "";
  26.             [ProtoMember(6, IsRequired = true)]
  27.             public uint Mesh;
  28.             [ProtoMember(7, IsRequired = true)]
  29.             public uint HairStyle;
  30.             [ProtoMember(8, IsRequired = true)]
  31.             public uint Hat;
  32.             [ProtoMember(9, IsRequired = true)]
  33.             public uint Garment;
  34.             [ProtoMember(10, IsRequired = true)]
  35.             public uint LeftWep;
  36.             [ProtoMember(11, IsRequired = true)]
  37.             public uint LeftWepAcc;
  38.             [ProtoMember(12, IsRequired = true)]
  39.             public uint RightWep;
  40.             [ProtoMember(13, IsRequired = true)]
  41.             public uint RightWepAcc;
  42.             [ProtoMember(14, IsRequired = true)]
  43.             public uint MountArmor;
  44.             [ProtoMember(15, IsRequired = true)]
  45.             public uint Armor;
  46.             [ProtoMember(16, IsRequired = true)]
  47.             public uint Wing;
  48.             [ProtoMember(17, IsRequired = true)]
  49.             public uint WingLevel;
  50.             [ProtoMember(18, IsRequired = true)]
  51.             public uint Title;
  52.             [ProtoMember(19, IsRequired = true)]
  53.             public uint Flag;
  54.         }
  55.         public void UpdateBestPlayer()
  56.         {
  57.             Stuff = new Dictionary<string, uint>();
  58.             BestPlayer = MsgUserAbilityScore.RankingList.OrderByDescending(i => i.TotalPerfectionScore).ThenByDescending(i => i.Level).ThenBy(i => i.UID).FirstOrDefault();
  59.             using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("items").Where("EntityID", BestPlayer.UID).And("Position", 0, true))
  60.             using (var reader = new MySqlReader(cmd))
  61.             {
  62.                 while (reader.Read())
  63.                 {
  64.                     if (reader.ReadByte("Position") == 1) Stuff.Add(GetPositionName(1), reader.ReadUInt32("ID"));
  65.                     if (reader.ReadByte("Position") == 3) Stuff.Add(GetPositionName(3), reader.ReadUInt32("ID"));
  66.                     if (reader.ReadByte("Position") == 5) Stuff.Add(GetPositionName(5), reader.ReadUInt32("ID"));
  67.                     if (reader.ReadByte("Position") == 9) Stuff.Add(GetPositionName(9), reader.ReadUInt32("ID"));
  68.                     if (reader.ReadByte("Position") == 16) Stuff.Add(GetPositionName(16), reader.ReadUInt32("ID"));
  69.                     if (reader.ReadByte("Position") == 17) Stuff.Add(GetPositionName(17), reader.ReadUInt32("ID"));
  70.                     if (reader.ReadByte("Position") == 4) Stuff.Add(GetPositionName(4), reader.ReadUInt32("ID"));
  71.                     if (reader.ReadByte("Position") == 15) Stuff.Add(GetPositionName(15), reader.ReadUInt32("ID"));
  72.                     if (reader.ReadByte("Position") == 19)
  73.                     {
  74.                         Stuff.Add(GetPositionName(19), reader.ReadUInt32("ID"));
  75.                         Stuff.Add(GetPositionName(255), reader.ReadByte("Plus"));
  76.                     }
  77.                 }
  78.                 if (!Stuff.Keys.Contains("MountArmor"))
  79.                 {
  80.                     using (var cmd2 = new MySqlCommand(MySqlCommandType.SELECT).Select("items").Where("EntityID", BestPlayer.UID).And("Position", 0, true))
  81.                     using (var reader2 = new MySqlReader(cmd2))
  82.                     {
  83.                         while (reader2.Read())
  84.                         {
  85.                             if (reader2.ReadByte("Position") == 12) Stuff.Add(GetPositionName(17), reader2.ReadUInt32("ID"));
  86.                         }
  87.                     }
  88.                 }
  89.             }
  90.         }
  91.         public static string GetPositionName(byte Position)
  92.         {
  93.             if (Position == 1) return "Hat";
  94.             if (Position == 3) return "Armor";
  95.             if (Position == 5) return "LeftWep";
  96.             if (Position == 9) return "Garment";
  97.             if (Position == 16) return "LeftWepAcc";
  98.             if (Position == 17) return "MountArmor";
  99.             if (Position == 4) return "RightWep";
  100.             if (Position == 15) return "RightWepAcc";
  101.             if (Position == 19) return "Wing";
  102.             if (Position == 255) return "WingLevel";
  103.             return "Unknwon";
  104.         }
  105.         public static Dictionary<string, uint> Stuff = new Dictionary<string, uint>();
  106.         public static Game.Player BestPlayer;
  107.         public void Handle(Client.GameState client)
  108.         {
  109.             switch (Info.ActionId)
  110.             {
  111.                 case 0:
  112.                     {
  113.                         var proto2 = new MsgRankMemberShowProto();
  114.                         proto2.ActionId = 0;
  115.                         proto2.proto = new MsgRankMemberShowProtoSer();
  116.                         proto2.proto.dwParam = 1;
  117.                         proto2.proto.Count = 1;
  118.                         proto2.proto.UID = BestPlayer.UID;
  119.                         proto2.proto.HairStyle = BestPlayer.HairStyle;
  120.                         proto2.proto.Mesh = BestPlayer.Mesh;
  121.                         proto2.proto.Name = BestPlayer.Name;
  122.                         proto2.proto.Guild = Kernel.Guilds.ContainsKey(BestPlayer.GuildID) ? Kernel.Guilds[BestPlayer.GuildID].Name : "";
  123.                         proto2.proto.Hat = Stuff.Where(i => i.Key == "Hat").FirstOrDefault().Value;
  124.                         proto2.proto.LeftWep = Stuff.Where(i => i.Key == "LeftWep").FirstOrDefault().Value;
  125.                         proto2.proto.LeftWepAcc = Stuff.Where(i => i.Key == "LeftWepAcc").FirstOrDefault().Value;
  126.                         proto2.proto.MountArmor = Stuff.Where(i => i.Key == "MountArmor").FirstOrDefault().Value;
  127.                         proto2.proto.Garment = Stuff.Where(i => i.Key == "Garment").FirstOrDefault().Value;
  128.                         proto2.proto.Armor = Stuff.Where(i => i.Key == "Armor").FirstOrDefault().Value;
  129.                         proto2.proto.RightWep = Stuff.Where(i => i.Key == "RightWep").FirstOrDefault().Value;
  130.                         proto2.proto.RightWepAcc = Stuff.Where(i => i.Key == "RightWepAcc").FirstOrDefault().Value;
  131.                         proto2.proto.Wing = BestPlayer.EquippedWing == 0 ? Stuff.Where(i => i.Key == "Wing").FirstOrDefault().Value : (uint)BestPlayer.EquippedWing;
  132.                         proto2.proto.WingLevel = Stuff.Where(i => i.Key == "WingLevel").FirstOrDefault().Value;
  133.                         proto2.proto.Title = (uint)BestPlayer.EquippedTitle;
  134.                         client.Send(Kernel.FinalizeProtoBuf(proto2, 3257));
  135.                         break;
  136.                     }
  137.                 case 1:
  138.                     {
  139.                         if (Kernel.GamePool.ContainsKey(Info.proto == null ? 0 : Info.proto.dwParam))
  140.                         {
  141.                             GeneralData.ObserveEquipment(new MsgAction(true) { ID = Core.Packet.PacketMsgAction.Mode.ObserveEquipment, UID = client.Player.UID, dwParam = Info.proto == null ? 0 : Info.proto.dwParam }, client);
  142.                         }
  143.                         else
  144.                         {
  145.                             client.Send(Kernel.FinalizeProtoBuf(Info, 3257));
  146.                         }
  147.                         break;
  148.                     }
  149.             }
  150.  
  151.         }
  152.         public bool Read(byte[] packet)
  153.         {
  154.             var mypkt = new byte[packet.Length - 4];
  155.             Array.Copy(packet, 4, mypkt, 0, mypkt.Length);
  156.             try
  157.             {
  158.                 using (var memoryStream = new MemoryStream(packet))
  159.                 {
  160.                     Info = Serializer.DeserializeWithLengthPrefix<MsgRankMemberShowProto>(memoryStream, PrefixStyle.Fixed32);
  161.                 }
  162.             }
  163.             catch (Exception e)
  164.             {
  165.                 Console.WriteLine(e);
  166.                 return false;
  167.             }
  168.             return true;
  169.         }
  170.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement