示例#1
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);
     }
 }