Exemplo n.º 1
0
 protected static void consoleCommand(ConCommand conCommand)
 {
     Lemma.Console.Console.AddConCommand(conCommand);
     WorldFactory.Instance.Add(new CommandBinding(WorldFactory.Instance.Delete, delegate()
     {
         Lemma.Console.Console.RemoveConCommand(conCommand.Name);
     }));
 }
    public static void HandleConCommand(string entry, string[] args = null)
    {
        if (commands.ContainsKey(entry) && !executing)
        {
            executing = true;
            ConCommand command = commands[entry];
            switch (command.type)
            {
            case CommandBackend.CommandType.Cheat:
                if (CommandBackend.allowedCommands < CommandBackend.CommandType.Cheat)
                {
                    PrintOutput("Cheats must be enabled to use this command.");
                }
                else
                {
                    string executedOutput = command.callback.Invoke(args);
                    if (executedOutput != "")
                    {
                        PrintOutput(executedOutput);
                    }
                }
                break;

            case CommandBackend.CommandType.Developer:
                if (CommandBackend.allowedCommands >= CommandBackend.CommandType.Developer)
                {
                    string commandOutput = command.callback.Invoke(args);
                    if (commandOutput != "")
                    {
                        PrintOutput(commandOutput);
                    }
                }
                PrintOutput("This command is only available within the editor.");
                break;

            default:
                string executedCommandOutput = command.callback.Invoke(args);
                if (executedCommandOutput != "")
                {
                    PrintOutput(executedCommandOutput);
                }
                break;
            }
            executing = false;
        }
        else
        {
            PrintOutput("Unknown command!");
        }
    }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            var info = VersionUtils.GetAssemblyNameInfo();

            _isRequestShutdown = false;

            Console.Title = "ZGrid Server";
            Logger.Info($"Starting ZGrid Server {info.Version.Major}.{info.Version.Minor}.{info.Version.MinorRevision} ({info.ProcessorArchitecture}) ...");
            _gridServer = new GridServer();

            ConCommand.Register(_gridServer);

            _mainThread = new Thread(ThreadMain)
            {
                IsBackground = true
            };
            _netThread = new Thread(ThreadNetwork)
            {
                IsBackground = true
            };

            try {
                _gridServer.Init();
                Logger.Info("Server is initialized");
            } catch (Exception e) {
                Logger.Error("Unable to initialize ZGrid Server", e);
                return;
            }

            _mainThread.Start();
            _netThread.Start();

            Logger.Info("Type 'exit' to exit from application");

            string input;

            while (!_isRequestShutdown && (input = Console.ReadLine()) != null)
            {
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                var cmdSelf = input.Contains(' ') ? input.Split(' ')[0] : input;

                var cmd = ConCommand.SearchByName(cmdSelf);
                if (cmd != null)
                {
                    try {
                        cmd.Execute(input.SlitToArgsFrom(1));
                    } catch (Exception e) {
                        Logger.Error($"Unable to execute command {cmd.GetName()}", e);
                    }

                    continue;
                }

                Console.WriteLine($"Unknown command '{cmdSelf}'");
            }

            WaitForThreadJoin(_netThread);
            WaitForThreadJoin(_mainThread);
        }