protected override void ProcessFirstMessage(bool isChecksummed)
        {
            if (!isChecksummed)
            {
                ProcessStatusMessage();
                return;
            }

            InMessage.GetByte();             //Protocol Id
            InMessage.GetUInt16();           //Client OS
            Version = InMessage.GetUInt16(); //Client Version

            if (Version < Constants.ClientVersionMin || Version > Constants.ClientVersionMax)
            {
                Disconnect("Only clients with protocol " + Constants.ClientVersionStr + " allowed!", Version);
                return;
            }

            //This is 10.76 server, only handling 10.76 client bytes
            InMessage.SkipBytes(17);

            /*
             * Skipped bytes:
             * 4 bytes: protocolVersion
             * 12 bytes: dat, spr, pic signatures (4 bytes each)
             * 1 byte: 0
             *
             */

            if (!InMessage.RsaDecrypt())
            {
                Logger.Log(LogLevels.Information, "LoginConnection: Message could not be decrypted");
                Disconnect();
                return;
            }

            XteaKey[0]          = InMessage.GetUInt32();
            XteaKey[1]          = InMessage.GetUInt32();
            XteaKey[2]          = InMessage.GetUInt32();
            XteaKey[3]          = InMessage.GetUInt32();
            IsEncryptionEnabled = true;

            string accountName = InMessage.GetString();

            byte[] password = InMessage.GetBytes(InMessage.GetUInt16());

            DispatcherManager.DatabaseDispatcher.AddTask(() => HandleLoginPacket(accountName, password));
        }
Exemple #2
0
        private bool CompleteRead(IAsyncResult ar)
        {
            try
            {
                int read = Stream.EndRead(ar);

                if (read == 0)
                {
                    // client disconnected
                    Close();
                    return(false);
                }

                int size = BitConverter.ToUInt16(InMessage.Buffer, 0) + 2;

                while (read < size)
                {
                    if (Stream.CanRead)
                    {
                        read += Stream.Read(InMessage.Buffer, read, size - read);
                    }
                }

                InMessage.Resize(size);
                InMessage.GetUInt16(); // total length

                return(true);
            }
            catch (Exception e)
            {
                // TODO: I must not swallow exceptions.
                // TODO: is closing the connection really necesary?
                Console.WriteLine(e.ToString());
                Close();
            }

            return(false);
        }