Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // set close handler
            m_pHandler += Handler;
            SetConsoleCtrlHandler(m_pHandler, true);

            ServerKernel.Log = new LogWriter(Environment.CurrentDirectory + @"\");

            Console.Title = "Starting server...";

            // Server header
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tProject WConquer: Conquer Online Private Server Emulator");
            Console.WriteLine("\t\tDeveloped by Felipe Vieira (FTW! Masters)");
            Console.WriteLine("\t\tNovember 10th, 2016 - All Rights Reserved");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.White;

            ServerKernel.Log.SaveLog(Environment.CurrentDirectory, true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("Computer Name: " + Environment.MachineName, true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("User Name: " + Environment.UserName, true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("System Directory: " + Environment.SystemDirectory, true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("Some environment variables:", true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("OS=" + Environment.OSVersion, true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("NUMBER_OF_PROCESSORS: " + Environment.ProcessorCount, true, LogType.DEBUG);
            ServerKernel.Log.SaveLog("PROCESSOR_ARCHITETURE: " + (Environment.Is64BitProcess ? "x64" : "x86"), true, LogType.DEBUG);
            Console.WriteLine();
            ServerKernel.Log.SaveLog("Initializing game server...", true);

            // read the configuration file
            ServerKernel.ConfigReader       = new IniFileName(Environment.CurrentDirectory + @"\Shell.ini");
            ServerKernel.LoginServerAddress = ServerKernel.ConfigReader.GetEntryValue("AccountServer", "ACCOUNT_IP").ToString();
            ServerKernel.ServerName         = ServerKernel.ConfigReader.GetEntryValue("AccountServer", "SERVERNAME").ToString();
            ServerKernel.LoginServerPort    = int.Parse(ServerKernel.ConfigReader.GetEntryValue("AccountServer", "ACCOUNT_PORT").ToString());
            ServerKernel.MaxOnlinePlayer    = ushort.Parse(ServerKernel.ConfigReader.GetEntryValue("AccountServer", "MAXLOGINTABLESIZE").ToString());
            ServerKernel.Username           = ServerKernel.ConfigReader.GetEntryValue("AccountServer", "LOGINNAME").ToString();
            ServerKernel.Password           = ServerKernel.ConfigReader.GetEntryValue("AccountServer", "PASSWORD").ToString();
            ServerKernel.TransferKey        = ServerKernel.ConfigReader.GetEntryValue("TransferKey", "Key").ToString();
            ServerKernel.TransferSalt       = ServerKernel.ConfigReader.GetEntryValue("TransferKey", "Salt").ToString();
            ServerKernel.Blowfish           = ServerKernel.ConfigReader.GetEntryValue("Blowfish", "Key").ToString();

            ServerKernel.Log.SaveLog("Initializing blowfish", true);
            // set the blowfish key before anything else
            BlowfishCipher.InitialKey = Encoding.ASCII.GetBytes(ServerKernel.Blowfish);

            ServerKernel.Log.SaveLog("Initializing Database", true);
            Database.Initialize();

            ServerKernel.Log.SaveLog("Starting sockets", true);

            ServerKernel.Log.SaveLog("Starting server socket...");
            try
            {
                ServerKernel.GameServer = new GameSocket();
                ServerKernel.GameServer.SetSecurity(IPProtectionLevel.Unrestricted, 6, 15);
                ServerKernel.GameServer.Bind("0.0.0.0", ServerKernel.GamePort);
                ServerKernel.GameServer.Listen(10);
                ServerKernel.Log.SaveLog("Game Server waiting for client connections...", true, LogType.MESSAGE);
            }
            catch (Exception ex)
            {
                ServerKernel.Log.SaveLog("Could not open game socket on port " + ServerKernel.GamePort, true, LogType.ERROR);
                ServerKernel.Log.SaveLog(ex.ToString(), false, LogType.EXCEPTION);
                Console.ReadKey();
                Environment.Exit(-1);
            }

            ServerKernel.Log.SaveLog("Starting threads");
            new GameAction().ProcessAction(80000000u, null, null, null, null);
            ThreadHandler.StartThreading();

            HandleCommands();

            SaveAll();

            Environment.Exit(0);
        }