コード例 #1
0
        private E <CommandError> SendCommandBase(WaitBlock wb, TsCommand com)
        {
            scheduler.VerifyOwnThread();

            if (status != TsClientStatus.Connecting && status != TsClientStatus.Connected)
            {
                return(CommandError.ConnectionClosed);
            }

            if (context is null)
            {
                throw new InvalidOperationException("context should be set");
            }

            if (com.ExpectResponse)
            {
                var responseNumber   = unchecked (++returnCode);
                var retCodeParameter = new CommandParameter("return_code", responseNumber);
                com.Add(retCodeParameter);
                msgProc.EnqueueRequest(retCodeParameter.Value, wb);
            }

            var message = com.ToString();

            Log.Debug("[O] {0}", message);
            byte[] data       = Tools.Utf8Encoder.GetBytes(message);
            var    sendResult = context.PacketHandler.AddOutgoingPacket(data, PacketType.Command);

            if (!sendResult)
            {
                Log.Debug("packetHandler couldn't send packet: {0}", sendResult.Error);
            }
            return(R.Ok);
        }
コード例 #2
0
ファイル: Ts3FullClient.cs プロジェクト: sertsch1/TS3AudioBot
        private E <CommandError> SendCommandBase(WaitBlock wb, Ts3Command com)
        {
            lock (statusLock)
            {
                if (context.WasExit || (!Connected && com.ExpectResponse))
                {
                    return(Util.TimeOutCommandError);
                }

                if (com.ExpectResponse)
                {
                    var responseNumber   = ++returnCode;
                    var retCodeParameter = new CommandParameter("return_code", responseNumber);
                    com.AppendParameter(retCodeParameter);
                    msgProc.EnqueueRequest(retCodeParameter.Value, wb);
                }

                var message = com.ToString();
                LogCmd.Debug("[O] {0}", message);
                byte[] data = Util.Encoder.GetBytes(message);
                packetHandler.AddOutgoingPacket(data, PacketType.Command);
            }
            return(E <CommandError> .OkR);
        }