//*********************************************************************************************
        //* Metodi eleborazione richieste
        //*********************************************************************************************
        // Richiesta autorizzazione cdkey
        private void OnCdKeyAuthorizationRequest(IPEndPoint sender, byte[] buffer)
        {
            try
            {
                UInt16 port;
                UInt16 keycount;
                UInt32 ip;
                UInt16 playerport;
                byte[] salt;
                UInt16 len;
                List<CDKeyInfo> keys;
                String playername;

                // Interazzi
                port = BitConverter.ToUInt16(buffer, 0);
                keycount = BitConverter.ToUInt16(buffer, 2);
                ip = BitConverter.ToUInt32(buffer, 4);
                playerport = BitConverter.ToUInt16(buffer, 8);
                len = BitConverter.ToUInt16(buffer, 10);

                // Imposta salt
                salt = new byte[len];

                // Bytazzi bufferazzi
                Buffer.BlockCopy(buffer, 12, salt, 0, len);

                // Contatore entries
                UInt16 count = BitConverter.ToUInt16(buffer, 12 + len);
                // Imposta lista
                keys = new List<CDKeyInfo>();
                // Offset
                int offset = 12 + len + 2;
                int index = count;

                while (index-- > 0)
                {
                    CDKeyInfo key = new CDKeyInfo();
                    // Lunghezza chiave pubblica
                    UInt16 pklen = BitConverter.ToUInt16(buffer, offset);
                    key.PublicCDKey = Encoding.UTF8.GetString(buffer, offset + 2, pklen);
                    offset += pklen + 2;
                    // Lunghezza hash
                    UInt16 hlen = BitConverter.ToUInt16(buffer, offset);
                    key.CDKeyHash = new byte[hlen];
                    Buffer.BlockCopy(buffer, offset + 2, key.CDKeyHash, 0, hlen);
                    offset += 2 + hlen;

                    // Aggiunge chiave alla lista
                    keys.Add(key);
                }

                // Legge lunghezza username
                UInt16 plen = BitConverter.ToUInt16(buffer, offset);
                playername = Encoding.UTF8.GetString(buffer, offset + 2, plen);

                SendCdKeyAuthorizationResponse(sender, keys, "");
            }
            catch (Exception e)
            {
            }
        }
Example #2
0
        /// <summary>
        /// This method parses and handles a CD-Key authorization request from
        /// from a game server.
        /// </summary>
        /// <param name="Parser">Supplies the message parse context.</param>
        /// <param name="Sender">Supplies the game server address.</param>
        /// <param name="Socket">Supplies the associated socket descriptor
        /// upon which the message was received.</param>
        private void OnRecvMstCDKeyAuthorizationRequest(ExoParseBuffer Parser, IPEndPoint Sender, SocketInfo Socket)
        {
            UInt16 DataPort;
            UInt16 EntryCount;
            UInt32 ClientIP;
            UInt16 ClientPort;
            byte[] ServerChallenge;
            UInt16 Length;
            List<CDKeyInfo> CDKeyHashes;
            CDKeyInfo CDKeyHash;
            string AccountName;
            int KeyIndex;
            int PortNumberHbo;

            if (!Parser.ReadWORD(out DataPort))
                return;
            if (!Parser.ReadWORD(out EntryCount))
                return;
            if (EntryCount != 1)
                return;
            if (!Parser.ReadDWORD(out ClientIP))
                return;
            if (!Parser.ReadWORD(out ClientPort))
                return;

            PortNumberHbo = IPAddress.NetworkToHostOrder(ClientPort);

            if ((PortNumberHbo == 0) || ((PortNumberHbo & 0xFFFF) != PortNumberHbo))
                PortNumberHbo = 5120;

            IPEndPoint ClientEndpoint = new IPEndPoint((long)ClientIP, PortNumberHbo);

            if (!Parser.ReadWORD(out Length))
                return;
            if ((ServerChallenge = Parser.ReadBytes(Length)) == null)
                return;
            if (!Parser.ReadWORD(out Length))
                return;

            CDKeyHashes = new List<CDKeyInfo>();
            CDKeyHash = new CDKeyInfo();

            KeyIndex = 0;
            while (Length-- != 0)
            {
                UInt16 HashLength;

                if (!Parser.ReadSmallString(out CDKeyHash.PublicCDKey, 16))
                    return;
                if (!Parser.ReadWORD(out HashLength))
                    return;
                if ((CDKeyHash.CDKeyHash = Parser.ReadBytes(HashLength)) == null)
                    return;

                //
                // N.B.  The following is somewhat of a hack in that we are not
                //       bothering to extract the (real) product type from the
                //       CD-Key.  As a result, it is possible that the wrong
                //       answer could be provided for clients without all of
                //       the expansions; this situation is considered unlikely
                //       in the current state of affairs.
                //
                //       A better fit could be had by examining the expansion
                //       mask required by the server in the data table, but
                //       this does not appear worthwhile at this stage.
                //

                if (KeyIndex == 0)
                    CDKeyHash.Product = 0;
                else
                    CDKeyHash.Product = (UInt16) (1 << (KeyIndex - 1));

                CDKeyHash.AuthStatus = (UInt16)ConnectStatus.CONNECT_ERR_SUCCESS;

                CDKeyHashes.Add(CDKeyHash);
            }

            if (!Parser.ReadSmallString(out AccountName, 16))
                return;

            SendMstCDKeyAuthorization(Sender, CDKeyHashes);
        }