void SendPing()
        {
            var pingRequest = PingRequest.CreateBuilder().SetTimestamp(UnixNow).Build();
            var packet      = ProtocolWrapper.WrapMessage <PingRequest>(PingRequest.RequestNumberFieldNumber, PingRequest.RequestNumber, pingRequest);

            this.ctx.WriteAndFlushAsync(packet);
        }
Exemple #2
0
        public virtual void ProcessAuthenciate()
        {
            var response = AsyncConnectionErrorRequest.CreateBuilder().SetCode(AsyncConnectionErrorRequest.Types.ConnectionError.SERVER_ERROR).Build();
            var packet   = ProtocolWrapper.WrapMessage <AsyncConnectionErrorRequest>(AsyncConnectionErrorRequest.RequestNumberFieldNumber, AsyncConnectionErrorRequest.RequestNumber, response);

            ctx.WriteAndFlushAsync(packet);
        }
        void SendUserPasswordAuthenticateRequest()
        {
            var authenticateRequest = AsyncAuthRequest.
                                      CreateBuilder().
                                      SetName("alice").
                                      SetPass("a123456").
                                      Build();
            var packet = ProtocolWrapper.WrapMessage <AsyncAuthRequest>(AsyncAuthRequest.RequestNumberFieldNumber, AsyncAuthRequest.RequestNumber, authenticateRequest);

            this.ctx.WriteAndFlushAsync(packet);
        }
        void SendActionCommitRequest()
        {
            var actionCommitRequest = ActionCommitedRequest.
                                      CreateBuilder().
                                      SetGameId(1).
                                      SetTurnIndex(1).
                                      Build();
            var packet = ProtocolWrapper.WrapMessage <ActionCommitedRequest>(ActionCommitedRequest.RequestNumberFieldNumber, ActionCommitedRequest.RequestNumber, actionCommitRequest);

            this.ctx.WriteAndFlushAsync(packet);
            Console.WriteLine($"Submit GameTurn: [GameId: {actionCommitRequest.GameId} TurnIndex: {actionCommitRequest.TurnIndex}]");
        }
Exemple #5
0
        public static IDisposable Bind <T>(
            Func <T> propertyAGetter,
            Action <T> propertyASetter,
            IReactiveProperty <T> propertyB,
            BindingTypes bindingTypes = BindingTypes.Default)
        {
            var getterObservable = Observable
                                   .EveryUpdate()
                                   .Select(x => propertyAGetter())
                                   .DistinctUntilChanged();

            var wrapper = new ProtocolWrapper <T>(getterObservable, propertyASetter);

            var binding = Bind(wrapper, propertyB, bindingTypes);

            return(new CompositeDisposable(wrapper, binding));
        }
        /// <summary>
        ///     写时间
        /// </summary>
        /// <param name="setTime">需要写入的时间</param>
        /// <returns>写入是否成功</returns>
        public async Task <bool> SetTimeAsync(DateTime setTime)
        {
            try
            {
                var inputStruct  = new SetSystemTimeModbusInputStruct(SlaveAddress, setTime);
                var outputStruct =
                    await ProtocolWrapper.SendReceiveAsync <SetSystemTimeModbusOutputStruct>(
                        ProtocolWrapper[typeof(SetSystemTimeModbusProtocal)], inputStruct);

                return(outputStruct?.WriteCount > 0);
            }
            catch (Exception e)
            {
                Log.Error(e, $"ModbusUtility -> SetTime: {ConnectionString} error");
                return(false);
            }
        }
        /// <summary>
        ///     读时间
        /// </summary>
        /// <returns>设备的时间</returns>
        public async Task <DateTime> GetTimeAsync()
        {
            try
            {
                var inputStruct  = new GetSystemTimeModbusInputStruct(SlaveAddress);
                var outputStruct =
                    await ProtocolWrapper.SendReceiveAsync <GetSystemTimeModbusOutputStruct>(
                        ProtocolWrapper[typeof(GetSystemTimeModbusProtocal)], inputStruct);

                return(outputStruct?.Time ?? DateTime.MinValue);
            }
            catch (Exception e)
            {
                Log.Error(e, $"ModbusUtility -> GetTime: {ConnectionString} error");
                return(DateTime.MinValue);
            }
        }
        /// <summary>
        ///     写数据
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="setContent">需要设置的数据</param>
        /// <returns>设置是否成功</returns>
        public async Task <bool> SetSingleDataAsync(string startAddress, object setContent)
        {
            try
            {
                var inputStruct = new WriteSingleDataModbusInputStruct(SlaveAddress, startAddress, setContent,
                                                                       (ModbusTranslatorBase)AddressTranslator, Endian);
                var outputStruct = await
                                   ProtocolWrapper.SendReceiveAsync <WriteSingleDataModbusOutputStruct>(ProtocolWrapper[typeof(WriteSingleDataModbusProtocal)],
                                                                                                        inputStruct);

                return(outputStruct?.WriteValue.ToString() == setContent.ToString());
            }
            catch (Exception e)
            {
                Log.Error(e, $"ModbusUtility -> SetSingleDatas: {ConnectionString} error");
                return(false);
            }
        }
        /// <summary>
        ///     写数据
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="setContents">需要设置的数据</param>
        /// <returns>设置是否成功</returns>
        public override async Task <bool> SetDatasAsync(string startAddress, object[] setContents)
        {
            try
            {
                var inputStruct = new WriteDataModbusInputStruct(SlaveAddress, startAddress, setContents,
                                                                 AddressTranslator, Endian);
                var outputStruct = await
                                   ProtocolWrapper.SendReceiveAsync <WriteDataModbusOutputStruct>(ProtocolWrapper[typeof(WriteDataModbusProtocal)],
                                                                                                  inputStruct);

                return(outputStruct?.WriteCount == setContents.Length);
            }
            catch (Exception e)
            {
                Log.Error(e, $"ModbusUtility -> SetDatas: {ConnectionString} error");
                return(false);
            }
        }
        /// <summary>
        ///     读数据
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="getByteCount">获取字节个数</param>
        /// <returns>获取的结果</returns>
        public override async Task <byte[]> GetDatasAsync(string startAddress, int getByteCount)
        {
            try
            {
                var inputStruct = new ReadDataModbusInputStruct(SlaveAddress, startAddress,
                                                                (ushort)getByteCount, AddressTranslator);
                var outputStruct = await
                                   ProtocolWrapper.SendReceiveAsync <ReadDataModbusOutputStruct>(ProtocolWrapper[typeof(ReadDataModbusProtocal)],
                                                                                                 inputStruct);

                return(outputStruct?.DataValue);
            }
            catch (Exception e)
            {
                Log.Error(e, $"ModbusUtility -> GetDatas: {ConnectionString} error");
                return(null);
            }
        }
Exemple #11
0
        protected Version GetClientBuildInfo(uint clientBuild)
        {
            var latest = m_suggestedProtocol = ProtocolManager.FindWrapper("WowLatest");

            if (clientBuild != 0)
            {
                int index = s_clientBuildInfos.BinaryIndexOf(info => info.ClientBuild.CompareTo(clientBuild));
                if (index >= 0)
                {
                    var info = s_clientBuildInfos[index];

                    var protocol = ProtocolManager.FindWrapper("Wow" + info.LatestBuild);
                    if (protocol != null)
                    {
                        m_suggestedProtocol = protocol;
                    }

                    return(info.ClientVersion);
                }
            }

            return(new Version(0, 0, 0, (int)clientBuild));
        }