Beispiel #1
0
 void model_MessageBroadcast(LobbyServer model, int userId, string content)
 {
     User u = model.GetUser(userId);
       UIDispatcher.Invoke(() =>
     {
       if (u != null) chat.AppendText("\n" + u.Name + ": " + content);
       else chat.AppendText("\n" + "[" + userId + "]" + ": " + content);
     });
 }
Beispiel #2
0
 void model_UserChanged(LobbyServer sender, int userId)
 {
     //thread
       UIDispatcher.Invoke(() =>
     {
       User u = sender.GetUser(userId);
       UserVM uvm = usersDictionary.ValueOrDefault(userId);
       if (u == null)
       {
     usersDictionary.Remove(userId);
     users.Remove(uvm);
     string x = "\n<SYSTEM> User"+ userId;
     if (uvm != null) x += " " + uvm.Name;
     chat.AppendText(x + " exits.");
       }
       else
       {
     if (uvm == null) AddUser(u);
     else uvm.RefreshProperties(u);
       }
     });
 }
Beispiel #3
0
 private void StartServer()
 {
     model = new LobbyServer(new TcpMessageServer(9898));
       model.UserChanged += model_UserChanged;
       model.MessageBroadcast += model_MessageBroadcast;
       try
       {
     model.Start();
       }
       catch (Exception e)
       {
     System.Windows.MessageBox.Show(e.Message);
     return;
       }
       s.Content = "Stop";
       mask.Visibility = System.Windows.Visibility.Hidden;
       usersDictionary = new Dictionary<int, UserVM>(50);//容量
       users = new ObservableCollection<UserVM>();
       var us = model.Users;
       foreach (User u in us) AddUser(u);
       usersView.ItemsSource = users;
 }