Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Program pro = new Program();

            GameServer.Definitions.Bootlogo._Load();
            Systems.Ini ini = null;
            LogConsole.Init();

            #region Default Settings
            int    LSPort  = 7000;
            int    IPCPort = 7000;
            string LSIP    = "127.0.0.1";
            string IPCIP   = "127.0.0.1";
            #endregion

            #region Load Settings
            try
            {
                if (File.Exists(Environment.CurrentDirectory + @"\Settings\GS-Settings.ini"))
                {
                    ini        = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\GS-Settings.ini");
                    LSPort     = Convert.ToInt32(ini.GetValue("GAMESERVER", "port", 7000));
                    LSIP       = ini.GetValue("SERVER", "ip", "127.0.0.1").ToString();
                    IPCPort    = Convert.ToInt32(ini.GetValue("IPC", "port", 7000));
                    IPCIP      = ini.GetValue("IPC", "ip", "127.0.0.1").ToString();
                    debug      = ini.GetValue("CONSOLE", "debug", false);
                    MYSQL_USER = ini.GetValue("MYSQL", "user", "root");
                    MYSQL_PASS = ini.GetValue("MYSQL", "pass", "123456");
                    MYSQL_DATA = ini.GetValue("MYSQL", "data", "godswar");
                    MYSQL_IP   = ini.GetValue("MYSQL", "ip", "127.0.0.1");
                    MYSQL_PORT = ini.GetValue("MYSQL", "port", 3306);
                    ini        = null;
                    LogConsole.Show("MYSQL Connection Server-Settings... LOADED!");
                }
                else
                {
                    LogConsole.Show("Server-Settings.ini could not be found, doing fallback to default settings!");
                }
            }
            catch (Exception)
            {
                return;
            }
            #endregion

            _SQL.Init(MYSQL_IP, MYSQL_USER, MYSQL_PASS, MYSQL_DATA, MYSQL_PORT);

            Systems.Server net = new Systems.Server();

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

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

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                LogConsole.Show("Error Initializing Server: {0}", ex);
            }

            #region Load GameServers
            //Systems.LoadServers("GameServers.ini", 6001);
            #endregion

            #region IPC Listener

            /*IPCServer = new Network.Servers.IPCServer();
             * IPCServer.OnReceive += new Network.Servers.IPCServer.dOnReceive(pro.OnIPC);
             * try
             * {
             *  IPCServer.Start(IPCIP, IPCPort);
             *  foreach (KeyValuePair<int, Systems.SRX_Serverinfo> Server in Systems.GSList)
             *  {
             *      byte[] rqPacket = IPCServer.PacketRequestServerInfo(IPCPort);
             *      Network.Servers.IPCenCode(ref rqPacket, Server.Value.code);
             *      IPCServer.Send(Server.Value.ip, Server.Value.ipcport, rqPacket);
             *      rqPacket = null;
             *  }
             * }
             * catch (Exception ex)
             * {
             *  LogConsole.Show("Error start ICP: {0}", ex);
             * }*/
            #endregion

            //LogConsole.Show("Ready for gameserver connection...");
            #region Loop Update GameServers
            while (true)
            {
                Thread.Sleep(100);

                /*foreach (KeyValuePair<int, Systems.SRX_Serverinfo> SSI in Systems.GSList)
                 * {
                 *  if (SSI.Value.status != 0 && SSI.Value.lastPing.AddMinutes(5) < DateTime.Now) // server unavailable
                 *  {
                 *      SSI.Value.status = 0;
                 *      LogConsole.Show("Server: {0}:({1}) has timed out, status changed to check", SSI.Value.id, SSI.Value.name);
                 *  }
                 * }*/
            }
            #endregion
        }