示例#1
0
 public static void ConsoleInputThread(object obj)
 {
     for (;;)
     {
         try
         {
             Program.ShowCmdHelp();
             string cmd = Console.ReadLine();
             if (null != cmd)
             {
                 Program.CmdDict.ExcuteCmd(cmd);
             }
             if (Program.NeedExitServer)
             {
                 KuaFuServerManager.OnStopServer();
                 break;
             }
         }
         catch (Exception ex)
         {
             LogManager.WriteException(ex.ToString());
         }
     }
 }
示例#2
0
文件: Program.cs 项目: chenchungit/ky
        static void Main(string[] args)
        {
            try
            {
                FileStream fs = File.Open("Pid.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
                if (fs != null)
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(Process.GetCurrentProcess().Id.ToString());
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Flush();
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("本程序已经启动了一个进程,按任意键退出!");
                Console.ReadKey();
                return;
            }

            //Console.TreatControlCAsInput = true;

            #region 控制台关闭控制

            HideCloseBtn();

            SetConsoleCtrlHandler(newDelegate, true);

            if (Console.WindowWidth < 88)
            {
                Console.BufferWidth = 88;
                Console.WindowWidth = 88;
            }

            #endregion 控制台关闭控制

            Console.WriteLine("跨服中心服务器启动!");
            LogManager.WriteLog(LogTypes.Info, "跨服中心服务器启动!");
            SetWindowMin();

            //new MoRiJudgeService();
            if (!KuaFuServerManager.CheckConfig())
            {
                Console.WriteLine("服务器无法启动!");
            }

            if (!KuaFuServerManager.LoadConfig())
            {
                Console.ReadLine();
                return;
            }

            KuaFuServerManager.StartServerConfigThread();

            RemotingConfiguration.Configure(Process.GetCurrentProcess().MainModule.FileName + ".config", false);
            InitCmdDict();

            //YongZheZhanChangService s = new YongZheZhanChangService();

            do
            {
                try
                {
                    ShowCmdHelp();
                    string cmd = Console.ReadLine();
                    if (null != cmd)
                    {
                        CmdDict.ExcuteCmd(cmd);
                    }

                    //判断是否需要退出
                    if (NeedExitServer)
                    {
                        KuaFuServerManager.OnStopServer();

                        Console.WriteLine("Press any key to Stop!");
                        Console.ReadKey();
                        break;
                    }
                }
                catch (System.Exception ex)
                {
                    LogManager.WriteException(ex.ToString());
                }
            } while (true);
        }