コード例 #1
0
        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(System.Globalization.CultureInfo.GetCultureInfo(TxtFile.GetSystemDefaultLangID()).ToString());

            Framework.Ini ini;

            DarkEmu_GameServer.Systemcore.Definitions.Bootlogo._Load();

            Program pro = new Program();

            // Begin connection to our database.
            Systems.MsSQL.OnDatabaseError += new Systems.MsSQL.dError(db_OnDatabaseError);
            // Read our database settings from our ini file.
            Systems.MsSQL.OnConnectedToDatabase += new Systems.MsSQL.dConnected(db_OnConnectedToDatabase);
            // Check if our ini file excists.
            string sqlConnect  = @"Data Source=(local)\SQLEXPRESS;Initial Catalog=silkroad;Integrated Security=True;MultipleActiveResultSets=True;";
            string sIpIPC      = "127.0.0.1";
            string sIpServer   = "127.0.0.1";
            UInt16 iPortIPC    = 15791;
            UInt16 iPortServer = 15780;
            UInt16 iPortCmd    = 10101;

            if (File.Exists("./Settings/Settings.ini"))
            {
                //Load our ini file
                ini = new Framework.Ini(Environment.CurrentDirectory + @"\Settings\Settings.ini");
                //Read line below given value.
                sqlConnect = ini.GetValue("Database", "connectionstring", @"Data Source=(local)\SQLEXPRESS;Initial Catalog=silkroad;Integrated Security=True;MultipleActiveResultSets=True;").ToString();
                //Load our rates.
                Systems.Rate.Gold     = Convert.ToByte(ini.GetValue("Rates", "Goldrate", 1));
                Systems.Rate.Item     = Convert.ToByte(ini.GetValue("Rates", "Droprate", 1));
                Systems.Rate.Xp       = Convert.ToByte(ini.GetValue("Rates", "XPrate", 1));
                Systems.Rate.Sp       = Convert.ToByte(ini.GetValue("Rates", "SPrate", 1));
                Systems.Rate.Sox      = Convert.ToByte(ini.GetValue("Rates", "Sealrate", 1));
                Systems.Rate.Elixir   = Convert.ToByte(ini.GetValue("Rates", "Elixirsrate", 1));
                Systems.Rate.Alchemyd = Convert.ToByte(ini.GetValue("Rates", "Alchemyrate", 1));
                Systems.Rate.ETCd     = Convert.ToByte(ini.GetValue("Rates", "ETCrate", 1));
                Systems.Rate.Spawns   = Convert.ToByte(ini.GetValue("Rates", "Spawnrate", 1));
                iPortIPC    = Convert.ToUInt16(ini.GetValue("IPC", "port", 15791));
                sIpIPC      = ini.GetValue("IPC", "ip", "127.0.0.1");
                iPortServer = Convert.ToUInt16(ini.GetValue("Server", "port", 15780));
                sIpServer   = ini.GetValue("Server", "ip", "127.0.0.1");
                iPortCmd    = Convert.ToUInt16(ini.GetValue("CMD", "port", 10101));
                DarkEmu_GameServer.Systems.maxSlots = Convert.ToInt32(ini.GetValue("Server", "MaxSlots", 100));
            }
            else
            {
                Systems.Rate.Gold     = 1;
                Systems.Rate.Item     = 1;
                Systems.Rate.Xp       = 1;
                Systems.Rate.Sp       = 1;
                Systems.Rate.Sox      = 1;
                Systems.Rate.Elixir   = 1;
                Systems.Rate.Alchemyd = 1;
                Systems.Rate.ETCd     = 1;
                Systems.Rate.Spawns   = 1;
                Systems.maxSlots      = 100;
            }
            Systems.MsSQL.Connection(sqlConnect);
            //Boot_Logo._Rates();
            // create servers
            try
            {
                net = new Systems.Server();

                net.OnConnect += new Systems.Server.dConnect(pro._OnClientConnect);
                net.OnError   += new Systems.Server.dError(pro._ServerError);

                Systems.ServerStartedTime = DateTime.Now;

                Systems.Client.OnReceiveData += new Systems.Client.dReceive(pro._OnReceiveData);
                Systems.Client.OnDisconnect  += new Systems.Client.dDisconnect(pro._OnClientDisconnect);

                #region CommandServer StartUp
                cmd = new Systems.CommandServer();
                cmd.OnCommandReceived += new Systems.CommandServer.dCommandReceived(pro._command);
                #endregion
                #region IPC Server StartUp
                Systems.IPC            = new Servers.IPCServer();
                Systems.IPC.OnReceive += new Servers.IPCServer.dOnReceive(pro._OnIPC);
                Systems.LoadServers("LoginServers.ini", 15790);
                #endregion
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
            }

            DarkEmu_GameServer.Systems.CheckDirectories();

            DarkEmu_GameServer.File.FileLoad.Load();
            //Update serverlist info
            DarkEmu_GameServer.Systems.clients.update += new EventHandler(Users.updateServerList);
            //Load random unique monsters.
            /*Random rand = new Random();*/

            /*
             * DarkEmu_GameServer.GlobalUnique.StartTGUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn tiger girl
             * DarkEmu_GameServer.GlobalUnique.StartUriUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn urichi
             * DarkEmu_GameServer.GlobalUnique.StartIsyUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn isy
             * DarkEmu_GameServer.GlobalUnique.StartLordUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn lord yarkan
             * DarkEmu_GameServer.GlobalUnique.StartDemonUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn demon shaitan
             * DarkEmu_GameServer.GlobalUnique.StartCerbUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn cerberus
             * DarkEmu_GameServer.GlobalUnique.StartMedusa(rand.Next(10, 20) * 90000, 600);   //Random spawn medusa
             * DarkEmu_GameServer.GlobalUnique.StartNeith(rand.Next(10, 20) * 90000, 600);   //Random spawn neith
             * //Game.GlobalUnique.StartSphinx       (rand.Next(10, 20) * 90000, 600);   //Random spawn medusa
             * DarkEmu_GameServer.GlobalUnique.StartIsis(rand.Next(10, 20) * 90000, 600);   //Random spawn isis
             * //Game.GlobalUnique.StartRoc          (rand.Next(10, 20) * 90000, 600);   //Random spawn roc
             * DarkEmu_GameServer.GlobalUnique.StartIvyUnique(rand.Next(10, 20) * 60000, 600);   //Random spawn captain ivy
             */

            // start listening servers
            cmd.Start("127.0.0.1", iPortCmd);
            Systems.IPC.Start(sIpIPC, iPortIPC);
            net.Start(sIpServer, iPortServer);
            Systems.UpdateServerInfo();

            //Run for commands in console.
            Program launch = new Program();
            Thread  run    = new Thread(new ThreadStart(launch.run));
            run.Start();

            // main loop
            lastPromote = DateTime.Now;
            while (run.IsAlive)
            {
                Thread.Sleep(10);
                if (lastPromote.AddSeconds(60) < DateTime.Now)
                {
                    lastPromote = DateTime.Now;
                    Systems.UpdateServerInfo();
                }
            }
            Systems.UpdateServerInfo(0);
            net.ServerCheck(false);
        }