public static void Handle(byte[] Data, Client.GameState Client)
        {
            QuestInfoPacket info = new QuestInfoPacket(8);
            ushort num = BitConverter.ToUInt16(Data, 4);
            if (num == 3)
            {
                MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
                cmd.Select("heroquests").Where("hero", Client.Entity.UID).And("quest", 0xb71b2);
                PhoenixProject.Database.MySqlReader reader = new PhoenixProject.Database.MySqlReader(cmd);
                if (Client != null)
                {
                    info.Type = 3;
                    while (reader.Read())
                    {
                        info.AddQuest(reader.ReadUInt32("quest"), (QuestCompleteTypes)((ushort)reader.ReadUInt32("completeflag")));
                        HeroQuest quest2 = new HeroQuest
                        {
                            Identifier = reader.ReadUInt32("quest"),
                            DailyFinishes =  reader.ReadUInt32("dailyfinishes"),
                            CompleteFlag = (QuestCompleteTypes)((ushort) reader.ReadUInt32("completeflag"))
                        };
                        DateTime time3 = new DateTime(0x7b2, 1, 1);
                        quest2.CompleteTime = time3.ToLocalTime().AddSeconds(reader.ReadUInt32("completetime"));

                       // quest2.CompleteTime = new DateTime().FromUnix(Convert.ToUInt32(reader["completetime"]));
                        quest2.Step = reader.ReadUInt32("step");
                        HeroQuest quest = quest2;
                        Client.Quests.GetOrAdd(quest.Identifier, quest);
                    }
                    reader.Close();
                    reader.Dispose();
                }
                Client.Send((byte[])info);
                if (Client != null)
                {
                    cmd.Select("killtargets").Where("hero", Client.Entity.UID);
                    while (reader.Read())
                    {
                        QuestQuery query = new QuestQuery
                        {
                            Identifier = reader.ReadUInt32("quest"),
                            Unknown2 = reader.ReadUInt32("count")
                        };
                        Client.Send((byte[])query);
                    }
                    reader.Close();
                    reader.Dispose();
                }
            }
            else
            {
                Console.WriteLine("Unhandled QuestInfo (1134) Type "+num+"");
            }
        }
 public static void Flowers(GameState client)
 {
     client.Entity.Flowers = new Flowers();
     if (!FlowerSystemTable.Exists(client.Entity.UID))
     {
         FlowerSystemTable.Insert(client);
     }
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
     cmd.Select("flowers").Where("id", (long)((ulong)client.Entity.UID));
     MySqlReader r = new MySqlReader(cmd);
     if (r.Read())
     {
         client.Entity.Flowers.id = client.Entity.UID;
         client.Entity.Flowers.RedRoses2day = 0u;
         client.Entity.Flowers.Lilies2day = 0u;
         client.Entity.Flowers.Tulips2day = 0u;
         client.Entity.Flowers.Orchads2day = 0u;
         client.Entity.Flowers.RedRoses = r.ReadUInt32("redroses");
         client.Entity.Flowers.Lilies = r.ReadUInt32("lilies");
         client.Entity.Flowers.Tulips = r.ReadUInt32("tulips");
         client.Entity.Flowers.Orchads = r.ReadUInt32("orchads");
     }
     r.Close();
     r.Dispose();
 }
        public static void LoadFlags()
        {
           
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("flags");
            PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
            if (r.Read())
            {
                TopSpouse = r.ReadString("TopSpouse");
                TopArcher = r.ReadString("TopArcher");
                TopWarrior = r.ReadString("TopWarrior");
                TopNinja = r.ReadString("TopNinja");
                TopWaterTaoist = r.ReadString("TopWaterTaoist");
                TopFireTaoist = r.ReadString("TopFireTaoist");
                TopTrojan = r.ReadString("TopTrojan");
                TopGuildLeader = r.ReadString("TopGuildLeader");
                TopDeputyLeader = r.ReadString("TopDeputyLeader");
                WeeklyPKChampion = r.ReadString("WeeklyPKChampion");
                MonthlyPKChampion = r.ReadString("MonthlyPKChampion");
                TopMonk = r.ReadString("TopMonk");
                TopDeputyLeader2 = r.ReadString("TopDeputyLeader2");
                TopDeputyLeader3 = r.ReadString("TopDeputyLeader3");
                TopDeputyLeader4 = r.ReadString("TopDeputyLeader4");
                TopDeputyLeader5 = r.ReadString("TopDeputyLeader5");
                TopPirate = r.ReadString("TopPirate");

            }
            r.Close();
            r.Dispose();
        }
        public static void KimoUpdateName(Client.GameState client)
        {
            
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities");
            PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
            String name = "";
            while (r.Read())
            {
                //newname = r.ReadString("namechange");//debug make
                name = r.ReadString("name");
                if (name != "")
                {
                    MySqlCommand cmdupdate = null;//lol i see the problem hold on ,,, hold on what? :$ try now
                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("apprentice").Set("MentorName", client.Entity.NewName).Where("MentorName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("apprentice").Set("ApprenticeName", client.Entity.NewName).Where("ApprenticeName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("arena").Set("EntityName", client.Entity.NewName).Where("EntityName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("claimitems").Set("OwnerName", client.Entity.NewName).Where("OwnerName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("claimitems").Set("GainerName", client.Entity.NewName).Where("GainerName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("detaineditems").Set("OwnerName", client.Entity.NewName).Where("OwnerName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("detaineditems").Set("GainerName", client.Entity.NewName).Where("GainerName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("enemy").Set("EnemyName", client.Entity.NewName).Where("EnemyName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("friends").Set("FriendName", client.Entity.NewName).Where("FriendName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("guilds").Set("Name", client.Entity.NewName).Where("Name", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("guilds").Set("LeaderName", client.Entity.NewName).Where("LeaderName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("nobility").Set("EntityName", client.Entity.NewName).Where("EntityName", name).Execute();

                    cmdupdate = new MySqlCommand(MySqlCommandType.UPDATE);
                    cmdupdate.Update("partners").Set("PartnerName", client.Entity.NewName).Where("PartnerName", name).Execute();
                    UpdateStaff(client);
                    return;
                }
            }
            r.Close();
            r.Dispose();
        }
        public static void LoadClaimableItems(Client.GameState client)
        {
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("claimitems").Where("GainerUID", client.Entity.UID);
            MySqlReader r = new MySqlReader(cmd);
            while (r.Read())
            {
                DetainedItem item = new DetainedItem(true);
                item.ItemUID = r.ReadUInt32("ItemUID");
                item.UID = item.ItemUID;
                item.Page = (byte)DetainedItem.ClaimPage;
                item.Item = ConquerItemTable.LoadItem(item.ItemUID);
                item.ConquerPointsCost = r.ReadUInt32("ConquerPointsCost");
                item.OwnerUID = r.ReadUInt32("OwnerUID");
                item.GainerName = r.ReadString("GainerName");
                item.GainerUID = r.ReadUInt32("GainerUID");
                item.OwnerName = r.ReadString("OwnerName");
                item.Date = DateTime.FromBinary(r.ReadInt64("Date"));
                item.DaysLeft = (uint)(TimeSpan.FromTicks(DateTime.Now.Ticks).Days - TimeSpan.FromTicks(item.Date.Ticks).Days);
                if (item.OwnerUID == 500)
                {
                    item.MakeItReadyToClaim();
                    item.GainerUID = r.ReadUInt32("GainerUID");
                    item.OwnerUID = r.ReadUInt32("OwnerUID");
                }
                client.ClaimableItem.Add(item.UID, item);
            }
            r.Close();
            r.Dispose();

            /*ClaimItemCollection items = new ClaimItemCollection();
            items.LoadAndCloseReader(ClaimItem.FetchByParameter("GainerUID", client.Entity.UID));
            for (int x = 0; x < items.Count; x++)
            {
                DetainedItem item = new DetainedItem(true);
                item.ItemUID = items[x].ItemUID;
                item.UID = item.ItemUID - 1;
                item.Page = (byte)DetainedItem.ClaimPage;
                item.Item = ConquerItemTable.LoadItem(item.ItemUID);
                item.ConquerPointsCost = items[x].ConquerPointsCost;
                item.OwnerUID = items[x].OwnerUID;
                item.GainerName = items[x].GainerName;
                item.GainerUID = items[x].GainerUID;
                item.OwnerName = items[x].OwnerName;
                item.Date = DateTime.FromBinary((long)items[x].DateX);
                item.DaysLeft = (uint)(TimeSpan.FromTicks(DateTime.Now.Ticks).Days - TimeSpan.FromTicks(item.Date.Ticks).Days);
                if (item.OwnerUID == 500)
                {
                    item.MakeItReadyToClaim();
                    item.GainerUID = items[x].GainerUID;
                    item.OwnerUID = items[x].OwnerUID;
                }
                client.ClaimableItem.Add(item.UID, item);
            }*/
        }
 public static void Load()
 {
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("prizenpc");
     PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
     if (r.Read())
     {
         PrizeNpcInfo info = new PrizeNpcInfo();
         info.Owner = r.ReadUInt32("Owner");
         info.type = r.ReadUInt32("type");
         info.amount = r.ReadUInt32("amount");
         info.itemid = r.ReadUInt32("itemid");
         PrizeNpcInformations.Add(info.Owner, info);                
     }
     Console.WriteLine("PrizeNpc Loaded.");
     r.Close();
     r.Dispose();
 }
 public static void Load(Client.GameState client)
 {
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
      cmd.Select("reincarnation").Where("uid", client.Entity.UID);
     MySqlReader r = new MySqlReader(cmd);
     while (r.Read())
     {
         ReincarnateInfo info = new ReincarnateInfo();
         info.UID = r.ReadUInt32("uid");
         info.Level = r.ReadByte("level");
         info.Experience = r.ReadUInt64("experience");
         if (!ServerBase.Kernel.ReincarnatedCharacters.ContainsKey(info.UID))
             ServerBase.Kernel.ReincarnatedCharacters.Add(info.UID, info);
     }
     r.Close();
     r.Dispose();
 }
        public static void Load()
        {
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("arena");
            MySqlReader reader = new MySqlReader(cmd);
            while (reader.Read())
            {
                Network.GamePackets.ArenaStatistic stat = new Network.GamePackets.ArenaStatistic(true);
                stat.EntityID = reader.ReadUInt32("EntityID");
                stat.Name = reader.ReadString("EntityName");
                stat.LastSeasonRank = reader.ReadUInt32("LastSeasonRank");
                stat.LastSeasonArenaPoints = reader.ReadUInt32("LastSeasonArenaPoints");
                stat.ArenaPoints = reader.ReadUInt32("ArenaPoints");
                stat.TodayWin = reader.ReadByte("TodayWin");
                stat.TodayBattles = reader.ReadByte("TodayBattles"); // doesn't exist in the DB, removed it
                stat.LastSeasonWin = reader.ReadUInt32("LastSeasonWin");
                stat.LastSeasonLose = reader.ReadUInt32("LastSeasonLose");
                stat.TotalWin = reader.ReadUInt32("TotalWin");
                stat.TotalLose = reader.ReadUInt32("TotalLose");
                stat.HistoryHonor = reader.ReadUInt32("HistoryHonor");
                stat.CurrentHonor = reader.ReadUInt32("CurrentHonor");
                stat.Level = reader.ReadByte("Level");
                stat.Class = reader.ReadByte("Class");
                stat.Model = reader.ReadUInt32("Model");
                stat.LastArenaPointFill = DateTime.FromBinary(reader.ReadInt64("ArenaPointFill"));

                if (DateTime.Now.DayOfYear != stat.LastArenaPointFill.DayOfYear)
                {
                    stat.LastSeasonArenaPoints = stat.ArenaPoints;
                    stat.LastSeasonWin = stat.TodayWin;
                    stat.LastSeasonLose = stat.TodayBattles - stat.TodayWin;
                    stat.ArenaPoints = ArenaPointFill(stat.Level);
                    stat.LastArenaPointFill = DateTime.Now;
                    stat.TodayWin = 0;
                    stat.TodayBattles = 0;
                }

                Game.ConquerStructures.Arena.ArenaStatistics.Add(stat.EntityID, stat);
            }
            reader.Close();
            reader.Dispose();
            Game.ConquerStructures.Arena.Sort();
            Game.ConquerStructures.Arena.YesterdaySort();
            Console.WriteLine("Arena information loaded.");
        }
 public static void Load()
 {
     MySqlCommand command = new MySqlCommand(MySqlCommandType.SELECT);
     command.Select("maps");
     MySqlReader reader = new MySqlReader(command);
     while (reader.Read())
     {
         MapInformation info = new MapInformation();
         info.ID = reader.ReadUInt64("id");
         info.BaseID = reader.ReadUInt64("mapdoc");
         //Console.WriteLine("id " + info.ID + "  base : " + info.BaseID + "");
         info.Status = reader.ReadUInt32("type");
         info.Weather = reader.ReadUInt32("weather");
         MapInformations.Add(info.ID, info);
     }
     reader.Close();
     reader.Dispose();
     Console.WriteLine("Map informations loaded.");
 }
        public static void LoadEnemy(Client.GameState client)
        {
            client.Enemy = new SafeDictionary<uint, PhoenixProject.Game.ConquerStructures.Society.Enemy>(50);
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd = new MySqlCommand(MySqlCommandType.SELECT);

            cmd.Select("enemy").Where("EntityID", client.Entity.UID);
            MySqlReader reader = new MySqlReader(cmd);
            reader = new MySqlReader(cmd);
            while (reader.Read())
            {
                Game.ConquerStructures.Society.Enemy enemy = new Game.ConquerStructures.Society.Enemy();
                enemy.ID = reader.ReadUInt32("EnemyID");
                enemy.Name = reader.ReadString("EnemyName");
                client.Enemy.Add(enemy.ID, enemy);
            }
            reader.Close();
            reader.Dispose();
        }
 public static void Load()
 {
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("nobility");
     MySqlReader reader = new MySqlReader(cmd);
     while (reader.Read())
     {
         Game.ConquerStructures.NobilityInformation nobilityinfo = new PhoenixProject.Game.ConquerStructures.NobilityInformation();
         nobilityinfo.EntityUID = reader.ReadUInt32("EntityUID");
         nobilityinfo.Name = reader.ReadString("EntityName");
         nobilityinfo.Donation = reader.ReadUInt64("Donation");
         nobilityinfo.Gender = reader.ReadByte("Gender");
         nobilityinfo.Mesh = reader.ReadUInt32("Mesh");
         Game.ConquerStructures.Nobility.Board.Add(nobilityinfo.EntityUID, nobilityinfo);
     }
     reader.Close();
     reader.Dispose();
     Game.ConquerStructures.Nobility.Sort(0);
     Console.WriteLine("Nobility information loaded.");
 }
 public static void Load()
 {
     MySqlCommand command = new MySqlCommand(MySqlCommandType.SELECT);
     command.Select("lottery");
     MySqlReader reader = new MySqlReader(command);
     while (reader.Read())
     {
         LotteryItem item = new LotteryItem();
         item.Rank = reader.ReadInt32("rank");
         item.Chance = reader.ReadInt32("chance");
         item.Name = reader.ReadString("prize_name");
         item.ID = reader.ReadUInt32("prize_item");
         item.Color = reader.ReadByte("color");
         item.Sockets = reader.ReadByte("hole_num");
         item.Plus = reader.ReadByte("addition_lev");
         LotteryItems.Add(item);
     }
     reader.Close();
     reader.Dispose();
     Console.WriteLine("Lottery items loaded.");
 }
        public static void RemoveCps(Client.GameState client)
        {
            MySqlCommand command = new MySqlCommand(MySqlCommandType.DELETE);
            command.Delete("prizenpc", "Owner", client.Entity.UID).And("type", "1").Execute();

            PrizeNpcInformations.Remove(client.Entity.UID);
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("prizenpc").Where("Owner", client.Entity.UID);
            PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
            if (r.Read())
            {
                PrizeNpcInfo info = new PrizeNpcInfo();
                info.Owner = r.ReadUInt32("Owner");
                info.type = r.ReadUInt32("type");
                info.amount = r.ReadUInt32("amount");
                info.itemid = r.ReadUInt32("itemid");
                PrizeNpcInformations.Add(info.Owner, info);
            }
            //Console.WriteLine("PrizeNpc Loaded.");
            r.Close();
            r.Dispose();
        }
 public static void PkExploitAdd(Client.GameState client, uint UIDEnemy, Game.PkExpeliate pk)
 {
     MySqlCommand cmds = new MySqlCommand(MySqlCommandType.SELECT);
     cmds.Select("pk_explorer").Where("uid", client.Account.EntityID);
     MySqlReader rdr = new MySqlReader(cmds);
     if (rdr.Read())
     {
         MySqlCommand cmd = new MySqlCommand(MySqlCommandType.UPDATE);
         cmd.Update("pk_explorer")
              .Set("killed_uid", UIDEnemy)
              .Set("killed_name", pk.Name).Set("killed_map", pk.KilledAt)
              .Set("lost_exp", pk.LostExp).Set("times", pk.Times++)
              .Set("battle_power", pk.Potency).Set("level", pk.Level);
         cmd.Execute();
         if (!client.Entity.PkExplorerValues.ContainsKey(pk.UID))
         {
             client.Entity.PkExplorerValues.Add(pk.UID, pk);
         }
         else
         {
             client.Entity.PkExplorerValues.Remove(pk.UID);
             client.Entity.PkExplorerValues.Add(pk.UID, pk);
         }
     }
     else
     {
         MySqlCommand cmd = new MySqlCommand(MySqlCommandType.INSERT);
         cmd.Insert("pk_explorer")
              .Insert("uid", pk.UID).Insert("killed_uid", UIDEnemy)
              .Insert("killed_name", pk.Name).Insert("killed_map", pk.KilledAt)
              .Insert("lost_exp", pk.LostExp).Insert("times", pk.Times)
              .Insert("battle_power", pk.Potency).Insert("level", pk.Level);
         cmd.Execute();
         if (!client.Entity.PkExplorerValues.ContainsKey(pk.UID))
             client.Entity.PkExplorerValues.Add(pk.UID, pk);
     }
     rdr.Close();
     rdr.Dispose();
 }
 private static bool Exists(uint id)
 {
     bool result;
     try
     {
         MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
         cmd.Select("flowers").Where("id", (long)((ulong)id));
         MySqlReader r = new MySqlReader(cmd);
         if (r.Read())
         {
             r.Close();
             r.Dispose();
             result = true;
             return result;
         }
     }
     catch
     {
     }
     result = false;
     return result;
 }
        public static void Load(Client.GameState client)
        {
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("pk_explorer").Where("uid", client.Account.EntityID);
            MySqlReader r = new MySqlReader(cmd);
            while (r.Read())
            {
                Game.PkExpeliate pk = new Game.PkExpeliate();
                pk.UID = r.ReadUInt32("killed_uid");
                pk.Name = r.ReadString("killed_name");
                pk.KilledAt = r.ReadString("killed_map");
                pk.LostExp = r.ReadUInt32("lost_exp");
                pk.Times = r.ReadUInt32("times");
                pk.Potency = r.ReadUInt32("battle_power");
                pk.Level = r.ReadByte("level");
                //client.Entity.PkExplorerValues.SafeAdd(pk.UID, pk);
                client.Entity.PkExplorerValues.Add(pk.UID, pk);

            }
            r.Close();
            r.Dispose();
        }
 public AccountTable(string username)
 {
     this.Username = username;
     this.Password = "";
     this.IP = "";
     this.LastCheck = DateTime.Now;
     this.State = AccountState.DoesntExist;
     this.EntityID = 0;
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
     cmd.Select("accounts").Where("Username", username);
     MySqlReader r = new MySqlReader(cmd);
     if (r.Read())
     {
         exists = true;
         this.Password = r.ReadString("Password");
         this.IP = r.ReadString("IP");
         this.EntityID = r.ReadUInt32("EntityID");
         this.LastCheck = DateTime.FromBinary(r.ReadInt64("LastCheck"));
         this.State = (AccountState)r.ReadByte("State");
         this.Email = r.ReadString("Email");
     }
     r.Close();
     r.Dispose();
 }
        public static void Load(Entity Entity)
        {
            MySqlCommand Command = new MySqlCommand(MySqlCommandType.SELECT);
            Command.Select("subclasses").Where("id", Entity.UID);
            MySqlReader Reader = new MySqlReader(Command);
            while (Reader.Read())
            {
                Statement.SubClass Sub = new Statement.SubClass();
                Sub.ID = Reader.ReadByte("uid");
                Sub.Level = Reader.ReadByte("level");
                Sub.Phase = Reader.ReadByte("phase");
                Entity.SubClasses.Classes.Add(Sub.ID, Sub);

                Game_SubClass packet = new Game_SubClass();
                packet.ClassId = (Game_SubClass.ID)Sub.ID;
                packet.Phase = Sub.Phase;
                packet.Type = Game_SubClass.Types.Learn;
                Entity.Owner.Send(packet);
                packet.Type = Game_SubClass.Types.MartialPromoted;
                Entity.Owner.Send(packet);
            }
            Reader.Close();
            Reader.Dispose();
        }
 public static void LoadTop8()
 {
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
     cmd.Select("elitepk");
     MySqlReader r = new MySqlReader(cmd);
     while (r.Read())
     {
         Elite_client client = new Elite_client(r.ReadUInt32("UID"), r.ReadUInt16("Avatar"), r.ReadUInt16("Mesh"), r.ReadString("Name"), r.ReadUInt32("Points"), r.ReadUInt16("Postion"), r.ReadByte("MyTitle"));
         if (!Top8.ContainsKey(client.UID))
             Top8.Add(client.UID, client);
     }
     r.Close();
     r.Dispose();
 }
 public void LoadAssociates()
 {
     MySqlCommand Command = new MySqlCommand(MySqlCommandType.SELECT);
     Command.Select("clanrelation").Where("clanid", this.ClanId);
     PhoenixProject.Database.MySqlReader cmd = new PhoenixProject.Database.MySqlReader(Command);
     while (cmd.Read())
     {
         UInt32 AssociateId = cmd.ReadUInt32("associatedid");
         Network.GamePackets.ClanRelations.RelationTypes Type = (Network.GamePackets.ClanRelations.RelationTypes)(cmd.ReadByte("type"));
         Game.Clans c;
         if (ServerBase.Kernel.ServerClans.TryGetValue(AssociateId, out c))
         {
             if (Type == Network.GamePackets.ClanRelations.RelationTypes.Allies)
                 this.Allies.Add(AssociateId, c);
             else
                 this.Enemies.Add(AssociateId, c);
         }
       
     }
     cmd.Close();
     cmd.Dispose();
     //Console.WriteLine("4444");
 }
        public static void LoadDetainedItems(Client.GameState client)
        {
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("detaineditems").Where("OwnerUID", client.Entity.UID);
            MySqlReader r = new MySqlReader(cmd);
            while (r.Read())
            {
                DetainedItem item = new DetainedItem(true);
                item.ItemUID = r.ReadUInt32("ItemUID");
                item.UID = item.ItemUID ;
               // Console.WriteLine("S " + item.UID + "");
                item.Item = ConquerItemTable.LoadItem(item.ItemUID);
                item.ConquerPointsCost = r.ReadUInt32("ConquerPointsCost");
                item.OwnerUID = r.ReadUInt32("OwnerUID");
                item.OwnerName = r.ReadString("OwnerName");
                item.GainerUID = r.ReadUInt32("GainerUID");
                item.GainerName = r.ReadString("GainerName");
                item.Date = DateTime.FromBinary(r.ReadInt64("Date"));
                item.DaysLeft = (uint)(TimeSpan.FromTicks(DateTime.Now.Ticks).Days - TimeSpan.FromTicks(item.Date.Ticks).Days);
                if (DateTime.Now < item.Date.AddDays(7))
                    client.DeatinedItem.Add(item.UID, item);
                else
                    if (item.Bound)
                        Claim(item.UID, client);
            }
            r.Close();

               /* DetaineditemCollection items = new DetaineditemCollection();
            items.LoadAndCloseReader(Detaineditem.FetchByParameter("OwnerUID", client.Entity.UID));
            for (int x = 0; x < items.Count; x++)
            {
                DetainedItem item = new DetainedItem(true);
                item.ItemUID = items[x].ItemUID;
                item.UID = item.ItemUID - 1;
                item.Item = ConquerItemTable.LoadItem(item.ItemUID);
                item.ConquerPointsCost = items[x].ConquerPointsCost;
                item.OwnerUID = items[x].OwnerUID;
                item.GainerName = items[x].OwnerName;
                item.GainerUID = items[x].GainerUID;
                item.OwnerName = items[x].GainerName;
                item.Date = DateTime.FromBinary((long)items[x].DateX);
                item.DaysLeft = (uint)(TimeSpan.FromTicks(DateTime.Now.Ticks).Days - TimeSpan.FromTicks(item.Date.Ticks).Days);
                if (DateTime.Now < item.Date.AddDays(7))
                    client.DeatinedItem.Add(item.UID, item);
                else
                    if (item.Bound)
                        Claim(item, client);
            }*/
        }
        public static bool LoadEntity(Client.GameState client)
        {
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("entities").Where("UID", client.Account.EntityID);
            MySqlReader r = new MySqlReader(cmd);
            if (r.Read())
            {

                client.WarehousePW = r.ReadString("WarehousePW");
                client.Entity = new Game.Entity(Game.EntityFlag.Player, false);
                client.Entity.Name = r.ReadString("Name");
                client.HeadgearClaim = r.ReadBoolean("HeadgearClaim");
                client.Entity.Spouse = r.ReadString("Spouse");
                client.Entity.NobalityDonation = r.ReadUInt64("Donation");
                client.Entity.Owner = client;
                client.Entity.AddFlower = r.ReadUInt32("Flower");
                client.MoneySave = r.ReadUInt32("MoneySave");
                client.Entity.Experience = r.ReadUInt64("Experience");
                client.Entity.RacePoints = (uint)r.ReadUInt32("RacePoints");
                client.Entity.BConquerPoints = (uint)r.ReadUInt32("BConquerPoints");
                client.Entity.Money = r.ReadUInt32("Money");
                client.Entity.EditeName = r.ReadUInt32("EditeName");
                client.Entity.ConquerPoints = (uint)r.ReadUInt32("ConquerPoints");
                client.Entity.KoKills = (uint)r.ReadUInt32("KoKills");
                client.Entity.ChiPoints = (uint)r.ReadUInt32("ChiPoints");
                client.Entity.UID = r.ReadUInt32("UID");
                //client.Entity.RacePoints = 54321;
                //client.Entity.RacePoints2 = 12345;
                client.Entity.Status = r.ReadUInt32("Status");
                client.Entity.CountryFlag = r.ReadUInt32("Status2");
                client.Entity.Status3 = r.ReadUInt32("Status3");
                client.Entity.Status4 = r.ReadUInt32("Status4");

                client.Entity.Hitpoints = r.ReadUInt32("Hitpoints");
                client.Entity.Quest = r.ReadUInt32("Quest");
                client.Entity.QuizPoints = r.ReadUInt32("QuizPoints");
                client.Entity.Body = r.ReadUInt16("Body");
                client.Entity.Face = r.ReadUInt16("Face");
                client.Entity.Strength = r.ReadUInt16("Strength");
                //client.Entity.ReincarnationLev = (byte)entities[0].ReincarnationLev;

                client.Entity.Agility = r.ReadUInt16("Agility");
                client.Entity.Spirit = r.ReadUInt16("Spirit");
                client.Entity.Vitality = r.ReadUInt16("Vitality");
                client.Entity.Atributes = r.ReadUInt16("Atributes");
                //client.Entity.SubClass = (byte)entities[0].SubClass;
                client.Entity.SubClassLevel = (uint)r.ReadUInt32("SubClassLevel");

                client.Entity.SubClasses.Active = (byte)r.ReadByte("SubClass");
                client.Entity.SubClasses.StudyPoints += r.ReadUInt32("StudyPoints");
                client.VirtuePoints = r.ReadUInt32("VirtuePoints");
                client.Entity.Mana = r.ReadUInt16("Mana");
                client.Entity.HairStyle = r.ReadUInt16("HairStyle");
                client.Entity.MapID = r.ReadUInt32("MapID");
                client.VendingDisguise = r.ReadUInt16("VendingDisguise");
                if (client.VendingDisguise == 0)
                    client.VendingDisguise = 223;
                client.Entity.X = r.ReadUInt16("X");
                client.Entity.Y = r.ReadUInt16("Y");
                if (client.Map.BaseID == 1844)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (ServerBase.Constants.PKFreeMaps2.Contains(client.Entity.MapID))
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 1950)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 3333)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 1)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 1225)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 3031)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 2060)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 3)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 2)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 7777)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 1090)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 4021)
                {
                    client.Entity.MapID = 1020;
                    client.Entity.X = 533;
                    client.Entity.Y = 483;
                }
                if (client.Entity.MapID == 4022)
                {
                    client.Entity.MapID = 1020;
                    client.Entity.X = 533;
                    client.Entity.Y = 483;
                }
                if (client.Entity.MapID == 4023)
                {
                    client.Entity.MapID = 1020;
                    client.Entity.X = 533;
                    client.Entity.Y = 483;
                }
                if (client.Entity.MapID == 4024)
                {
                    client.Entity.MapID = 1020;
                    client.Entity.X = 533;
                    client.Entity.Y = 483;
                }
                if (client.Entity.MapID == 4025)
                {
                    client.Entity.MapID = 1020;
                    client.Entity.X = 533;
                    client.Entity.Y = 483;
                }
                if (client.Entity.MapID == 1508)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 1518)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Map.BaseID == 1005 && client.Entity.MapID != 1005)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Map.BaseID == 1730)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 7005)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 7006)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 7008)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (client.Entity.MapID == 1801)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 428;
                    client.Entity.Y = 378;
                }
                if (Game.Flags.WeeklyPKChampion == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.WeeklyPKChampion);
                }
                if (Game.Flags.MonthlyPKChampion == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.MonthlyPKChampion);
                }
                if (Game.Flags.TopTrojan == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopTrojan);
                }
                if (Game.Flags.TopWarrior == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopWarrior);
                }
                if (Game.Flags.TopArcher == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopArcher);
                }
                if (Game.Flags.TopNinja == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopNinja);
                }
                if (Game.Flags.TopMonk == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.Top2Monk);
                }
                if (Game.Flags.TopWaterTaoist == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopWaterTaoist);
                }
                if (Game.Flags.TopFireTaoist == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopFireTaoist);
                }
                if (Game.Flags.TopPirate == client.Entity.Name)
                {
                    client.Entity.AddFlag2(Network.GamePackets.Update.Flags2.TopPirate);
                }
                if (Game.Flags.TopGuildLeader == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopGuildLeader);
                }
                if (Game.Flags.TopDeputyLeader == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopDeputyLeader);
                }
                if (Game.Flags.TopSpouse == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopSpouse);
                }
                if (Game.Flags.TopSpouse == client.Entity.Spouse)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopSpouse);
                }
                if (Game.Flags.TopDeputyLeader2 == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopDeputyLeader);
                }
                if (Game.Flags.TopDeputyLeader3 == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopDeputyLeader);
                }
                if (Game.Flags.TopDeputyLeader4 == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopDeputyLeader);
                }
                if (Game.Flags.TopDeputyLeader5 == client.Entity.Name)
                {
                    client.Entity.AddFlag(Network.GamePackets.Update.Flags.TopDeputyLeader);
                }
                client.BlessTime = r.ReadUInt32("BlessTime");
                //client.HeadgearClaim = entities[0].HeadgearClaim;
                client.NecklaceClaim = r.ReadBoolean("NecklaceClaim");
                client.ArmorClaim = r.ReadBoolean("ArmorClaim");
                client.WeaponClaim = r.ReadBoolean("WeaponClaim");
                client.RingClaim = r.ReadBoolean("RingClaim");
                client.BootsClaim = r.ReadBoolean("BootsClaim");
                client.FanClaim = r.ReadBoolean("FanClaim");
                client.TowerClaim = r.ReadBoolean("TowerClaim");
                client.HeadgearClaim = r.ReadBoolean("HeadgearClaim");
                client.InLottery = r.ReadBoolean("InLottery");
                client.LotteryEntries = r.ReadByte("LotteryEntries");
                client.LastLotteryEntry = DateTime.FromBinary(r.ReadInt64("LastLotteryEntry"));
                if (client.Entity.MapID >= 7008)
                {
                    client.Entity.MapID = 1002;
                    client.Entity.X = 430;
                    client.Entity.Y = 380;
                }
                client.Entity.PreviousMapID = r.ReadUInt16("PreviousMapID");
                client.Entity.PKPoints = r.ReadUInt16("PKPoints");
                client.Entity.Class = r.ReadByte("Class");
                client.Entity.Reborn = r.ReadByte("Reborn");
                client.Entity.Level = r.ReadByte("Level");
                client.Entity.FirstRebornClass = r.ReadByte("FirstRebornClass");
                client.Entity.SecondRebornClass = r.ReadByte("SecondRebornClass");
                client.Entity.FirstRebornLevel = r.ReadByte("FirstRebornLevel");
                client.Entity.SecondRebornLevel = r.ReadByte("SecondRebornLevel");
                if (client.Entity.Reborn == 0)
                {

                }
                else
                {
                    if (client.Entity.Reborn == 1 && client.Entity.FirstRebornLevel == 0)
                    {
                        client.Entity.FirstRebornLevel = 140;
                    }
                    else
                    {
                        if (client.Entity.Reborn == 2 && client.Entity.FirstRebornLevel == 0 || client.Entity.Reborn == 2 && client.Entity.SecondRebornLevel == 0)
                        {
                            client.Entity.FirstRebornLevel = 140;
                            client.Entity.SecondRebornLevel = 140;
                        }
                    }
                }
                client.LastDragonBallUse = DateTime.FromBinary(r.ReadInt64("LastDragonBallUse"));
                client.LastResetTime = DateTime.FromBinary(r.ReadInt64("LastResetTime"));
                client.Entity.EnlightenPoints = r.ReadUInt16("EnlightenPoints");
                client.Entity.EnlightmentTime = r.ReadUInt16("EnlightmentWait");
                if (client.Entity.EnlightmentTime > 0)
                {
                    if (client.Entity.EnlightmentTime % 20 > 0)
                    {
                        client.Entity.EnlightmentTime -= (ushort)(client.Entity.EnlightmentTime % 20);
                        client.Entity.EnlightmentTime += 20;
                    }
                }
                client.Entity.ReceivedEnlightenPoints = r.ReadByte("EnlightsReceived");
                client.Entity.DoubleExperienceTime = r.ReadUInt16("DoubleExpTime");
                client.DoubleExpToday = r.ReadBoolean("DoubleExpToday");
                client.Entity.HeavenBlessing = r.ReadUInt32("HeavenBlessingTime");
                client.Entity.VIPLevel = r.ReadByte("VIPLevel");
                client.Entity.PrevX = r.ReadUInt16("PreviousX");
                client.Entity.PrevY = r.ReadUInt16("PreviousY");
                client.ExpBalls = r.ReadByte("ExpBalls");
                client.Entity.ClanId = r.ReadUInt32("ClanId");
                //client.Entity.ClanRank = (Clan.Ranks)entities[0].ClanRank;

                if (client.Entity.ClanId != 0)
                {
                    if (PhoenixProject.ServerBase.Kernel.ServerClans.ContainsKey(client.Entity.ClanId))
                    {
                        client.Entity.ClanId = r.ReadUInt32("ClanId");
                        client.Entity.Myclan = PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.ClanId];
                        client.Entity.ClanName = client.Entity.Myclan.ClanName;
                        if (PhoenixProject.ServerBase.Kernel.ServerClans[client.Entity.ClanId].ClanLider == client.Entity.Name)
                        {
                            client.Entity.ClanRank = 100;
                        }
                        else
                        {
                            client.Entity.ClanRank = 10;
                        }
                        //Console.WriteLine("dddddd");
                    }
                }
                UInt64 lastLoginInt = (ulong)r.ReadInt64("LastLogin");
               // Console.WriteLine(" " + lastLoginInt + "");
                if (lastLoginInt != 0)
                    client.Entity.LastLogin = Kernel.FromDateTimeInt(lastLoginInt);
                else
                    client.Entity.LastLogin = DateTime.Now;

                if (client.Entity.MapID == 601)
                    client.OfflineTGEnterTime = DateTime.FromBinary(r.ReadInt64("OfflineTGEnterTime"));

                Game.ConquerStructures.Nobility.Sort(client.Entity.UID);

                if (ServerBase.Kernel.Guilds.ContainsKey(r.ReadUInt16("GuildID")))
                {
                    client.Guild = ServerBase.Kernel.Guilds[r.ReadUInt16("GuildID")];
                    if (client.Guild.Members.ContainsKey(client.Entity.UID))
                    {
                        client.AsMember = client.Guild.Members[client.Entity.UID];
                        if (client.AsMember.GuildID == 0)
                        {
                            client.AsMember = null;
                            client.Guild = null;
                        }
                        else
                        {
                            client.Entity.GuildID = (ushort)client.Guild.ID;
                            client.Entity.GuildRank = (ushort)client.AsMember.Rank;
                        }
                    }
                    else
                        client.Guild = null;
                }
                if (!Game.ConquerStructures.Nobility.Board.TryGetValue(client.Entity.UID, out client.NobilityInformation))
                {
                    client.NobilityInformation = new PhoenixProject.Game.ConquerStructures.NobilityInformation();
                    client.NobilityInformation.EntityUID = client.Entity.UID;
                    client.NobilityInformation.Name = client.Entity.Name;
                    client.NobilityInformation.Donation = 0;
                    client.NobilityInformation.Rank = PhoenixProject.Game.ConquerStructures.NobilityRank.Serf;
                    client.NobilityInformation.Position = -1;
                    client.NobilityInformation.Gender = 1;
                    client.NobilityInformation.Mesh = client.Entity.Mesh;
                    if (client.Entity.Body % 10 >= 3)
                        client.NobilityInformation.Gender = 0;
                }
                else
                    client.Entity.NobilityRank = client.NobilityInformation.Rank;

                if (DateTime.Now.DayOfYear != client.LastResetTime.DayOfYear)
                {
                    if (client.Entity.Level >= 90)
                    {
                        client.Entity.EnlightenPoints = 100;
                        if (client.Entity.NobilityRank == PhoenixProject.Game.ConquerStructures.NobilityRank.Knight ||
                            client.Entity.NobilityRank == PhoenixProject.Game.ConquerStructures.NobilityRank.Baron)
                            client.Entity.EnlightenPoints += 100;
                        else if (client.Entity.NobilityRank == PhoenixProject.Game.ConquerStructures.NobilityRank.Earl ||
                            client.Entity.NobilityRank == PhoenixProject.Game.ConquerStructures.NobilityRank.Duke)
                            client.Entity.EnlightenPoints += 200;
                        else if (client.Entity.NobilityRank == PhoenixProject.Game.ConquerStructures.NobilityRank.Prince)
                            client.Entity.EnlightenPoints += 300;
                        else if (client.Entity.NobilityRank == PhoenixProject.Game.ConquerStructures.NobilityRank.King)
                            client.Entity.EnlightenPoints += 400;
                        if (client.Entity.VIPLevel != 0)
                        {
                            if (client.Entity.VIPLevel <= 3)
                                client.Entity.EnlightenPoints += 100;
                            else if (client.Entity.VIPLevel <= 5)
                                client.Entity.EnlightenPoints += 200;
                            else if (client.Entity.VIPLevel == 6)
                                client.Entity.EnlightenPoints += 300;
                        }
                    }
                    client.Entity.ReceivedEnlightenPoints = 0;
                    client.DoubleExpToday = false;
                    client.ExpBalls = 0;
                    client.LotteryEntries = 0;
                    client.Entity.Quest = 0;
                    client.Entity.SubClassLevel = 0;
                    client.LastResetTime = DateTime.Now;
                }
                Game.ConquerStructures.Arena.ArenaStatistics.TryGetValue(client.Entity.UID, out client.ArenaStatistic);
                if (client.ArenaStatistic == null || client.ArenaStatistic.EntityID == 0)
                {
                    client.ArenaStatistic = new PhoenixProject.Network.GamePackets.ArenaStatistic(true);
                    client.ArenaStatistic.EntityID = client.Entity.UID;
                    client.ArenaStatistic.Name = client.Entity.Name;
                    client.ArenaStatistic.Level = client.Entity.Level;
                    client.ArenaStatistic.Class = client.Entity.Class;
                    client.ArenaStatistic.Model = client.Entity.Mesh;
                    client.ArenaStatistic.ArenaPoints = ArenaTable.ArenaPointFill(client.Entity.Level);
                    client.ArenaStatistic.LastArenaPointFill = DateTime.Now;
                    ArenaTable.InsertArenaStatistic(client);
                    client.ArenaStatistic.Status = Network.GamePackets.ArenaStatistic.NotSignedUp;
                    Game.ConquerStructures.Arena.ArenaStatistics.Add(client.Entity.UID, client.ArenaStatistic);
                }
                else
                {
                    client.ArenaStatistic.Level = client.Entity.Level;
                    client.ArenaStatistic.Class = client.Entity.Class;
                    client.ArenaStatistic.Model = client.Entity.Mesh;
                    if (DateTime.Now.DayOfYear != client.ArenaStatistic.LastArenaPointFill.DayOfYear)
                    {
                        client.ArenaStatistic.LastSeasonArenaPoints = client.ArenaStatistic.ArenaPoints;
                        client.ArenaStatistic.LastSeasonWin = client.ArenaStatistic.TodayWin;
                        client.ArenaStatistic.LastSeasonLose = client.ArenaStatistic.TodayBattles - client.ArenaStatistic.TodayWin;
                        client.ArenaStatistic.ArenaPoints = ArenaTable.ArenaPointFill(client.Entity.Level);
                        client.ArenaStatistic.LastArenaPointFill = DateTime.Now;
                        client.ArenaStatistic.TodayWin = 0;
                        client.ArenaStatistic.TodayBattles = 0;
                        Game.ConquerStructures.Arena.Sort();
                        Game.ConquerStructures.Arena.YesterdaySort();
                    }
                }
                //PhoenixProject.Database.ConquerItemTable.LoadItems(client);
                //PhoenixProject.Database.SkillTable.LoadProficiencies(client);
                //PhoenixProject.Database.SkillTable.LoadSpells(client);
                //PhoenixProject.Database.KnownPersons.LoadKnownPersons(client);
                //PhoenixProject.Database.ClaimItemTable.LoadClaimableItems(client);
                //PhoenixProject.Database.DetainedItemTable.LoadDetainedItems(client);
                //Database.SubClassTable.Load(client.Entity);
                //PhoenixProject.Database.FlowerSystemTable.Flowers(client);
                //Game.Tournaments.EliteTournament.LoginClient(client);
                client.Entity.FullyLoaded = true;
                r.Close();
                r.Dispose();
            }
            else

                return false;
            return true;
        }
        public static void Load()
        {
            MySqlCommand command = new MySqlCommand(MySqlCommandType.SELECT);
            command.Select("guilds");
            MySqlReader reader = new MySqlReader(command);
            while (reader.Read())
            {
                PhoenixProject.Game.ConquerStructures.Society.Guild guild = new PhoenixProject.Game.ConquerStructures.Society.Guild(reader.ReadString("LeaderName"));
                guild.ID = reader.ReadUInt16("ID");
                guild.Name = reader.ReadString("Name");
                guild.Wins = reader.ReadUInt32("Wins");
                guild.Losts = reader.ReadUInt32("Losts");
                guild.Bulletin = reader.ReadString("Bulletin");
                guild.SilverFund = reader.ReadUInt32("SilverFund");
                guild.ConquerPointFund = reader.ReadUInt32("ConquerPointFund");
                MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
                cmd.Select("entities").Where("GuildID", guild.ID);
                MySqlReader rdr = new MySqlReader(cmd);
                while (rdr.Read())
                {
                    PhoenixProject.Game.ConquerStructures.Society.Guild.Member member = new PhoenixProject.Game.ConquerStructures.Society.Guild.Member(guild.ID);
                    member.ID = rdr.ReadUInt32("UID");
                    member.Name = rdr.ReadString("Name");
                    member.Level = rdr.ReadByte("Level");

                    if (Game.ConquerStructures.Nobility.Board.ContainsKey(member.ID))
                    {
                        member.NobilityRank = Game.ConquerStructures.Nobility.Board[member.ID].Rank;
                        member.Gender = Game.ConquerStructures.Nobility.Board[member.ID].Gender;
                    }

                    member.Rank = (PhoenixProject.Game.Enums.GuildMemberRank)rdr.ReadUInt16("GuildRank");
                    if (member.Rank == PhoenixProject.Game.Enums.GuildMemberRank.GuildLeader)
                        guild.LeaderName = member.Name;
                    else if (member.Rank == PhoenixProject.Game.Enums.GuildMemberRank.DeputyLeader)
                        guild.DeputyLeaderCount++;
                    member.SilverDonation = rdr.ReadUInt64("GuildSilverDonation");
                    member.ConquerPointDonation = rdr.ReadUInt64("GuildConquerPointDonation");
                    guild.Members.Add(member.ID, member);
                }
                guild.MemberCount = (uint)guild.Members.Count;
                ServerBase.Kernel.Guilds.Add(guild.ID, guild);
                Database.ArsenalTable.LoadArsenal(guild);
                rdr.Close();
                rdr.Dispose();
            }
            reader.Close();
            reader.Dispose();
            command = new MySqlCommand(MySqlCommandType.SELECT);
            command.Select("guildally");
            reader = new MySqlReader(command);
            while (reader.Read())
            {
                ushort guildID = reader.ReadUInt16("GuildID");
                ushort allyID = reader.ReadUInt16("AllyID");
                if (ServerBase.Kernel.Guilds.ContainsKey(allyID))
                {
                    if (PhoenixProject.ServerBase.Kernel.Guilds.ContainsKey(guildID))
                        if (PhoenixProject.ServerBase.Kernel.Guilds.ContainsKey(allyID))
                            ServerBase.Kernel.Guilds[guildID].Ally.Add(allyID, ServerBase.Kernel.Guilds[allyID]);
                }
            }
            reader.Close();
            reader.Dispose();
            command = new MySqlCommand(MySqlCommandType.SELECT);
            command.Select("guildenemy");
            reader = new MySqlReader(command);
            while (reader.Read())
            {
                ushort guildID = reader.ReadUInt16("GuildID");
                ushort enemyID = reader.ReadUInt16("EnemyID");
                if (ServerBase.Kernel.Guilds.ContainsKey(guildID))
                    if (ServerBase.Kernel.Guilds.ContainsKey(enemyID))
                    {
                        if (PhoenixProject.ServerBase.Kernel.Guilds.ContainsKey(guildID))
                            if (PhoenixProject.ServerBase.Kernel.Guilds.ContainsKey(enemyID))
                                ServerBase.Kernel.Guilds[guildID].Enemy.Add(enemyID, ServerBase.Kernel.Guilds[enemyID]);
                    }
            }
            reader.Close();
            reader.Dispose();

            Console.WriteLine("Guild information loaded.");
        }
 public static void ClanWarTime()
 {
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("KimoTimes").Where("Type", "ClanWar");
     PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
     if (r.Read())
     {
         ClanHour = r.ReadUInt32("Hour");
         ClanMinute = r.ReadUInt32("Minute");
         ClanDay = r.ReadString("Day");
         ClanEndHour = r.ReadUInt32("End");
     }
     Console.WriteLine("ClanWarTime Loaded.");
     r.Close();
     r.Dispose();
 }
 public static void GetAddingsForItem(Interfaces.IConquerItem item)
 {
     if (item != null)
     {
         MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
         cmd.Select("itemadding").Where("UID", item.UID);
         MySqlReader r = new MySqlReader(cmd);
         while (r.Read())
         {
             uint type = r.ReadUInt32("addingtype");
             if (type == 0)
             {
                 ItemAdding.Purification_ purification = new ItemAdding.Purification_();
                 purification.ItemUID = item.UID;
                 purification.Available = true;
                 purification.PurificationItemID = r.ReadUInt32("addingid");
                 purification.PurificationDuration = r.ReadUInt32("duration");
                 purification.PurificationLevel = r.ReadUInt32("addinglevel");
                 purification.AddedOn = DateTime.FromBinary(r.ReadInt64("addedon"));
                 if (purification.PurificationDuration != 0)
                 {
                     TimeSpan span1 = new TimeSpan(purification.AddedOn.AddSeconds(purification.PurificationDuration).Ticks);
                     TimeSpan span2 = new TimeSpan(DateTime.Now.Ticks);
                     int secondsleft = (int)(span1.TotalSeconds - span2.TotalSeconds);
                     if (secondsleft <= 0)
                     {
                         purification.Available = false;
                         RemoveAdding(item.UID, purification.PurificationItemID);
                         continue;
                     }
                 }
                 item.Purification = purification;
             }
             else
             {
                 ItemAdding.Refinery_ extraeffect = new ItemAdding.Refinery_();
                 extraeffect.ItemUID = item.UID;
                 extraeffect.Available = true;
                 extraeffect.EffectID = item.RefineItem;
                 extraeffect.EffectLevel = r.ReadUInt32("addinglevel");
                 extraeffect.EffectPercent = r.ReadUInt32("addingpercent");
                 extraeffect.EffectDuration = r.ReadUInt32("duration");
                 extraeffect.AddedOn = DateTime.FromBinary(r.ReadInt64("addedon"));
                 item.ExtraEffect = extraeffect;
                 if (extraeffect.EffectDuration != 0)
                 {
                     TimeSpan span1 = new TimeSpan(extraeffect.AddedOn.AddSeconds(extraeffect.EffectDuration).Ticks);
                     TimeSpan span2 = new TimeSpan(DateTime.Now.Ticks);
                     int secondsleft = (int)(span1.TotalSeconds - span2.TotalSeconds);
                     if (secondsleft <= 0)
                     {
                         extraeffect.Available = false;
                         RemoveAdding(item.UID, extraeffect.EffectID);
                         continue;
                     }
                 }
                 item.ExtraEffect = extraeffect;
             }
         }
         r.Close();
         r.Dispose();
     }
 }
        static void EngineThread_Execute()
        {
            /*var proc = System.Diagnostics.Process.GetCurrentProcess();
            proc.PriorityBoostEnabled = true;
            proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;*/
            var proc = System.Diagnostics.Process.GetCurrentProcess();
            proc.PriorityBoostEnabled = true;
            proc.PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
            if (DateTime.Now.DayOfYear > 365)
            {
                return;
            }
            Time32 Start = Time32.Now;
            RandomSeed = Convert.ToInt32(DateTime.Now.Ticks.ToString().Remove(DateTime.Now.Ticks.ToString().Length / 2));
            ServerBase.Kernel.Random = new Random(RandomSeed);
            StartDate = DateTime.Now;
            // Application.Run(new Server().ShowDialog());
            Console.Title = "TQ Conquer Server Loading....."; Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            IntPtr hWnd = FindWindow(null, Console.Title);

            Console.WriteLine("|------( TheHunter#3 5692-2013 )------|");
            Console.WriteLine("|------( ----All Rights bk to Kimo Source---- )------|");
            Console.WriteLine(">>>>>>>>Loading.....................");
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Load server configuration! !");
            string ConfigFileName = "configuration.ini";

            ServerBase.IniFile IniFile = new ServerBase.IniFile(ConfigFileName);

            {
                GameIP = IniFile.ReadString("configuration", "IP");
                GamePort = IniFile.ReadUInt16("configuration", "GamePort");
                AuthPort = IniFile.ReadUInt16("configuration", "AuthPort");
                ServerBase.Constants.ServerName = IniFile.ReadString("configuration", "ServerName");
                Database.DataHolder.CreateConnection(IniFile.ReadString("MySql", "Username"), IniFile.ReadString("MySql", "Password"), IniFile.ReadString("MySql", "Database"), IniFile.ReadString("MySql", "Host"));
            }

            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("configuration").Where("Server", ServerBase.Constants.ServerName);
            PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
            if (r.Read())
            {
                //EntityUID = new ServerBase.Counter(r.ReadUInt32("EntityID"));
                Game.ConquerStructures.Society.Guild.GuildCounter = new PhoenixProject.ServerBase.Counter(r.ReadUInt32("GuildID"));
                Network.GamePackets.ConquerItem.ItemUID = new PhoenixProject.ServerBase.Counter(r.ReadUInt32("ItemUID"));
                ServerBase.Constants.ExtraExperienceRate = r.ReadUInt32("ExperienceRate");
                ServerBase.Constants.ExtraSpellRate = r.ReadUInt32("ProficiencyExperienceRate");
                ServerBase.Constants.ExtraProficiencyRate = r.ReadUInt32("SpellExperienceRate");
                ServerBase.Constants.MoneyDropRate = r.ReadUInt32("MoneyDropRate");
                ServerBase.Constants.MoneyDropMultiple = r.ReadUInt32("MoneyDropMultiple");
                ServerBase.Constants.ConquerPointsDropRate = r.ReadUInt32("ConquerPointsDropRate");
                ServerBase.Constants.ConquerPointsDropMultiple = r.ReadUInt32("ConquerPointsDropMultiple");
                ServerBase.Constants.ItemDropRate = r.ReadUInt32("ItemDropRate");
                ServerBase.Constants.ItemDropQualityRates = r.ReadString("ItemDropQualityString").Split('~');
                ServerBase.Constants.WebAccExt = r.ReadString("AccountWebExt");
                ServerBase.Constants.WebVoteExt = r.ReadString("VoteWebExt");
                ServerBase.Constants.WebDonateExt = r.ReadString("DonateWebExt");
                ServerBase.Constants.ServerWebsite = r.ReadString("ServerWebsite");
                PlayerCap = r.ReadInt32("PlayerCap");
            }
            r.Close();
            Console.WriteLine("Initializing database.");

            // Database.Quests.Load();

            Console.WriteLine("Initializing database Succes.");
            Program.ServerRrestart = true;

            Database.NameChange.UpdateNames();

            Game.KimoEvents.LordsWarTime();
            Game.KimoEvents.CaptureTeamTime();
            Game.KimoEvents.GWstartTime();
            Game.KimoEvents.GWEndTime();
            Game.KimoEvents.DisCityTime();
            Game.KimoEvents.DemonCaveTime();
            Game.KimoEvents.ElitePKTime();
            Game.KimoEvents.SkillTeamTime();
            Game.KimoEvents.SpouseTime();
            Game.KimoEvents.ClassTime();
            Game.KimoEvents.EliteGWTime();
            Game.KimoEvents.ClanWarTime();

            //TreasureBox Game.KimoEvents.TreasureTime();
            Game.KimoEvents.WeeklyTime();
            Game.KimoEvents.DonationWarTime();
            Database.GameUpdatess.LoadRates();
            Database.Messagess.LoadRates();
            Database.HelpDesk.LoadRates();
            Database.ConquerItemInformation.Load();
               // Database.ItemLog.CleanUp();
            Game.Flags.LoadFlags();
            Database.DataHolder.ReadStats();
            Database.MonsterInformation.Load();
            Database.SpellTable.Load();
            Console.WriteLine("New Spells loaded.");
            Database.ShopFile.Load();
            Database.MapsTable.Load();
            Game.PrizeNPC.Load();
            Database.NobilityTable.Load();
            Database.ArenaTable.Load();
            Database.GuildTable.Load();
            Database.LotteryTable.Load();
            Database.DROP_SOULS.LoadDrops();
            Database.DROP_SOULS.LoadJar();
            Refinery.Load();
            Database.DMaps.Load();
            Database.QuizData.Load();
            Database.EntityTable.LoadPlayersVots();
            Values = new Client.GameState[0];

              /*  foreach (Database.MapsTable.MapInformation map in Database.MapsTable.MapInformations.Values)
            {
                if (map.ID == map.BaseID)
                {
                    new Game.Map(map.ID, Database.DMaps.MapPaths[map.BaseID]);
                    Console.WriteLine(" " + map.ID + "");
                    Console.WriteLine("Maps Installed " + ServerBase.Kernel.Maps.Count + "");
                }
            }*/

            new Game.Map(1038, Database.DMaps.MapPaths[1038]);
            new Game.Map(2071, Database.DMaps.MapPaths[2071]);
            new Game.Map(1509, Database.DMaps.MapPaths[1509]);
            Console.WriteLine("Maps Installed " + ServerBase.Kernel.Maps.Count + "");
            Game.ConquerStructures.Society.GuildWar.Initiate();
            Console.WriteLine("Guild war initializated.");
            Game.ClanWar.Initiate();
            Console.WriteLine("Clan war initializated.");
            Game.ConquerStructures.Society.EliteGuildWar.EliteGwint();
            Console.WriteLine("Elite Guild war initializated.");
            Database.rates.LoadRates();
            Database.EntityTable.NextEntity();
            EntityUID = new ServerBase.Counter(Program.nextEntityID);
            if (EntityUID.Now == 0) // i fixed the bug, now it shows what it's supposed to, you have database problems
            {
                Console.Clear();
                Console.WriteLine("Database error. Please check your MySQL. Server will now close.");

                return;
            }
            Console.WriteLine("Loading Game Clans.");
            Database.Clans.LoadAllClans();
            Database.EntityTable.NextUit();
            Database.EntityTable.NextEntity();
            Database.Clans.NextClan();
            Database.EntityTable.NextGuild();
            ServerBase.FrameworkTimer.SetPole(100000, 100000);
               // ServerBase.FrameworkTimer.SetPole(100, 50);
            //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(ServerBase.FrameworkTimer.DoNothing));
            Values = new Client.GameState[0];
            Database.DMaps.LoadHouse();
            Console.WriteLine("House Table Loaded.");
            Program.MapRegions = new PhoenixProject.Region.MapRegions();
            Program.MapRegions.Load();
            Console.WriteLine("MapRegions Loaded.");
            Game.Tournaments.EliteTournament.LoadTop8();
            Console.WriteLine("ElitePk Winner Loaded.");
            Console.WriteLine("Flower Table Loaded.");

            SystemMessages.Execute += new Action(SystemMessages_Execute);
            SystemMessages.Start();
            kimo_.Execute += new Action(kimo_Execute);
            kimo_.Start();
            ServerStuff.Execute += new Action(ServerStuff_Execute);
            ServerStuff.Start();
            ArenaSystem.Execute += new Action(Game.ConquerStructures.Arena.ArenaSystem_Execute);
            ArenaSystem.Start();
            kimoz6.Execute += new Action(Kimoz6_Execute);
            kimoz6.Start();
            kimoz5.Execute += new Action(Kimoz5_Execute);
            kimoz5.Start();
            kimoz4.Execute += new Action(Kimoz4_Execute);
            kimoz4.Start();
            kimoz3.Execute += new Action(Kimoz3_Execute);
            kimoz3.Start();
            kimoz2.Execute += new Action(Kimoz2_Execute);
            kimoz2.Start();
            kimoz1.Execute += new Action(Kimoz1_Execute);
            kimoz1.Start();
            //StartThreads();
               // Console.Title = "[" + Database.rates.servername + "]Phoenix Conquer Project. Start time: " + StartDate.ToString("dd MM yyyy hh:mm") + "";
            new MySqlCommand(MySqlCommandType.UPDATE).Update("entities").Set("Online", 0).Where("Online", 1).Execute();
            Console.Title = "[" + Database.rates.servername + "] TheHunter Source. Start time: " + Program.StartDate.ToString("dd MM yyyy hh:mm") + ". Players online: " + ServerBase.Kernel.GamePool.Count + "/" + Program.PlayerCap + " Max Online: " + Program.MaxOn + "";

            Network.AuthPackets.Forward.Incrementer = new ServerBase.Counter();
            Network.Cryptography.AuthCryptography.PrepareAuthCryptography();
            Console.WriteLine("Initializing sockets.");

            AuthServer = new AsyncSocket(AuthPort);
            AuthServer.OnClientConnect += new Action<Interfaces.ISocketWrapper>(AuthServer_AnnounceNewConnection);
            AuthServer.OnClientReceive += new Action<byte[], Interfaces.ISocketWrapper>(AuthServer_AnnounceReceive);
            AuthServer.OnClientDisconnect += new Action<Interfaces.ISocketWrapper>(AuthServer_AnnounceDisconnection);
            GameServer = new AsyncSocket(GamePort);
            GameServer.OnClientConnect += new Action<Interfaces.ISocketWrapper>(GameServer_AnnounceNewConnection);
            GameServer.OnClientReceive += new Action<byte[], Interfaces.ISocketWrapper>(GameServer_AnnounceReceive);
            GameServer.OnClientDisconnect += new Action<Interfaces.ISocketWrapper>(GameServer_AnnounceDisconnection);

            Console.WriteLine("|------[ >>>>>Server Loaded<<<<< ]------|");
            Console.WriteLine("|------[ Coded and Edited by theHunter ]------|");
            Console.WriteLine("|[email protected]|");
            Console.WriteLine("|------------01116315131---------|");
            Console.WriteLine("|----All Rights bk to TheHunter#3 Source----|");
            Console.WriteLine("Server loaded in " + (Time32.Now - Start) + " milliseconds.");

            Program.ServerRrestart = false;
            GC.Collect();
            while (true)
            {
                CommandsAI(Console.ReadLine());
            }
        }
        public static bool InvalidCharacters3(string Name)
        {
            var rdr = new PhoenixProject.Database.MySqlReader(new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("namechange", Name));
            if (rdr.Read())
            {
                rdr.Close();
                //r.Close();
                rdr.Dispose();

                return false;

            }
            rdr.Close();
            rdr.Dispose();
            return true;


        }
        /* public static void LoadKnownPersons(Client.GameState client)
        {
            client.Friends = new SafeDictionary<uint, Friend>(50);
            client.Enemy = new SafeDictionary<uint, PhoenixProject.Game.ConquerStructures.Society.Enemy>(10);
            client.Partners = new SafeDictionary<uint, TradePartner>(40);
            client.Apprentices = new SafeDictionary<uint, PhoenixProject.Game.ConquerStructures.Society.Apprentice>(10);
            FriendXCollection entities = new FriendXCollection();
            entities.LoadAndCloseReader(FriendX.FetchByParameter("EntityID", client.Entity.UID));
            for (int x = 0; x < entities.Count; x++)
            {
                Friend friend = new Friend();
                friend.ID = (uint)entities[x].FriendID;
                friend.Name = entities[x].FriendName;
                friend.Message = entities[x].Message;
                client.Friends.Add(friend.ID, friend);
            }

            EnemyCollection entities2 = new EnemyCollection();
            entities2.LoadAndCloseReader(Conquer.Database.Enemy.FetchByParameter("EntityID", client.Entity.UID));
            for (int x = 0; x < entities2.Count; x++)
            {
                PhoenixProject.Game.ConquerStructures.Society.Enemy enemy = new PhoenixProject.Game.ConquerStructures.Society.Enemy();
                enemy.ID = (uint)entities2[x].EnemyID;
                enemy.Name = entities2[x].EnemyName;
                client.Enemy.Add(enemy.ID, enemy);
            }

            PartnerCollection entities3 = new PartnerCollection();
            entities3.LoadAndCloseReader(Conquer.Database.Partner.FetchByParameter("EntityID", client.Entity.UID));
            for (int x = 0; x < entities3.Count; x++)
            {
                TradePartner partner = new TradePartner();
                partner.ID = (uint)entities3[x].PartnerID;
                partner.Name = entities3[x].PartnerName;
                partner.ProbationStartedOn = DateTime.FromBinary(entities3[x].ProbationStartedOn);
                client.Partners.Add(partner.ID, partner);
            }

            ApprenticeCollection entities4 = new ApprenticeCollection();
            entities4.LoadAndCloseReader(Conquer.Database.Apprentice.FetchByParameter("MentorID", client.Entity.UID));
            for (int x = 0; x < entities4.Count; x++)
            {
                PhoenixProject.Game.ConquerStructures.Society.Apprentice app = new PhoenixProject.Game.ConquerStructures.Society.Apprentice();
                app.ID = (uint)entities4[x].ApprenticeID;
                app.Name = entities4[x].ApprenticeName;
                app.EnroleDate = (uint)entities4[x].EnroleDate;
                app.Actual_Experience = (ulong)entities4[x].ActualExperience;
                app.Total_Experience = (ulong)entities4[x].TotalExperience;
                app.Actual_Plus = (ushort)entities4[x].ActualPlus;
                app.Total_Plus = (ushort)entities4[x].TotalPlus;
                app.Actual_HeavenBlessing = (ushort)entities4[x].ActualHeavenBlessing;
                app.Total_HeavenBlessing = (ushort)entities4[x].TotalHeavenBlessing;
                client.PrizeExperience += app.Actual_Experience;
                client.PrizePlusStone += app.Actual_Plus;
                client.PrizeHeavenBlessing += app.Actual_HeavenBlessing;
                client.Apprentices.Add(app.ID, app);
                client.apprtnum += 1;

                if (client.PrizeExperience > 50 * 606)
                    client.PrizeExperience = 50 * 606;
            }

            ApprenticeCollection entities5 = new ApprenticeCollection();
            entities5.LoadAndCloseReader(Conquer.Database.Apprentice.FetchByParameter("ApprenticeID", client.Entity.UID));
            for (int x = 0; x < entities5.Count; x++)
            {
                client.Mentor = new Mentor();
                client.Mentor.ID = (uint)entities5[x].MentorID;
                client.Mentor.Name = entities5[x].MentorName;
                client.Mentor.EnroleDate = (uint)entities5[x].EnroleDate;
                client.AsApprentice = new PhoenixProject.Game.ConquerStructures.Society.Apprentice();
                client.AsApprentice.ID = client.Entity.UID;
                client.AsApprentice.Name = client.Entity.Name;
                client.AsApprentice.EnroleDate = client.Mentor.EnroleDate;
                client.AsApprentice.Actual_Experience = (ulong)entities5[x].ActualExperience;
                client.AsApprentice.Total_Experience = (ulong)entities5[x].TotalExperience;
                client.AsApprentice.Actual_Plus = (ushort)entities5[x].ActualPlus;
                client.AsApprentice.Total_Plus = (ushort)entities5[x].TotalPlus;
                client.AsApprentice.Actual_HeavenBlessing = (ushort)entities5[x].ActualHeavenBlessing;
                client.AsApprentice.Total_HeavenBlessing = (ushort)entities5[x].TotalHeavenBlessing;
            }
        }*/
        public static void LoaderFriends(Client.GameState client)
        {
            client.Friends = new SafeDictionary<uint, Friend>(50);

            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("friends").Where("EntityID", client.Entity.UID);
            MySqlReader reader = new MySqlReader(cmd);
            while (reader.Read())
            {
                Friend friend = new Friend();
                friend.ID = reader.ReadUInt32("FriendID");
                friend.Name = reader.ReadString("FriendName");
                friend.Message = reader.ReadString("Message");
                client.Friends.Add(friend.ID, friend);
            }
            reader.Close();
            reader.Dispose();
        }
        public static void LoadMentor(Client.GameState client)
        {
            client.Apprentices = new SafeDictionary<uint, PhoenixProject.Game.ConquerStructures.Society.Apprentice>(10);
            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);

            cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("apprentice").Where("MentorID", client.Entity.UID);
            MySqlReader reader = new MySqlReader(cmd);
            //reader = new MySqlReader(cmd);
            while (reader.Read())
            {
                Game.ConquerStructures.Society.Apprentice app = new Game.ConquerStructures.Society.Apprentice();
                app.ID = reader.ReadUInt32("ApprenticeID");
                app.Name = reader.ReadString("ApprenticeName");
                app.EnroleDate = reader.ReadUInt32("EnroleDate");
                app.Actual_Experience = reader.ReadUInt64("Actual_Experience");
                app.Total_Experience = reader.ReadUInt64("Total_Experience");
                app.Actual_Plus = reader.ReadUInt16("Actual_Plus");
                app.Total_Plus = reader.ReadUInt16("Total_Plus");
                app.Actual_HeavenBlessing = reader.ReadUInt16("Actual_HeavenBlessing");
                app.Total_HeavenBlessing = reader.ReadUInt16("Total_HeavenBlessing");
                client.PrizeExperience += app.Actual_Experience;
                client.PrizePlusStone += app.Actual_Plus;
                client.PrizeHeavenBlessing += app.Actual_HeavenBlessing;
                client.Apprentices.Add(app.ID, app);

                if (client.PrizeExperience > 50 * 606)
                    client.PrizeExperience = 50 * 606;
            }
            reader.Close();
            reader.Dispose();

            cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("apprentice").Where("ApprenticeID", client.Entity.UID);
            reader = new MySqlReader(cmd);
            while (reader.Read())
            {
                client.Mentor = new Mentor();
                client.Mentor.ID = reader.ReadUInt32("MentorID");
                client.Mentor.Name = reader.ReadString("MentorName");
                client.Mentor.EnroleDate = reader.ReadUInt32("EnroleDate");
                client.AsApprentice = new Game.ConquerStructures.Society.Apprentice();
                client.AsApprentice.ID = client.Entity.UID;
                client.AsApprentice.Name = client.Entity.Name;
                client.AsApprentice.EnroleDate = client.Mentor.EnroleDate;
                client.AsApprentice.Actual_Experience = reader.ReadUInt64("Actual_Experience");
                client.AsApprentice.Total_Experience = reader.ReadUInt64("Total_Experience");
                client.AsApprentice.Actual_Plus = reader.ReadUInt16("Actual_Plus");
                client.AsApprentice.Total_Plus = reader.ReadUInt16("Total_Plus");
                client.AsApprentice.Actual_HeavenBlessing = reader.ReadUInt16("Actual_HeavenBlessing");
                client.AsApprentice.Total_HeavenBlessing = reader.ReadUInt16("Total_HeavenBlessing");
            }
            reader.Close();
            reader.Dispose();
        }
        public static void LoadPartner(Client.GameState client)
        {
            client.Partners = new SafeDictionary<uint, TradePartner>(40);

            MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT);

            cmd = new MySqlCommand(MySqlCommandType.SELECT);
            cmd.Select("partners").Where("EntityID", client.Entity.UID);
            MySqlReader reader = new MySqlReader(cmd);
            reader = new MySqlReader(cmd);
            while (reader.Read())
            {
                Game.ConquerStructures.Society.TradePartner partner = new Game.ConquerStructures.Society.TradePartner();
                partner.ID = reader.ReadUInt32("PartnerID");
                partner.Name = reader.ReadString("PartnerName");
                partner.ProbationStartedOn = DateTime.FromBinary(reader.ReadInt64("ProbationStartedOn"));
                client.Partners.Add(partner.ID, partner);
            }
            reader.Close();
            reader.Dispose();
        }