static void Postfix()
        {
            new Thread(delegate()
            {
                try
                {
                    var line = string.Empty;
                    while (line != "exit" && line != "stop")
                    {
                        line = Console.ReadLine() ?? string.Empty;
                        line = line.Trim();

                        IEvent evt = new ConsoleInputEvent(line);
                        EventManager.CallEvent(ref evt);
                    }

                    var startupType = Assembly.GetEntryAssembly().GetType("Eco.Server.Startup");
                    var fi          = startupType.GetField("ShutDowned", BindingFlags.Static | BindingFlags.NonPublic);
                    var ShutDowned  = fi.GetValue(null) as ManualResetEvent;
                    ShutDowned.Set();
                }
                catch (Exception e)
                {
                    Log.WriteLine(Localizer.DoStr("Caught an exception checking for console input, console input disabled. (probably safe to ignore)"));
                    Log.WriteLine(Localizer.DoStr(e.Message));
                }
            })
            {
                IsBackground = true,
                Name         = "Asphalt Input Thread"
            }.Start();
        }
        /// <summary>
        /// Starts the read loop for command-line input.
        /// </summary>
        public void StartReading()
        {
            new Thread(() => {
                while (true)
                {
                    var consoleKeyInfo = Console.ReadKey();

                    if (consoleKeyInfo.Key == ConsoleKey.Escape)
                    {
                        CurrentInput = "";
                        continue;
                    }

                    if (consoleKeyInfo.Key == ConsoleKey.Backspace)
                    {
                        if (CurrentInput.Length > 0)
                        {
                            for (var i = 0; i < CurrentInput.Length; i++)
                            {
                                Console.Write(" ");
                            }

                            CurrentInput = CurrentInput.Substring(0, CurrentInput.Length - 1);
                        }

                        ResetCursor();
                        Console.Write(CurrentInput);

                        continue;
                    }

                    if (consoleKeyInfo.Key == ConsoleKey.Enter)
                    {
                        Clear();

                        var input    = CurrentInput;
                        CurrentInput = "";

                        ConsoleInputEvent?.Invoke(input);

                        continue;
                    }

                    CurrentInput += consoleKeyInfo.KeyChar;

                    ResetCursor();
                    Console.Write(CurrentInput);
                }
                // ReSharper disable once FunctionNeverReturns
            }).Start();
        }
        public void OnConsoleInput(ConsoleInputEvent evt)
        {
            string text = evt.Text + " ";

            string command    = text.Substring(0, text.IndexOf(" "));
            string parameters = text.Substring(text.IndexOf(" ")).Trim();

            switch (command.ToLower())
            {
            case "say":
            {
                ChatManager.ServerMessageToAll(new LocString($"<i>[CONSOLE]</i>  <color=red><size=30><b>{parameters}</b></size></color>"), false, DefaultChatTags.Notifications, ChatCategory.Default);
                Console.WriteLine("[CONSOLE] " + parameters);
                break;
            }

            case "online":
            {
                foreach (User u in UserManager.OnlineUsers)
                {
                    Console.WriteLine(u.Name);
                }
                Console.WriteLine(UserManager.OnlineUsers.Count() + " players online");
                break;
            }

            case "whois":
            {
                Whois(parameters);
                break;
            }

            case "admin":
            {
                Admin(parameters);
                break;
            }

            case "save":
            {
                StorageManager.SaveAndFlush();
                break;
            }
            }
        }
Beispiel #4
0
        public void HandleOutputEvent(ConsoleInputEvent inputEvent)
        {
            string outputText = inputEvent.ConsoleInputText;

            if (outputText.StartsWith("plugin"))
            {
                outputText = outputText.Replace("plugin", "");
                FindPluginInFolder(outputText);
                Application.Current.Dispatcher.Invoke(
                    InitializePlugins);
            }
            else if (outputText.StartsWith("plugins"))
            {
                outputText = outputText.Replace("plugins", "");
                FindPlugins(outputText);
                Application.Current.Dispatcher.Invoke(
                    InitializePlugins);
            }
        }
