public bool Start() { if (IsListening) { return(true); } IsListening = true; Config.Load(); //本地api InitDeulListener(); try { m_apilistener.Start(); } catch (Exception e) { Logger.Error(e); } if (Config.Ports != null) { foreach (int port in Config.Ports) { ServerProcess server = new ServerProcess(port, Config.ApiPort, Config.ServerExe, Config.Config); server.Start(); Porcess.Add(server); } } else { Logger.Error("no configs"); } InitRoomListener(); try { m_listener.Start(); } catch (Exception e) { Logger.Error(e); Stop(); } if (IsListening) { infoTimer.Start(); } return(IsListening); }
public static void OnCommand(this RoomServer server, string cmd, bool tip = true) { if (cmd == null) { return; } cmd = cmd.Trim(); string[] args = cmd.Split(new char[] { ' ' }, 2); switch (args[0]) { case "say": if (args.Length > 1) { server.Tip = args[1]; server.Message(args[1]); Console.WriteLine(">>say ok"); } else { Console.WriteLine(">>say fail"); } break; case "server": if (args.Length > 1) { int i = 0; int.TryParse(args[1], out i); //Service information, number of players and number of rooms server.PrintServer(i); } else { //The number of server.PrintServer(); } break; case "hide": if (args.Length > 1) { int i = 0; int.TryParse(args[1], out i); //Service information, number of players and number of rooms lock (server.Porcess) { if (i < server.Porcess.Count) { ServerProcess p = server.Porcess[i]; Console.WriteLine(">>hide " + i + " => " + p.Hide()); } } } else { //The number of Console.WriteLine(">>hide %1"); } break; case "show": if (args.Length > 1) { int i = 0; int.TryParse(args[1], out i); //Service information, number of players and number of rooms lock (server.Porcess) { if (i < server.Porcess.Count) { ServerProcess p = server.Porcess[i]; Console.WriteLine(">>show " + i + " => " + p.Show()); } } } else { //The number of Console.WriteLine(">>show %1"); } break; case "close": if (args.Length > 1) { int i = 0; int.TryParse(args[1], out i); //Service information, number of players and number of rooms lock (server.Porcess){ if (i < server.Porcess.Count) { ServerProcess p = server.Porcess[i]; Console.WriteLine(">>close " + i + ":" + p.Port); p.Close(); server.Porcess.Remove(p); } } } else { //The number of server.Stop(); } break; case "help": Console.WriteLine(">>server %1 View all server information"); Console.WriteLine(">>say %1 View all server information"); Console.WriteLine(">>hide %1 View all server information"); Console.WriteLine(">>show %1 View all server information "); Console.WriteLine(">>close %1 shutdown server"); break; default: if (tip) { Console.WriteLine(">>no invalid:" + cmd); } break; } }