Example #1
0
        private void loginButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (bnManager == null)
            {
                bnManager = new BattleNetManager("www.jy-x.com", 4502, this.Dispatcher);
                //bnManager = new BattleNetManager("127.0.0.1", 4502, this.Dispatcher);
                bnManager.OnNewChatNotify += (s, ee) =>
                {
                    TextBlock tb = new TextBlock()
                    {
                        Text = string.Format("[{0}]{1}:{2}", ee.Channel, ee.User.Name, ee.Message)
                    };
                    chatBox.Items.Add(tb);
                    chatBox.ScrollIntoView(tb);
                };
                bnManager.OnDroppedNotify += (s, ee) =>
                {
                    MessageBox.Show("与服务器失去连接!");
                    bnStatus = BattleNetStatus.NotLogin;
                };
            }
            string username = userText.Text;
            string password = passwordText.Password;

            bnManager.Login(username, password, (b, timeout) =>
            {
                if (timeout)
                {
                    MessageBox.Show("登陆超时");
                }
                else if (b)
                {
                    MessageBox.Show("登陆成功");
                    bnStatus = BattleNetStatus.Normal;

                    string channel = "PRIVATE_" + username;
                    bnManager.JoinChannel(new string[] { "ALL", channel }, (isOk, to) =>
                    {
                        RefreshSave();
                        RefreshOnlineUser();
                    });
                }
                else
                {
                    MessageBox.Show("登陆失败,用户名或密码错误");
                    bnManager = null;
                }
            });
        }
Example #2
0
 private void logoutButton_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     bnManager.Logout();
     bnStatus = BattleNetStatus.NotLogin;
 }