/// <summary> /// 拥有一定数量 /// </summary> /// <param name="name"></param> /// <param name="room"></param> /// <param name="deck"></param> /// <returns></returns> private static bool AddAI(ServerConfig Config, string room){ lock(AIs){ if(AIs.Count >= Config.MaxAICount){ return false; } } Process ai=new Process(); ai.StartInfo.FileName = "ai"; //设定程式执行参数 ai.StartInfo.Arguments = " "+Config.AIPass +" 127.0.0.1 " +Config.ServerPort +" "+ Config.ClientVersion + " "+room +" \""+Tool.Combine(Config.Path, "cards.cdb")+"\""; ai.EnableRaisingEvents=true; #if !DEBUG ai.StartInfo.WindowStyle=ProcessWindowStyle.Hidden; #endif ai.Exited+=new EventHandler(ai_Exited); try{ ai.Start(); }catch(Exception e){ Logger.Error(e); return false; } lock(AIs){ AIs.Add(ai); } return true; }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Config = new ServerConfig(); bool loaded = args.Length > 1 ? Config.Load(args[1]) : Config.Load(); if (Config.SplashScreen == true) { Logger.WriteLine(" __ _______ ____ _____", false); Logger.WriteLine(" \\ \\ / / ____|/ __ \\ / ____|", false); Logger.WriteLine(" \\ \\_/ / | __| | | | | ___ _ __ ___", false); Logger.WriteLine(" \\ /| | |_ | | | | | / _ \\| '__/ _ \\", false); Logger.WriteLine(" | | | |__| | |__| | |___| (_) | | | __/", false); Logger.WriteLine(" |_| \\_____|\\____/ \\_____\\___/|_| \\___| Version: " + Version, false); Logger.WriteLine(string.Empty, false); } Logger.WriteLine("Accepting client version 0x" + Config.ClientVersion.ToString("x") + " or higher."); if (loaded) Console.WriteLine("Config loaded."); else Console.WriteLine("Unable to load config.txt, using default settings."); int coreport = 0; if (args.Length > 0) int.TryParse(args[0], out coreport); Random = new Random(); Server server = new Server(); if (!server.Start(coreport)) Thread.Sleep(5000); if (server.IsListening == true && Config.STDOUT == true) Console.WriteLine("::::network-ready"); while (server.IsListening) { server.Process(); Thread.Sleep(1); } if (Config.STDOUT == true) Console.WriteLine("::::network-end"); Process.GetCurrentProcess().Kill(); }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Console.CancelKeyPress+= new ConsoleCancelEventHandler(Console_CancelKeyPress); System.Net.ServicePointManager.DefaultConnectionLimit = 512; ThreadPool.SetMaxThreads(128, 256); // Config = new ServerConfig(); bool loaded = args.Length > 0 ? Config.Load(args[0]): Config.Load(); int tmp =0 ; if(args.Length > 1){ int.TryParse(args[1], out tmp); if(tmp > 0){ Config.SetServerPort(tmp); } } if(args.Length > 2){ int.TryParse(args[2], out tmp); if(tmp > 0){ Config.SetApiPort(tmp); } } if(args.Length > 3) { Config.SetNeedAuth(args[3].Trim().ToLower() == "true"); } Logger.SetErrorFile(Tool.Combine(Config.Path, "error_"+ DateTime.UtcNow.ToString("yyyy-MM-dd")+"_"+Config.ServerPort + ".log")); Logger.SetLogLevel(Config.LogLevel); #if DEBUG Logger.SetLogLevel(LogLevel.Debug); #endif Console.Title = "GameServer:"+Config.ServerPort; GameServer Server = new GameServer(Config); Server.WriteHead(); if(loaded) Logger.Debug("Config loaded."); else Logger.Warn("Unable to load config.txt, using default settings."); if (!Server.Start()){ Console.WriteLine(">>server start fail."); Console.ReadKey(); }else{ Command(Server); } }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Console.CancelKeyPress+= new ConsoleCancelEventHandler(Console_CancelKeyPress); Config = new ServerConfig(); bool loaded = args.Length > 0 ? Config.Load(args[0]): Config.Load(); ChatCommand.WriteHead(Config); if(loaded) Logger.WriteLine("Config loaded."); else Logger.WriteLine("Unable to load config.txt, using default settings."); if(Config.HandShuffle){ Logger.WriteLine("Warning: Hand shuffle requires a custom ocgcore to work."); } int coreport = Config.ServerPort; // // if (args.Length > 0){ // int.TryParse(args[0], out coreport); // if(coreport==0){ // coreport=Config.ServerPort; // }else{ // Config.setValue("serverport", ""+coreport); // if(coreport<=9999){ // Config.setValue("apiport", ""+(10000+coreport)); // } // } // } Random = new Random(); Server server = new Server(); if (!server.Start(coreport)) Thread.Sleep(5000); ThreadPool.SetMaxThreads(128, 256); Thread inputThread=new Thread(new ParameterizedThreadStart(Command)); inputThread.IsBackground=true; inputThread.Start(server); while (server.IsListening) { server.Process(); Thread.Sleep(1); } }
public static void WriteHead(ServerConfig config){ if(config==null){ return; } string Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); Console.Title=(string.IsNullOrEmpty(config.ServerName)?"YgoServer":config.ServerName); Logger.WriteLine("┌───────────────────────────────────",false); Logger.WriteLine("│ __ _______ ____ _____",false); Logger.WriteLine("│ \\ \\ / / ____|/ __ \\ / ____|", false); Logger.WriteLine("│ \\ \\_/ / | __| | | | | ___ _ __ ___", false); Logger.WriteLine("│ \\ /| | |_ | | | | | / _ \\| '__/ _ \\", false); Logger.WriteLine("│ | | | |__| | |__| | |___| (_) | | | __/", false); Logger.WriteLine("│ |_| \\_____|\\____/ \\_____\\___/|_| \\___| Build: " + Version, false); Logger.WriteLine("│", false); Logger.WriteLine("│Client version 0x" + config.ClientVersion.ToString("x") + " or new, MaxRooms = "+config.MaxRoomCount, false); Logger.WriteLine("│NeedAtuh="+config.isNeedAuth+", AutoReplay="+config.AutoReplay +", RecordWin="+config.RecordWin +", BanMode="+config.BanMode, false); Logger.WriteLine("│"+config.ServerDesc,false); Logger.WriteLine("└───────────────────────────────────",false); }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; Config = new ServerConfig(); bool loaded = args.Length > 1 ? Config.Load(args[1]) : Config.Load(); if (Config.SplashScreen == true) { Logger.WriteLine(" __ _______ ____ _____", false); Logger.WriteLine(" \\ \\ / / ____|/ __ \\ / ____|", false); Logger.WriteLine(" \\ \\_/ / | __| | | | | ___ _ __ ___", false); Logger.WriteLine(" \\ /| | |_ | | | | | / _ \\| '__/ _ \\", false); Logger.WriteLine(" | | | |__| | |__| | |___| (_) | | | __/", false); Logger.WriteLine(" |_| \\_____|\\____/ \\_____\\___/|_| \\___| Version: " + Version, false); Logger.WriteLine(string.Empty, false); } Logger.WriteLine("Accepting client version 0x" + Config.ClientVersion.ToString("x") + " or higher."); if (loaded) { Console.WriteLine("Config loaded."); } else { Console.WriteLine("Unable to load config.ini, using default settings."); } int coreport = 0; if (args.Length > 0) { int.TryParse(args[0], out coreport); } Random = new Random(); Server server = new Server(); if (!server.Start(coreport)) { Thread.Sleep(5000); } if (server.IsListening == true && Config.STDOUT == true) { Console.WriteLine("::::network-ready"); } while (server.IsListening) { server.Process(); Thread.Sleep(1); } if (Config.STDOUT == true) { Console.WriteLine("::::network-end"); } if (Config.Recycle == false) { System.Environment.Exit(0); } }