Esempio n. 1
0
        private void RunCommand(string argument)
        {
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var command = commandLine.Argument(0);
                if (command != null)
                {
                }
                else
                {
                    Init();
                    Search();
                }

                string current_group = "";
                if (commandLine.ArgumentCount > 1)
                {
                    current_group = commandLine.Argument(1);
                }
                if (Airlocks != null)
                {
                    Airlocks.ForEach(delegate(Airlock airlock)
                    {
                        if (current_group.Equals("") || airlock.GroupFilter.Contains(current_group))
                        {
                            airlock.RunCommand(argument);
                        }
                    });
                }
            }
        }
            private bool ParseArgs(string args)
            {
                CommandLine.TryParse(args);

                if (CommandLine.Argument(0) == null)
                {
                    return(true);
                }

                bool valid  = false;
                bool result = true;

                if (Commands.Keys.Any(x => x == CommandLine.Argument(0)))
                {
                    if (Commands[CommandLine.Argument(0)].MinumumArguments < CommandLine.ArgumentCount)
                    {
                        result = Commands[CommandLine.Argument(0)].Action(CommandLine);
                        valid  = true;
                    }
                }

                SaveEvent("Command:" + (valid?"":"invalid:") + "\"" + args + "\"");

                return(result);
            }
Esempio n. 3
0
        void Command(MyCommandLine cmd)
        {
            switch (cmd.Argument(1))
            {
            case "help": Owner.Log(Help); break;

            case "amount":
            {
                string name  = cmd.Argument(2);
                bool   found = false;
                foreach (var item in _Stock)
                {
                    if (item.Value.Name.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        found = true;
                        Owner.Log($"{item.Value.Name}: {item.Value.FormatAmount()}");
                    }
                }
                if (!found)
                {
                    Owner.Log("No items found.");
                }
            }; break;

            case "reset":
            {
                Updating = true;
                _Stock.Clear();
                Owner.ScanGrid();
                Owner.Log("Stock reset. Scanning grid...");
            }; break;
            }
        }
Esempio n. 4
0
            /// <summary>
            /// Handler for processing any of the 'trigger' upatetypes
            /// </summary>
            /// <param name="argument"></param>
            /// <param name="updateSource"></param>
            public void ProcessTrigger(MyCommandLine myCommandLine, UpdateType updateSource)
            {
                //                string[] args = argument.Trim().Split(' ');
                if (myCommandLine != null)
                {
                    if (myCommandLine.Argument(0) == "setmode")
                    {
                        int theNewState = 0;
                        if (myCommandLine.Argument(1) != null)
                        {
                            int theNewMode = Convert.ToInt32(myCommandLine.Argument(1));
                            if (myCommandLine.Argument(2) != null)
                            {
                                theNewState = Convert.ToInt32(myCommandLine.Argument(2));
                            }
                            SetMode(theNewMode, theNewState);
                        }
                        else
                        {
                            thisProgram.Echo("Invalid Syntax");
                        }
                    }
                }
                // else no arguments

                /*
                 *              // Debugging/play information
                 *              if (bIAmMain)
                 *              {
                 *                  SendToAllSubscribers(UnicastTagTrigger, argument);
                 *              }
                 *              else thisProgram.Echo("Trigger found, not not master");
                 */
            }
Esempio n. 5
0
        public void Main(string arg, UpdateType updateSource)
        {
            if (_commandLine.TryParse(arg))
            {
                Action commandAction;

                string command = _commandLine.Argument(0);

                if (_commands.TryGetValue(_commandLine.Argument(0), out commandAction))
                {
                    commandAction();
                    message = command + "\n" + message;
                }
                else
                {
                    message = $"Unknown command {command}";
                }
            }

            message = "Drill Deployed:\n" + status["deployed"];

            CheckDeploy();

            Echo(message);
            Echo("\nExecution Time: " + Runtime.LastRunTimeMs.ToString() + "ms");

            Me.GetSurface(0).WriteText(message);
        }
