コード例 #1
0
        /// <summary>
        /// Start the execution of the server.
        /// </summary>
        public static void Run()
        {
            if (!File.Exists(CONFIG_FILE))
            {
                sLogger.Fatal("Couldn't find the configuration file at '{0}'.", CONFIG_FILE);
                Environment.Exit(0);
            }

            UInt16 port    = 0;
            Int32  backlog = 0;

            String mysql_host, mysql_db, mysql_user, mysql_pwd;
            int    mysql_nb_connections;

            String ip2loc_host, ip2loc_db, ip2loc_user, ip2loc_pwd;
            int    ip2loc_nb_connections;

            using (Ini doc = new Ini(CONFIG_FILE))
            {
                port             = doc.ReadUInt16("Socket", "Port", 9958);
                backlog          = doc.ReadInt32("Socket", "BackLog", 100);
                Program.Encoding = Encoding.GetEncoding(doc.ReadString("Program", "Encoding", "iso-8859-1"));
                Program.Debug    = doc.ReadBoolean("Program", "Debug", false);

                mysql_host           = doc.ReadString("MySQL", "Host", "localhost");
                mysql_db             = doc.ReadString("MySQL", "Database", "zfserver");
                mysql_user           = doc.ReadString("MySQL", "Username", "zfserver");
                mysql_pwd            = doc.ReadString("MySQL", "Password", "");
                mysql_nb_connections = doc.ReadInt32("MySQL", "NbConnections", 1);

                Database.IP2LOCATION_ENABLED = doc.ReadBoolean("IP2Location", "Enabled", false);
                ip2loc_host           = doc.ReadString("IP2Location", "Host", "localhost");
                ip2loc_db             = doc.ReadString("IP2Location", "Database", "zfserver");
                ip2loc_user           = doc.ReadString("IP2Location", "Username", "zfserver");
                ip2loc_pwd            = doc.ReadString("IP2Location", "Password", "");
                ip2loc_nb_connections = doc.ReadInt32("IP2Location", "NbConnections", 1);
            }

            if (!Database.SetupMySQL(mysql_nb_connections, mysql_host, mysql_db, mysql_user, mysql_pwd))
            {
                sLogger.Fatal("Failed to setup MySQL...");
                Console.ReadLine();
                Environment.Exit(0);
            }

            if (Database.IP2LOCATION_ENABLED)
            {
                if (!Database.SetupIP2Location(ip2loc_nb_connections, ip2loc_host, ip2loc_db, ip2loc_user, ip2loc_pwd))
                {
                    sLogger.Fatal("Failed to setup IP2Location...");
                    Console.ReadLine();
                    Environment.Exit(0);
                }
            }

            Database.GetBannedIPs();

            sSocket               = new TcpServer();
            sSocket.OnConnect    += new NetworkClientConnection(ConnectionHandler);
            sSocket.OnReceive    += new NetworkClientReceive(ReceiveHandler);
            sSocket.OnDisconnect += new NetworkClientConnection(DisconnectionHandler);
            sSocket.Listen(port, backlog);
            sSocket.Accept();

            sLogger.Info("Waiting for new connection...");
            ServiceEventsListener.Create();
        }
コード例 #2
0
        /// <summary>
        /// Start the execution of the server.
        /// </summary>
        public static void Run()
        {
            if (!File.Exists(CONFIG_FILE))
            {
                sLogger.Fatal("Couldn't find the configuration file at '{0}'.", CONFIG_FILE);
                Environment.Exit(0);
            }

            UInt16 port         = 0;
            Int32  backlog      = 0;
            Byte   threadAmount = 1;

            String mysql_host, mysql_db, mysql_user, mysql_pwd;
            int    mysql_nb_connections;

            String acc_host, acc_db, acc_user, acc_pwd;
            int    acc_nb_connections;

            String mongo_host, mongo_db, mongo_user, mongo_pwd;

            using (Ini doc = new Ini(CONFIG_FILE))
            {
                port         = doc.ReadUInt16("Socket", "Port", 5816);
                backlog      = doc.ReadInt32("Socket", "BackLog", 100);
                threadAmount = doc.ReadUInt8("Socket", "ThreadAmount", 1);

                Name             = doc.ReadString("Program", "Name", "NULL");
                Program.Encoding = Encoding.GetEncoding(doc.ReadString("Program", "Encoding", "iso-8859-1"));
                Program.Debug    = doc.ReadBoolean("Program", "Debug", false);

                mysql_host           = doc.ReadString("MySQL", "Host", "localhost");
                mysql_db             = doc.ReadString("MySQL", "Database", "zfserver");
                mysql_user           = doc.ReadString("MySQL", "Username", "zfserver");
                mysql_pwd            = doc.ReadString("MySQL", "Password", "");
                mysql_nb_connections = doc.ReadInt32("MySQL", "NbConnections", 1);

                acc_host           = doc.ReadString("AccMySQL", "Host", "localhost");
                acc_db             = doc.ReadString("AccMySQL", "Database", "zfserver");
                acc_user           = doc.ReadString("AccMySQL", "Username", "zfserver");
                acc_pwd            = doc.ReadString("AccMySQL", "Password", "");
                acc_nb_connections = doc.ReadInt32("AccMySQL", "NbConnections", 1);

                mongo_host = doc.ReadString("MongoDB", "Host", "localhost");
                mongo_db   = doc.ReadString("MongoDB", "Database", "zfserver");
                mongo_user = doc.ReadString("MongoDB", "Username", "zfserver");
                mongo_pwd  = doc.ReadString("MongoDB", "Password", "");
            }

            StrRes.LoadStrRes();

            if (!Database.SetupAccMySQL(acc_nb_connections, acc_host, acc_db, acc_user, acc_pwd))
            {
                sLogger.Fatal("Failed to setup MySQL...");
                Environment.Exit(0);
            }

            if (!Database.SetupMySQL(mysql_nb_connections, mysql_host, mysql_db, mysql_user, mysql_pwd))
            {
                sLogger.Fatal("Failed to setup MySQL...");
                Environment.Exit(0);
            }

            if (!Database.SetupMongo(mongo_host, mongo_db, mongo_user, mongo_pwd))
            {
                sLogger.Fatal("Failed to setup MongoDB...");
                Environment.Exit(0);
            }


            // load Lua VM
            Task.RegisterFunctions(); // register Lua functions
            TaskHandler.LoadAllTasks();

            if (!MapManager.LoadData())
            {
                sLogger.Fatal("Failed to load DMaps in memory...");
                Environment.Exit(0);
            }

            Database.GetItemsInfo();
            Database.GetItemsBonus();
            Database.GetShopsInfo();
            Database.GetMagicsInfo();
            Database.GetLevelsInfo();
            Database.GetPointAllotInfo();
            Database.LoadWeaponSkillReqExp();
            Database.GetPortalsInfo();
            Database.GetAllMaps();
            Database.GetMonstersInfo();
            Database.GetSpawnsInfo();
            Database.GetAllNPCs();
            Database.GetAllItems();
            Database.LoadAllSyndicates();

            ServiceEventsListener.Create();

            NetworkIO = new NetworkIO(threadAmount);

            sSocket               = new TcpServer();
            sSocket.OnConnect    += new NetworkClientConnection(ConnectionHandler);
            sSocket.OnReceive    += new NetworkClientReceive(ReceiveHandler);
            sSocket.OnDisconnect += new NetworkClientConnection(DisconnectionHandler);
            sSocket.Listen(port, backlog);
            sSocket.Accept();

            LaunchTime = DateTime.Now;
            sLogger.Info("Waiting for new connection...");
        }