private async void LoginAccountOld()
        {
            switch (_settings.Client.ProductCode)
            {
            case "W2BN":
                BncsPacket pck0x29 = new BncsPacket(BncsPacketId.LogonResponse, _storage.Acquire());
                pck0x29.InsertInt32(_clientToken);
                pck0x29.InsertInt32(_srvToken);
                pck0x29.InsertByteArray(OldAuth.DoubleHashPassword(_settings.Password, _clientToken, _srvToken));
                pck0x29.InsertCString(_settings.Username);

                await pck0x29.SendAsync(_connection);

                break;

            case "STAR":
            case "SEXP":
            case "D2DV":
            case "D2XP":
                BncsPacket pck0x3a = new BncsPacket(BncsPacketId.LogonResponse2, _storage.Acquire());
                pck0x3a.InsertInt32(_clientToken);
                pck0x3a.InsertInt32(_srvToken);
                pck0x3a.InsertByteArray(OldAuth.DoubleHashPassword(_settings.Password, _clientToken, _srvToken));
                pck0x3a.InsertCString(_settings.Username);

                await pck0x3a.SendAsync(_connection);

                break;

            default:
                throw new NotSupportedException(string.Format("Client '{0}' is not supported with old-style account login.", _settings.Client.ProductCode));
            }
        }
Example #2
0
        private void LoginAccountOld()
        {
            switch (m_settings.Client)
            {
            case "W2BN":
                BncsPacket pck0x29 = new BncsPacket((byte)BncsPacketId.LogonResponse);
                pck0x29.Insert(m_clientToken);
                pck0x29.Insert(m_srvToken);
                pck0x29.InsertByteArray(OldAuth.DoubleHashPassword(m_settings.Password, m_clientToken, m_srvToken));
                pck0x29.InsertCString(m_settings.Username);

                Send(pck0x29);
                break;

            case "STAR":
            case "SEXP":
            case "D2DV":
            case "D2XP":
                BncsPacket pck0x3a = new BncsPacket((byte)BncsPacketId.LogonResponse2);
                pck0x3a.Insert(m_clientToken);
                pck0x3a.Insert(m_srvToken);
                pck0x3a.InsertByteArray(OldAuth.DoubleHashPassword(
                                            m_settings.Password,
                                            m_clientToken, m_srvToken));
                pck0x3a.InsertCString(m_settings.Username);

                Send(pck0x3a);
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, Strings.BnetClient_LoginAccountOld_ClientNotSupported_fmt, m_settings.Client));
            }
        }
Example #3
0
        private void CreateAccountOld()
        {
            byte[]     passwordHash = OldAuth.HashPassword(m_settings.Password);
            BncsPacket pck          = new BncsPacket((byte)BncsPacketId.CreateAccount2);

            pck.InsertByteArray(passwordHash);
            pck.InsertCString(m_settings.Username);

            Send(pck);
        }
Example #4
0
        private void Send_SID_LOGONREALMEX(string a_sRealmTitle)
        {
            BncsPacket bncsPacket = new BncsPacket(62);

            byte[] b = OldAuth.DoubleHashPassword("password", this.g_iClientToken, this.g_iServerToken);
            bncsPacket.InsertInt32(this.g_iClientToken);
            bncsPacket.InsertByteArray(b);
            bncsPacket.InsertCString(a_sRealmTitle);
            this.SendPacket(bncsPacket.UnderlyingBuffer);
        }
        private async void CreateAccountOld()
        {
            byte[]     passwordHash = OldAuth.HashPassword(_settings.Password);
            BncsPacket pck          = new BncsPacket(BncsPacketId.CreateAccount2, _storage.Acquire());

            pck.InsertByteArray(passwordHash);
            pck.InsertCString(_settings.Username);

            await pck.SendAsync(_connection);
        }
Example #6
0
        private void Send_SID_LOGONRESPONSE()
        {
            byte[] b = new byte[0];
            b = OldAuth.DoubleHashPassword(this.BnetInfo.BnetPassword, this.g_iClientToken, this.g_iServerToken);
            BncsPacket bncsPacket = new BncsPacket(58);

            bncsPacket.InsertInt32(this.g_iClientToken);
            bncsPacket.InsertInt32(this.g_iServerToken);
            bncsPacket.InsertByteArray(b);
            bncsPacket.InsertCString(this.BnetInfo.BnetUserName);
            this.SendPacket(bncsPacket.UnderlyingBuffer);
        }
