Exemplo n.º 1
0
 public static bool LoadEntity(Client.GameClient client)
 {
     using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("characters").Where("UID", client.Account.EntityID))
         using (var reader = new MySqlReader(cmd))
         {
             if (reader.Read())
             {
                 try
                 {
                     client.Entity               = new Entity();
                     client.Entity.Owner         = client;
                     client.Entity.UID           = reader.ReadUInt32("UID");
                     client.Entity.Experience    = reader.ReadUInt32("Experience");
                     client.Entity.Clan          = reader.ReadString("Clan");
                     client.Entity.Name          = reader.ReadString("Name");
                     client.Entity.Deserion      = reader.ReadUInt32("Deserion");
                     client.Entity.GeneradeKills = reader.ReadUInt32("GeneradeKills");
                     client.Entity.GP            = reader.ReadUInt32("GP");
                     client.Entity.ZP            = reader.ReadUInt32("ZP");
                     client.Entity.MP            = reader.ReadUInt32("MP");
                     client.Entity.VIP           = reader.ReadBoolean("VIP");
                     client.Entity.HeadshotKills = reader.ReadUInt32("HeadshotKills");
                     client.Entity.KnifeKills    = reader.ReadUInt32("KnifeKills");
                     client.Entity.TeamKills     = reader.ReadUInt32("TeamKills");
                     client.Entity.Settings      = reader.ReadBlob("Settings");
                     client.Entity.Battles       = new System.Collections.Generic.List <Battle>();
                     byte[] Battles = reader.ReadBlob("Battles");
                     if (Battles.Length > 0)
                     {
                         using (var stream = new System.IO.MemoryStream(Battles))
                             using (var rdr = new System.IO.BinaryReader(stream))
                             {
                                 int count = rdr.ReadInt32();
                                 for (int i = 0; i < count; i++)
                                 {
                                     Battle battle = new Battle
                                     {
                                         GameMode = (Enums.GameMode)rdr.ReadByte(),
                                         Won      = rdr.ReadBoolean(),
                                         Kills    = rdr.ReadUInt16(),
                                         Deaths   = rdr.ReadUInt16()
                                     };
                                     client.Entity.Battles.Add(battle);
                                 }
                             }
                     }
                     return(true);
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e);
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
 }
Exemplo n.º 2
0
 public AccountTable(string username)
 {
     if (username == null)
     {
         return;
     }
     this.Username = username;
     this.Password = "";
     this.IP       = "";
     this.State    = Enums.AccountState.Default;
     this.EntityID = 0;
     using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("accounts").Where("Username", username))
         using (var reader = new MySqlReader(cmd))
         {
             if (reader.Read())
             {
                 exists        = true;
                 this.Password = reader.ReadString("Password");
                 this.IP       = reader.ReadString("Ip");
                 this.EntityID = reader.ReadUInt32("EntityID");
                 this.State    = (Enums.AccountState)reader.ReadInt32("State");
                 using (var cmd2 = new MySqlCommand(MySqlCommandType.SELECT).Select("characters").Where("UID", EntityID))
                     using (var reader2 = new MySqlReader(cmd2))
                     {
                         if (reader2.Read())
                         {
                             Name = reader2.ReadString("Name");
                             Rank = (ushort)Entity.RankExperiences.Where(i => i.Value >= reader2.ReadUInt32("Experience")).FirstOrDefault().Key;
                             byte[] Battles = reader2.ReadBlob("Battles");
                             var    battles = new List <Battle>();
                             if (Battles.Length > 0)
                             {
                                 using (var stream = new System.IO.MemoryStream(Battles))
                                     using (var rdr = new System.IO.BinaryReader(stream))
                                     {
                                         int count = rdr.ReadInt32();
                                         for (int i = 0; i < count; i++)
                                         {
                                             Battle battle = new Battle
                                             {
                                                 GameMode = (Enums.GameMode)rdr.ReadByte(),
                                                 Won      = rdr.ReadBoolean(),
                                                 Kills    = rdr.ReadUInt16(),
                                                 Deaths   = rdr.ReadUInt16()
                                             };
                                             battles.Add(battle);
                                         }
                                     }
                             }
                             TotalDeaths = (uint)battles.Sum(i => i.Deaths);
                             TotalKills  = (uint)battles.Sum(i => i.Kills);
                         }
                     }
             }
         }
 }