Esempio n. 1
0
        //   server sends C packet to client, which contains the shared key, and also the temporary client key the client sent
        //    server knows key now, client will receive it
        //    Packet format:   [int32 xxx][short xxx][char 'C'][temporary client key][shared key]
        //    server replies to any R packet, generating the shared key if the connection didnt exist before
        public void RPacketHandler(object source, PacketHandlerArgs e)
        {
            if (isserver)
            {
                byte[] packet           = e.Data;
                int    tempnextposition = e.NextPosition;
                int    tempclientkey    = (int)binarypacker.ReadValueFromBuffer(packet, ref tempnextposition, typeof(int));

                LogFile.WriteLine("R packet received, sending C packet, tempclientkey: " + tempclientkey.ToString() + " sharedkey: " + SharedSecretKey.ToString());

                byte[] newpacket = new byte[8];
                tempnextposition = 0;
                binarypacker.WriteValueToBuffer(newpacket, ref tempnextposition, tempclientkey);
                binarypacker.WriteValueToBuffer(newpacket, ref tempnextposition, SharedSecretKey);

                parent.SendNonAckable('C', newpacket);
                if (!Validated)
                {
                    Validated = true;
                    LogFile.WriteLine("Shared key sent; marking connection open");
                    parent.OnConnectionValidated();
                }
            }
        }