Esempio n. 6
0
        public void Main(string argument, UpdateType updateSource)
        {
            if ((updateSource & ~(UpdateType.Update1 | UpdateType.Update10 | UpdateType.Update100)) != 0)
            {
                if (Cmd.TryParse(argument))
                {
                    switch (Cmd.Argument(0))
                    {
                    case "fly": FlyForward(); break;

                    case "dock": PerformDocking(); break;

                    case "scan": QuickScan(); break;

                    case "halt": QuickHalt(); break;

                    default:
                        Log($"Unknown command: {Cmd.Argument(0)}"); break;
                    }
                }
            }
            if ((updateSource & (UpdateType.Update1 | UpdateType.Update10 | UpdateType.Update100)) != 0)
            {
                if (Pilot.Tasks.Count > 0)
                {
                    Pilot.Update(Runtime.TimeSinceLastRun.TotalSeconds);
                }
                if (Cockpit.IsUnderControl)
                {
                    UpdateShipInfo();
                    UpdateStorageInfo();
                }
            }
        }
Esempio n. 7
0
        public void Main(string argument, UpdateType updateSource)
        {
            // MDK command parsing
            if (_commandLine.TryParse(argument))
            {
                Action commandAction;

                // Retrieve the first argument. Switches are ignored.
                string command = _commandLine.Argument(0);

                // Now we must validate that the first argument is actually specified,
                // then attempt to find the matching command delegate.
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (_commands.TryGetValue(_commandLine.Argument(0), out commandAction))
                {
                    // We have found a command. Invoke it.
                    commandAction();
                }
                else
                {
                    Echo($"Unknown command {command}");
                }
            }
        }
Esempio n. 8
0
        private void ProcessCommand(string command)
        {
            if (Cmd.TryParse(command) && Cmd.ArgumentCount > 0)
            {
                switch (Cmd.Argument(0))
                {
                case "id": Message($"Drone computer IGC ID: 0x{IGC.Me:X}"); break;

                case "start": Start(Cmd.Argument(1)); break;

                case "capture": CaptureScanned(); break;

                case "grind": Grind(); break;

                case "halt": Halt("Warning: drone halted."); break;

                case "reload": Reload(); break;

                case "recall": Recall(); break;

                case "process_message": ProcessUnicast(); break;

                default:
                    Start(command);  break;
                }
            }
        }
Esempio n. 9
0
        public override void Execute(MyCommandLine parser)
        {
            bool rgb = (parser.Argument(1) == "rgb");

            float[] values = new float[3];

            if (rgb && parser.Argument(2).StartsWith("#", COMPARE_TYPE))
            {
                string hexText = parser.Argument(2);

                if (hexText.Length < 7)
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "Invalid HEX color, needs 6 characters after #.", MyFontEnum.Red);
                    return;
                }

                int c = 0;

                for (int i = 1; i < 7; i += 2)
                {
                    values[c++] = Convert.ToInt32(hexText[i].ToString() + hexText[i + 1].ToString(), 16);
                }
            }
            else
            {
                if (parser.ArgumentCount != 5)
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, "Need to specify 3 numbers separated by spaces.", MyFontEnum.Red);
                    return;
                }

                for (int i = 0; i < 3; i++)
                {
                    string arg = parser.Argument(i + 2);
                    if (!float.TryParse(arg, out values[i]))
                    {
                        Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, $"'{arg}' is not a valid number!", MyFontEnum.Red);
                        return;
                    }
                }
            }

            Vector3 colorMask;

            if (rgb)
            {
                colorMask = Utils.RGBToColorMask(new Color(MathHelper.Clamp((int)values[0], 0, 255), MathHelper.Clamp((int)values[1], 0, 255), MathHelper.Clamp((int)values[2], 0, 255)));
            }
            else
            {
                colorMask = Utils.HSVToColorMask(new Vector3(MathHelper.Clamp(values[0], 0f, 360f) / 360.0f, MathHelper.Clamp(values[1], 0f, 100f) / 100.0f, MathHelper.Clamp(values[2], 0f, 100f) / 100.0f));
            }

            PaintMaterial material = new PaintMaterial(colorMask, Main.Palette.GetLocalPaintMaterial().Skin);

            Main.Palette.GrabPaletteFromPaint(material);
        }
