public GameBrowser(ServerConnection connection, ChessCom.UserData userdata)
 {
     _connection = connection;
     _userdata   = userdata;
     InitializeComponent();
     Task.Run(() => {
         var matches = MatchesBind.FromChesscom(_connection.Call.AvailableGames(new ChessCom.Void()));
         Dispatcher.Invoke(() => this.dgMatchesDataGrid.ItemsSource = matches);
     });
 }
Exemple #2
0
        private void LoginButtonClick(object sender, RoutedEventArgs args)
        {
            string username = nameTextBox.Text;
            var    ver      = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);

            Title = $"Slug Chess v{ver.FileMajorPart}.{ver.FileMinorPart}.{ver.FileBuildPart}";
            var result = _connection.Call.Login(new ChessCom.LoginForm {
                Username = username, MajorVersion = ver.FileMajorPart.ToString(), MinorVersion = ver.FileMinorPart.ToString(), BuildVersion = ver.FileBuildPart.ToString()
            });

            if (result.SuccessfullLogin)
            {
                _userdata = new ChessCom.UserData
                {
                    Username  = result.UserData.Username,
                    Usertoken = result.UserData.Usertoken,
                    Elo       = result.UserData.Elo
                };
                WriteTextNonInvoke("Logged in as " + username);
                if (result.LoginMessage != "")
                {
                    WriteTextNonInvoke(result.LoginMessage);
                }
                //_userToken = result.UserToken;
                //loginButton.Content = "U logged in";
                loginButton.IsEnabled        = false;
                lookForMatchButton.IsEnabled = true;
                foreach (var item in ((MenuItem)TopMenu.Items[0]).Items)
                {
                    if (item is MenuItem menuitem)
                    {
                        if ((string)menuitem.Header != "_Host" || (string)menuitem.Header != "_Browse Games")
                        {
                            menuitem.IsEnabled = true;
                        }
                    }
                }
                tbLoginStatus.Text = $"{_userdata.Username}";

                _matchMessageStream = _connection.Call.ChatMessageStream();
                _matchMessageStream.RequestStream.WriteAsync(new ChessCom.ChatMessage {
                    SenderUsertoken  = _userdata.Usertoken,
                    ReciverUsertoken = "system",
                    SenderUsername   = _userdata.Username,
                    Message          = "init"
                });
                Task.Run(() => MessageCallRunner());
                _heartbeatTimer.Elapsed += (obj, e) =>
                {
                    _connection?.Call.Alive(new ChessCom.Heartbeat {
                        Alive = true
                    });
                };
                _heartbeatTimer.AutoReset = true;
                _heartbeatTimer.Enabled   = true;
                //TODO recive message callback
                //TODO handle shutdown of message
            }
            else
            {
                WriteTextNonInvoke("Login failed. " + result.LoginMessage);
            }
        }
Exemple #3
0
 public CreateGame(ServerConnection connection, ChessCom.UserData userdata)
 {
     _connection = connection;
     _userdata   = userdata;
     InitializeComponent();
 }