예제 #1
0
파일: Program.cs 프로젝트: A2152225/YGOCore
        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();

        }
예제 #2
0
		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);
			}
		}
예제 #3
0
		public static void onCommand(Server server,string cmd){
			if(cmd==null){
				return;
			}
			cmd=cmd.Trim();
			if(cmd=="roomcount"){
				Console.WriteLine(">>room count:"+server.getRoomCount());
			}else if(cmd=="playercount"){
				Console.WriteLine(">>player count:"+server.getPlayerCount());
			}else if(cmd=="cls"){
				Console.Clear();
				WriteHead(Program.Config);
			}else if(cmd=="roomlist"){
				Console.WriteLine(">>count:"+server.getRoomCount());
				string json=server.getRoomJson(true, true);
				Console.WriteLine(json);
				File.WriteAllText("room.json", json);
			}else if(cmd.StartsWith("say ")){
				try{
					int count=server.Say(GameManager.getMessage("[Server] "+cmd.Substring("say ".Length),
					                                            PlayerType.Yellow)).Count;
					Console.WriteLine(">>count:"+count);
				}catch{
					
				}
			}else if(cmd.StartsWith("warring ")){
				try{
					int count =server.Say(GameManager.getMessage("[Server] "+cmd.Substring("warring ".Length),
					                                             PlayerType.Red)).Count;
					Console.WriteLine(">>count:"+count);
				}catch{
					
				}
			}else if(cmd.StartsWith("to ")){
				string[] names=cmd.Split(' ');
				if(names.Length>=2){
					try{
						if(server.Say(GameManager.getMessage("[Server] "+cmd.Substring(("to "+names[1]).Length+1)
						                                     , PlayerType.Yellow)
						              ,names[1]).Count>0){
							Console.WriteLine(">>send to "+names[1]);
						}else{
							Console.WriteLine(">>send fail. no find "+names[1]);
						}
					}catch{
						
					}
				}
			}else if(cmd.StartsWith("config ")){
				string[] args=cmd.Split(' ');
				if(args.Length>=3){
					if(Program.Config.setValue(args[1], args[2])){
						Console.WriteLine(">>"+args[1]+"="+ args[2]);
					}
				}
			}else if(cmd=="reload"){
				server.Reload();
				Console.WriteLine(">>reload ok");
			}else if(cmd=="banlist"){
				if(BanlistManager.Banlists!=null && BanlistManager.Banlists.Count>0){
					Console.WriteLine(">>Banlist = "+BanlistManager.Banlists[0].Name);
				}
			}else if(cmd=="close"){
				Console.WriteLine(">>Server will close after 5 minute.");
				server.CloseDealyed();
			}else if(cmd == "cancel close"){
				Console.WriteLine(">>Server cancel close.");
				server.CacelCloseDealyed();
			}else if(cmd=="addai"){
				try{
					GameRoom room=GameManager.GetRandomGame();
					string _rname=GameManager.RandomRoomName();
					if(room!=null){
						_rname=room.Game.Config.Name;
					}
					if(AddAI(_rname)){
						Console.WriteLine("Add AI success:"+_rname+" "
						                  +(Program.Config.MaxAICount-AIs.Count)+"/"+Program.Config.MaxAICount);
					}else{
						Console.WriteLine("Add AI fail, max="+Program.Config.MaxAICount);
					}
				}catch(Exception){
					
				}
			}else if(cmd=="ai count"){
				Console.WriteLine(">>count " +AIs.Count+"/"+Program.Config.MaxAICount);
			}else if(cmd=="help"){
				Console.WriteLine(">>");
				Console.WriteLine("roomcount		room count");
				Console.WriteLine("playercount		plyaer count");
				Console.WriteLine("cls			clear");
				Console.WriteLine("roomlist		room list json");
				Console.WriteLine("say xxx			text is yellow");
				Console.WriteLine("warring xxx		text is red");
				Console.WriteLine("config {key} {value}   	set key=value");
				Console.WriteLine("load config		reload config,but some config need restart.");
				Console.WriteLine("banlist			look banlist");
				Console.WriteLine("to xxx			send msg to player");
				Console.WriteLine("close			close server");
				Console.WriteLine("cancel close		cancel close server");
				Console.WriteLine("maxai			max Ai count");
				Console.WriteLine("addai			add a AI to random room");
			}
			else{
				Console.WriteLine(">>no this cmd", ConsoleColor.Yellow);
			}
		}