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); }
private static void Main(string[] args) { try { string exeFile = Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName; string version = Program.GetVersionDateTime(); Console.Title = string.Format("跨服中心服务器@{0}@{1}", version, exeFile); File.WriteAllText("Pid.txt", Process.GetCurrentProcess().Id.ToString()); FileStream fs = File.Open("Pid.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read); } catch (Exception ex) { LogManager.WriteLog(LogTypes.Fatal, "本程序已经启动了一个进程,按任意键退出!", ex, true); return; } if (args.Contains("-gmsettime")) { KuaFuServerManager.EnableGMSetAllServerTime = true; } if (args.Contains("-testmode")) { Global.TestMode = true; Consts.TestMode = true; } if (args.Contains("-waitdebug")) { Console.WriteLine("等待调试器连接,按任意键继续!"); do { Thread.Sleep(100); }while (!Console.KeyAvailable); Console.ReadKey(); } Program.HideCloseBtn(); Program.SetConsoleCtrlHandler(Program.newDelegate, true); if (Console.WindowWidth < 88) { Console.BufferWidth = 88; Console.WindowWidth = 88; } Console.WriteLine("跨服中心服务器启动!"); LogManager.WriteLog(LogTypes.Info, "跨服中心服务器启动!", null, true); if (!KuaFuServerManager.CheckConfig()) { Console.WriteLine("服务器无法启动!"); Thread.Sleep(300000); } else { RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off; KuaFuServerManager.StartServerConfigThread(); if (!KuaFuServerManager.LoadConfig()) { Console.WriteLine("服务器无法启动!"); Thread.Sleep(300000); } else { KuaFuServerManager.InitServer(); Program.StartServices(); Program.InitCmdDict(); KuaFuServerManager.OnStartServer(); new Thread(new ParameterizedThreadStart(Program.ConsoleInputThread)) { IsBackground = true }.Start(); while (!KuaFuServerManager.WaitStop(0)) { Thread.Sleep(1000); } } } }