private static void Command(GameServer server){ string cmd=""; while(server.IsListening){ cmd=Console.ReadLine(); server.OnCommand(cmd); } }
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); } }
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); } }
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"); } }
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; } }
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"); }