Esempio n. 10
0
        /* * * * * * * * * *
        * Main & Commands *
        * * * * * * * * * */

        public void Main(string argument, UpdateType updateSource)
        {
            //shit run every tick
            if ((updateSource & UpdateType.Update1) != 0)
            {
                //if we use the elevator
                if (useElevator && stations != null && stations.Count != 0)
                {
                    for (int i = 0; i < stations.Count; i++)
                    {
                        if (stations[i].Update())
                        {
                            broadcasts.Enqueue("request " + stations[i].name);
                        }
                    }
                }
            }

            //shit with arguments
            if ((updateSource & (UpdateType.Antenna | UpdateType.Trigger | UpdateType.Terminal)) != 0)
            {
                //if arguments are actually given
                if (cline.TryParse(argument))
                {
                    Action cAction;

                    String command = cline.Argument(0);

                    if (command == null)
                    {
                        writeLog("No Command was given!");
                    }
                    else if (commands.TryGetValue(command, out cAction))
                    {
                        cAction();
                    }
                    else
                    {
                        writeLog("Unknown Command: " + command);
                    }
                }
            }

            //at the end of every run we transmit one of the queued messages
            if (antenna != null && broadcasts.Count > 0)
            {
                if (sendable)
                {
                    antenna.TransmitMessage(broadcasts.Dequeue());
                    sendable = false;
                }
                else
                {
                    sendable = true;
                }
            }
        }
Esempio n. 11
0
        public void TogglePatrol()
        {
            bool enable = _commandLine.Argument(1).ToLower() == "enable";

            _patrolEnabled = enable;
            if (_remoteBlock != null && !_patrolEnabled)
            {
                _remoteBlock.FlightMode = FlightMode.OneWay;
            }
        }
Esempio n. 12
0
 public void Main(string argument, UpdateType updateSource)
 {
     subsystemManager.UpdateTime();
     if (commandLine.TryParse(argument))
     {
         subsystemManager.Command(commandLine.Argument(0), commandLine.Argument(1), commandLine.ArgumentCount > 2 ? commandLine.Argument(2) : null);
     }
     else
     {
         subsystemManager.Update(updateSource);
         Echo(subsystemManager.GetStatus());
     }
 }
Esempio n. 13
0
        void Command(MyCommandLine args)
        {
            switch (args.Argument(1))
            {
            case "write": AddLine(args.Argument(2)); break;

            case "clear": Buffer.Clear(); break;

            case "help": Owner.Log(HELP); break;

            default: Owner.Log($"Unknown command: {args.ToString()}"); break;
            }
        }
