Beispiel #1
0
        // =============== Process Data ===================

        void ProcessData(Connection conn, byte[] payload, int len)
        {
            Header header = MessageUtil.DeserializeHeader(payload, len);

            // ======== Encypted Message ===============
            if (header.Channel == MessageTypes.AESMessage)
            {
                if (AESKeys.TryGetValue(conn, out string key))
                {
                    try
                    {
                        AESMessage message = AESMessage.Desserialize(payload, len);
                        message.Decrypt(key);
                        payload = message.message;
                        header  = MessageUtil.DeserializeHeader(payload, payload.Length);

                        if (header.Parted)
                        {
                            ProcessMesagePart(ref header, conn, payload, payload.Length);
                        }
                        else
                        {
                            ProcessMessage(ref header, conn, payload, payload.Length);
                        }
                        return;
                    }
                    catch { Log.WriteNow("Failed to pass Encrypted Message. Wrong Key?"); return; }
                }
                else
                {
                    Log.WriteNow("Failed to pass Encrypted Message. No Key Found For Connection"); return;
                }
            }
            // ========= End Encrpted Message ==================

            if (header.Parted)
            {
                ProcessMesagePart(ref header, conn, payload, len);
            }
            else
            {
                ProcessMessage(ref header, conn, payload, len);
            }
        }
Beispiel #2
0
        // ============== Processing Data ===============

        void ProcessData(byte[] payload, int len)
        {
            Header header = MessageUtil.DeserializeHeader(payload, len);

            // ======== Encypted Message ===============
            if (header.Channel == MessageTypes.AESMessage)
            {
                try
                {
                    AESMessage message = AESMessage.Desserialize(payload, len);
                    message.Decrypt(AESKey);
                    payload = message.message;
                    header  = MessageUtil.DeserializeHeader(payload, payload.Length);

                    if (header.Parted)
                    {
                        ProcessMessagePart(ref header, payload, payload.Length);
                    }
                    else
                    {
                        ProcessMessage(ref header, payload, payload.Length);
                    }

                    return;
                }
                catch { Log.WriteNow("Failed to pass Encrypted Message. Wrong Key?"); return; }
            }
            // ========= End Encrpted Message ==================

            if (header.Parted)
            {
                ProcessMessagePart(ref header, payload, len);
            }
            else
            {
                ProcessMessage(ref header, payload, len);
            }
        }