コード例 #1
0
        private void HandleLogonResponse(ParseData data)
        {
            DataReader dr     = new DataReader(data.Data);
            int        status = dr.ReadInt32();

            if (status == 1)
            {
                OnLoginSucceeded(BaseEventArgs.GetEmpty(data));
                Product product = Product.GetByProductCode(m_settings.Client);
                if (product.UsesUdpPing)
                {
                    BncsPacket pck = new BncsPacket((byte)BncsPacketId.UdpPingResponse);
                    pck.InsertDwordString("bnet");
                    Send(pck);
                }

                EnterChat();
            }
            else
            {
                LoginFailedEventArgs args = new LoginFailedEventArgs(LoginFailureReason.InvalidAccountOrPassword, status)
                {
                    EventData = data
                };
                OnLoginFailed(args);
            }
        }
コード例 #2
0
        public override bool Connect()
        {
            eventsToFire.Enqueue(new InvokeHelper <EventArgs> {
                Target = OnConnected, Arguments = EventArgs.Empty
            });
            eventsToFire.Enqueue(new InvokeHelper <BaseEventArgs> {
                Target = OnClientCheckPassed, Arguments = BaseEventArgs.GetEmpty(null)
            });
            eventsToFire.Enqueue(new InvokeHelper <InformationEventArgs> {
                Target = OnInformation, Arguments = new InformationEventArgs("Login succeeded!")
            });
            eventsToFire.Enqueue(new InvokeHelper <BaseEventArgs> {
                Target = OnLoginSucceeded, Arguments = BaseEventArgs.GetEmpty(null)
            });
            eventsToFire.Enqueue(new InvokeHelper <EnteredChatEventArgs> {
                Target = OnEnteredChat, Arguments = new EnteredChatEventArgs(Settings.Username, CreateStatstringForClient(Settings.Client), Settings.Username)
            });
            eventsToFire.Enqueue(new InvokeHelper <ServerChatEventArgs> {
                Target = OnServerBroadcast, Arguments = new ServerChatEventArgs(ChatEventType.Information, 0, "Welcome to Battle.net!  This server is simulated.")
            });
            eventsToFire.Enqueue(new InvokeHelper <ChannelListEventArgs> {
                Target = OnChannelListReceived, Arguments = new ChannelListEventArgs(new string[] { "Starcraft USA-1", "Clan Recruitment", "The Void", "Public Tech Support", "Blizzard Tech Support" })
            });
            EnqueueNewChannelEvents("Starcraft USA-1");
            tmrGo.Start();

            return(true);
        }
コード例 #3
0
        private void HandleAuthAccountLogonProof(ParseData data)
        {
            DataReader dr = new DataReader(data.Data);

            int status = dr.ReadInt32();

            byte[] m2 = dr.ReadByteArray(20);
            // 0 = success
            // 2 = incorrect password
            // 14 = success; register e-mail
            // 15 = custom error
            switch (status)
            {
            case 0:
                // success
                if (!m_nls.VerifyServerProof(m2))
                {
                    //CloseWithError(BattleNet.LoginProofServerProofFailed);
                    OnError(new ErrorEventArgs(ErrorType.LoginServerProofFailed, Strings.LoginProofServerProofFailed, false));
                    EnterChat();
                }
                else
                {
                    OnInformation(new InformationEventArgs(Strings.LoginProofSuccess));
                    OnLoginSucceeded(BaseEventArgs.GetEmpty(null));
                    EnterChat();
                }
                break;

            case 2:
                CloseWithError(Strings.LoginProofClientProofFailed, ErrorType.InvalidUsernameOrPassword);
                break;

            case 14:
                if (!m_nls.VerifyServerProof(m2))
                {
                    OnError(new ErrorEventArgs(ErrorType.LoginServerProofFailed, Strings.LoginProofServerProofFailed, false));
                    EnterChat();
                }
                else
                {
                    OnInformation(new InformationEventArgs(Strings.LoginProofRegisterEmail));
                    EnterChat();
                }
                break;

            case 15:
                CloseWithError(
                    string.Format(CultureInfo.CurrentCulture, Strings.LoginProofCustomError, dr.ReadCString()),
                    ErrorType.InvalidUsernameOrPassword
                    );
                break;
            }

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
        }
コード例 #4
0
        private void HandleLogonResponse2(PD data)
        {
            DataReader dr      = new DataReader(data.Data);
            int        success = dr.ReadInt32();

            if (success == 0)
            {
                m_events.OnLoginSucceeded(BaseEventArgs.GetEmpty(data));

                BncsPacket pck = new BncsPacket((byte)BncsPacketId.QueryRealms2);
            }
            else
            {
                m_events.OnLoginFailed(new LoginFailedEventArgs(LoginFailureReason.AccountDoesNotExist, success));
            }
        }
