Esempio n. 1
0
		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);
			}
		}