Esempio n. 14
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (commandLine.TryParse(argument))
            {
                Action action;
                string command = commandLine.Argument(0);

                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (commands.TryGetValue(command, out action))
                {
                    action();
                }
            }

            string[] entries = Storage.Split(';');
            if (entries.Length == 5)
            {
                bool.TryParse(entries[0], out enableAltitude);
                bool.TryParse(entries[1], out enableProximity);
                bool.TryParse(entries[2], out firstRun);

                Enum.TryParse(entries[3], out gearState);

                double.TryParse(entries[4], out previousAltitude);
            }

            Echo("Altitude: " + enableAltitude.ToString());
            Echo("Proximity: " + enableProximity.ToString());

            if (enableProximity)
            {
                SetUpProximity();
            }
            if (enableAltitude)
            {
                SetUpAltitude();
            }

            if (firstRun)
            {
                //Calibrate gearState in case gear has never been deployed before
                List <IMyLandingGear> landingGear = new List <IMyLandingGear>();
                GridTerminalSystem.GetBlocksOfType(landingGear);

                CalibrateGearState(landingGear);
                firstRun = false;
            }
        }
        public bool TryParse(string line)
        {
            bool success = myCommandLine.TryParse(line);

            if (success)
            {
                Subsystem = myCommandLine.Argument(0);
                int index = line.IndexOf(Subsystem);
                line = line.Remove(index, Subsystem.Length);

                success = myCommandLine.TryParse(line);
            }
            return(success);
        }
 /// <summary>
 /// Handler for processing any of the 'trigger' upatetypes
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="updateSource"></param>
 internal void ProcessTrigger(string sArgument, MyCommandLine myCommandLine, UpdateType updateSource)
 {
     if (myCommandLine.ArgumentCount > 1)
     {
         if (myCommandLine.Argument(0) == "setmode")
         {
             int  toMode = 0;
             bool bOK    = int.TryParse(myCommandLine.Argument(1), out toMode);
             if (bOK)
             {
                 SetMode(toMode);
             }
         }
     }
 }
            private bool CMD_evaluate(MyCommandLine commandLine)
            {
                if (commandLine.Argument(1) == "all")
                {
                    foreach (var x in JobNames)
                    {
                        TryRegisterEvaluation(x);
                    }
                }
                else
                {
                    TryRegisterEvaluation(commandLine.Argument(1));
                }

                return(true);
            }
Esempio n. 18
0
        void MessageEntered(string msg, ref bool send)
        {
            try
            {
                if (!msg.StartsWith(MAIN_COMMAND))
                {
                    return;
                }

                if (!argParser.TryParse(msg))
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, $"Couldn't parse command \"{msg}\" for some reason, please report!", MyFontEnum.Red);
                    Log.Error($"Couldn't parse command for some reason. Text entered: \"{msg}\"");
                    return;
                }

                send = false;

                string             alias = argParser.Argument(1) ?? string.Empty;
                CommandHandlerBase handler;

                if (AliasToCommandHandler.TryGetValue(alias, out handler))
                {
                    handler.Execute(argParser);
                }
                else
                {
                    Utils.ShowColoredChatMessage(PaintGunMod.MOD_NAME, $"Unknown command: {MAIN_COMMAND} {alias}", MyFontEnum.Red);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Esempio n. 19
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (_commandLine.TryParse(argument))
            {
                string command = _commandLine.Argument(0);
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (!command.Equals("land") && !command.Equals("scan"))
                {
                    Echo("Wrong command issued, should be 'scan' or 'land'");
                }
                else if (command.Equals("scan"))
                {
                    ExecuteScan();
                }
                else if (command.Equals("land"))
                {
                    ExecuteLanding();
                }
            }

            Echo("Status: " + Status);
            Scan();
            Land();
        }
Esempio n. 20
0
 public override void onCommand(MyCommandLine args)
 {
     if (args.Argument(0) == "reset")
     {
         Counter = 0;
     }
 }
Esempio n. 21
0
            public void ParseCommand(string argument)
            {
                if (_commandLine.TryParse(argument))
                {
                    switch (_commandLine.Argument(0))
                    {
                    case Constants.C_ASSIGN:
                        myProgram.platformController.AddCommandToStack(_commandLine);
                        break;

                    default:
                        myProgram.Echo($"No valid command specified: {_commandLine.Argument(0)}");
                        break;
                    }
                }
            }
Esempio n. 22
0
        public void Main(string argument, UpdateType updateSource)
        {
            if (commandLine.TryParse(argument))
            {
                Action commandAction;

                string command = commandLine.Argument(0);
                if (command == null)
                {
                    Echo("No command specified");
                }
                else if (commands.TryGetValue(command, out commandAction))
                {
                    // We have found a command. Invoke it.
                    commandAction();
                }
                else
                {
                    echoBuilder.AppendLine($"Unknown command {command}");
                }
            }
            else
            {
                echoBuilder.Clear();
                echoBuilder.Append(setupBuilder.ToString());

                Action updateAction;
                if (updates.TryGetValue(currentState, out updateAction))
                {
                    updateAction();
                }

                doDisplay();
            }
        }