コード例 #5
0
ファイル: BattleNetClient.cs プロジェクト: wjlafrance/jinxbot
        /// <summary>
        /// Begins the connection to Battle.net.
        /// </summary>
        /// <returns><see langword="true" /> if the connection succeeded; otherwise <see langword="false" />.</returns>
        public override bool Connect()
        {
            BattleNetClientResources.RegisterClient(this);

            bool ok = base.Connect();

            if (ok)
            {
                InitializeListenState();

                CultureInfo ci = CultureInfo.CurrentCulture;
                RegionInfo  ri = RegionInfo.CurrentRegion;
                TimeSpan    ts = DateTime.UtcNow - DateTime.Now;

                OnConnected(BaseEventArgs.GetEmpty(null));

                Send(new byte[] { 1 });

                BncsPacket pck = new BncsPacket((byte)BncsPacketId.AuthInfo);
                pck.Insert(0);
                pck.InsertDwordString(PLATFORM_TYPE);     // platform
                pck.InsertDwordString(m_settings.Client); // product
                pck.InsertInt32(m_settings.VersionByte);  // verbyte
                pck.InsertDwordString(string.Concat(ci.TwoLetterISOLanguageName, ri.TwoLetterISORegionName));
                pck.InsertByteArray(LocalEP.Address.GetAddressBytes());
                pck.InsertInt32((int)ts.TotalMinutes);
                pck.InsertInt32(ci.LCID);
                pck.InsertInt32(ci.LCID);
                pck.InsertCString(ri.ThreeLetterWindowsRegionName);
                pck.InsertCString(ri.DisplayName);

                Send(pck);

                if (Settings.PingMethod == PingType.ZeroMs)
                {
                    pck = new BncsPacket((byte)BncsPacketId.Ping);
                    pck.InsertInt32(new Random().Next());
                    Send(pck);
                }

                StartParsing();

                StartListening();
            }

            return(ok);
        }
コード例 #6
0
        private void HandleAuthCheck(ParseData data)
        {
            DataReader dr        = new DataReader(data.Data);
            uint       result    = dr.ReadUInt32();
            string     extraInfo = dr.ReadCString();

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);

            if (result == 0)
            {
                OnClientCheckPassed(BaseEventArgs.GetEmpty(null));
            }
            else
            {
                OnClientCheckFailed(new ClientCheckFailedEventArgs((ClientCheckFailureCause)result, extraInfo));
                Close();
                return;
            }

            ContinueLogin();
        }
コード例 #7
0
ファイル: BattleNetClient.cs プロジェクト: wjlafrance/jinxbot
        /// <summary>
        /// Closes the connection.
        /// </summary>
        public override void Close()
        {
            base.Close();
            if (!m_closing)
            {
                m_closing = true;

                BattleNetClientResources.UnregisterClient(this);

                OnDisconnected(BaseEventArgs.GetEmpty(null));

                m_queue.Clear(); // clear the outgoing command queue

                StopParsingAndListening();

                ResetConnectionState();
            }
            else
            {
                m_closing = false;
            }
        }
コード例 #8
0
        private void HandleLogonResponse2(ParseData data)
        {
            DataReader dr      = new DataReader(data.Data);
            int        success = dr.ReadInt32();

            if (success == 0)
            {
                OnLoginSucceeded(BaseEventArgs.GetEmpty(data));
                Product product = Product.GetByProductCode(m_settings.Client);
                if (product.UsesUdpPing)
                {
                    BncsPacket pck = new BncsPacket((byte)BncsPacketId.UdpPingResponse);
                    pck.InsertDwordString("bnet");
                    Send(pck);
                }

                EnterChat();
            }
            else
            {
                LoginFailureReason reason = LoginFailureReason.Unknown;
                switch (success)
                {
                case 1:     // account DNE
                    reason = LoginFailureReason.AccountDoesNotExist; break;

                case 2:     // invalid password
                    reason = LoginFailureReason.InvalidAccountOrPassword; break;

                case 6:     // account closed
                    reason = LoginFailureReason.AccountClosed; break;
                }
                LoginFailedEventArgs args = new LoginFailedEventArgs(reason, success, dr.ReadCString())
                {
                    EventData = data
                };
                OnLoginFailed(args);
            }
        }
コード例 #9
0
        private void HandleWarden(ParseData data)
        {
            if (m_warden != null)
            {
                byte[] total = new byte[4 + data.Length];
                total[0] = 0xff;
                total[1] = (byte)BncsPacketId.Warden;
                byte[] len = BitConverter.GetBytes(data.Length);
                total[2] = len[0];
                total[3] = len[1];

                Buffer.BlockCopy(data.Data, 0, total, 4, data.Length);

                m_warden.ProcessWarden(total);
            }
            else
            {
                OnWardenUnhandled(BaseEventArgs.GetEmpty(null));
            }

            BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data);
        }