예제 #1
0
		private static void Command(GameServer server){
			string cmd="";
			while(server.IsListening){
				cmd=Console.ReadLine();
				server.OnCommand(cmd);
			}
		}
예제 #2
0
		public static void OnServerInfo(GameServer server){
			ServerConfig Config = server.Config;
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.Info);
				writer.Write(Config.ServerPort);
				writer.Write(Config.isNeedAuth);
				Send(writer.Content);
			}
		}
예제 #3
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);
			}
		}
예제 #4
0
		private static void AddAI(GameServer Server){
			string name = null;
			GameRoom room = RoomManager.CreateOrGetGame(GameConfigBuilder.Build(""));
			if(room == null && room.Config!=null){
				name = RoomManager.RandomRoomName();
			}else{
				name = room.Config.Name;
			}
			if(AddAI(Server.Config, ""+name)){
				Console.WriteLine(">>add ai to "+name);
			}else{
				Console.WriteLine(">>add ai fail");
			}
		}
예제 #5
0
		private static void AICmd(GameServer Server,string[] args){
			switch(args[1]){
				case "add":
					AddAI(Server);
					break;
				case "kill":
					KillAIs();
					break;
				default:
					lock(AIs)
						Console.WriteLine(">>AI count:"+AIs.Count);
					break;
			}
		}
예제 #6
0
		public RoomServer(GameServer server,int port): base(port) {
			this.server=server;
			json=new string[4];
			lastTime=new int[4];
			Logger.Info("Room List = http://{your ip}:"+port+"/room.json");
		}