Example #1
0
        public void GetCommandType2Test()
        {
            Command target = new Command();

            Command.Type expected = Command.Type.Null;
            Command.Type actual;
            actual = target.GetCommandType();
            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void GetCommandTypeTest()
        {
            Command target = new Command("", Command.Type.Search, "", new List <string>());

            Command.Type expected = Command.Type.Search;
            Command.Type actual;
            actual = target.GetCommandType();
            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public SourceCode getSourceCode()
        {
            SourceCode lines   = new SourceCode();
            IntPtr     cur_cmd = m_CodePointer;

            while (cur_cmd != IntPtr.Zero)
            {
                Command.Type cmd_type = getCommandType(cur_cmd);
                if (cmd_type == Command.Type.StackCmd)
                {
                    StackCommand cmd = new StackCommand();
                    cmd.Number = getStackCommandNumber(cur_cmd);
                    cmd.Type   = getStackCommandType(cur_cmd);
                    lines.Commands.Add(cmd);
                }
                else if (cmd_type == Command.Type.ArithmeticCmd)
                {
                    ArithmeticCommand cmd = new ArithmeticCommand();
                    cmd.Type = getArithmeticCommandType(cur_cmd);
                    lines.Commands.Add(cmd);
                }
                else if (cmd_type == Command.Type.HeapCmd)
                {
                    HeapCommand cmd = new HeapCommand();
                    cmd.Type = getHeapCommandType(cur_cmd);
                    lines.Commands.Add(cmd);
                }
                else if (cmd_type == Command.Type.FlowCmd)
                {
                    FlowCommand cmd = new FlowCommand();
                    cmd.Type      = getFlowCommandType(cur_cmd);
                    cmd.LabelName = Marshal.PtrToStringAnsi(getFlowCommandLabelName(cur_cmd));
                    if (cmd.LabelName == null)
                    {
                        cmd.LabelName = " ";
                    }
                    lines.Commands.Add(cmd);
                }
                else if (cmd_type == Command.Type.IOCmd)
                {
                    IOCommand cmd = new IOCommand();
                    cmd.Type = getIOCommandType(cur_cmd);
                    lines.Commands.Add(cmd);
                }


                cur_cmd = getNextCommand(cur_cmd);
            }

            return(lines);
        }
Example #4
0
    public static void ProcessCommand(NetBuffer inCommandBuffer)
    {
        Command.Type commandType = (Command.Type)inCommandBuffer.ReadVariableInt32();

        switch (commandType)
        {
        case Command.Type.SpawnMech:
            new Command.SpawnMech(inCommandBuffer).Execute();
            break;

        case Command.Type.MoveMech:
            new Command.MoveMech(inCommandBuffer).Execute();
            break;

        case Command.Type.EndTurn:
            new Command.EndTurn(inCommandBuffer).Execute();
            break;

        default:
            Debug.LogError("Unknown command recieved. Did you forget to add it to the CommandManager?");
            break;
        }
    }
Example #5
0
        private void UpdateWriteInfo()
        {
            for (int i = 0; i < itb.header.ItemsTotal; i++)
            {
                ushort TrsrID = itb.AllITB[i].TreasureBoxID;

                foreach (TabPage page in ItbTabControl.TabPages)
                {
                    foreach (ItbEntry ent in page.Controls[0].Controls)
                    {
                        if (ent.NumericTreasureBoxID.Value == TrsrID)
                        {
                            itb.AllITB[i].ItemKind = (byte)ent.ItemKindComboBox.SelectedIndex;

                            switch (itb.AllITB[i].ItemKind)
                            {
                            case 0:
                                Item.Type nItem   = (Item.Type)ent.ItemIDComboBox.SelectedItem;
                                ushort    ItemVal = (ushort)nItem;
                                itb.AllITB[i].ItemID = ItemVal;
                                break;

                            case 1:
                                Command.Type nCommand   = (Command.Type)ent.ItemIDComboBox.SelectedItem;
                                ushort       CommandVal = (ushort)nCommand;
                                itb.AllITB[i].ItemID = CommandVal;
                                break;
                            }

                            itb.AllITB[i].ReportID = (byte)ent.NumericReportID.Value;
                            break;
                        }
                    }
                }
            }
        }
Example #6
0
 public static void ProcessCommand(NetIncomingMessage inMsg)
 {
     Command.Type commandType = (Command.Type)inMsg.ReadVariableInt32();
     _serverCommands[commandType].RecieveAndExecute(inMsg);
 }
Example #7
0
 protected Command(Command.Type cmdType)
 {
     _cmdType = cmdType;
 }
Example #8
0
        /// <summary>
        /// Handle Falcom commands. Determine if command is valid,
        /// what is the type of it, and execute (if valid).
        /// </summary>
        /// <param name="input">Falcon command (including cmd char)</param>
        /// <param name="output">Execution result</param>
        /// <returns>Is command valid, Command message, Command Type, On or Off flag</returns>
        public static bool Parse(string cmd, ref string message, ref Command.Type type, ref Argument argumentObj)
        {
            // extract command name and arguments
            string[] cmdArr  = cmd.Split(CMD_SPLITTER);
            string   cmdName = cmdArr[CMD_NAME_INDX];


            bool noArgument = (cmdArr.Length <= 1) ? true : false;

            SshCommand     sshCmd     = new SshCommand();
            PingCommand    pingCmd    = new PingCommand();
            ClearCommand   clearCmd   = new ClearCommand();
            HelpCommand    helpCmd    = new HelpCommand();
            InvalidCommand invalidCmd = new InvalidCommand();

            // return values to caller according to cmd name
            switch (cmdName)
            {
            case "ssh":

                if (noArgument)
                {
                    message = sshCmd.GetNoArgumentMsg();
                    return(false);
                }

                if (cmdArr.Length < 4)
                {
                    message = sshCmd.GetInvalidArgumentMsg();
                    return(false);
                }

                string sshArgs = cmdArr[CMD_ARG_INDX] + " " +
                                 cmdArr[CMD_ARG_INDX + 1] + " " +
                                 cmdArr[CMD_ARG_INDX + 2];

                sshCmd.InitArgument(sshArgs);
                type = sshCmd.GetCommandType();

                if (!sshCmd.IsValidArgument())
                {
                    message = sshCmd.GetInvalidArgumentMsg();
                    return(false);
                }
                argumentObj = sshCmd.GetArgumentObject();
                return(true);

            case "ping":

                if (noArgument)
                {
                    message = pingCmd.GetNoArgumentMsg();
                    return(false);
                }

                pingCmd.InitArgument(cmdArr[CMD_ARG_INDX]);
                type = pingCmd.GetCommandType();

                argumentObj = pingCmd.GetArgumentObject();
                message     = pingCmd.GetSuccessMsg();
                return(true);

            case "clear":
                type    = clearCmd.GetCommandType();
                message = clearCmd.GetSuccessMsg();
                return(true);

            case "help":
                if (noArgument)
                {
                    message = helpCmd.GetNoArgumentMsg();
                    return(false);
                }
                helpCmd.InitArgument(cmdArr[CMD_ARG_INDX]);
                if (!helpCmd.IsValidArgument())
                {
                    message = helpCmd.GetInvalidArgumentMsg();
                    return(false);
                }

                switch (cmdArr[CMD_ARG_INDX])
                {
                case "ssh":
                    message = sshCmd.GetHelpMsg();
                    break;

                case "ping":
                    message = pingCmd.GetHelpMsg();
                    break;

                case "clear":
                    message = clearCmd.GetHelpMsg();
                    break;

                case "help":
                    message = helpCmd.GetHelpMsg();
                    break;
                }
                break;

            default:
            {
                invalidCmd.InitArgument(cmd);
                type    = invalidCmd.GetCommandType();
                message = invalidCmd.GetInvalidArgumentMsg();
                break;
            }
            }
            return(false);
        }
        /// <summary>
        /// Parse and execute command line
        /// </summary>
        /// <param name="commandLine">Falcon command line string</param>
        private void ExecuteCli(string commandLine)
        {
            // ignore empty command line
            if (commandLine == "")
            {
                PrintLinePrefix();
                return;
            }

            historyBuff.ResetNavigation();
            historyBuff.AddItem(commandLine);

            if (displayMode == DisplayMode.SSH)
            {
                ssh_.RunCommand(commandLine);
                if (commandLine == "exit")
                {
                    ssh_.Close();
                    PrintToScreen("ssh session terminated.", Color.White, true);
                    ssh_        = null;
                    displayMode = DisplayMode.NORMAL;
                }
                return;
            }

            Argument argumentObj  = null;
            string   reply        = "";
            string   parserAnswer = "";

            Command.Type cmdType = Command.Type.INVALID;
            bool         validCmd;

            validCmd = CommandParser.Parse(commandLine, ref parserAnswer, ref cmdType, ref argumentObj);

            if (validCmd)
            {
                switch (cmdType)
                {
                case Command.Type.PING:
                    string targetIp = ((PingArgument)argumentObj).GetIp();
                    int    timeout  = ((PingArgument)argumentObj).GetTimeout();

                    if (timeout != -1)     // use timeout
                    {
                        Pinger.Ping(targetIp, timeout, ref reply);
                    }
                    else     // disable timeout
                    {
                        Pinger.Ping(targetIp, 0, ref reply);
                    }

                    break;

                case Command.Type.SSH:
                    bool success = ConnectSsh(((SshArgument)argumentObj).GetHostAddress(),
                                              ((SshArgument)argumentObj).GetUserName(),
                                              ((SshArgument)argumentObj).GetPassword(),
                                              ref reply,
                                              ref ssh_);
                    if (success)
                    {
                        displayMode = DisplayMode.SSH;
                    }
                    break;

                case Command.Type.CLEAR:
                    cliDisplayTxtBx.Text = "";
                    break;

                case Command.Type.INVALID:
                    break;
                }
            }

            if (parserAnswer != "")
            {
                PrintToScreen(parserAnswer + "\n", Color.White, true);
            }
            if (reply != "")
            {
                PrintToScreen(reply + "\n", Color.White, true);
            }

            PrintLinePrefix();
        }
Example #10
0
 public HandlesCommand(Command.Type typeToHandle)
 {
     this.TypeHandled = typeToHandle;
 }