Beispiel #5
0
        public void HandleOutputEvent(ConsoleInputEvent inputEvent)
        {
            string input = inputEvent.ConsoleInputText;

            if (!inputEvent.ConsoleInputText.StartsWith("context"))
            {
                return;
            }

            string[] parts = input.Split(' ');
            if (parts[1].Equals("load"))
            {
                LoadContext();
            }
            else if (parts[1].Equals("save"))
            {
                SaveContext();
            }
            else if (parts[1].Equals("view"))
            {
                PrintContext();
            }
        }
Beispiel #6
0
        public void HandleOutputEvent(ConsoleInputEvent inputEvent)
        {
            string outputText = inputEvent.ConsoleInputText;

            string[] args = outputText.Split(' ');
            if (outputText.StartsWith("plugin") && args[1].Trim().Equals("restore"))
            {
                RestorePlugins();
            }
            else if (outputText.StartsWith("plugin"))
            {
                outputText = outputText.Replace("plugin", "");
                FindPluginInFolder(outputText);
                Application.Current.Dispatcher.Invoke(
                    InitializePlugins);
            }
            else if (outputText.StartsWith("plugins"))
            {
                outputText = outputText.Replace("plugins", "");
                FindPlugins(outputText);
                Application.Current.Dispatcher.Invoke(
                    InitializePlugins);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Fires the <seealso cref="ConsoleInputEvent"/> event
 /// </summary>
 /// <param name="inputCommand">The user input</param>
 protected void OnConsoleInputEvent(string inputCommand)
 {
     ConsoleInputEvent?.Invoke(this, inputCommand);
 }
Beispiel #8
0
    private void ProcessCommand(String text)
    {
        //Spilt all the words that are sent for precessing and strip any empty strings
        string[] argumentsString = text.Split(" ", false);

        if (argumentsString.Length <= 0)
        {
            return;
        }

        String commandWord = argumentsString[0];

        //We remove the first element from the arguments array as it was the command
        argumentsString = argumentsString.Skip(1).ToArray();

        foreach (var command in commandHandler.ValidCommands)
        {
            //If we do not find the command word in the llist we notify the user that it does not exist
            if (command.Key == commandWord)
            {
                //If the nummber of arguments passed are not the same as needed then we give an error reply
                if (command.Value.Count == argumentsString.Length)
                {
                    //if this argument is set to false some of the arguments are incorrect and the method will not be called
                    bool argumentTypesCorrect = true;
                    //Run through all the arguments in the string and check if they corespond with what the method is looking for
                    for (int i = 0; i < argumentsString.Length - 1; i++)
                    {
                        //Here we check if all the arguments are valid types
                        if (!CheckType(argumentsString[i], command.Value[i]))
                        {
                            argumentTypesCorrect = false;
                        }
                    }
                    //If all checks passed we call the method
                    if (argumentTypesCorrect)
                    {
                        //Converted arguments to a godot array to inject it into callv
                        Godot.Collections.Array argumentsArray = new Godot.Collections.Array();

                        foreach (String argument in argumentsString)
                        {
                            argumentsArray.Add(argument);
                        }
                        commandHandler.Callv(commandWord, argumentsArray);

                        ConsoleInputEvent consoleInput = new ConsoleInputEvent();
                        //Populate the event message with info here
                        consoleInput.FireEvent();
                    }
                    else
                    {
                        OutputText("Arguments are of the wrong type");
                        foreach (var argument in command.Value)
                        {
                            OutputText(argument.ToString());
                        }
                    }
                }
                else
                {
                    OutputText("Number of command arguments not correct, looking for:");
                    foreach (var argument in command.Value)
                    {
                        OutputText(argument.ToString());
                    }
                }
                //Breaks out of the loop where it looks for valid commands when a vaid command is found, if we dont it keeps looking and gives errors
                break;
            }
            else if (command.Equals(commandHandler.ValidCommands.Last()))
            {
                OutputText("Command not recognised: " + commandWord);
            }
        }
        //Output the commands to the output text box
        OutputText(text);
    }