123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using CommonAI.Zone.Instance;
- using CommonLang;
- using CommonLang.Property;
- using CommonServer.Command;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XmdsCommon.Plugin;
- using XmdsCommonServer.Plugin;
- using XmdsServerNode.Node;
- namespace XmdsServerTest.Server
- {
- public class NodeTestConsoleCommands : CommandList<NodeTestConsoleCommands.Cmd>
- {
- public static NodeTestConsoleCommands Instance { get; private set; }
- public NodeTestConsoleCommands()
- {
- Instance = this;
- }
- public void Run()
- {
- Console.WriteLine("使用cmdlist列出所有指令");
- while (NodeTestServer.Instance.Running)
- {
- string input = Console.In.ReadLine();
- if (!DoCommand(input, Console.Out))
- {
- Console.WriteLine();
- Console.WriteLine("未知的命令:" + input);
- Console.WriteLine("使用cmdlist列出所有指令");
- }
- else
- {
- Console.WriteLine();
- }
- }
- }
- // -------------------------------------------------------------------------------------------------
- public abstract class Cmd : AbstractCommand
- {
- }
- [DescAttribute("列出所有命令")]
- public class CMD_LIST : Cmd
- {
- public override string Key { get { return "cmdlist"; } }
- public override string Help
- {
- get
- {
- return
- "列出所有命令\n" +
- " cmdlist 列出所有控制台命令\n" +
- " cmdlist [前缀] 列出所有前缀相符的控制台命令";
- }
- }
- public override void DoCommand(string arg, TextWriter output)
- {
- output.WriteLine(NodeTestConsoleCommands.Instance.ListCommand(arg));
- }
- }
- [DescAttribute("关闭服务器")]
- public class CMD_EXIT : Cmd
- {
- public override string Key { get { return "exit"; } }
- public override void DoCommand(string arg, TextWriter output)
- {
- NodeTestServer.Instance.Shutdown();
- }
- }
- [DescAttribute("清理内存")]
- public class CMD_GC : Cmd
- {
- public override string Key { get { return "gc"; } }
- public override void DoCommand(string arg, TextWriter output)
- {
- GC.Collect();
- // GC.WaitForFullGCComplete();
- // GC.WaitForPendingFinalizers();
- output.WriteLine(string.Format("场景实例数 = {0}/{1}", InstanceZone.ActiveZoneCount, InstanceZone.AllocZoneCount));
- output.WriteLine(string.Format("单位实例数 = {0}/{1}", InstanceZoneObject.ActiveObjectCount, InstanceZoneObject.AllocObjectCount));
- output.WriteLine(string.Format("ZoneNode.PlayerClient = {0}/{1}", ServerZoneNode.PlayerClient.ActiveCount, ServerZoneNode.PlayerClient.AllocCount));
- output.WriteLine(string.Format("ZoneNode.ZoneNodePlayer = {0}", ServerZoneNode.ZoneNodePlayer.AllocCount));
- output.WriteLine(string.Format("AppSessionPlayer = {0}", AppSessionPlayer.AllocCount));
- output.WriteLine(string.Format("XmdsBuffVirtual = {0}/{1}", XmdsBuffVirtual.AllocCount, XmdsBuffVirtual.ActiveCount));
- output.WriteLine(string.Format("XmdsVirtual = {0}", XmdsVirtual.AllocCount));
- using(var blist = ListObjectPool<XmdsBuffVirtual>.AllocAutoRelease())
- {
- foreach(var bf in ZoneNodeManager.Templates.Templates.getAllBuffs())
- {
- var zb = (bf.Properties as XmdsBuffProperties);
- blist.AddRange(zb.GetBuffVirtualList());
- }
- output.WriteLine(string.Format("XmdsBuffVirtual.Templates = {0}", blist.Count));
- }
- output.WriteLine(string.Format("HEAP = {0}", CUtils.ToBytesSizeString(GC.GetTotalMemory(false))));
- }
- }
- [DescAttribute("添加测试场景")]
- public class CMD_ADD_TEST_SCENE : Cmd
- {
- public override string Key { get { return "add"; } }
- public override string Help
- {
- get
- {
- return
- "添加测试场景\n" +
- " add [场景ID] [数量]";
- }
- }
- public override void DoCommand(string arg, TextWriter output)
- {
- var args = ToArgs(arg);
- if (args.Length >= 2)
- {
- var sceneID = int.Parse(args[0]);
- var count = int.Parse(args[1]);
- for (int i = 0; i < count; i++)
- {
- var node = NodeTestServer.Instance.AddTestScene(sceneID);
- Console.WriteLine(string.Format("node {0} : {1} added", node.UUID, node));
- }
- }
- else if (args.Length >= 1)
- {
- var sceneID = int.Parse(args[0]);
- var node = NodeTestServer.Instance.AddTestScene(sceneID);
- Console.WriteLine(string.Format("node {0} : {1} added", node.UUID, node));
- }
- }
- }
- [DescAttribute("添加所有测试场景")]
- public class CMD_ADD_ALL_SCENE : Cmd
- {
- public override string Key { get { return "addall"; } }
- public override string Help
- {
- get
- {
- return
- "添加所有测试场景\n" +
- " addall";
- }
- }
- public override void DoCommand(string arg, TextWriter output)
- {
- foreach (var sceneID in ZoneNodeManager.Templates.ListScenes())
- {
- var node = NodeTestServer.Instance.AddTestScene(sceneID);
- Console.WriteLine(string.Format("node {0} : {1} added", node.UUID, node));
- }
- }
- }
- [DescAttribute("列出所有场景")]
- public class CMD_LIST_SCENES : Cmd
- {
- public override string Key { get { return "ls"; } }
- public override void DoCommand(string arg, TextWriter output)
- {
- var list = NodeTestServer.Instance.ListZoneNodes();
- foreach (var node in list)
- {
- Console.WriteLine(string.Format("node {0} : {1} Player={2}", node.UUID, node, node.PlayerCount));
- }
- }
- }
- }
- }
|