public CryptoInitializer(SmartFox sfs)
 {
     if (!sfs.IsConnected)
     {
         throw new InvalidOperationException("Cryptography cannot be initialized before connecting to SmartFoxServer!");
     }
     if (sfs.GetSocketEngine().CryptoKey != null)
     {
         throw new InvalidOperationException("Cryptography is already initialized!");
     }
     this.sfs = sfs;
 }
        private void OnHttpResponse(string rawData)
        {
            byte[]    data       = Convert.FromBase64String(rawData);
            ByteArray byteArray  = new ByteArray();
            ByteArray byteArray2 = new ByteArray();

            byteArray.WriteBytes(data, 0, 16);
            byteArray2.WriteBytes(data, 16, 16);
            sfs.GetSocketEngine().CryptoKey = new CryptoKey(byteArray2, byteArray);
            Hashtable hashtable             = new Hashtable();

            hashtable["success"] = true;
            sfs.DispatchEvent(new SFSEvent(SFSEvent.CRYPTO_INIT, hashtable));
        }
Example #3
0
 public UDPManager(SmartFox sfs)
 {
     this.sfs = sfs;
     packetId = 0L;
     if (sfs != null)
     {
         log = sfs.Log;
     }
     else
     {
         log = new Logger(null);
     }
     currentAttempt  = 1;
     packetEncrypter = new DefaultPacketEncrypter(sfs.GetSocketEngine() as BitSwarmClient);
 }
Example #4
0
        private void OnUDPData(byte[] bt)
        {
            //Discarded unreachable code: IL_014c
            ByteArray byteArray = new ByteArray(bt);

            if (byteArray.BytesAvailable < 4)
            {
                log.Warn("Too small UDP packet. Len: " + byteArray.Length);
                return;
            }
            if (sfs.Debug)
            {
                log.Info("UDP Data Read: " + DefaultObjectDumpFormatter.HexDump(byteArray));
            }
            byte  b     = byteArray.ReadByte();
            bool  flag  = (b & 0x20) > 0;
            bool  flag2 = (b & 0x40) > 0;
            short num   = byteArray.ReadShort();

            if (num != byteArray.BytesAvailable)
            {
                log.Warn("Insufficient UDP data. Expected: " + num + ", got: " + byteArray.BytesAvailable);
                return;
            }
            byte[]    buf        = byteArray.ReadBytes(byteArray.BytesAvailable);
            ByteArray byteArray2 = new ByteArray(buf);

            if (flag2)
            {
                try
                {
                    packetEncrypter.Decrypt(byteArray2);
                }
                catch (Exception ex)
                {
                    log.Warn("UDP data decryption failed due to error: " + ex.Message + " " + ex.StackTrace);
                    return;
                }
            }
            if (flag)
            {
                byteArray2.Uncompress();
            }
            ISFSObject iSFSObject = SFSObject.NewFromBinaryData(byteArray2);

            if (iSFSObject.ContainsKey("h"))
            {
                if (!initSuccess)
                {
                    StopTimer();
                    locked      = false;
                    initSuccess = true;
                    Hashtable hashtable = new Hashtable();
                    hashtable["success"] = true;
                    sfs.DispatchEvent(new SFSEvent(SFSEvent.UDP_INIT, hashtable));
                }
            }
            else
            {
                sfs.GetSocketEngine().IoHandler.Codec.OnPacketRead(iSFSObject);
            }
        }