Advertisement
Guest User

Untitled

a guest
Jun 7th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.16 KB | None | 0 0
  1. public void Process()
  2.         {
  3.             {
  4.                 try
  5.                 {
  6.                     Stream = client.GetStream();
  7.                     // получаем имя пользователя
  8.                     string message = GetMessage();
  9.                     string[] words = message.Split(':');
  10.                     string userName = words[0];
  11.                     string password = words[1];
  12.                     string userName_db = null;
  13.                     string password_db = null;
  14.                     // string Login = message;
  15.  
  16.                     string db_name = "H:\\2 семестр\\курсач\\DB.db";
  17.                     SQLiteConnection m_dbConnection2;
  18.                     m_dbConnection2 = new SQLiteConnection("Data Source=" + db_name + ";Version=3;");
  19.  
  20.                     m_dbConnection2.Open();
  21.  
  22.                     string sql3 = "SELECT * FROM Blacklist WHERE Login =\'" + userName + "\'; ";
  23.                     SQLiteCommand command2 = new SQLiteCommand(sql3, m_dbConnection2);
  24.                     SQLiteDataReader reader2 = command2.ExecuteReader();
  25.                     while (reader2.Read())
  26.                     {
  27.  
  28.                         string Login = (reader2["Login"] + ":" + reader2["Password"]);
  29.                         string[] words1 = Login.Split(':');
  30.                         userName_db = words1[0];
  31.                         password_db = words1[1];
  32.                     }
  33.                     //if (userName == password) { }
  34.                     m_dbConnection2.Close();
  35.                     if ((password == password_db)&&(userName == userName_db))
  36.                     {
  37.                         server.RemoveConnection(Id);
  38.                         //Close();
  39.                         throw new Exception("Вы в черном списке");
  40.                     }
  41.  
  42.                    
  43.                     SQLiteConnection m_dbConnection;
  44.                     m_dbConnection = new SQLiteConnection("Data Source=" + db_name + ";Version=3;");
  45.  
  46.                     m_dbConnection.Open();
  47.  
  48.                     string sql = "SELECT * FROM Loginpasword WHERE Login =\'" + userName + "\'; ";
  49.                     SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
  50.                     SQLiteDataReader reader = command.ExecuteReader();
  51.                     while (reader.Read())
  52.                     {
  53.  
  54.                        string Login = (reader["Login"] + ":" + reader["Password"]);
  55.                         string[] words1 = Login.Split(':');
  56.                         userName_db = words1[0];
  57.                         password_db = words1[1];
  58.                     }                    
  59.                     //if (userName == password) { }
  60.                     m_dbConnection.Close();
  61.                     if (userName_db == null)
  62.                     {
  63.                         string db_name1 = "H:\\2 семестр\\курсач\\DB.db";
  64.                         SQLiteConnection m_dbConnection1;
  65.                         m_dbConnection1 = new SQLiteConnection("Data Source=" + db_name1 + ";Version=3;");
  66.  
  67.                         m_dbConnection1.Open();
  68.                         string sql2 = "INSERT INTO Loginpasword (Login, Password) VALUES ('" + userName + "','" + password + "')";
  69.                         SQLiteCommand command1 = new SQLiteCommand(sql2, m_dbConnection1);
  70.                         command1.ExecuteNonQuery();
  71.                         m_dbConnection.Close();
  72.                     }
  73.                     if (((password == password_db) == false) && ((password_db == null) == false))
  74.                     {
  75.                         //MessageBox.Show("Неверный пароль");
  76.                         server.RemoveConnection(Id);
  77.                         //Close();
  78.                         throw new Exception("Неверный пароль");
  79.                     }
  80.                      else
  81.                             {
  82.                             message = userName + " вошел в чат";
  83.                         if (MainWindow.Instance != null)
  84.                         {
  85.                             MainWindow.Instance.lb1.Dispatcher.BeginInvoke(new Action(delegate ()
  86.                             {
  87.                                 MainWindow.Instance.lb1.Items.Add(userName);
  88.                             }));
  89.                         }
  90.                           //  MainWindow.Instance.lb1.Items.Add(userName);
  91.                         server.BroadcastMessage(message, Id);
  92.                         MessageBox.Show(message);
  93.                         for (int i = 0; i < server.count; i++)
  94.                         {
  95.                             server.BroadcastMessage1(server.lastmsg[i], Id);
  96.                             Thread.Sleep(100);
  97.                         }
  98.                           //  server.BroadcastMessage(message, Id);
  99.                             while (true)
  100.                             {
  101.                                 try
  102.                                 {
  103.                                 message = GetMessage();
  104.                                 message = String.Format("{0}: {1}", userName, message);                          
  105.                                 server.lastmsg[server.count] = message;
  106.                                 server.count++;
  107.                                 if (server.count == 10)
  108.                                 {
  109.                                     for (int j = 1; j < 9; j++)
  110.                                     {
  111.                                         server.lastmsg[j] = server.lastmsg[j + 1];
  112.                                     }
  113.                                     server.count--;
  114.                                 }
  115.                                 server.BroadcastMessage(message, Id);
  116.                             }
  117.                             catch
  118.                             {
  119.                                 message = String.Format("{0}: покинул чат", userName);
  120.                                 server.BroadcastMessage(message, Id);
  121.                                 break;
  122.                             }
  123.                                 Thread.Sleep(100);
  124.                             }
  125.                        
  126.                     }
  127.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement