Esempio n. 1
0
        void CheckUserCredentials(String ClientId, Byte[] _Data)
        {
            try
            {
                PacketData IncomingData = new PacketData();
                IncomingData = (PacketData)PacketFunctions.ByteArrayToStructure(_Data, typeof(PacketData));

                lock (_WorkerSockets)
                {
                    if (PacketFunctions.Verify(IncomingData))
                    {
                        _WorkerSockets[ClientId].Timestamp = IncomingData.Timestamp;
                        _WorkerSockets[ClientId].Accepted  = true;
                        _WorkerSockets[ClientId].Signature = IncomingData.Signature.NormalizeChars();
                        _WorkerSockets[ClientId].PublicKey = IncomingData.PublicKey.NormalizeChars();

                        SendRegisteredMessage(ClientId);
                    }
                    else
                    {
                        ClientDisconnect(ClientId);
                    }
                }
            }
            catch (Exception ex)
            {
                // ToDo
            }
        }
Esempio n. 2
0
        void AssembleMessage(String _ClientID, Byte[] _Data)
        {
            try
            {
                PacketData IncomingData = new PacketData();
                IncomingData = (PacketData)PacketFunctions.ByteArrayToStructure(_Data, typeof(PacketData));

                if (IncomingData.Verify() == false)
                {
                    return;
                }

                switch (IncomingData.Packet_SubType)
                {
                case (UInt16)PacketTypeSubmessage.SUBMSG_MessageStart:
                {
                    if (_WorkerSockets.ContainsKey(_ClientID))
                    {
                        _WorkerSockets[_ClientID].MessageBuilder = new List <byte>(IncomingData.Data);
                    }
                }
                break;

                case (UInt16)PacketTypeSubmessage.SUBMSG_MessageBody:
                {
                    _WorkerSockets[_ClientID].MessageBuilder.AddRange(IncomingData.Data);
                }
                break;

                case (UInt16)PacketTypeSubmessage.SUBMSG_MessageEnd:
                {
                    _WorkerSockets[_ClientID].MessageBuilder.AddRange(IncomingData.Data);

                    var _UncompressedData = Helpers.DataCompressor.Unzip(_WorkerSockets[_ClientID].MessageBuilder.ToArray());
                    var _JObj             = JObject.Parse(_UncompressedData);
                    if (_FinalizedMessages.ContainsKey(_ClientID))
                    {
                        _FinalizedMessages[_ClientID].Add(_JObj);
                    }
                    else
                    {
                        _FinalizedMessages.Add(_ClientID, new List <JObject>()
                            {
                                _JObj
                            });
                    }

                    _WorkerSockets[_ClientID].MessageBuilder = new List <byte>();

                    PacketData _Responce = new PacketData();
                    _Responce.Packet_Type = (UInt16)PacketType.TYPE_MessageReceived;
                    Helpers.DataCompressor.Zip((String)_JObj["id"]).CopyTo(_Responce.Data, 0);
                    //_FinalizedMessages
                    Byte[] _ResponceData = PacketFunctions.StructureToByteArray(_Responce);

                    SendMessage(_ClientID, _ResponceData, PacketType.TYPE_MessageReceived);
                }
                break;
                }
            }
            catch
            {
                // ToDo
            }
        }