Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Process()
- {
- {
- try
- {
- Stream = client.GetStream();
- // получаем имя пользователя
- string message = GetMessage();
- string[] words = message.Split(':');
- string userName = words[0];
- string password = words[1];
- string userName_db = null;
- string password_db = null;
- // string Login = message;
- string db_name = "H:\\2 семестр\\курсач\\DB.db";
- SQLiteConnection m_dbConnection2;
- m_dbConnection2 = new SQLiteConnection("Data Source=" + db_name + ";Version=3;");
- m_dbConnection2.Open();
- string sql3 = "SELECT * FROM Blacklist WHERE Login =\'" + userName + "\'; ";
- SQLiteCommand command2 = new SQLiteCommand(sql3, m_dbConnection2);
- SQLiteDataReader reader2 = command2.ExecuteReader();
- while (reader2.Read())
- {
- string Login = (reader2["Login"] + ":" + reader2["Password"]);
- string[] words1 = Login.Split(':');
- userName_db = words1[0];
- password_db = words1[1];
- }
- //if (userName == password) { }
- m_dbConnection2.Close();
- if ((password == password_db)&&(userName == userName_db))
- {
- server.RemoveConnection(Id);
- //Close();
- throw new Exception("Вы в черном списке");
- }
- SQLiteConnection m_dbConnection;
- m_dbConnection = new SQLiteConnection("Data Source=" + db_name + ";Version=3;");
- m_dbConnection.Open();
- string sql = "SELECT * FROM Loginpasword WHERE Login =\'" + userName + "\'; ";
- SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
- SQLiteDataReader reader = command.ExecuteReader();
- while (reader.Read())
- {
- string Login = (reader["Login"] + ":" + reader["Password"]);
- string[] words1 = Login.Split(':');
- userName_db = words1[0];
- password_db = words1[1];
- }
- //if (userName == password) { }
- m_dbConnection.Close();
- if (userName_db == null)
- {
- string db_name1 = "H:\\2 семестр\\курсач\\DB.db";
- SQLiteConnection m_dbConnection1;
- m_dbConnection1 = new SQLiteConnection("Data Source=" + db_name1 + ";Version=3;");
- m_dbConnection1.Open();
- string sql2 = "INSERT INTO Loginpasword (Login, Password) VALUES ('" + userName + "','" + password + "')";
- SQLiteCommand command1 = new SQLiteCommand(sql2, m_dbConnection1);
- command1.ExecuteNonQuery();
- m_dbConnection.Close();
- }
- if (((password == password_db) == false) && ((password_db == null) == false))
- {
- //MessageBox.Show("Неверный пароль");
- server.RemoveConnection(Id);
- //Close();
- throw new Exception("Неверный пароль");
- }
- else
- {
- message = userName + " вошел в чат";
- if (MainWindow.Instance != null)
- {
- MainWindow.Instance.lb1.Dispatcher.BeginInvoke(new Action(delegate ()
- {
- MainWindow.Instance.lb1.Items.Add(userName);
- }));
- }
- // MainWindow.Instance.lb1.Items.Add(userName);
- server.BroadcastMessage(message, Id);
- MessageBox.Show(message);
- for (int i = 0; i < server.count; i++)
- {
- server.BroadcastMessage1(server.lastmsg[i], Id);
- Thread.Sleep(100);
- }
- // server.BroadcastMessage(message, Id);
- while (true)
- {
- try
- {
- message = GetMessage();
- message = String.Format("{0}: {1}", userName, message);
- server.lastmsg[server.count] = message;
- server.count++;
- if (server.count == 10)
- {
- for (int j = 1; j < 9; j++)
- {
- server.lastmsg[j] = server.lastmsg[j + 1];
- }
- server.count--;
- }
- server.BroadcastMessage(message, Id);
- }
- catch
- {
- message = String.Format("{0}: покинул чат", userName);
- server.BroadcastMessage(message, Id);
- break;
- }
- Thread.Sleep(100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement