private async Task ExecAlignCommand(SubCommand aCommand, TeleporterPermission aPermission, ChatInfo info, Dictionary <string, string> args)
        {
            Log($"**HandleEmpyrionTeleporter {info.type}:{info.msg} {args.Aggregate("", (s, i) => s + i.Key + "/" + i.Value + " ")}", LogLevel.Message);

            if (info.type != (byte)ChatType.Faction)
            {
                return;
            }

            switch (aCommand)
            {
            case SubCommand.Help:       DisplayHelp(info.playerId); break;

            case SubCommand.Back: await ExecTeleportPlayerBack(info.playerId); break;

            case SubCommand.Delete: await DeleteTeleporterRoutes(info.playerId, getIntParam(args, "SourceId"), getIntParam(args, "TargetId")); break;

            case SubCommand.List: await ListTeleporterRoutes(info.playerId, getIntParam(args, "Id")); break;

            case SubCommand.ListAll: await ListAllTeleporterRoutes(info.playerId); break;

            case SubCommand.CleanUp: await CleanUpTeleporterRoutes(info.playerId); break;

            case SubCommand.Save: await SaveTeleporterRoute(info.playerId, aPermission, getIntParam(args, "SourceId"), getIntParam(args, "TargetId")); break;

            case SubCommand.Teleport: await TeleportPlayer(info.playerId); break;
            }
        }
Esempio n. 2
0
 public bool RegisterSubCommand(SubCommand Command)
 {
     SubCommand sc = GetSubCommand(Command.Name);
     if (sc != null) return false;
     SubCommandList.Add(Command);
     return true;
 }
Esempio n. 3
0
        public void SubCommandSectionFooter()
        {
            // Given
            var logger     = new StringBuilderLogger();
            var subCommand = new SubCommand()
                             .RegisterSubCommand(new KatasCommand())
            ;
            var root = new DefaultCommand()
                       .RegisterSubCommand(subCommand)
                       .Use(logger)
            ;

            // When
            var result = root.Execute("sub", "help");

            // Then
            Assert.That(result, Is.EqualTo(0), logger.ErrorBuilder.ToString());

            var lines = logger.InfoBuilder.ToString()
                        .Split('\n')
                        .Select(row => row.Replace("\r", ""))
                        .SkipUntil(row => row == "To get help for subcommands")
                        .ToArray()
            ;

            var i = -1;

            lines[++i].Trim().ShouldBe("To get help for subcommands");
            lines[++i].Trim().ShouldBe("sub help <subcommand>");
        }
Esempio n. 4
0
 void ICapiSerializable.Read(BinaryReader reader) {
     _totalLength = reader.ReadInt16();
     _appID = reader.ReadInt16();
     _command = (Command)reader.ReadByte();
     _scommand = (SubCommand)reader.ReadByte();
     _number = reader.ReadInt16();
 }
        private async Task ExecCommand(SubCommand aCommand, ChatInfo info, Dictionary <string, string> args)
        {
            try
            {
                Log($"**HandleEmpyrionChatAutoTranslate {info.type}#{aCommand}:{info.msg} {args.Aggregate("", (s, i) => s + i.Key + "/" + i.Value + " ")}", LogLevel.Message);

                if (info.type != (byte)ChatType.Faction)
                {
                    return;
                }

                switch (aCommand)
                {
                case SubCommand.Help: await DisplayHelp(info.playerId, ""); break;

                case SubCommand.Set: await SetTranslation(info.playerId, args["language"]); break;

                case SubCommand.Box: await Translate(info.playerId, args["text"]); break;

                case SubCommand.Clear: await ClearTranslation(info.playerId); break;

                case SubCommand.ListAll: await ListAllChatAutoTranslates(info.playerId); break;
                }
            }
            catch (Exception error)
            {
                Log($"ExecCommand: {error}", LogLevel.Error);
            }
        }
        private async Task ExecCommand(SubCommand aCommand, ChatInfo info, Dictionary <string, string> args)
        {
            Log($"**HandleEmpyrionPassenger {info.type}#{aCommand}:{info.msg} {args.Aggregate("", (s, i) => s + i.Key + "/" + i.Value + " ")}", LogLevel.Message);

            if (info.type != (byte)ChatType.Faction)
            {
                return;
            }

            switch (aCommand)
            {
            case SubCommand.Help: await DisplayHelp(info.playerId); break;

            case SubCommand.Back: await ExecTeleportPlayerBack(info.playerId); break;

            case SubCommand.Delete: await DeletePassengers(info.playerId, getIntParam(args, "ID")); break;

            case SubCommand.List: await ListTeleporterRoutes(info.playerId, getIntParam(args, "ID")); break;

            case SubCommand.ListAll: await ListAllPassengers(info.playerId); break;

            case SubCommand.CleanUp: await CleanUpTeleporterRoutes(info.playerId); break;

            case SubCommand.Save: await SavePassengersDestination(info.playerId, getIntParam(args, "ID")); break;

            case SubCommand.Teleport: await TeleportPlayer(info.playerId); break;
            }
        }
        public Type GetValue(Command command, SubCommand subcommand)
        {
            Type type;

            TryGetValue(new MessageIdentity(command, subcommand), out type);
            return(type);
        }
Esempio n. 8
0
    /**End Arg Update*/
    public void UpdateSubCommand(SubCommand.Code newSubCode)
    {
        DestructSubCMD();
        switch (newSubCode)
        {
        case SubCommand.Code.Boss:
            subCommandRef = (Instantiate(Resources.Load("BossCMDPrefab", typeof(SubCommand))) as SubCommand);
            break;

        case SubCommand.Code.Distrust:
            subCommandRef = (Instantiate(Resources.Load("DistrustCMDPrefab", typeof(SubCommand))) as SubCommand);
            break;

        case SubCommand.Code.Zero:
            subCommandRef = (Instantiate(Resources.Load("ZeroCMDPrefab", typeof(SubCommand))) as SubCommand);
            break;

        case SubCommand.Code.One:
            subCommandRef = (Instantiate(Resources.Load("OneCMDPrefab", typeof(SubCommand))) as SubCommand);
            break;
        }
        subCommandRef.transform.SetParent(transform);
        subCommandRef.transform.localPosition = new Vector2(80.0f, 0.0f);
        foreach (Transform child in subCommandRef.transform)
        {
            child.gameObject.SetActive(false);
        }
    }
Esempio n. 9
0
        public void HelpForSubSubCommands()
        {
            // Given
            var logger     = new StringBuilderLogger();
            var subCommand = new SubCommand()
                             .RegisterSubCommand(new KatasCommand())
            ;
            var root = new DefaultCommand()
                       .RegisterSubCommand(subCommand)
                       .Use(logger)
            ;

            // When
            var result = root.Execute("sub", "katas", "help");

            // Then
            Assert.That(result, Is.EqualTo(0), logger.ErrorBuilder.ToString());

            var lines = logger.InfoBuilder.ToString()
                        .Split('\n')
                        .Where(row => !string.IsNullOrWhiteSpace(row))
                        .Select(row => row.Replace("\r", ""))
                        .ToArray()
            ;

            var i = -1;

            lines[++i].Trim().ShouldBe("This command is intended for demonstration purposes. It provides some katas");
        }
Esempio n. 10
0
 void ICapiSerializable.Read(BinaryReader reader)
 {
     _totalLength = reader.ReadInt16();
     _appID       = reader.ReadInt16();
     _command     = (Command)reader.ReadByte();
     _scommand    = (SubCommand)reader.ReadByte();
     _number      = reader.ReadInt16();
 }
Esempio n. 11
0
        public void TestSubRegRegMismatch10()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.DX], P[PET.Comma], P[PET.CL]
            };
            var command = new SubCommand(tokens, OperandsSetType.RR);

            runExpectedExceptionTest(command);
        }
Esempio n. 12
0
        public void TestSubMemRegMismatch10()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.WordMemCell], P[PET.Comma], P[PET.CH]
            };
            var command = new SubCommand(tokens, OperandsSetType.MR);

            runExpectedExceptionTest(command);
        }
Esempio n. 13
0
        public void TestSubMemImMismatch()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.ByteMemCell], P[PET.Comma], P[PET.WordConst]
            };
            var command = new SubCommand(tokens, OperandsSetType.MI);

            runExpectedExceptionTest(command);
        }
Esempio n. 14
0
        public void TestSubRegMemMismatchIdLabel()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.AH], P[PET.Comma], P[PET.Label1]
            };
            var command = new SubCommand(tokens, OperandsSetType.RM);

            runExpectedExceptionTest(command);
        }
Esempio n. 15
0
 public void AddSubCmd(SubCommand cmd)
 {
     cmd.m_parentCmd = this;
     cmd.Initialize();
     foreach (string aliase in cmd.Aliases)
     {
         m_subCommands[aliase] = cmd;
         m_subCommandSet.Add(cmd);
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Returns the SubCommand, following the given set of aliases through the SubCommand structure.
        /// </summary>
        public SubCommand SelectSubCommand(StringStream cmdString)
        {
            SubCommand subCommand = SelectSubCommand(cmdString.NextWord());

            if (subCommand != null && subCommand.SubCommands.Count > 0 && cmdString.HasNext)
            {
                return(subCommand.SelectSubCommand(cmdString));
            }
            return(subCommand);
        }
Esempio n. 17
0
        public void TestSubMemIm00()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.ByteMemCell], P[PET.Comma], P[PET.ByteConst]
            };
            var command = new SubCommand(tokens, OperandsSetType.MI);

            runTest(command, new List <byte[]> {
                new byte[] { 0x80, 0x2E, 0x00, 0x00, 0x64 }
            });
        }
Esempio n. 18
0
        public void TestSubRegIm11()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.DX], P[PET.Comma], P[PET.WordConst]
            };
            var command = new SubCommand(tokens, OperandsSetType.RI);

            runTest(command, new List <byte[]> {
                new byte[] { 0x81, 0xEA, 0x10, 0x27 }
            });
        }
Esempio n. 19
0
        public void TestSubRegIm10()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.CX], P[PET.Comma], P[PET.ByteConst]
            };
            var command = new SubCommand(tokens, OperandsSetType.RI);

            runTest(command, new List <byte[]> {
                new byte[] { 0x83, 0xE9, 0x64 }
            });
        }
Esempio n. 20
0
        public void TestSubMemReg1()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.WordMemCell], P[PET.Comma], P[PET.DX]
            };
            var command = new SubCommand(tokens, OperandsSetType.MR);

            runTest(command, new List <byte[]> {
                new byte[] { 0x29, 0x16, 0x00, 0x00 }
            });
        }
Esempio n. 21
0
        public bool RegisterSubCommand(SubCommand Command)
        {
            SubCommand sc = GetSubCommand(Command.Name);

            if (sc != null)
            {
                return(false);
            }
            SubCommandList.Add(Command);
            return(true);
        }
Esempio n. 22
0
        /// <summary>
        /// メッセージ構築
        /// </summary>
        /// <param name="command">送信サブコマンド</param>
        /// <param name="messageBody">コマンドコード、サブコマンドコードを除いたパラメータ</param>
        /// <returns>送信データ</returns>
        private byte[] CreateMessage(SubCommand command, byte[] messageBody)
        {
            var length          = (byte)(messageBody != null ? messageBody.Length + 2 : 2);
            var parameterLength = length - 2;
            var frameBytes      = 0;

            if (length <= 255)
            {
                frameBytes = 7;
            }
            else
            {
                frameBytes = 8;
            }
            var buf = new byte[length + frameBytes];

            buf[0] = 0x00;  // Preamble 00固定
            buf[1] = 0x00;  // Start Of Packet 00ff固定
            buf[2] = 0xff;
            if (length <= 255)
            {
                // normal frame
                buf[3] = length;  // データ部のバイト数(最大255バイト)
                buf[4] = (byte)-length;
                buf[5] = Define.COMMAND_CODE;
                buf[6] = (byte)command;
                // メッセージボディを転記する。
                if (messageBody != null)
                {
                    Array.Copy(messageBody, 0, buf, 7, parameterLength);
                }
                buf[7 + parameterLength] = CalculateDCS(buf.Skip(5).Take(length).ToArray()); // dcs
                buf[8 + parameterLength] = 0x00;                                             // Postamble 00固定
            }
            else
            {
                // extended frame
                buf[3] = 0xff;                         // 2バイトフレーム識別用コード
                buf[4] = 0xff;
                buf[5] = (byte)((length >> 8) & 0xff); // LENEx
                buf[6] = (byte)((length >> 0) & 0xff);
                buf[7] = (byte)-(buf[5] + buf[6]);     // LCSEx
                buf[8] = Define.COMMAND_CODE;
                buf[9] = (byte)command;
                // メッセージボディを転記する。
                if (messageBody != null)
                {
                    Array.Copy(messageBody, 0, buf, 10, parameterLength);
                }
                buf[10 + parameterLength] = CalculateDCS(buf.Skip(8).Take(length).ToArray()); // dcs
                buf[11 + parameterLength] = 0x00;                                             // Postamble 00固定
            }
            return(buf);
        }
Esempio n. 23
0
        ///////////////////////////////////////////////////////////////////////

        private void SetupSubCommands(
            ICommandData commandData,
            IEnsembleData ensembleData
            )
        {
            //
            // NOTE: Get the IExecute configured to handle the sub-commands
            //       for this ensemble.
            //
            IExecute execute = this.SubCommandExecute;

            if (execute == null)
            {
                if (ensembleData != null)
                {
                    execute = ensembleData.SubCommandExecute;
                }
                else
                {
                    ISubCommandData subCommandData = null;

                    if (commandData != null)
                    {
                        subCommandData = new SubCommandData(
                            commandData.Name, commandData.Group,
                            commandData.Description, commandData.ClientData,
                            commandData.TypeName, commandData.Flags,
                            SubCommandFlags.None, this, commandData.Token);
                    }

                    execute = new SubCommand(subCommandData, this.Plugin);
                }

                //
                // NOTE: Set the IExecute that we either obtained from the
                //       passed IEnsembleData -OR- the one that we created
                //       ourselves.
                //
                this.SubCommandExecute = execute;
            }

            EnsembleDictionary subCommands = this.SubCommands;

            if (subCommands == null)
            {
                subCommands = new EnsembleDictionary();

                subCommands["about"]    = execute as ISubCommand;
                subCommands["isolated"] = execute as ISubCommand;
                subCommands["options"]  = execute as ISubCommand;

                this.SubCommands = subCommands;
            }
        }
Esempio n. 24
0
        public void TestSubMemIm11()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.WordMemCell], P[PET.Comma], P[PET.WordConst]
            };
            var command = new SubCommand(tokens, OperandsSetType.MI);

            runTest(command, new List <byte[]> {
                new byte[] { 0x81, 0x2E, 0x00, 0x00, 0x10, 0x27 }
            });
        }
Esempio n. 25
0
        public void TestSubRegMem1()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.BX], P[PET.Comma], P[PET.WordMemCell]
            };
            var command = new SubCommand(tokens, OperandsSetType.RM);

            runTest(command, new List <byte[]> {
                new byte[] { 0x2B, 0x1E, 0x00, 0x00 }
            });
        }
Esempio n. 26
0
        public void TestSubRegReg1()
        {
            var tokens = new List <Token> {
                P[PET.SUB], P[PET.BX], P[PET.Comma], P[PET.AX]
            };
            var command = new SubCommand(tokens, OperandsSetType.RR);

            runTest(command, new List <byte[]> {
                new byte[] { 0x2B, 0xD8 }
            });
        }
Esempio n. 27
0
        public void HelpBuilding_BuildingFullHelp_OutputsVersionInformationToHelp()
        {
            //Arrange
            var command = new SubCommand();
            var builder = new HelpBuilder(command, command.Help);

            //Act
            builder.BuildHelp();

            //Assert
            Assert.Equal("1.0.0.0", command.Help.Version);
        }
Esempio n. 28
0
        public void Parsing_ProvidingSimpleTypeOption_FillOptionWithCorrectSimpleType()
        {
            //Arrange
            var arguments = new[] { "--long-type-option", long.MaxValue.ToString() };
            var command   = new SubCommand();

            //Act
            command.Execute(arguments);

            //Assert
            Assert.Equal(long.MaxValue, command.LongOption);
        }
