public string Read(string login, string password) { try { string nameUser = ""; SQLiteCommand command = new SQLiteCommand("SELECT * FROM 'RegistredUsers' WHERE login = '******' AND " + "password = '******';", connection); SQLiteDataReader reader = command.ExecuteReader(); foreach (DbDataRecord record in reader) { nameUser = record["name"].ToString(); } if (nameUser != "" && nameUser != null) { return(nameUser); } else { return("Not registred"); } } catch (Exception e) { CrashReports.Add(e.Message, "RegistredUsers - Read"); return(null); } }
public void AutomaticUnban() { try { while (true) { SQLiteCommand command = new SQLiteCommand("SELECT * FROM 'Banned';", connection); SQLiteDataReader reader = command.ExecuteReader(); foreach (DbDataRecord record in reader) { string nameUser = record["value"].ToString(); string time = record["time"].ToString(); if (time != "forever" && time != "Forever") { DateTime dateNow = DateTime.Now; DateTime dateInDB = Convert.ToDateTime(time); if (dateInDB <= dateNow) { Unban(nameUser); } } } } } catch (Exception e) { CrashReports.Add(e.Message, "BannedUsers - AutomaticUnban"); } }
public List <string> GetBannedList() { try { Read(); return(list); } catch (Exception e) { CrashReports.Add(e.Message, "BannedUsers - GetBannedList"); return(null); } }
public static void AuthorizationWithOtherService(Client client) { try { Content content = new Content("Authorization", client.name, "*", "*", "*", "*"); string sms = content.GetContent(content); SendMessage(sms, client); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - AuthorizationWithOtherService"); } Log.Add(client.name, "AuthorizationWithOtherService", "ClientComands - AuthorizationWithOtherService "); }
public static void PrivatMessage(string senderLogin, string takerLogin, string message) { try { Content content = new Content("PrivatMessage", "*", senderLogin, "*", senderLogin, message); string sms = content.GetContent(content); SendMessage(sms, OnlineUsers.onlineUsers.First(u => u.name == takerLogin)); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - PrivatMessage"); } Log.Add(senderLogin, "PrivatMessage", "ClientComands - PrivatMessage "); }
public bool Update(string name, string newPass) { try { SQLiteCommand command = new SQLiteCommand("UPDATE 'RegistredUsers' SET password='******' WHERE name='" + name + "';", connection); SQLiteDataReader reader = command.ExecuteReader(); return(true); } catch (Exception e) { CrashReports.Add(e.Message, "RegistredUsers - Update"); return(false); } }
public static void Unbanned(Client client) { try { Content content = new Content("Unbaned", "Server", "*", "*", "*", "*"); string sms = content.GetContent(content); SendMessage(sms, client); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - Unbanned"); } Log.Add(client.name, "Unbanned", "ClientComands - Unbanned "); }
public static void InviteToDialog(string login, string nameDialog) { try { Content content = new Content("Invite", "*", login, "*", nameDialog, "*"); string sms = content.GetContent(content); ListOfDialogs.GetListDialogs().First(d => d.NameDialog == nameDialog).dialog.Add(OnlineUsers.onlineUsers.First(c => c.name == login)); SendMessage(sms, OnlineUsers.onlineUsers.First(c => c.name == login)); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - InviteToDialog"); } Log.Add(login, "InviteToDialog", "ClientComands - InviteToDialog "); }
public void Ban(string login, string time) { try { OnlineUsers.onlineUsers.First(u => u.login == login).Ban = true; SQLiteCommand command = new SQLiteCommand("INSERT INTO 'Banned' ('value','time' ) VALUES ('" + login + "','" + time + "');", connection); command.ExecuteNonQuery(); Read(); ClientComands.Banned(OnlineUsers.onlineUsers.First(u => u.login == login)); } catch (Exception e) { CrashReports.Add(e.Message, "BannedUsers - Ban"); } Log.Add("admin", "Ban", "BannedUsers - Ban"); }
private static void SendMessage(string message, Client client) { try { if (client != null) { lock (block) { client.client.Send(message); } } } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - SendMessage"); } }
public static void ChangePassword(string login, string newPass, Client client) { try { if (registredUsers.Update(login, newPass)) { Content content = new Content("ChangePassword", "Server", "*", "*", "*", "*"); string sms = content.GetContent(content); SendMessage(sms, client); } } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - ChangePassword"); } Log.Add(login, "ChangePassword", "ClientComands - ChangePassword "); }
public void Unban(string login) { try { SQLiteCommand command = new SQLiteCommand("DELETE FROM Banned WHERE value= '" + login + "';", connection); SQLiteDataReader reader = command.ExecuteReader(); Read(); if (OnlineUsers.onlineUsers.Any(u => u.login == login)) { ClientComands.Unbanned(OnlineUsers.onlineUsers.First(u => u.login == login)); } } catch (Exception e) { CrashReports.Add(e.Message, "BannedUsers - Unban"); } Log.Add("admin", "Unban", "BannedUsers - Unban"); }
public bool Create(string name, string login, string password) { try { if (FindUser(name, login) == false) { SQLiteCommand command = new SQLiteCommand("INSERT INTO 'RegistredUsers' ('name','login','password' ) VALUES ('" + name + "','" + login + "','" + password + "');", connection); command.ExecuteNonQuery(); return(true); } return(false); } catch (Exception e) { CrashReports.Add(e.Message, "RegistredUsers - Create"); return(false); } }
public string GetData(string login) { try { string pass = ""; SQLiteCommand command = new SQLiteCommand("SELECT * FROM 'RegistredUsers' WHERE login = '******';", connection); SQLiteDataReader reader = command.ExecuteReader(); foreach (DbDataRecord record in reader) { pass = record["password"].ToString(); } return(pass); } catch (Exception e) { CrashReports.Add(e.Message, "RegistredUsers - GetData"); return(null); } }
public static void ShowBannedUsers(Client client) { try { Content content = new Content("ShowBannedUsers", "*", "*", "*", "*", ""); foreach (string users in banedUsers.GetBannedList()) { var parts = users.Split('_'); content.Message += parts[0] + ";"; } string sms = content.GetContent(content); SendMessage(sms, client); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - ShowBannedUsers"); } Log.Add(client.name, "ShowBannedUsers", "ClientComands - ShowBannedUsers "); }
public static void Authorization(string login, string password, Client client) { try { client.name = registredUsers.Read(login, password); Content content = new Content("Authorization", client.name, login, "*", "*", banedUsers.FindUsers(login).ToString()); string sms = content.GetContent(content); SendMessage(sms, OnlineUsers.onlineUsers.First(c => c.login == login)); if (client.name == "" || client.name == "Not registred") { OnlineUsers.onlineUsers.Remove(client); } } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - Authorization"); } Log.Add(login, "Authorization", "ClientComands - Authorization "); }
public void Read() { try { list = new List <string>(); SQLiteCommand command = new SQLiteCommand("SELECT * FROM 'Banned';", connection); SQLiteDataReader reader = command.ExecuteReader(); foreach (DbDataRecord record in reader) { string nameUser = record["value"].ToString(); string time = record["time"].ToString(); string result = nameUser + "_" + time; list.Add(result); } } catch (Exception e) { CrashReports.Add(e.Message, "BannedUsers - Read"); } }
public bool FindUsers(string login) { try { foreach (string user in list) { var parts = user.Split(':'); if (parts[0] == login) { return(true); } } return(false); } catch (Exception e) { CrashReports.Add(e.Message, "BannedUsers - FindUsers"); return(false); } }
public static void ShowAllUsersForAdmin(Client client) { try { Content content = new Content("ShowAllUsersForAdmin", "*", "*", "", "*", "*"); foreach (Client cl in OnlineUsers.onlineUsers) { if (cl.role != "admin" && cl.login != client.login) { content.Message += cl.login + ";"; } } string sms = content.GetContent(content); SendMessage(sms, client); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - ShowAllUsersForAdmin"); } Log.Add(client.login, "ShowAllUsersForAdmin", "ClientComands - ShowAllUsersForAdmin "); }
public static void ShowAllDialogs(Client client) { try { Content content = new Content("ShowAllDialogs", "*", "*", "", "*", ""); foreach (Dialog dialog in ListOfDialogs.GetListDialogs()) { if (dialog.PrivatDialog == false) { content.Message += dialog.NameDialog + ";"; } } string sms = content.GetContent(content); SendMessage(sms, client); } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - ShowAllDialogs"); } Log.Add(client.login, "ShowAllDialogs", "ClientComands - ShowAllDialogs "); }
private bool FindUser(string name, string login) { try { SQLiteCommand command = new SQLiteCommand("SELECT * FROM 'RegistredUsers';", connection); SQLiteDataReader reader = command.ExecuteReader(); foreach (DbDataRecord record in reader) { if (name == record["name"].ToString() || login == record["login"].ToString()) { return(true); } } return(false); } catch (Exception e) { CrashReports.Add(e.Message, "RegistredUsers - FindUser"); return(false); } }
public static void NewMessage(string nameDialog, string message, string login) { try { Content content = new Content("SendMessage", "*", login, "*", nameDialog, message); string sms = content.GetContent(content); ListOfDialogs.GetListDialogs().First(d => d.NameDialog == nameDialog).messages.Add(message); foreach (Client client in ListOfDialogs.GetListDialogs().First(d => d.NameDialog == nameDialog).dialog) { if (client != null && client.name != login) { SendMessage(sms, client); } } } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - NewMessage"); } Log.Add(login, "NewMessage", "ClientComands - NewMessage "); }
public static void ForgotPassword(string pass, string mail) { try { if (pass != "" && pass != null) { SmtpClient Smtp = new SmtpClient("smtp.gmail.com", 587); Smtp.Credentials = new NetworkCredential("*****@*****.**", "bestchat"); MailMessage Message = new MailMessage(); Message.From = new MailAddress("*****@*****.**"); Message.To.Add(new MailAddress(mail)); Message.Subject = "Пароль"; Message.Body = "Ваш пароль : " + pass; Smtp.EnableSsl = true; Smtp.Send(Message); } } catch (Exception e) { CrashReports.Add(e.Message, "SendToEmail - ForgotPassword"); } Log.Add(mail, "ForgotPassword", "SendToEmail - ForgotPassword"); }
public static void SignUP(string name, string login, string password, Client client) { try { if (registredUsers.Create(name, login, password) == true) { Content content = new Content("SignUP", "*", "*", "*", "*", "Success"); string sms = content.GetContent(content); SendMessage(sms, client); } else { Content content = new Content("SignUP", "*", "*", "*", "*", "No success"); string sms = content.GetContent(content); SendMessage(sms, client); } } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - SignUP"); } Log.Add(login, "SignUP", "ClientComands - SignUP "); }
public static void LogOut(string login) { try { OnlineUsers.onlineUsers.Remove(OnlineUsers.onlineUsers.First(c => c.name == login)); foreach (Dialog dialog in ListOfDialogs.GetListDialogs()) { foreach (Client client in dialog.dialog) { if (client.name == login) { dialog.dialog.Remove(client); return; } } } } catch (Exception e) { CrashReports.Add(e.Message, "ClientComands - LogOut"); } Log.Add(login, "LogOut", "ClientComands - LogOut "); }
public static void GetMessage(string content, Client client) { contentFromClient = new Content(); contentFromClient = contentFromClient.SetContent(content); try { switch (contentFromClient.Action) { case "Authorization": client.login = contentFromClient.Login; client.role = contentFromClient.Role; AuthorizationServerCommand.Authorization(contentFromClient.Login, contentFromClient.Password, client); break; case "Google": client.login = contentFromClient.Login; client.role = contentFromClient.Role; client.name = contentFromClient.Name; ClientComands.AuthorizationWithOtherService(client); break; case "FaceBook": client.login = contentFromClient.Login; client.role = contentFromClient.Role; client.name = contentFromClient.Name; ClientComands.AuthorizationWithOtherService(client); break; case "SignUP": AuthorizationServerCommand.SignUP(contentFromClient.Name, contentFromClient.Login, contentFromClient.Password, client); break; case "Invite": ClientComands.InviteToDialog(contentFromClient.Login, contentFromClient.NameDialog); break; case "SendMessage": ClientComands.NewMessage(contentFromClient.NameDialog, contentFromClient.Message, contentFromClient.Login); HistoryMessagesInDialogs.SaveHistory(contentFromClient.Login, contentFromClient.NameDialog, contentFromClient.Message); break; case "CloseDialog": ListOfDialogs.ExitDialog(contentFromClient.Login, contentFromClient.NameDialog); break; case "ToComeIn": ListOfDialogs.ToComeIn(contentFromClient.Login, contentFromClient.NameDialog); break; case "ShowAllDialogs": ClientComands.ShowAllDialogs(client); break; case "ShowOnlineUsers": ClientComands.ShowOnlineUsers(client); break; case "CreateDialog": ListOfDialogs.AddDialogToList(contentFromClient.NameDialog, client); break; case "LogOut": ClientComands.LogOut(contentFromClient.Login); break; case "ShowBannedUsers": if (contentFromClient.Login == "admin") { ClientComands.ShowBannedUsers(client); } break; case "ShowAllUsersForAdmin": ClientComands.ShowAllUsersForAdmin(client); break; case "BanUser": banedUsers.Ban(contentFromClient.Login, contentFromClient.Message); break; case "UnbanUser": banedUsers.Unban(contentFromClient.Login); break; case "PrivatMessage": ClientComands.PrivatMessage(contentFromClient.Login, contentFromClient.NameDialog, contentFromClient.Message); break; case "ForgotPassword": AuthorizationServerCommand.ForgotPassword(contentFromClient.Login, contentFromClient.Message, client); break; case "ChangePassword": AuthorizationServerCommand.ChangePassword(contentFromClient.Login, contentFromClient.Message, client); break; default: break; } } catch (Exception e) { CrashReports.Add(e.Message, "Dispatcher : Action - " + contentFromClient.Action); } contentFromClient = null; }