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 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 CaptureTeamTime()
 {
     MySqlCommand cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("KimoTimes").Where("Type", "Flag");
     PhoenixProject.Database.MySqlReader r = new PhoenixProject.Database.MySqlReader(cmd);
     if (r.Read())
     {
         CFHour = r.ReadUInt32("Hour");
         CFMinute = r.ReadUInt32("Minute");
         CFDay = r.ReadString("Day");
         CFEndHour = r.ReadUInt32("End");
     }
     Console.WriteLine("CaptureTeamTime Time Loaded.");
     r.Close();
     r.Dispose();
 }
        public static void LoadArsenal(PhoenixProject.Game.ConquerStructures.Society.Guild Syn)
        {
            Syn.Arsenal = new Arsenal((ushort)Syn.ID);
            MySqlCommand Command = new MySqlCommand(MySqlCommandType.SELECT);
            Command.Select("pt_arsenal").Where("syn_id", Syn.ID).Execute();
            MySqlReader Reader = new MySqlReader(Command);
            while (Reader.Read())
            {
                PhoenixProject.Game.Features.Arsenal_State Arsenal = new PhoenixProject.Game.Features.Arsenal_State();
                Arsenal.ID = (PhoenixProject.Game.Features.Arsenal_ID)Reader.ReadByte("arsenal_id");
                Arsenal.Unlocked = (Reader.ReadByte("arsenal_unlocked") == 1);
                Arsenal.Donation = Reader.ReadUInt32("arsenal_donation");

                if (!Syn.Arsenal.Arsenals.ContainsKey(Arsenal.ID))
                    Syn.Arsenal.Arsenals.Add(Arsenal.ID, Arsenal);
            }
            if (Syn.Arsenal.Arsenals.Count > 0)
            {
                Command = new MySqlCommand(MySqlCommandType.SELECT);
                Command.Select("pt_arsenal_inscribed").Where("syn_id", Syn.ID).Execute();
                Reader = new MySqlReader(Command);
                while (Reader.Read())
                {
                    uint OWNER = Reader.ReadUInt32("uid");
                    string Name = Reader.ReadString("name");
                    uint UID = Reader.ReadUInt32("iten_id");
                    PhoenixProject.Game.Features.Arsenal_ID ID = (PhoenixProject.Game.Features.Arsenal_ID)Reader.ReadByte("iten_atype");
                    if (Syn.Arsenal.Arsenals.ContainsKey(ID))
                    {
                        if (!Syn.Arsenal.Arsenals[ID].Inscribed.ContainsKey(UID))
                        {
                            Syn.Arsenal.Arsenals[ID].Inscribed.Add(UID, new PhoenixProject.Game.Features.Arsenal_Client() { UID = OWNER, Name = Name, iUID = UID });
                        }
                    }
                }
            }
            foreach (PhoenixProject.Game.Features.Arsenal_State astate in Syn.Arsenal.Arsenals.Values)
            {
                foreach (PhoenixProject.Game.Features.Arsenal_Client ac in astate.Inscribed.Values)
                {
                    if (ac.Item == null)
                    {
                        ac.Item = ConquerItemTable.LoadItem(ac.iUID);
                    }
                }
            }
            Reader.Close();
        }
 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).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()
        {
            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 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 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 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 RemoveItem(Client.GameState client)
        {
            MySqlCommand command = new MySqlCommand(MySqlCommandType.DELETE);
            command.Delete("prizenpc", "Owner", client.Entity.UID).And("type", "2").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 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 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 void Load(Client.GameState h)
        {
            MySqlCommand Command = new MySqlCommand(MySqlCommandType.SELECT);
            Command.Select("heroquests").Where("hero", h.Entity.UID).And("quest", 0xb71b0);
            PhoenixProject.Database.MySqlReader cmd2 = new PhoenixProject.Database.MySqlReader(Command);

            if (cmd2.Read())
            {
                this.QuestGiver = cmd2.ReadUInt32("npc");
                this.Kills = cmd2.ReadUInt16("step");
                this.CompletedTimes = cmd2.ReadByte("dailyfinishes");
            }
            else
            {
                MySqlCommand cmd = new MySqlCommand(MySqlCommandType.INSERT);
                cmd.Insert("heroquests").Insert("hero", h.Entity.UID).Insert("quest", 0xb71b0).Execute();

            }
        }
        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 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();
        }
 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();
 }
        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());
            }
        }