예제 #1
0
 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);
     }
 }
예제 #2
0
 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");
     }
 }
예제 #3
0
 public List <string> GetBannedList()
 {
     try
     {
         Read();
         return(list);
     }
     catch (Exception e)
     {
         CrashReports.Add(e.Message, "BannedUsers - GetBannedList");
         return(null);
     }
 }
예제 #4
0
 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 ");
 }
예제 #5
0
 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 ");
 }
예제 #6
0
 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);
     }
 }
예제 #7
0
 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 ");
 }
예제 #8
0
        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 ");
        }
예제 #9
0
        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");
        }
예제 #10
0
 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");
     }
 }
예제 #11
0
 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 ");
 }
예제 #12
0
 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");
 }
예제 #13
0
 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);
     }
 }
예제 #14
0
 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);
     }
 }
예제 #15
0
 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 ");
 }
예제 #16
0
 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 ");
 }
예제 #17
0
 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");
     }
 }
예제 #18
0
 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);
     }
 }
예제 #19
0
 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 ");
 }
예제 #20
0
 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 ");
 }
예제 #21
0
        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);
            }
        }
예제 #22
0
        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 ");
        }
예제 #23
0
 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");
 }
예제 #24
0
 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 ");
 }
예제 #25
0
 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 ");
 }
예제 #26
0
        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;
        }