Пример #1
0
        private void Receive(IAsyncResult ar)
        {
            if (IsClientConnected())
            {
                int bytesReceived = tcpClient.Client.EndReceive(ar);
                if (bytesReceived != 0)
                {
                    Interlocked.Increment(ref transferred);
                    Interlocked.Increment(ref received);

                    AuthenticationCrypto.Decrypt(Buffer, 0, 1);
                    if ((Buffer[0] & 0x80) != 0)
                    {
                        byte temp = Buffer[0];
                        Buffer    = new byte[5];
                        Buffer[0] = (byte)((0x7f & temp));

                        remaining = 4;
                    }
                    else
                    {
                        remaining = 3;
                    }

                    index = 1;
                    tcpClient.Client.BeginReceive(Buffer, index, remaining, SocketFlags.None, new AsyncCallback(ReceiveHeader), null);
                }
            }
        }
Пример #2
0
        private void ReceiveHeader(IAsyncResult ar)
        {
            if (IsClientConnected())
            {
                int bytesReceived = tcpClient.Client.EndReceive(ar);
                if (bytesReceived != 0)
                {
                    Interlocked.Add(ref transferred, bytesReceived);
                    Interlocked.Add(ref received, bytesReceived);

                    if (bytesReceived == remaining)
                    {
                        AuthenticationCrypto.Decrypt(Buffer, 1, Buffer.Length - 1);
                        ServerHeader header = new ServerHeader(Buffer);

                        if (header.Opcode == Opcodes.SMSG_GM_MESSAGECHAT || header.Opcode == Opcodes.SMSG_MESSAGECHAT)
                        {
                            Debug.WriteLine(header.Opcode);
                        }


                        if (header.Size > 0)
                        {
                            index     = 0;
                            remaining = header.Size;
                            Buffer    = new byte[header.Size];
                            tcpClient.Client.BeginReceive(Buffer, index, remaining, SocketFlags.None, new AsyncCallback(ReceivePayload), header);
                        }
                        else
                        {
                            HandleIncoming(new PacketReader(header));
                            Start();
                        }
                    }
                    else
                    {
                        index     += bytesReceived;
                        remaining -= bytesReceived;
                        tcpClient.Client.BeginReceive(Buffer, index, remaining, SocketFlags.None, new AsyncCallback(ReceiveHeader), null);
                    }
                }
            }
        }
Пример #3
0
        void HandleServerAuthChallenge(PacketReader reader)
        {
            uint one  = reader.ReadUInt32();
            uint seed = reader.ReadUInt32();

            BigInteger seed1 = reader.ReadBytes(16).ToBigInteger();
            BigInteger seed2 = reader.ReadBytes(16).ToBigInteger();

            var rand = System.Security.Cryptography.RandomNumberGenerator.Create();

            byte[] bytes = new byte[4];
            rand.GetBytes(bytes);

            BigInteger _seed = bytes.ToBigInteger();

            uint zero = 0;

            byte[] response = HashAlgorithm.SHA1.Hash(Encoding.ASCII.GetBytes(Manager.m_WorldServer.username.ToUpper()),
                                                      BitConverter.GetBytes(zero),
                                                      BitConverter.GetBytes((uint)_seed),
                                                      BitConverter.GetBytes(seed),
                                                      Manager.m_WorldServer.SessionKey.ToCleanByteArray());

            PacketWriter writer = new PacketWriter(Opcodes.ClientAuthSession);

            writer.Write((uint)12340);
            writer.Write(zero);
            writer.Write(Manager.m_WorldServer.username.ToUpper().ToCString());
            writer.Write(zero);
            writer.Write((uint)_seed);
            writer.Write(zero);
            writer.Write(zero);
            writer.Write(zero);
            writer.Write((ulong)zero);
            writer.Write(response);
            writer.Write(zero);

            Send(writer);

            AuthenticationCrypto.Initialize(Manager.m_WorldServer.SessionKey.ToCleanByteArray());
        }