Esempio n. 23
0
 public void AddCommandToStack(MyCommandLine _commandLine)
 {
     if (null != _commandLine.Argument(1))
     {
         if (_commandLine.Argument(1).Equals(Constants.P_ON))
         {
             myProgram.isLeakManagementOn = true;
         }
         else if (_commandLine.Argument(1).Equals(Constants.P_OFF))
         {
             myProgram.isLeakManagementOn = false;
         }
         else
         {
             myProgram.Echo("No valid command\n");
         }
     }
 }
Esempio n. 24
0
        private void ProcessCommand(string argument)
        {
            if (CommandLine.TryParse(argument))
            {
                switch (CommandLine.Argument(0).ToLower())
                {
                case "initialize":
                case "init":
                    Output.AppendLine("Reinitializing");
                    Initialize();
                    break;

                default:
                    ProcessAirlockCommand();
                    break;
                }
            }
        }
Esempio n. 25
0
 void SetName(MyCommandLine args)
 {
     if (args.ArgumentCount != 2)
     {
         Echo("Usage: setname <name>"); return;
     }
     Name = args.Argument(1);
     updateMessage();
 }
Esempio n. 26
0
 /// <summary>
 /// Handler for processing any of the 'trigger' upatetypes
 /// </summary>
 /// <param name="argument"></param>
 /// <param name="updateSource"></param>
 public void ProcessTrigger(MyCommandLine myCommandLine, UpdateType updateSource)
 {
     if (myCommandLine != null)
     {
         if (myCommandLine.Argument(0) == "orbitallaunch")
         {
             thisProgram.wicoControl.SetMode(WicoControl.MODE_ORBITALLAUNCH);
         }
     }
 }
Esempio n. 27
0
        public void Main(string argument, UpdateType updateSource)
        {
            debug = SleepMode() ? "sleeping\n" : "working\n";
            if (solarMoving)
            {
                debug += solarRaising ? "solar raising\n" : "solar lowering\n";
            }
            if (drillMoving)
            {
                debug += drillRaising ? "drill raising\n" : "drill lowering\n";
            }

            LCD.GetSurface(0).WriteText(debug);

            if (_commandLine.TryParse(argument))
            {
                Action commandAction;

                string command = _commandLine.Argument(0);

                if (_commands.TryGetValue(_commandLine.Argument(0), out commandAction))
                {
                    commandAction();
                }
                else
                {
                    Echo($"Unknown command {command}");
                }
            }

            if (SleepMode())
            {
                return;
            }
            if (solarMoving)
            {
                SolarToggle();
            }
            else if (drillMoving)
            {
                DrillArmToggle();
            }
        }
Esempio n. 28
0
        private void RunCommand(string argument)
        {
            Init();
            if (argument != null)
            {
                commandLine.TryParse(argument);
                var    command = commandLine.Argument(0);
                string tag     = commandLine.Argument(1);
                switch (command)
                {
                case "prefix":
                    RenamePrefix(tag);
                    break;

                case "unprefix":
                    UnRenamePrefix(tag);
                    break;
                }
            }
        }
 private bool CMD_run(MyCommandLine commandLine)
 {
     if (commandLine.ArgumentCount == 1)
     {
         return(true);
     }
     else
     {
         TryQueueJob(commandLine.Argument(1)); return(true);
     }
 }
            private bool CMD_freq(MyCommandLine commandLine)
            {
                int i;

                if (commandLine.ArgumentCount > 1 && int.TryParse(commandLine.Argument(1), out i))
                {
                    TrySetInterval(i);
                }
                else if (commandLine.ArgumentCount > 2 && int.TryParse(commandLine.Argument(2), out i))
                {
                    if (commandLine.Argument(1) == "all")
                    {
                        TrySetInterval(i);
                    }
                    else
                    {
                        TrySetInterval(i, commandLine.Argument(1));
                    }
                }
                return(true);
            }