Esempio n. 29
0
        public void AddSubCmd(SubCommand cmd)
        {
            cmd.m_parentCmd = this;
            cmd.Initialize();
            cmd.Usage = cmd.CreateUsage();

            foreach (var alias in cmd.Aliases)
            {
                m_subCommands[alias] = cmd;
                m_subCommandSet.Add(cmd);
            }
        }
        protected override void PutBody(ByteBuffer buf)
        {
            switch (SubCommand)
            {
            case AddFriendAuthSubCmd.Approve:
            case AddFriendAuthSubCmd.ApproveAndAdd:
            case AddFriendAuthSubCmd.Reject:
            case AddFriendAuthSubCmd.NoAuth:
                //03 (01表示不需要验证时的加对方为好友,03表示接受并加对方为好友,04表示只接受,05表示拒绝)
                //25 D0 1F E1
                //00 00 00
                buf.Put((byte)SubCommand);
                buf.PutInt(To);
                buf.PutUShort(0);        //00 00
                byte[] b = Utils.Util.GetBytes(Message);
                buf.Put((byte)b.Length); //长度
                buf.Put(b);
                break;

            case AddFriendAuthSubCmd.Add:
            case AddFriendAuthSubCmd.AnswerAdd:
            case AddFriendAuthSubCmd.NeedAuthor:
                buf.Put((byte)SubCommand);
                buf.PutInt(To);
                buf.Put((byte)ReverseAdd);   //00
                buf.Put((byte)DestGroup);    //00
                buf.PutUShort((ushort)AddFriendToken.Length);
                buf.Put(AddFriendToken);
                if (AnswerToken != null)
                {
                    buf.PutUShort((ushort)AnswerToken.Length);
                    buf.Put(AnswerToken);
                }
                buf.Put(0x01);
                buf.Put(0x00);
                if (!string.IsNullOrEmpty(Message))
                {
                    b = Utils.Util.GetBytes(Message);
                    buf.Put((byte)b.Length);
                    buf.Put(b);
                }
                break;

            default:
                throw new Exception("unknown AddFriendAuthSubCmd=0x" + SubCommand.ToString("X"));
            }


#if DEBUG
            Client.LogManager.Log(ToString() + " " + Utils.Util.ToHex(buf.ToByteArray()));
#endif
        }
Esempio n. 31
0
        static void Execute(SubCommand command)
        {
            int length = 3;

            byte[] tx_data = new byte[length];
            byte[] rx_data = new byte[length];

            tx_data[0] = 42;
            tx_data[1] = (byte)command;
            tx_data[2] = 0;

            _spi.WriteRead(tx_data, rx_data);
        }
Esempio n. 32
0
        public void HelpBuilding_BuildingFullHelp_OutputsAllOptionsToHelp()
        {
            //Arrange
            var command = new SubCommand();
            var builder = new HelpBuilder(command, command.Help);

            //Act
            builder.BuildHelp();

            //Assert
            Assert.Contains("-s|--long", command.Help.Usage);
            Assert.Contains("--long-type-option", command.Help.Usage);
        }
 public MessageIdentityAttribute(Command command, SubCommand subcommand) {
     _command = command;
     _subcommand = subcommand;
 }
Esempio n. 34
0
        static void Execute(SubCommand command, byte[] data)
        {
            int length = data.Length + 2;

            byte[] tx_data = new byte[length];
            byte[] rx_data = new byte[length];

            tx_data[0] = 42;
            tx_data[1] = (byte)command;

            for (int i = 0; i < data.Length; i++)
            {
                tx_data[i + 2] = data[i];
            }

            _spi.WriteRead(tx_data, rx_data);
        }
Esempio n. 35
0
        static void Execute(SubCommand command)
        {
            int length = 3;

            byte[] tx_data = new byte[length];
            byte[] rx_data = new byte[length];

            tx_data[0] = 42;
            tx_data[1] = (byte)command;
            tx_data[2] = 0;

            _spi.WriteRead(tx_data, rx_data);
        }
Esempio n. 36
0
 internal static Type GetMessageType(Command command, SubCommand subcommand) {
     return IdentityDictionary.GetValue(command, subcommand);
 }