/// <summary>
 /// Default copy constructor
 /// </summary>
 /// <param name="b">the object to copy from</param>
 public ParallelServer(ParallelServer b)
     : base(b)
 {
     m_port = b.m_port;
     m_serverOps = b.m_serverOps;
     m_receiveType = b.m_receiveType;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompackageEventArgs"/> class.
 /// </summary>
 /// <param name="type">
 /// The type.
 /// </param>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="dataBytes">
 /// The data bytes.
 /// </param>
 /// <param name="port">
 /// The port.
 /// </param>
 /// <param name="ip">
 /// The ip.
 /// </param>
 /// <param name="phoneNumber">
 /// The phone number.
 /// </param>
 public CompackageEventArgs(ReceiveType type, string sender, byte[] dataBytes, int port, string ip, string phoneNumber)
     : this(type, sender, dataBytes)
 {
     this.IPAddress   = ip;
     this.PhoneNumber = phoneNumber;
     this.Port        = port;
 }
示例#3
0
        /// <summary>
        /// Disconnect the client from the server, disconnect all proxies that
        /// are held by this client, and dispose of other resources associated
        /// with this client.
        /// </summary>
        public void Disconnect()
        {
            if (_stream != null)
            {
                _stream.Close();
                _readOffset      = 0;
                _writeOffset     = 0;
                _readableDataLen = 0;
                _payloadLen      = 0;
                _payloadBuffer   = null;
                _receiveState    = ReceiveType.Header;
                //_singleWriteMutex.Dispose(); TODO: fix socket re-use by creating new client on disconnect

                if (_proxyClients != null)
                {
                    lock (_proxyClientsLock)
                    {
                        try
                        {
                            foreach (ReverseProxyClient proxy in _proxyClients)
                            {
                                proxy.Disconnect();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }

            OnClientState(false);
        }
示例#4
0
 /// <summary>
 /// Constructor to create an instace of IrcMessageData
 /// </summary>
 /// <param name="ircclient">IrcClient the message originated from</param>
 /// <param name="from">combined nickname, identity and host of the user that sent the message (nick!ident@host)</param>
 /// <param name="nick">nickname of the user that sent the message</param>
 /// <param name="ident">identity (username) of the userthat sent the message</param>
 /// <param name="host">hostname of the user that sent the message</param>
 /// <param name="channel">channel the message originated from</param>
 /// <param name="message">message</param>
 /// <param name="rawmessage">raw message sent by the server</param>
 /// <param name="type">message type</param>
 /// <param name="replycode">message reply code</param>
 public IrcMessageData(IrcClient ircclient,
      string from,
      string nick,
      string ident,
      string host,
      string channel,
      string message,
      string rawmessage,
      ReceiveType type,
      ReplyCode replycode)
 {
     _Irc = ircclient;
     _RawMessage = rawmessage;
     _RawMessageArray = rawmessage.Split(new[] {' '});
     _Type = type;
     _ReplyCode = replycode;
     _From = from;
     _Nick = nick;
     _Ident = ident;
     _Host = host;
     _Channel = channel;
     if (message != null)
     {
         // message is optional
         _Message = message;
         _MessageArray = message.Split(new[] {' '});
     }
 }
示例#5
0
        public IrcMsg(IrcComm irc, IrcEventArgs msg, string triggerPrefix)
        {
            Irc  = irc;
            type = msg.Data.Type;

            Channel = msg.Data.Channel;
            Nick    = msg.Data.Nick;
            Ident   = msg.Data.Ident;
            Host    = msg.Data.Host;

            ReturnTo = Channel ?? Nick;

            if (msg is ActionEventArgs e)
            {
                Message = e.ActionMessage;
                DoParts(Message.Split(' '));
                // Don't parse trigger if it's an action message.
            }
            else
            {
                Message = msg.Data.Message;
                DoParts(msg.Data.MessageArray);
                Trigger = ParseTrigger(triggerPrefix);
            }
        }
示例#6
0
        /// <summary>
        /// Disconnect the client from the server, disconnect all proxies that
        /// are held by this client, and dispose of other resources associated
        /// with this client.
        /// </summary>
        public void Disconnect()
        {
            if (_handle != null)
            {
                _handle.Close();
                _handle           = null;
                _readOffset       = 0;
                _writeOffset      = 0;
                _tempHeaderOffset = 0;
                _readableDataLen  = 0;
                _payloadLen       = 0;
                _payloadBuffer    = null;
                _receiveState     = ReceiveType.Header;

                if (_proxyClients != null)
                {
                    lock (_proxyClientsLock)
                    {
                        foreach (ReverseProxyClient proxy in _proxyClients)
                        {
                            proxy.Disconnect();
                        }
                    }
                }

                if (Commands.CommandHandler.StreamCodec != null)
                {
                    Commands.CommandHandler.StreamCodec.Dispose();
                    Commands.CommandHandler.StreamCodec = null;
                }
            }

            OnClientState(false);
        }
        /// <summary>
        /// Disconnect the client from the server and dispose of
        /// resources associated with the client.
        /// </summary>
        public void Disconnect()
        {
            if (_handle != null)
            {
                _handle.Close();
                _handle           = null;
                _readOffset       = 0;
                _writeOffset      = 0;
                _tempHeaderOffset = 0;
                _readableDataLen  = 0;
                _payloadLen       = 0;
                _payloadBuffer    = null;
                _receiveState     = ReceiveType.Header;

                if (Value != null)
                {
                    Value.Dispose();
                    Value = null;
                }

                if (_parentServer.BufferManager != null)
                {
                    _parentServer.BufferManager.ReturnBuffer(_readBuffer);
                }
            }

            _parentServer.RemoveClient(this);

            OnClientState(false);
        }
示例#8
0
        protected MessageTransceiver(ModuleGlobalInfo globalInfo, ReceiveType receiveType)
        {
            this.GlobalInfo = globalInfo;
            // 创建上行队列
            FormatterType   formatterType = GlobalInfo.ConfigData.GetProperty <FormatterType>("EngineQueueFormat");
            MessengerOption receiveOption = new MessengerOption(CoreConstants.UpLinkMQName, GetMessageType)
            {
                Type        = MessengerType.MSMQ,
                HostAddress = Constants.LocalHostAddr,
                ReceiveType = receiveType,
                Formatter   = formatterType
            };

            UpLinkMessenger = Messenger.GetMessenger(receiveOption);
            this._consumers = new Dictionary <string, IMessageHandler>(Constants.DefaultRuntimeSize);
            // 创建下行队列
            MessengerOption sendOption = new MessengerOption(CoreConstants.DownLinkMQName, GetMessageType)
            {
                Type        = MessengerType.MSMQ,
                HostAddress = Constants.LocalHostAddr,
                ReceiveType = receiveType,
                Formatter   = formatterType
            };

            DownLinkMessenger   = Messenger.GetMessenger(sendOption);
            this._operationLock = new SpinLock();

            this.ZombieCleaner = new ZombieMessageCleaner(DownLinkMessenger, globalInfo);
        }
        private IReceiveMessage ParseDirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line)
        {
            Match results = regex.Match(line);

            if (results.Success && results.Groups[1].Success)
            {
                String         receiverName = results.Groups[1].Value;
                IMessageTarget receiver     = ParseReceiver(receiverName);
                String         message      = String.Empty;
                if (results.Groups[2].Success)
                {
                    message = results.Groups[2].Value;
                }

                IMessageTarget realSender = sender;
                if (sender.Type == MessageTargetType.User && receiver.Type == MessageTargetType.Channel)
                {
                    IChannel channel = receiver as IChannel;
                    realSender = channel.GetUser(sender.Name);
                }
                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, realSender, receiver, type,
                                                   ReplyType.Unknown));
            }
            return(null);
        }
示例#10
0
 public IrcMessageData(
     IrcClient ircclient,
     string from,
     string nick,
     string ident,
     string host,
     string channel,
     string message,
     string rawmessage,
     ReceiveType type,
     ReplyCode replycode)
 {
     this._Irc             = ircclient;
     this._RawMessage      = rawmessage;
     this._RawMessageArray = rawmessage.Split(' ');
     this._Type            = type;
     this._ReplyCode       = replycode;
     this._From            = from;
     this._Nick            = nick;
     this._Ident           = ident;
     this._Host            = host;
     this._Channel         = channel;
     if (message == null)
     {
         return;
     }
     this._Message      = message;
     this._MessageArray = message.Split(' ');
 }
        public Microsoft.XLANGs.Core.StopConditions segment0(Microsoft.XLANGs.Core.StopConditions stopOn)
        {
            Microsoft.XLANGs.Core.Segment __seg__  = _segments[0];
            Microsoft.XLANGs.Core.Context __ctx__  = (Microsoft.XLANGs.Core.Context)_stateMgrs[0];
            __MainOrchestration_root_0    __ctx0__ = (__MainOrchestration_root_0)_stateMgrs[0];
            __MainOrchestration_1         __ctx1__ = (__MainOrchestration_1)_stateMgrs[1];

            switch (__seg__.Progress)
            {
            case 0:
                ReceivePort = new ReceiveType(0, this);
                __ctx__.PrologueCompleted = true;
                __ctx0__.__subWrapper0    = new Microsoft.XLANGs.Core.SubscriptionWrapper(ActivationSubGuids[0], ReceivePort, this);
                if (!PostProgressInc(__seg__, __ctx__, 1))
                {
                    return(Microsoft.XLANGs.Core.StopConditions.Paused);
                }
                if ((stopOn & Microsoft.XLANGs.Core.StopConditions.Initialized) != 0)
                {
                    return(Microsoft.XLANGs.Core.StopConditions.Initialized);
                }
                goto case 1;

            case 1:
                __ctx1__      = new __MainOrchestration_1(this);
                _stateMgrs[1] = __ctx1__;
                if (!PostProgressInc(__seg__, __ctx__, 2))
                {
                    return(Microsoft.XLANGs.Core.StopConditions.Paused);
                }
                goto case 2;

            case 2:
                __ctx0__.StartContext(__seg__, __ctx1__);
                if (!PostProgressInc(__seg__, __ctx__, 3))
                {
                    return(Microsoft.XLANGs.Core.StopConditions.Paused);
                }
                return(Microsoft.XLANGs.Core.StopConditions.Blocked);

            case 3:
                if (!__ctx0__.CleanupAndPrepareToCommit(__seg__))
                {
                    return(Microsoft.XLANGs.Core.StopConditions.Blocked);
                }
                if (!PostProgressInc(__seg__, __ctx__, 4))
                {
                    return(Microsoft.XLANGs.Core.StopConditions.Paused);
                }
                goto case 4;

            case 4:
                __ctx1__.Finally();
                ServiceDone(__seg__, (Microsoft.XLANGs.Core.Context)_stateMgrs[0]);
                __ctx0__.OnCommit();
                break;
            }
            return(Microsoft.XLANGs.Core.StopConditions.Completed);
        }
 public ReceiveTypeDto MapEntityToDto(ReceiveType fuelReportDetail)
 {
     var res = new ReceiveTypeDto()
                   {
                       Id = fuelReportDetail.Id,
                       Code=fuelReportDetail.Code,
                       Name=fuelReportDetail.Name
                   };
     return res;
 }
示例#13
0
 public ReceiveMessage(IClientConnection connection, String contents, DateTime date, IMessageTarget sender,
                       IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     Connection = connection;
     Contents   = contents;
     Date       = date;
     Sender     = sender;
     Receiver   = receiver;
     Type       = type;
     ReplyType  = replyType;
 }
示例#14
0
 public ReceiveMessage(IClientConnection connection, String contents, DateTime date, IMessageTarget sender, 
     IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     Connection = connection;
     Contents = contents;
     Date = date;
     Sender = sender;
     Receiver = receiver;
     Type = type;
     ReplyType = replyType;
 }
示例#15
0
        protected IrcEventArgs CreateCtcpEventArgs(string aChannel, string aBot, string aMessage, ReceiveType aType, string aCtcpCommand)
        {
            IrcMessageData data = new IrcMessageData(null, "", aBot, "", "", aChannel, aMessage, aMessage, aType, ReplyCode.Null);
            CtcpEventArgs args = (CtcpEventArgs)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(CtcpEventArgs));
            FieldInfo[] EventFields = typeof(IrcEventArgs).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            EventFields[0].SetValue(args, data);

            FieldInfo[] EventFields2 = typeof(CtcpEventArgs).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            EventFields2[0].SetValue(args, aCtcpCommand);

            return args;
        }
示例#16
0
        // Cloning constructor.
        public IrcMsg(IrcMsg msg)
        {
            Irc  = msg.Irc;
            type = msg.type;

            Message      = msg.Message;
            MessageParts = msg.MessageParts;

            Channel = msg.Channel;
            Nick    = msg.Nick;
            Ident   = msg.Ident;
            Host    = msg.Host;

            Trigger  = msg.Trigger;
            ReturnTo = msg.ReturnTo;
        }
示例#17
0
        //EVENT
        public void disconnect()
        {
            if (_clientSocket != null)
            {
                _clientSocket.Close();
                _clientSocket     = null;
                _readOffset       = 0;
                _writeOffset      = 0;
                _tempHeaderOffset = 0;
                _payloadLen       = 0;
                _payloadBuffer    = null;
                _receiveState     = ReceiveType.Header;
            }

            connected     = false;
            authenticated = false;
        }
示例#18
0
        /// <summary>
        /// Disconnect the client from the server and dispose of
        /// resources associated with the client.
        /// </summary>
        public void Disconnect()
        {
            if (_stream != null)
            {
                _stream.Close();
                _readOffset       = 0;
                _writeOffset      = 0;
                _tempHeaderOffset = 0;
                _readableDataLen  = 0;
                _payloadLen       = 0;
                _payloadBuffer    = null;
                _receiveState     = ReceiveType.Header;

                _bufferPool.ReturnBuffer(_readBuffer);
            }

            OnClientState(false);
        }
示例#19
0
        private IReceiveMessage ParseUndirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line,
                                                       IMessageTarget receiver)
        {
            Match results = regex.Match(line);

            if (results.Success)
            {
                String message = String.Empty;
                if (results.Groups[1].Success)
                {
                    message = results.Groups[1].Value;
                }

                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                                                   ReplyType.Unknown));
            }
            return(null);
        }
示例#20
0
        /// <summary>
        /// Constructor to create an instace of IrcMessageData
        /// </summary>
        /// <param name="ircclient">IrcClient the message originated from</param>
        /// <param name="from">combined nickname, identity and host of the user that sent the message (nick!ident@host)</param>
        /// <param name="nick">nickname of the user that sent the message</param>
        /// <param name="ident">identity (username) of the userthat sent the message</param>
        /// <param name="host">hostname of the user that sent the message</param>
        /// <param name="channel">channel the message originated from</param>
        /// <param name="message">message</param>
        /// <param name="rawmessage">raw message sent by the server</param>
        /// <param name="type">message type</param>
        /// <param name="replycode">message reply code</param>
        public IrcMessageData(IrcClient ircclient, string from, string nick, string ident, string host, string channel, string message, string rawmessage, ReceiveType type, ReplyCode replycode)
        {
            irc = ircclient;
            rawMessage = rawmessage;
            rawMessageArray = rawmessage.Split(new[] { ' ' });
            this.type = type;
            replyCode = replycode;
            prefix = from;
            this.nick = nick;
            this.ident = ident;
            this.host = host;
            this.channel = channel;

            // message is optional
            if (message == null) return;

            rest = message;
            messageArray = message.Split(new[] { ' ' });
        }
示例#21
0
 /// <summary>
 /// Constructor to create an instace of IrcMessageData
 /// </summary>
 /// <param name="ircclient">IrcClient the message originated from</param>
 /// <param name="from">combined nickname, identity and host of the user that sent the message (nick!ident@host)</param>
 /// <param name="nick">nickname of the user that sent the message</param>
 /// <param name="ident">identity (username) of the userthat sent the message</param>
 /// <param name="host">hostname of the user that sent the message</param>
 /// <param name="channel">channel the message originated from</param>
 /// <param name="message">message</param>
 /// <param name="rawmessage">raw message sent by the server</param>
 /// <param name="type">message type</param>
 /// <param name="replycode">message reply code</param>
 public IrcMessageData(IrcClient ircclient, string from, string nick, string ident, string host, string channel, string message, string rawmessage, ReceiveType type, ReplyCode replycode)
 {
     _Irc             = ircclient;
     _RawMessage      = rawmessage;
     _RawMessageArray = rawmessage.Split(new char[] { ' ' });
     _Type            = type;
     _ReplyCode       = replycode;
     _From            = from;
     _Nick            = nick;
     _Ident           = ident;
     _Host            = host;
     _Channel         = channel;
     if (message != null)
     {
         // message is optional
         _Message      = message;
         _MessageArray = message.Split(new char[] { ' ' });
     }
 }
示例#22
0
        /// <summary>
        /// Disconnect the client from the server, disconnect all proxies that
        /// are held by this client, and dispose of other resources associated
        /// with this client.
        /// </summary>
        public void Disconnect()
        {
            try {
                if (_handle != null)
                {
                    _handle.Close();
                    _handle           = null;
                    _readOffset       = 0;
                    _writeOffset      = 0;
                    _tempHeaderOffset = 0;
                    _readableDataLen  = 0;
                    _payloadLen       = 0;
                    _payloadBuffer    = null;
                    _receiveState     = ReceiveType.Header;

                    if (_proxyClients != null)
                    {
                        lock (_proxyClientsLock) {
                            try {
                                foreach (ReverseProxyClient proxy in _proxyClients)
                                {
                                    proxy.Disconnect();
                                }
                            }
                            catch (Exception) {
                            }
                        }
                    }

                    if (Commands.CommandHandler.StreamCodec != null)
                    {
                        Commands.CommandHandler.StreamCodec.Dispose();
                        Commands.CommandHandler.StreamCodec = null;
                    }
                }

                OnClientState(false);
            }
            catch (Exception ex) {
                Debug.WriteLine($@"{ex.Message}\n{ex.StackTrace}\n{ex.Source}");
            }
        }
 /// <summary>
 /// Constructor to create an instance of IrcMessageData
 /// </summary>
 /// <param name="ircclient">IrcClient the message originated from</param>
 /// <param name="from">combined nickname, identity and host of the user that sent the message (nick!ident@host)</param>
 /// <param name="nick">nickname of the user that sent the message</param>
 /// <param name="ident">identity (username) of the userthat sent the message</param>
 /// <param name="host">hostname of the user that sent the message</param>
 /// <param name="channel">channel the message originated from</param>
 /// <param name="message">message</param>
 /// <param name="rawmessage">raw message sent by the server</param>
 /// <param name="type">message type</param>
 /// <param name="replycode">message reply code</param>
 /// <param name="tags">Dictionary of separated and unescaped tags</param>
 public IrcMessageData(IrcClient ircclient, string from, string nick, string ident, string host, string channel, string message, string rawmessage, ReceiveType type, ReplyCode replycode, Dictionary <string, string> tags)
 {
     Irc             = ircclient;
     RawMessage      = rawmessage;
     RawMessageArray = rawmessage.Split(new char[] { ' ' });
     Type            = type;
     ReplyCode       = replycode;
     From            = from;
     Nick            = nick;
     Ident           = ident;
     Host            = host;
     Channel         = channel;
     if (message != null)
     {
         // message is optional
         Message      = message;
         MessageArray = message.Split(new char[] { ' ' });
     }
     Tags = tags;
 }
示例#24
0
        private IReceiveMessage ParseModeMessage(IMessageTarget sender, String line)
        {
            Match results = ModeRegex.Match(line);

            if (results.Success && results.Groups[1].Success)
            {
                String         receiverName = results.Groups[1].Value;
                IMessageTarget receiver     = ParseReceiver(receiverName);
                String         message      = String.Empty;
                if (results.Groups[2].Success)
                {
                    message = results.Groups[2].Value;
                }

                ReceiveType type = receiver.Type == MessageTargetType.Channel ? ReceiveType.ChannelModeChange :
                                   ReceiveType.UserModeChange;
                return(Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                                                   ReplyType.Unknown));
            }
            return(null);
        }
示例#25
0
        public void Disconnect()
        {
            if (_handle != null)
            {
                _handle.Close();
                _handle           = null;
                _readOffset       = 0;
                _writeOffset      = 0;
                _tempHeaderOffset = 0;
                _readableDataLen  = 0;
                _payloadLen       = 0;
                _payloadBuffer    = null;
                _receiveState     = ReceiveType.Header;

                if (_proxyClients != null)
                {
                    lock (_proxyClientsLock)
                    {
                        try
                        {
                            foreach (ReverseProxyClient proxy in _proxyClients)
                            {
                                proxy.Disconnect();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                if (Eylemler.Eylemİşleyicisi.StreamCodec != null)
                {
                    Eylemler.Eylemİşleyicisi.StreamCodec.Dispose();
                    Eylemler.Eylemİşleyicisi.StreamCodec = null;
                }
            }

            OnClientState(false);
        }
        /// <summary>
        /// Disconnect the client from the server, disconnect all proxies that
        /// are held by this client, and dispose of other resources associated
        /// with this client.
        /// </summary>
        public void Disconnect()
        {
            if (_stream != null)
            {
                _stream.Close();
                _readOffset      = 0;
                _writeOffset     = 0;
                _readableDataLen = 0;
                _payloadLen      = 0;
                _payloadBuffer   = null;
                _receiveState    = ReceiveType.Header;
                _singleWriteMutex.Dispose();

                if (_proxyClients != null)
                {
                    lock (_proxyClientsLock)
                    {
                        try
                        {
                            foreach (ReverseProxyClient proxy in _proxyClients)
                            {
                                proxy.Disconnect();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }

                if (Commands.CommandHandler.StreamCodec != null)
                {
                    Commands.CommandHandler.StreamCodec.Dispose();
                    Commands.CommandHandler.StreamCodec = null;
                }
            }

            OnClientState(false);
        }
示例#27
0
        //EVENT
        public void disconnect()
        {
            if (_clientSocket != null)
            {
                _clientSocket.Close();
                _clientSocket     = null;
                _readOffset       = 0;
                _writeOffset      = 0;
                _tempHeaderOffset = 0;
                _payloadLen       = 0;
                _payloadBuffer    = null;
                _receiveState     = ReceiveType.Header;
            }

            if (value != null)
            {
                value = null;
            }

            authenticated = false;

            DvgUpdater(this, false);
        }
 public ReceiveType MapDtoToEntity(ReceiveTypeDto fuelReportDetail)
 {
     var entity = new ReceiveType(fuelReportDetail.Id,fuelReportDetail.Name,fuelReportDetail.Code);
     return entity;
 }
示例#29
0
文件: Client.cs 项目: werkamsus/xRAT
        private void AsyncReceive(object state)
        {
            while (true)
            {
                byte[] readBuffer;
                lock (_readBuffers)
                {
                    if (_readBuffers.Count == 0)
                    {
                        _readingPackets = false;
                        return;
                    }

                    readBuffer = _readBuffers.Dequeue();
                }

                _readableDataLen += readBuffer.Length;
                bool process = true;
                while (process)
                {
                    switch (_receiveState)
                    {
                    case ReceiveType.Header:
                    {
                        process = _readableDataLen >= HEADER_SIZE;
                        if (process)
                        {
                            try
                            {
                                _payloadLen = BitConverter.ToInt32(readBuffer, _readOffset);
                            }
                            catch (Exception)
                            {
                                break;
                            }
                            if (_payloadLen <= 0)
                            {
                                process = false;
                                break;
                            }

                            _readableDataLen -= HEADER_SIZE;
                            _readOffset      += HEADER_SIZE;
                            _receiveState     = ReceiveType.Payload;
                        }
                        break;
                    }

                    case ReceiveType.Payload:
                    {
                        process = _readableDataLen >= _payloadLen;
                        if (process)
                        {
                            if (_payloadBuffer == null || _payloadBuffer.Length != _payloadLen)
                            {
                                _payloadBuffer = new byte[_payloadLen];
                            }
                            try
                            {
                                Array.Copy(readBuffer, _readOffset, _payloadBuffer, 0, _payloadBuffer.Length);
                            }
                            catch
                            {
                                Disconnect();
                            }

                            if (encryptionEnabled)
                            {
                                _payloadBuffer = AES.Decrypt(_payloadBuffer, Encoding.UTF8.GetBytes(Settings.PASSWORD));
                            }

                            if (_payloadBuffer.Length > 0)
                            {
                                if (compressionEnabled)
                                {
                                    _payloadBuffer = new SafeQuickLZ().Decompress(_payloadBuffer, 0, _payloadBuffer.Length);
                                }

                                using (MemoryStream deserialized = new MemoryStream(_payloadBuffer))
                                {
                                    IPacket packet = Serializer.DeserializeWithLengthPrefix <IPacket>(deserialized,
                                                                                                      PrefixStyle.Fixed32);

                                    OnClientRead(packet);
                                }
                            }

                            _readOffset      += _payloadLen;
                            _readableDataLen -= _payloadLen;
                            _receiveState     = ReceiveType.Header;
                        }
                        else         // handle payload that does not fit in one buffer
                        {
                            if (_payloadBuffer == null || _payloadBuffer.Length != _payloadLen)
                            {
                                _payloadBuffer = new byte[_payloadLen];
                            }
                            try
                            {
                                Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, _readableDataLen);
                            }
                            catch
                            {
                                Disconnect();
                            }

                            _writeOffset    += _readableDataLen;
                            _readOffset     += _readableDataLen;
                            _readableDataLen = 0;

                            if (_writeOffset == _payloadLen)
                            {
                                if (encryptionEnabled)
                                {
                                    _payloadBuffer = AES.Decrypt(_payloadBuffer, Encoding.UTF8.GetBytes(Settings.PASSWORD));
                                }

                                if (_payloadBuffer.Length > 0)
                                {
                                    if (compressionEnabled)
                                    {
                                        _payloadBuffer = new SafeQuickLZ().Decompress(_payloadBuffer, 0, _payloadBuffer.Length);
                                    }

                                    using (MemoryStream deserialized = new MemoryStream(_payloadBuffer))
                                    {
                                        IPacket packet = Serializer.DeserializeWithLengthPrefix <IPacket>(deserialized,
                                                                                                          PrefixStyle.Fixed32);

                                        OnClientRead(packet);
                                    }
                                }

                                _receiveState = ReceiveType.Header;
                            }
                        }
                        break;
                    }
                    }
                }

                if (_receiveState == ReceiveType.Header)
                {
                    _writeOffset = 0; // prepare for next packet
                }
                _readOffset      = 0;
                _readableDataLen = 0;
            }
        }
示例#30
0
 public RecordForm(ReceiveType _type)
 {
     InitializeComponent();
     cboResult.SelectedIndex = 0;
     type = _type;
 }
示例#31
0
 /// <remarks/>
 public void GetReceiveSMSAsync(ReceiveType RecType, System.Nullable<int> Count, string FromDate, string ToDate, object userState) {
     if ((this.GetReceiveSMSOperationCompleted == null)) {
         this.GetReceiveSMSOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetReceiveSMSOperationCompleted);
     }
     this.InvokeAsync("GetReceiveSMS", new object[] {
                 RecType,
                 Count,
                 FromDate,
                 ToDate}, this.GetReceiveSMSOperationCompleted, userState);
 }
示例#32
0
 public ReceiveSMS[] GetReceiveSMS(ReceiveType RecType, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] System.Nullable<int> Count, string FromDate, string ToDate) {
     object[] results = this.Invoke("GetReceiveSMS", new object[] {
                 RecType,
                 Count,
                 FromDate,
                 ToDate});
     return ((ReceiveSMS[])(results[0]));
 }
 public void Delete(ReceiveType entity)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="acceptor">acceptor object</param>
 /// <param name="callBackObj">callback object</param>
 /// <param name="port">port</param>
 /// <param name="receiveType">receive type</param>
 /// <param name="noDelay">noDelay falg</param>
 public ParallelServerOps(IParallelServerAcceptor acceptor, String port, IParallelServerCallback callBackObj = null, IParallelRoomCallback roomCallBackObj = null, ReceiveType receiveType = ReceiveType.SEQUENTIAL, int socketCount = SocketCount.Infinite, int streamCountPerSocket = SocketCount.Infinite)
 {
     this.Port = port;
     this.Acceptor = acceptor;
     this.CallBackObj = callBackObj;
     this.RoomCallBackObj = roomCallBackObj;
     this.ReceiveType = receiveType;
     MaxSocketCount = socketCount;
     MaxStreamCountPerSocket = streamCountPerSocket;
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="callBackObj">callback object</param>
 /// <param name="hostName">hostname</param>
 /// <param name="port">port</param>
 /// <param name="receiveType">receive type</param>
 /// <param name="maxSocketCount">maximum number of sockets to use</param>
 /// <param name="noDelay">flag for no delay</param>
 /// <param name="connectionTimeOut">connection wait time in millisecond</param>
 public ParallelClientOps(IParallelClientCallback callBackObj, String hostName, String port, ReceiveType receiveType = ReceiveType.SEQUENTIAL, int maxSocketCount = ParallelSocketConf.DEFAULT_MAX_SOCKET_NUM, int connectionTimeOut = Timeout.Infinite)
 {
     this.CallBackObj = callBackObj;
     this.HostName = hostName;
     this.Port = port;
     this.ReceiveType = receiveType;
     this.MaxSocketCount = maxSocketCount;
     this.ConnectionTimeOut = connectionTimeOut;
 }
示例#36
0
        private IReceiveMessage ParseDirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line)
        {
            Match results = regex.Match(line);
            if(results.Success && results.Groups[1].Success)
            {
                String receiverName = results.Groups[1].Value;
                IMessageTarget receiver = ParseReceiver(receiverName);
                String message = String.Empty;
                if(results.Groups[2].Success)
                    message = results.Groups[2].Value;

                IMessageTarget realSender = sender;
                if(sender.Type == MessageTargetType.User && receiver.Type == MessageTargetType.Channel)
                {
                    IChannel channel = receiver as IChannel;
                    realSender = channel.GetUser(sender.Name);
                }
                return Client.CreateReceiveMessage(Connection, message, DateTime.Now, realSender, receiver, type,
                    ReplyType.Unknown);
            }
            return null;
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="callBackObj">callback object</param>
 /// <param name="port">port</param>
 /// <param name="receiveType">receive type</param>
 /// <param name="noDelay">noDelay falg</param>
 public ParallelServerOps(IParallelServerCallback callBackObj, String port,ReceiveType receiveType)
 {
     this.Port = port;
     this.CallBackObj = callBackObj;
     this.ReceiveType = receiveType;
 }
示例#38
0
 private IReceiveMessage ParseInformationMessage(IMessageTarget sender, ReceiveType type, ReplyType replyType, 
     String parameters)
 {
     return Client.CreateReceiveMessage(Connection, parameters, DateTime.Now, sender, Connection.Me, type,
         replyType);
 }
        private void AynsReceive(IAsyncResult result)
        {
            int BytesTransferred = -1;
            try
            {
                BytesTransferred = Handle.EndReceive(result);

                SysLogger.Log("Received " + BytesTransferred, SysLogType.Network);

                if (BytesTransferred <= 0)
                {
                    Disconnect();
                    return;
                }
            }
            catch(Exception ex)
            {
                SysLogger.Log(ex.Message, SysLogType.Error);
                Disconnect();
                return;
            }

            try
            {
                //let's check the certificate
                if (Client.Server != null && Client.Server.serverProperties != null)
                {
                    if (Client.ConnectionTime > Client.Server.serverProperties.ClientTimeConnected)
                    {
                        //we need to wait till the time is right
                        Disconnect();
                        return;
                    }
                }

                this.LastPacketRecvSW = Stopwatch.StartNew();
                ReadableDataLen += BytesTransferred;
                DataIn += (ulong)BytesTransferred;
                bool Process = true;

                while (Process)
                {
                    if (ReceiveState == ReceiveType.Header)
                    {
                        Process = ReadableDataLen >= HEADER_SIZE;
                        if (ReadableDataLen >= HEADER_SIZE)
                        {
                            lock (HeaderEncryption)
                            {
                                headerConfuser.Deobfuscate(ref Buffer, ReadOffset);
                                HeaderEncryption.Decrypt(Buffer, ReadOffset, HEADER_SIZE);
                            }

                            using(PayloadReader pr = new PayloadReader(Buffer))
                            {
                                pr.Position = ReadOffset;
                                PayloadLen = pr.ReadThreeByteInteger();
                                CurPacketId = pr.ReadByte();
                                ConnectionId = pr.ReadUShort();
                                HeaderId = pr.ReadUShort();
                                HeaderChecksum = pr.ReadByte();
                                FeatureId = pr.ReadInteger();
                            }

                            byte ReChecksum = 0; //re-calculate the checksum
                            ReChecksum += (byte)PayloadLen;
                            ReChecksum += CurPacketId;
                            ReChecksum += (byte)ConnectionId;
                            ReChecksum += (byte)HeaderId;
                            ReChecksum += (byte)FeatureId;

                            if (ReChecksum != HeaderChecksum ||
                                PayloadLen >= MAX_PACKET_SIZE ||
                                PayloadLen < 0)
                            {
                                Disconnect();
                                return;
                            }

                            if(PayloadLen > Buffer.Length)
                            {
                                ResizeBuffer(PayloadLen);
                            }

                            TotalReceived = HEADER_SIZE;
                            ReadableDataLen -= HEADER_SIZE;
                            ReadOffset += HEADER_SIZE;
                            ReceiveState = ReceiveType.Payload;
                        }
                    }
                    else if (ReceiveState == ReceiveType.Payload)
                    {
                        Process = ReadableDataLen >= PayloadLen;
                        if (ReadableDataLen >= PayloadLen)
                        {
                            byte[] DecryptedBuffer = null;
                            int DecryptedBuffLen = 0;

                            messageHandler.DecryptMessage(this, Buffer, ReadOffset, PayloadLen, ref DecryptedBuffer, ref DecryptedBuffLen);

                            if (DecryptedBuffer == null)
                            {
                                //failed to decrypt data
                                Disconnect();
                                return;
                            }

                            TotalReceived += PayloadLen;

                            using (PayloadReader pr = new PayloadReader(DecryptedBuffer))
                            {
                                OperationalSocket OpSocket = null;
                                if (ConnectionId > 0)
                                {
                                    lock(OperationalSockets)
                                    {
                                        if (!OperationalSockets.TryGetValue(ConnectionId, out OpSocket))
                                        {
                                            //strange...
                                            Disconnect();
                                            return;
                                        }
                                    }
                                }

                                Type type = Headers.GetHeaderType(HeaderId);

                                if (type != null)
                                {
                                    Header header = Header.DeSerialize(type, pr);

                                    if(header == null)
                                    {
                                        Disconnect();
                                        return;
                                    }

                                    uint MessageId = pr.ReadUInteger();
                                    IMessage message = OpSocket != null ? OpSocket.MessageHandler.DeSerialize(pr, MessageId) : messageHandler.DeSerialize(pr, MessageId);

                                    if (message != null)
                                    {
                                        message.RawSize = TotalReceived;
                                        message.Header = header;

                                        if (!HandShakeCompleted)
                                        {
                                            if (message.GetType() == typeof(MsgHandshake))
                                            {
                                                //process the handshake messages straight away
                                                message.ProcessPayload(Client, null);
                                            }
                                        }
                                        else
                                        {
                                            ProcessMessage(new SystemPacket(header, message, ConnectionId, OpSocket));
                                        }
                                    }
                                }
                                else
                                {
                                    Disconnect();
                                    return;
                                }
                            }
                            TotalReceived = 0;

                            PacketsIn++;
                            ReadOffset += PayloadLen;
                            ReadableDataLen -= PayloadLen;
                            ReceiveState = ReceiveType.Header;
                        }
                    }
                }

                int len = ReceiveState == ReceiveType.Header ? HEADER_SIZE : PayloadLen;
                if (ReadOffset + len >= this.Buffer.Length)
                {
                    //no more room for this data size, at the end of the buffer ?

                    //copy the buffer to the beginning
                    Array.Copy(this.Buffer, ReadOffset, this.Buffer, 0, ReadableDataLen);

                    WriteOffset = ReadableDataLen;
                    ReadOffset = 0;
                }
                else
                {
                    //payload fits in the buffer from the current offset
                    //use BytesTransferred to write at the end of the payload
                    //so that the data is not split
                    WriteOffset += BytesTransferred;
                }

                if (Buffer.Length - WriteOffset > 0)
                {
                    Handle.BeginReceive(this.Buffer, WriteOffset, Buffer.Length - WriteOffset, SocketFlags.None, AynsReceive, null);
                }
                else
                {
                    //Shoudln't be even possible... very strange
                    Disconnect();
                }
            }
            catch(Exception ex)
            {
                //unexpected error, client might have disconnected itself, or else report this error
                SysLogger.Log(ex.Message, SysLogType.Error);
                Disconnect();
                return;
            }
        }
        /// <summary>
        /// Receive data on the TCP connection
        /// </summary>
        /// <description>
        /// This method has two sections based on what we want to receive (<see cref="ReceiveType"/>)
        /// 1. HTTP : We want to receive a HTTP response from the server
        /// 2. DATA : We are waiting data from the server
        /// </description>
        /// <param name="rt">Receive Type</param>
        public void Receive(ReceiveType rt)
        {
            _receiveDone.Reset ();

            // Create the state object.
            StateObject state = new StateObject();
            state.workSocket = _tcpSocket;

            // Begin receiving the data from the remote device.
            if (rt == ReceiveType.Http) {
                _receiveHttpStatus = SendStatus.Ok;
                _tcpSocket.BeginReceive (state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback (receiveCallBackHttp), state);
            } else if (rt == ReceiveType.Alert) {
                _receiveAlertStatus = SendStatus.Ok;
                _tcpSocket.BeginReceive (state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback (receiveCallBackAlert), state);
            } else {
                _tcpSocket.BeginReceive (state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback (receiveCallBackData), state);
            }
        }
示例#41
0
        private void AsyncReceive(IAsyncResult result)
        {
            int bytesTransferred = -1;

            try
            {
                bytesTransferred = _handle.EndReceive(result);

                if (bytesTransferred <= 0)
                {
                    OnClientState(false);
                    return;
                }
            }
            catch (Exception)
            {
                OnClientState(false);
                return;
            }

            _parentServer.BytesReceived += bytesTransferred;

            _readableDataLen += bytesTransferred;
            bool process = true;

            while (process)
            {
                switch (_receiveState)
                {
                case ReceiveType.Header:
                {
                    process = _readableDataLen >= HEADER_SIZE;
                    if (process)
                    {
                        _payloadLen = BitConverter.ToInt32(_buffer, _readOffset);

                        _readableDataLen -= HEADER_SIZE;
                        _readOffset      += HEADER_SIZE;
                        _receiveState     = ReceiveType.Payload;
                    }
                    break;
                }

                case ReceiveType.Payload:
                {
                    process = _readableDataLen >= _payloadLen;
                    if (process)
                    {
                        byte[] payload = new byte[_payloadLen];
                        try
                        {
                            Array.Copy(this._buffer, _readOffset, payload, 0, payload.Length);
                        }
                        catch
                        {
                            Disconnect();
                        }

                        if (encryptionEnabled)
                        {
                            payload = AES.Decrypt(payload, Encoding.UTF8.GetBytes(XMLSettings.Password));
                        }

                        if (payload.Length > 0)
                        {
                            if (compressionEnabled)
                            {
                                payload = new SafeQuickLZ().Decompress(payload, 0, payload.Length);
                            }

                            using (MemoryStream deserialized = new MemoryStream(payload))
                            {
                                IPacket packet = Serializer.DeserializeWithLengthPrefix <IPacket>(deserialized,
                                                                                                  PrefixStyle.Fixed32);

                                OnClientRead(packet);
                            }
                        }

                        _readOffset      += _payloadLen;
                        _readableDataLen -= _payloadLen;
                        _receiveState     = ReceiveType.Header;
                    }
                    break;
                }
                }
            }

            int len = _receiveState == ReceiveType.Header ? HEADER_SIZE : _payloadLen;

            if (_readOffset + len >= this._buffer.Length)
            {
                //copy the buffer to the beginning
                Array.Copy(this._buffer, _readOffset, this._buffer, 0, _readableDataLen);
                _writeOffset = _readableDataLen;
                _readOffset  = 0;
            }
            else
            {
                //payload fits in the buffer from the current offset
                //use BytesTransferred to write at the end of the payload
                //so that the data is not split
                _writeOffset += bytesTransferred;
            }

            try
            {
                if (_buffer.Length - _writeOffset > 0)
                {
                    _handle.BeginReceive(this._buffer, _writeOffset, _buffer.Length - _writeOffset, SocketFlags.None,
                                         AsyncReceive, null);
                }
                else
                {
                    //Shoudln't be even possible... very strange
                    Disconnect();
                }
            }
            catch
            {
                Disconnect();
            }
        }
 public ReceiveType Update(ReceiveType entity)
 {
     throw new NotImplementedException();
 }
示例#43
0
        /// <summary>
        /// Constructor to create an instace of IrcMessageData
        /// </summary>
        /// <param name="ircClient">IrcClient the message originated from</param>
        /// <param name="rawMessage">message as it appears on wire, stripped of newline</param>
        public IrcMessageData(IrcClient ircClient, string rawMessage)
        {
            if (rawMessage == null)
            {
                throw new ArgumentException("Cannot parse null message");
            }
            if (rawMessage == "")
            {
                throw new ArgumentException("Cannot parse empty message");
            }

            irc = ircClient;
            this.rawMessage = rawMessage;
            rawMessageArray = rawMessage.Split(' ');
            prefix = "";
            rest = "";

            int start = 0;
            int len = 0;
            if (rawMessageArray[0][0] == ':')
            {
                prefix = rawMessageArray[0].Substring(1);
                start = 1;
                len += prefix.Length + 1;
            }

            command = rawMessageArray[start];
            len += command.Length + 1;

            int length = rawMessageArray.Length;

            if (start + 1 < length)
            {
                for (int i = start + 1; i < rawMessageArray.Length; i++)
                {
                    if (rawMessageArray[i][0] == ':')
                    {
                        length = i;
                        break;
                    }
                    len += rawMessageArray[i].Length + 1;
                }

                args = new string[length - start - 1];
                Array.Copy(rawMessageArray, start + 1, args, 0, length - start - 1);
                if (length < rawMessageArray.Length)
                {
                    rest = this.rawMessage.Substring(this.rawMessage.IndexOf(':', len) + 1);
                    messageArray = rest.Split(' ');
                }
            }
            else
            {
                args = new string[0];
            }

            replyCode = ReplyCode.Null;
            type = ReceiveType.Unknown;

            ParseLegacyInfo();
        }
示例#44
0
 /// <remarks/>
 public void GetReceiveSMSWithNumberAsync(ReceiveType RecType, string LineNumber, System.Nullable<int> Count, string FromDate, string ToDate) {
     this.GetReceiveSMSWithNumberAsync(RecType, LineNumber, Count, FromDate, ToDate, null);
 }
示例#45
0
        // refactored old field parsing code below, ignore for own sanity
        private void ParseLegacyInfo()
        {
            Match match = PrefixRegex.Match(prefix);

            if (match.Success)
            {
                if (match.Groups[2].Success || match.Groups[3].Success || (prefix.IndexOf('.') < 0))
                    nick = match.Groups[1].ToString();
            }

            if (match.Groups[2].Success)
                ident = match.Groups[2].ToString().Substring(1);
            if (match.Groups[3].Success)
                host = match.Groups[3].ToString().Substring(1);

            int code;
            if (int.TryParse(command, out code))
            {
                replyCode = (ReplyCode)code;
            }
            else
            {
                replyCode = ReplyCode.Null;
            }
            if (replyCode != ReplyCode.Null)
            {
                // categorize replies

                switch (replyCode)
                {
                    case ReplyCode.Welcome:
                    case ReplyCode.YourHost:
                    case ReplyCode.Created:
                    case ReplyCode.MyInfo:
                    case ReplyCode.Bounce:
                    case ReplyCode.SaslSuccess:
                    case ReplyCode.SaslFailure1:
                    case ReplyCode.SaslFailure2:
                    case ReplyCode.SaslAbort:
                        type = ReceiveType.Login;
                        break;

                    case ReplyCode.LuserClient:
                    case ReplyCode.LuserOp:
                    case ReplyCode.LuserUnknown:
                    case ReplyCode.LuserMe:
                    case ReplyCode.LuserChannels:
                        type = ReceiveType.Info;
                        break;

                    case ReplyCode.MotdStart:
                    case ReplyCode.Motd:
                    case ReplyCode.EndOfMotd:
                        type = ReceiveType.Motd;
                        break;

                    case ReplyCode.NamesReply:
                    case ReplyCode.EndOfNames:
                        type = ReceiveType.Name;
                        break;

                    case ReplyCode.WhoReply:
                    case ReplyCode.EndOfWho:
                        type = ReceiveType.Who;
                        break;

                    case ReplyCode.ListStart:
                    case ReplyCode.List:
                    case ReplyCode.ListEnd:
                        type = ReceiveType.List;
                        break;

                    case ReplyCode.BanList:
                    case ReplyCode.EndOfBanList:
                        type = ReceiveType.BanList;
                        break;

                    case ReplyCode.Topic:
                    case ReplyCode.NoTopic:
                        type = ReceiveType.Topic;
                        break;

                    case ReplyCode.WhoIsUser:
                    case ReplyCode.WhoIsServer:
                    case ReplyCode.WhoIsOperator:
                    case ReplyCode.WhoIsIdle:
                    case ReplyCode.WhoIsChannels:
                    case ReplyCode.EndOfWhoIs:
                        type = ReceiveType.WhoIs;
                        break;

                    case ReplyCode.WhoWasUser:
                    case ReplyCode.EndOfWhoWas:
                        type = ReceiveType.WhoWas;
                        break;

                    case ReplyCode.UserModeIs:
                        type = ReceiveType.UserMode;
                        break;

                    case ReplyCode.ChannelModeIs:
                        type = ReceiveType.ChannelMode;
                        break;

                    default:
                        if ((code >= 400) &&
                            (code <= 599))
                        {
                            type = ReceiveType.ErrorMessage;
                        }
                        else
                        {
                            type = ReceiveType.Unknown;
                        }
                        break;
                }
            }
            else
            {
                // categorize commands

                switch (command)
                {
                    case "PING":
                        type = ReceiveType.Unknown;
                        break;

                    case "ERROR":
                        type = ReceiveType.Error;
                        break;

                    case "PRIVMSG":
                        if (args.Length > 0 && rest.StartsWith("\x1" + "ACTION") && rest.EndsWith("\x1"))
                        {
                            switch (args[0][0])
                            {
                                case '#':
                                case '!':
                                case '&':
                                case '+':
                                    type = ReceiveType.ChannelAction;
                                    break;

                                default:
                                    type = ReceiveType.QueryAction;
                                    break;
                            }
                        }
                        else if (rest.StartsWith("\x1") && rest.EndsWith("\x1"))
                        {
                            type = ReceiveType.CtcpRequest;
                        }
                        else if (args.Length > 0)
                        {
                            switch (args[0][0])
                            {
                                case '#':
                                case '!':
                                case '&':
                                case '+':
                                    type = ReceiveType.ChannelMessage;
                                    break;

                                default:
                                    type = ReceiveType.QueryMessage;
                                    break;
                            }
                        }
                        break;

                    case "NOTICE":
                        if (rest.StartsWith("\x1") && rest.EndsWith("\x1"))
                        {
                            type = ReceiveType.CtcpReply;
                        }
                        else if (args.Length > 0)
                        {
                            switch (args[0][0])
                            {
                                case '#':
                                case '!':
                                case '&':
                                case '+':
                                    type = ReceiveType.ChannelNotice;
                                    break;

                                default:
                                    type = ReceiveType.QueryNotice;
                                    break;
                            }
                        }
                        break;

                    case "INVITE":
                        type = ReceiveType.Invite;
                        break;

                    case "JOIN":
                        type = ReceiveType.Join;
                        break;

                    case "PART":
                        type = ReceiveType.Part;
                        break;

                    case "TOPIC":
                        type = ReceiveType.TopicChange;
                        break;

                    case "NICK":
                        type = ReceiveType.NickChange;
                        break;

                    case "KICK":
                        type = ReceiveType.Kick;
                        break;

                    case "MODE":
                        switch (args[0][0])
                        {
                            case '#':
                            case '!':
                            case '&':
                            case '+':
                                type = ReceiveType.ChannelModeChange;
                                break;

                            default:
                                type = ReceiveType.UserModeChange;
                                break;
                        }
                        break;

                    case "QUIT":
                        type = ReceiveType.Quit;
                        break;

                    case "CAP":
                    case "AUTHENTICATE":
                        type = ReceiveType.Other;
                        break;
                }
            }

            switch (type)
            {
                case ReceiveType.Join:
                case ReceiveType.Kick:
                case ReceiveType.Part:
                case ReceiveType.TopicChange:
                case ReceiveType.ChannelModeChange:
                case ReceiveType.ChannelMessage:
                case ReceiveType.ChannelAction:
                case ReceiveType.ChannelNotice:
                    channel = rawMessageArray[2];
                    break;

                case ReceiveType.Who:
                case ReceiveType.Topic:
                case ReceiveType.Invite:
                case ReceiveType.BanList:
                case ReceiveType.ChannelMode:
                    channel = rawMessageArray[3];
                    break;

                case ReceiveType.Name:
                    channel = rawMessageArray[4];
                    break;
            }

            switch (replyCode)
            {
                case ReplyCode.List:
                case ReplyCode.ListEnd:
                case ReplyCode.ErrorNoChannelModes:
                    channel = args[1];
                    break;
            }

            if (channel != null && channel.StartsWith(":"))
            {
                channel = Channel.Substring(1);
            }
        }
示例#46
0
 /// <remarks/>
 public void GetReceiveSMSAsync(ReceiveType RecType, System.Nullable<int> Count, string FromDate, string ToDate) {
     this.GetReceiveSMSAsync(RecType, Count, FromDate, ToDate, null);
 }
示例#47
0
        /// <summary>
        /// 批量录入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBatchEntry_Click(object sender, RoutedEventArgs e)
        {
            if (!AuthMgr.HasFunctionPoint(AuthKeyConst.EIMS_InvoiceEntry_BathcInput))
            {
                Window.Alert(ResEIMSInvoiceEntry.Msg_HasNoRight);
                return;
            }
            if (viewList == null ||
                viewList.Count == 0)
            {
                this.Window.Alert(ResEIMSInvoiceEntry.Msg_PleaseSelect);
                return;
            }

            List <EIMSInvoiceEntryVM> selectList = new List <EIMSInvoiceEntryVM>();

            foreach (var view in viewList)
            {
                if (view.IsCheck)
                {
                    selectList.Add(view);
                }
            }
            List <string> invoiceNumberList = new List <string>();
            string        invoiceNumber     = string.Empty;
            int           vendorNo          = 0;
            ReceiveType   receiveType       = ReceiveType.AccountDeduction;

            if (selectList.Count == 0)
            {
                this.Window.Alert(ResEIMSInvoiceEntry.Msg_PleaseSelect);
                return;
            }
            for (int i = 0; i < selectList.Count; i++)
            {
                vendorNo    = selectList[0].VendorNumber;
                receiveType = selectList[0].ReceiveType;
                if (selectList[i].IsSAPImportedDes == "已上传" || selectList[i].InvoiceInputStatus == "已录入")
                {
                    invoiceNumberList.Add(selectList[i].InvoiceNumber);
                }
                if (selectList[i].VendorNumber != vendorNo || selectList[i].ReceiveType != receiveType)
                {
                    this.Window.Alert(ResEIMSInvoiceEntry.Msg_NotTheSameVendorOrReceiveType);
                    return;
                }
            }
            if (invoiceNumberList.Count > 0)
            {
                for (int i = 0; i < invoiceNumberList.Count; i++)
                {
                    if (i > 0)
                    {
                        invoiceNumber += ";";
                    }
                    invoiceNumber += invoiceNumberList[i];
                }
                this.Window.Alert(string.Format(ResEIMSInvoiceEntry.Msg_HadInputed, invoiceNumber));
            }
            else
            {
                UCBatchInvoiceInput uc = new UCBatchInvoiceInput(selectList);
                uc.Dialog = this.Window.ShowDialog("批量发票录入", uc, (o, s) =>
                {
                    if (s.isForce)
                    {
                        LoadingDataEventArgs m = new LoadingDataEventArgs(this.CurrentPageIndex, this.CurrentPageSize, null, null);
                        dataGrid_LoadingDataSource(null, m);
                    }
                }, new Size(700, 260));
            }
        }
示例#48
0
        private void onBeginReceive(IAsyncResult ar)
        {
            int BytesTransferred = 0;
            try
            {
                BytesTransferred = client.EndReceive(ar);

                if (BytesTransferred <= 0)
                {
                    Disconnect();
                    return;
                }
            }
            catch { }

            ReadableDataLen += BytesTransferred;

            bool Process = true;

            while (Process)
            {
                if (ReceiveState == ReceiveType.Header)
                {
                    Process = ReadableDataLen >= HEADER_SIZE;

                    if (ReadableDataLen >= HEADER_SIZE)
                    {
                        net.ReadHeader(Buffer, ReadOffset);

                        ReadableDataLen -= HEADER_SIZE;
                        ReadOffset += HEADER_SIZE;
                        ReceiveState = ReceiveType.Payload;
                    }
                }
                else if (ReceiveState == ReceiveType.Payload)
                {
                    Process = ReadableDataLen >= PayloadLen;
                    if (ReadableDataLen >= PayloadLen)
                    {
                        net.ReadPayload(Buffer, ReadOffset);
                        //Debug.WriteLine("Command: " + net.nh_type + ", Len: " + net.nh_len + ", " + BitConverter.ToString(net.nh_data, 0, net.nh_data.Length > 100 ? 100 : net.nh_data.Length));

                        Packet packet = PacketDotNet.Packet.ParsePacket(PacketDotNet.LinkLayers.Ieee80211, net.nh_data);

                        if (packet != null)
                        {
                            DateTime ArrivalTime = DateTime.Now;
                            onPacketArrival(packet, ArrivalTime);
                        }

                        ReadOffset += PayloadLen;
                        ReadableDataLen -= PayloadLen;
                        ReceiveState = ReceiveType.Header;
                    }
                }
            }

            int len = ReceiveState == ReceiveType.Header ? HEADER_SIZE : (int)net.nh_len;
            if (ReadOffset + len >= this.Buffer.Length)
            {
                //no more room for this data size, at the end of the buffer ?

                //copy the buffer to the beginning
                Array.Copy(this.Buffer, ReadOffset, this.Buffer, 0, ReadableDataLen);

                WriteOffset = ReadableDataLen;
                ReadOffset = 0;
            }
            else
            {
                //payload fits in the buffer from the current offset
                //use BytesTransferred to write at the end of the payload
                //so that the data is not split
                WriteOffset += BytesTransferred;
            }

            client.BeginReceive(this.Buffer, WriteOffset, Buffer.Length - WriteOffset, SocketFlags.None, onBeginReceive, null);
        }
 public ReceiveTypeDto MapToModel(ReceiveType entity)
 {
     throw new NotImplementedException();
 }
示例#50
0
文件: Client.cs 项目: tidusjar/xRAT
        private void AsyncReceive(object state)
        {
            while (true)
            {
                byte[] readBuffer;
                lock (_readBuffers)
                {
                    if (_readBuffers.Count == 0)
                    {
                        lock (_readingPacketsLock)
                        {
                            _readingPackets = false;
                        }
                        return;
                    }

                    readBuffer = _readBuffers.Dequeue();
                }

                _readableDataLen += readBuffer.Length;
                bool process = true;
                while (process)
                {
                    switch (_receiveState)
                    {
                    case ReceiveType.Header:
                    {
                        if (_readableDataLen >= HEADER_SIZE)
                        {         // we can read the header
                            int size = (_appendHeader) ?
                                       HEADER_SIZE - _tempHeaderOffset
                                        : HEADER_SIZE;

                            try
                            {
                                if (_appendHeader)
                                {
                                    Array.Copy(readBuffer, _readOffset, _tempHeader, _tempHeaderOffset, size);
                                    _payloadLen       = (int)_tempHeader[0] | _tempHeader[1] << 8 | _tempHeader[2] << 16;
                                    _tempHeaderOffset = 0;
                                    _appendHeader     = false;
                                }
                                else
                                {
                                    _payloadLen = (int)readBuffer[_readOffset] | readBuffer[_readOffset + 1] << 8 |
                                                  readBuffer[_readOffset + 2] << 16;
                                }

                                if (_payloadLen <= 0)
                                {
                                    throw new Exception("invalid header");
                                }
                            }
                            catch (Exception)
                            {
                                process = false;
                                break;
                            }

                            _readableDataLen -= size;
                            _readOffset      += size;
                            _receiveState     = ReceiveType.Payload;
                        }
                        else         // _parentServer.HEADER_SIZE < _readableDataLen
                        {
                            _appendHeader = true;
                            Array.Copy(readBuffer, _readOffset, _tempHeader, _tempHeaderOffset, _readableDataLen);
                            _tempHeaderOffset += _readableDataLen;
                            process            = false;
                        }
                        break;
                    }

                    case ReceiveType.Payload:
                    {
                        if (_payloadBuffer == null || _payloadBuffer.Length != _payloadLen)
                        {
                            _payloadBuffer = new byte[_payloadLen];
                        }

                        int length = _readableDataLen;
                        if (_writeOffset + _readableDataLen >= _payloadLen)
                        {
                            length = _payloadLen - _writeOffset;
                        }

                        try
                        {
                            Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, length);
                        }
                        catch
                        {
                            Disconnect();
                        }

                        _writeOffset     += length;
                        _readOffset      += length;
                        _readableDataLen -= length;

                        if (_writeOffset == _payloadLen)
                        {
                            if (encryptionEnabled)
                            {
                                _payloadBuffer = AES.Decrypt(_payloadBuffer, Encoding.UTF8.GetBytes(Settings.PASSWORD));
                            }

                            if (_payloadBuffer.Length > 0)
                            {
                                if (compressionEnabled)
                                {
                                    _payloadBuffer = new SafeQuickLZ().Decompress(_payloadBuffer, 0, _payloadBuffer.Length);
                                }

                                using (MemoryStream deserialized = new MemoryStream(_payloadBuffer))
                                {
                                    IPacket packet =
                                        Serializer.DeserializeWithLengthPrefix <IPacket>(deserialized, PrefixStyle.Fixed32);

                                    OnClientRead(packet);
                                }
                            }
                            else         // payload decryption failed
                            {
                                process = false;
                            }

                            _receiveState  = ReceiveType.Header;
                            _payloadBuffer = null;
                            _payloadLen    = 0;
                            _writeOffset   = 0;
                        }

                        if (_readableDataLen == 0)
                        {
                            process = false;
                        }

                        break;
                    }
                    }
                }

                if (_receiveState == ReceiveType.Header)
                {
                    _writeOffset = 0; // prepare for next packet
                }
                _readOffset      = 0;
                _readableDataLen = 0;
            }
        }
示例#51
0
        private IReceiveMessage ParseUndirectedMessage(Regex regex, ReceiveType type, IMessageTarget sender, String line,
            IMessageTarget receiver)
        {
            Match results = regex.Match(line);
            if(results.Success)
            {
                String message = String.Empty;
                if(results.Groups[1].Success)
                    message = results.Groups[1].Value;

                return Client.CreateReceiveMessage(Connection, message, DateTime.Now, sender, receiver, type,
                    ReplyType.Unknown);
            }
            return null;
        }
示例#52
0
 public IReceiveMessage CreateReceiveMessage(IClientConnection connection, String contents, DateTime date,
                                             IMessageTarget sender, IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     return(new ReceiveMessage(connection, contents, date, sender, receiver, type, replyType));
 }
示例#53
0
 public IReceiveMessage CreateReceiveMessage(IClientConnection connection, String contents, DateTime date,
     IMessageTarget sender, IMessageTarget receiver, ReceiveType type, ReplyType replyType)
 {
     return new ReceiveMessage(connection, contents, date, sender, receiver, type, replyType);
 }
示例#54
0
        private void AsyncReceive(object state)
        {
            while (true)
            {
                byte[] readBuffer;
                lock (_readBuffers)
                {
                    if (_readBuffers.Count == 0)
                    {
                        lock (_readingMessagesLock)
                        {
                            _readingMessages = false;
                        }
                        return;
                    }

                    readBuffer = _readBuffers.Dequeue();
                }

                _readableDataLen += readBuffer.Length;
                bool process = true;
                while (process)
                {
                    switch (_receiveState)
                    {
                    case ReceiveType.Header:
                    {
                        if (_payloadBuffer == null)
                        {
                            _payloadBuffer = new byte[HEADER_SIZE];
                        }

                        if (_readableDataLen + _writeOffset >= HEADER_SIZE)
                        {
                            // completely received header
                            int headerLength = HEADER_SIZE - _writeOffset;

                            try
                            {
                                Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, headerLength);

                                _payloadLen = BitConverter.ToInt32(_payloadBuffer, _readOffset);

                                if (_payloadLen <= 0 || _payloadLen > MAX_MESSAGE_SIZE)
                                {
                                    throw new Exception("invalid header");
                                }

                                // try to re-use old payload buffers which fit
                                if (_payloadBuffer.Length <= _payloadLen + HEADER_SIZE)
                                {
                                    Array.Resize(ref _payloadBuffer, _payloadLen + HEADER_SIZE);
                                }
                            }
                            catch (Exception)
                            {
                                process = false;
                                Disconnect();
                                break;
                            }

                            _readableDataLen -= headerLength;
                            _writeOffset     += headerLength;
                            _readOffset      += headerLength;
                            _receiveState     = ReceiveType.Payload;
                        }
                        else         // _readableDataLen + _writeOffset < HeaderSize
                        {
                            // received only a part of the header
                            try
                            {
                                Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, _readableDataLen);
                            }
                            catch (Exception)
                            {
                                process = false;
                                Disconnect();
                                break;
                            }
                            _readOffset  += _readableDataLen;
                            _writeOffset += _readableDataLen;
                            process       = false;
                            // nothing left to process
                        }
                        break;
                    }

                    case ReceiveType.Payload:
                    {
                        int length = (_writeOffset - HEADER_SIZE + _readableDataLen) >= _payloadLen
                                    ? _payloadLen - (_writeOffset - HEADER_SIZE)
                                    : _readableDataLen;

                        try
                        {
                            Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, length);
                        }
                        catch (Exception)
                        {
                            process = false;
                            Disconnect();
                            break;
                        }

                        _writeOffset     += length;
                        _readOffset      += length;
                        _readableDataLen -= length;

                        if (_writeOffset - HEADER_SIZE == _payloadLen)
                        {
                            // completely received payload
                            try
                            {
                                using (PayloadReader pr = new PayloadReader(_payloadBuffer, _payloadLen + HEADER_SIZE, false))
                                {
                                    IMessage message = pr.ReadMessage();

                                    OnClientRead(message, _payloadBuffer.Length);
                                }
                            }
                            catch (Exception)
                            {
                                process = false;
                                Disconnect();
                                break;
                            }

                            _receiveState = ReceiveType.Header;
                            _payloadLen   = 0;
                            _writeOffset  = 0;
                        }

                        if (_readableDataLen == 0)
                        {
                            process = false;
                        }

                        break;
                    }
                    }
                }

                _readOffset      = 0;
                _readableDataLen = 0;
            }
        }
示例#55
0
        private void asyncReceive(object state)
        {
            while (true)
            {
                byte[] readBuffer;

                lock (_readBuffers)
                {
                    if (_readBuffers.Count == 0)
                    {
                        lock (_readingPacketsLock)
                        {
                            _readingPackets = false;
                        }
                        return;
                    }

                    readBuffer = _readBuffers.Dequeue();
                }

                _readableDataLen += readBuffer.Length;
                bool process = true;

                while (process)
                {
                    switch (_receiveState)
                    {
                    case ReceiveType.Header:     // PayloadLength
                    {
                        if (_readableDataLen >= HEADER_SIZE)
                        {
                            int headerLength = (_appendHeader) ? HEADER_SIZE - _tempHeaderOffset : HEADER_SIZE;

                            try
                            {
                                if (_appendHeader)
                                {
                                    try
                                    {
                                        Array.Copy(readBuffer, _readOffset, _tempHeader, _tempHeaderOffset,
                                                   headerLength);
                                    }
                                    catch (Exception)
                                    {
                                        process = false;
                                        disconnect();
                                        break;
                                    }
                                    _payloadLen       = BitConverter.ToInt32(_tempHeader, 0);
                                    _tempHeaderOffset = 0;
                                    _appendHeader     = false;
                                }
                                else
                                {
                                    _payloadLen = BitConverter.ToInt32(readBuffer, _readOffset);
                                }

                                if (_payloadLen <= 0 || _payloadLen > MAX_PACKET_SIZE)
                                {
                                    throw new Exception("invalid header");
                                }
                            }
                            catch (Exception)
                            {
                                process = false;
                                disconnect();
                                break;
                            }

                            _readableDataLen -= headerLength;
                            _readOffset      += headerLength;
                            _receiveState     = ReceiveType.Payload;
                        }
                        else        //  _readableDataLen < HEADER_SIZE
                        {
                            try
                            {
                                Array.Copy(readBuffer, _readOffset, _tempHeader, _tempHeaderOffset, _readableDataLen);
                            }
                            catch (Exception)
                            {
                                process = false;
                                disconnect();
                                break;
                            }
                            _tempHeaderOffset += _readableDataLen;
                            _appendHeader      = true;
                            process            = false;
                        }
                        break;
                    }

                    case ReceiveType.Payload:     //Deserialize Payload
                    {
                        if (_payloadBuffer == null || _payloadBuffer.Length != _payloadLen)
                        {
                            _payloadBuffer = new byte[_payloadLen];
                        }

                        int length = (_writeOffset + _readableDataLen >= _payloadLen) ? _payloadLen - _writeOffset : _readableDataLen;


                        try
                        {
                            Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, length);
                        }
                        catch (Exception)
                        {
                            process = false;
                            disconnect();
                            break;
                        }

                        _writeOffset     += length;
                        _readOffset      += length;
                        _readableDataLen -= length;

                        if (_writeOffset == _payloadLen)
                        {
                            bool isError = _payloadBuffer.Length == 0;

                            if (isError)
                            {
                                process = false;
                                disconnect();
                                break;
                            }

                            try
                            {
                                IPackets packet = ZeroFormatterSerializer.Deserialize <IPackets>(_payloadBuffer);
                                packetReader(packet);
                            }
                            catch (Exception)
                            {
                                process = false;
                                disconnect();
                                break;
                            }

                            _receiveState  = ReceiveType.Header;
                            _payloadBuffer = null;
                            _payloadLen    = 0;
                            _writeOffset   = 0;
                        }

                        if (_readableDataLen == 0)
                        {
                            process = false;
                        }
                        break;
                    }
                    }
                }

                if (_receiveState == ReceiveType.Header)
                {
                    _writeOffset = 0;
                }
                _readOffset      = 0;
                _readableDataLen = 0;
            }
        }
示例#56
0
        private void AsyncReceive(object state)
        {
            while (true)
            {
                byte[] readBuffer;
                lock (_readBuffers)
                {
                    if (_readBuffers.Count == 0)
                    {
                        lock (_readingPacketsLock)
                        {
                            _readingPackets = false;
                        }
                        return;
                    }

                    readBuffer = _readBuffers.Dequeue();
                }

                _readableDataLen += readBuffer.Length;
                bool process = true;
                while (process)
                {
                    switch (_receiveState)
                    {
                    case ReceiveType.Header:
                    {
                        if (_readableDataLen >= _parentServer.HEADER_SIZE)
                        {         // we can read the header
                            int headerLength = (_appendHeader)
                                        ? _parentServer.HEADER_SIZE - _tempHeaderOffset
                                        : _parentServer.HEADER_SIZE;

                            try
                            {
                                if (_appendHeader)
                                {
                                    try
                                    {
                                        Array.Copy(readBuffer, _readOffset, _tempHeader, _tempHeaderOffset,
                                                   headerLength);
                                    }
                                    catch (Exception)
                                    {
                                        process = false;
                                        Disconnect();
                                        break;
                                    }
                                    _payloadLen       = BitConverter.ToInt32(_tempHeader, 0);
                                    _tempHeaderOffset = 0;
                                    _appendHeader     = false;
                                }
                                else
                                {
                                    _payloadLen = BitConverter.ToInt32(readBuffer, _readOffset);
                                }

                                if (_payloadLen <= 0 || _payloadLen > _parentServer.MAX_PACKET_SIZE)
                                {
                                    throw new Exception("invalid header");
                                }
                            }
                            catch (Exception)
                            {
                                process = false;
                                Disconnect();
                                break;
                            }

                            _readableDataLen -= headerLength;
                            _readOffset      += headerLength;
                            _receiveState     = ReceiveType.Payload;
                        }
                        else         // _parentServer.HEADER_SIZE < _readableDataLen
                        {
                            try
                            {
                                Array.Copy(readBuffer, _readOffset, _tempHeader, _tempHeaderOffset, _readableDataLen);
                            }
                            catch (Exception)
                            {
                                process = false;
                                Disconnect();
                                break;
                            }
                            _tempHeaderOffset += _readableDataLen;
                            _appendHeader      = true;
                            process            = false;
                        }
                        break;
                    }

                    case ReceiveType.Payload:
                    {
                        if (_payloadBuffer == null || _payloadBuffer.Length != _payloadLen)
                        {
                            _payloadBuffer = new byte[_payloadLen];
                        }

                        int length = (_writeOffset + _readableDataLen >= _payloadLen)
                                    ? _payloadLen - _writeOffset
                                    : _readableDataLen;

                        try
                        {
                            Array.Copy(readBuffer, _readOffset, _payloadBuffer, _writeOffset, length);
                        }
                        catch (Exception)
                        {
                            process = false;
                            Disconnect();
                            break;
                        }

                        _writeOffset     += length;
                        _readOffset      += length;
                        _readableDataLen -= length;

                        if (_writeOffset == _payloadLen)
                        {
                            if (encryptionEnabled)
                            {
                                _payloadBuffer = AES.Decrypt(_payloadBuffer);
                            }

                            bool isError = _payloadBuffer.Length == 0;         // check if payload decryption failed

                            if (_payloadBuffer.Length > 0)
                            {
                                if (compressionEnabled)
                                {
                                    _payloadBuffer = SafeQuickLZ.Decompress(_payloadBuffer);
                                }

                                isError = _payloadBuffer.Length == 0;         // check if payload decompression failed
                            }

                            if (isError)
                            {
                                process = false;
                                Disconnect();
                                break;
                            }

                            using (MemoryStream deserialized = new MemoryStream(_payloadBuffer))
                            {
                                IPacket packet = (IPacket)_serializer.Deserialize(deserialized);

                                OnClientRead(packet);
                            }

                            _receiveState  = ReceiveType.Header;
                            _payloadBuffer = null;
                            _payloadLen    = 0;
                            _writeOffset   = 0;
                        }

                        if (_readableDataLen == 0)
                        {
                            process = false;
                        }

                        break;
                    }
                    }
                }

                if (_receiveState == ReceiveType.Header)
                {
                    _writeOffset = 0; // prepare for next packet
                }
                _readOffset      = 0;
                _readableDataLen = 0;
            }
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        public ParallelServerOps()
        {
            CallBackObj = null;
            Port = ParallelSocketConf.DEFAULT_PORT;
            ReceiveType = ReceiveType.SEQUENTIAL;

        }