Beispiel #1
0
        public static void Main(string[] args)
        {
            File.WriteAllText(AppProperties.ServerLogPath, "");  // Erase server log file.

            // Set console window position on desktop.
            //try
            //{
            //    //Console.SetWindowPosition(0, 100);
            //    Console.WindowLeft = 0;
            //    Console.WindowTop = 0;
            //}
            //catch (Exception error)
            //{
            //    Console.WriteLine("Error: " + error.Message);
            //    File.AppendAllText(AppProperties.ServerLogPath, "Error: " +
            //        error.Message + Environment.NewLine);
            //}

            ServerTCPConnection.Start();
            //ServerTCPConnection.GetConnection();

            Knowledgebase.Connect();
            Knowledgebase.LoadLang();

            File.AppendAllText(AppProperties.ServerLogPath, "Entering server loop." +
                               Environment.NewLine);
            bool continueRunning = true;
            // For writing to the console only after a number of passes through the server loop.
            int cycleCount = 0;

            while (continueRunning)
            {
                if (cycleCount == 0)
                {
                    Console.Write(DateTime.Now.ToLongTimeString() +
                                  "\r\nServer running...\n");
                }
                if (cycleCount == 0 || cycleCount == 10)
                {
                    Console.Write("Getting commands...\r\n");
                }
                Thread.Sleep(50);
                string commands = ServerTCPConnection.HandleConnection();
                if (!string.IsNullOrEmpty(commands))
                {
                    continueRunning = ProcessCommands(commands);
                }
                cycleCount++;
                if (cycleCount == 20)
                {
                    cycleCount = 0;
                }
            }

            Console.WriteLine("Closing Server...");
            File.AppendAllText(AppProperties.ServerLogPath, "Closing server." +
                               Environment.NewLine);
            Thread.Sleep(300);
            //return 0;
        }