Пример #1
0
 public void InputLoop()
 {
     while (_threadRunning)
     {
         _waitingForInput = true;
         var input = Console.ReadLine();
         _waitingForInput = false;
         var result = HandleCommand(new Command(input));
         if (result.Info != "")
         {
             LogPort.Debug(result.Info);
         }
     }
 }
Пример #2
0
        private void InitBuiltinCommands()
        {
            _commands.RegisterCommand("help", new CommandInfo("internal", "Help"),
                                      cmd =>
            {
                var helpString = "\nAvailable commands:\n";
                foreach (var command in _commands.GetCommandMap())
                {
                    helpString += command.Key + " - " + command.Value.Key.Author
                                  + " : " + command.Value.Key.Help + "\n";
                }

                return(new CommandExecuteStat(true, helpString));
            });

            _commands.RegisterCommand("server.stop", new CommandInfo("internal", "Stop the server."),
                                      cmd =>
            {
                Services.Get <Server>("Game.Server").Stop();
                LogPort.Debug("Server RPC stopped.");
                _commands.SetRunningStatus(false);
                return(new CommandExecuteStat(true, ""));
            });

            _commands.RegisterCommand("server.ups", new CommandInfo("internal", "Show the ups."),
                                      cmd =>
            {
                // TODO: AddReadOnlyTask UPS counter for server
                return(new CommandExecuteStat(true, "[Server UPS counter not finished yet!]"));
            });

            _commands.RegisterCommand("server.connections", new CommandInfo("internal", "Count Connections."),
                                      cmd =>
            {
                LogPort.Debug($"{Services.Get<Server>("Game.Server").CountConnections()}");
                return(new CommandExecuteStat(true, ""));
            });

            _commands.RegisterCommand("chunks.count",
                                      new CommandInfo("internal", "Show how many chunks are loaded"),
                                      cmd =>
            {
                var ret    = "Chunks loaded: ";
                long sum   = 0;
                var worlds = ChunkService.Worlds;
                foreach (var world in worlds)
                {
                    ret += $"\n{world.Id} {world.Name} :\t{world.GetChunkCount()}";
                    sum += world.GetChunkCount();
                }

                return(new CommandExecuteStat(true,
                                              ret + $"\nTotal: {worlds.Count} worlds loaded, {sum} chunks loaded"));
            });

            _commands.RegisterCommand("system.gc", new CommandInfo("internal", "Collect Garbage"),
                                      cmd =>
            {
                GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                GC.Collect();
                GC.WaitForFullGCComplete();
                LogPort.Debug("GC Completed");
                return(new CommandExecuteStat(true, ""));
            });
        }