Example #7
0
        public virtual void LogonRealm(RealmServer server)
        {
            if (object.ReferenceEquals(server, null))
            {
                throw new ArgumentNullException("server");
            }

            Random r           = new Random();
            int    clientToken = r.Next();

            byte[]     passwordHash = OldAuth.DoubleHashPassword("password", clientToken, m_serverToken);
            BncsPacket pck          = new BncsPacket((byte)BncsPacketId.LogonRealmEx);

            pck.InsertInt32(clientToken);
            pck.InsertByteArray(passwordHash);
            pck.InsertCString(server.Title);

            m_client.Send(pck);
        }
Example #8
0
        public override bool Invoke(MessageContext context)
        {
            switch (context.Direction)
            {
            case MessageDirection.ClientToServer:
            {
                Logging.WriteLine(Logging.LogLevel.Debug, Logging.LogType.Client_Game, context.Client.RemoteEndPoint, $"[{Common.DirectionToString(context.Direction)}] SID_LOGONRESPONSE ({4 + Buffer.Length} bytes)");

                if (Buffer.Length < 29)
                {
                    throw new GameProtocolViolationException(context.Client, "SID_LOGONRESPONSE buffer must be at least 29 bytes");
                }

                /**
                 * (UINT32)     Client Token
                 * (UINT32)     Server Token
                 *  (UINT8)[20] Password Hash
                 * (STRING)     Username
                 */

                var m = new MemoryStream(Buffer);
                var r = new BinaryReader(m);

                var clientToken  = r.ReadUInt32();
                var serverToken  = r.ReadUInt32();
                var passwordHash = r.ReadBytes(20);
                context.Client.GameState.Username = r.ReadString();

                Statuses status = Statuses.None;

                Battlenet.Common.AccountsDb.TryGetValue(context.Client.GameState.Username, out Account account);

                if (status == Statuses.None && account == null)
                {
                    status = Statuses.Failure;
                }

                if (status == Statuses.None)
                {
                    var passwordHashDb = (byte[])account.Get(Account.PasswordKey, new byte[20]);
                    var compareHash    = OldAuth.CheckDoubleHashData(passwordHashDb, clientToken, serverToken);
                    if (compareHash.Equals(passwordHash))
                    {
                        status = Statuses.Failure;
                    }
                }

                if (status == Statuses.None)
                {
                    var flags = (Account.Flags)account.Get(Account.FlagsKey, Account.Flags.None);
                    if ((flags & Account.Flags.Closed) != 0)
                    {
                        status = Statuses.Failure;
                    }
                }

                if (status == Statuses.None)
                {
                    context.Client.GameState.ActiveAccount = account;
                    context.Client.GameState.LastLogon     = (DateTime)account.Get(Account.LastLogonKey, DateTime.Now);

                    account.Set(Account.IPAddressKey, context.Client.RemoteEndPoint.ToString().Split(":")[0]);
                    account.Set(Account.LastLogonKey, DateTime.Now);
                    account.Set(Account.PortKey, context.Client.RemoteEndPoint.ToString().Split(":")[1]);

                    lock (Battlenet.Common.ActiveAccounts)
                    {
                        var serial     = 1;
                        var onlineName = context.Client.GameState.Username;

                        while (Battlenet.Common.ActiveAccounts.ContainsKey(onlineName))
                        {
                            onlineName = $"{context.Client.GameState.Username}#{++serial}";
                        }

                        context.Client.GameState.OnlineName = onlineName;
                        Battlenet.Common.ActiveAccounts.Add(onlineName, account);
                    }

                    context.Client.GameState.Username = (string)account.Get(Account.UsernameKey, context.Client.GameState.Username);

                    lock (Battlenet.Common.ActiveGameClients)
                    {
                        Battlenet.Common.ActiveGameClients.Add(context.Client.GameState.OnlineName, context.Client.GameState);
                    }

                    status = Statuses.Success;
                }

                r.Close();
                m.Close();

                return(new SID_LOGONRESPONSE2().Invoke(new MessageContext(context.Client, MessageDirection.ServerToClient, new Dictionary <string, object> {
                        { "status", status },
                    })));
            }

            case MessageDirection.ServerToClient:
            {
                /**
                 * (UINT32) Status
                 */

                Buffer = new byte[4];

                var m = new MemoryStream(Buffer);
                var w = new BinaryWriter(m);

                w.Write((UInt32)(Statuses)context.Arguments["status"]);

                w.Close();
                m.Close();

                Logging.WriteLine(Logging.LogLevel.Debug, Logging.LogType.Client_Game, context.Client.RemoteEndPoint, $"[{Common.DirectionToString(context.Direction)}] SID_LOGONRESPONSE ({4 + Buffer.Length} bytes)");
                context.Client.Send(ToByteArray());
                return(true);
            }
            }

            return(false);
        }