Exemplo n.º 1
0
 private void _signUp(typedata td)
 {
     td.command = "reguser";
     td.data    = new string[2];
     td.data[0] = inputBoxx("login:    "******"password: ");
     sendDataToServer(td);
 }
Exemplo n.º 2
0
        public void _delChatByMaker()
        {
            typedata td = new typedata();

            td.command = "delgr";
            td.msg     = this.currentGroup;
            sendDataToServer(td);
        }
Exemplo n.º 3
0
        public void _openPrivate(string logg)
        {
            typedata td = new typedata();

            td.command = "openPrivate";
            td.msg     = login;
            td.target  = logg;
            sendDataToServer(td);
        }
Exemplo n.º 4
0
        public void _delUserFromChatByMaker(string logg)
        {
            typedata td = new typedata();

            td.command = "deluserfromchat";
            td.msg     = logg;
            td.target  = currentGroup;
            sendDataToServer(td);
        }
Exemplo n.º 5
0
        public void _createNewChat(string name)
        {
            typedata td = new typedata();

            td.command = "makegr";
            td.msg     = this.login;
            td.target  = name;
            sendDataToServer(td);
        }
Exemplo n.º 6
0
        public void _assignNmae(string newname)
        {
            typedata td = new typedata();

            td.command = "assignname";
            td.target  = this.login;
            td.msg     = newname;
            sendDataToServer(td);
        }
Exemplo n.º 7
0
 private void conn_message(object sender, WebSocket4Net.MessageReceivedEventArgs msg)
 {
     if (msg.Message != "empty")
     {
         typedata income = new typedata();
         income = (typedata)primeJSON.DeserializeObject(msg.Message, income.GetType());
         doMessage(income);
     }
 }
Exemplo n.º 8
0
        public void _getFriends(string login, string forwhat)
        {
            typedata td = new typedata();

            td.command = "sendfr";
            td.target  = login;
            td.msg     = forwhat;
            sendDataToServer(td);
        }
Exemplo n.º 9
0
 public void _updateUsersInCurrent()
 {
     if (currentGroup != "none")
     {
         typedata td = new typedata();
         td.command = "sendugr";
         td.target  = currentGroup;
         sendDataToServer(td);
     }
 }
Exemplo n.º 10
0
 private void _logIn(typedata td)
 {
     td.command = "authuser";
     td.data    = new string[2];
     td.data[0] = inputBoxx("login:    "******"password: ");
     sendDataToServer(td);
     //Util.logTime();
     login = td.data[0];
 }
Exemplo n.º 11
0
 public void _delFriend(string logg)
 {
     if (authorized == true)
     {
         typedata td = new typedata();
         td.command = "delfr";
         td.msg     = this.login;
         td.target  = logg;
         sendDataToServer(td);
     }
 }
Exemplo n.º 12
0
        private void _sendRefreshMsg(object obj)
        {
            // if(this.currentGroup!="none")
            //{
            typedata td = new typedata();

            td.command = "updmsg";
            td.target  = this.currentGroup;
            sendDataToServer(td);
            //}
        }
Exemplo n.º 13
0
 private void _changeCurrren(typedata td)
 {
     if (this.authorized == true)
     {
         currentGroup = inputBoxx("chat:     ");//UNSAFE!!!
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 14
0
 public void _addPersonToCurrentChat(string idS)
 {
     if (currentGroup != "none")
     {
         typedata td = new typedata();
         td.command = "joingr";
         td.msg     = idS;
         td.target  = currentGroup;
         sendDataToServer(td);
     }
 }
Exemplo n.º 15
0
 public void _leaveCurrentChat()
 {
     if (currentGroup != "none")
     {
         typedata td = new typedata();
         td.command = "leavegr";
         td.msg     = this.login;
         td.target  = this.currentGroup;
         sendDataToServer(td);
     }
 }
Exemplo n.º 16
0
 private void _leaveCurrent(typedata td)
 {
     if (this.authorized == true)
     {
         currentGroup = "none";
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 17
0
        public void _sendMsgFromClient(string msg)
        {
            //MessageBox.Show("send empty", "notification", MessageBoxButtons.OK);
            typedata td = new typedata();

            td.command = "sendmsg";
            td.msg     = msg;
            td.data    = new string[1];
            td.data[0] = this.login;
            td.target  = this.currentGroup;
            sendDataToServer(td);
        }
Exemplo n.º 18
0
        public void _testLogIn(string log, string pass, loginWindow lw1)
        {
            System.Threading.Thread.Sleep(900);
            typedata td = new typedata();

            td.command = "authuser";
            td.data    = new string[2] {
                log, pass
            };
            sendDataToServer(td);
            this.login  = log;
            this.loginW = lw1;
        }
Exemplo n.º 19
0
 private void _logOut(typedata td)
 {
     if (this.authorized == true)
     {
         td.command = "enduser";
         td.msg     = login;
         sendDataToServer(td);
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 20
0
 private void _showChats(typedata td)
 {
     if (this.authorized == true)
     {
         td.command = "sendgru";
         td.target  = login;
         sendDataToServer(td);
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 21
0
 private void _leaveChat(typedata td)
 {
     if (this.authorized == true)
     {
         td.command = "leavegr";
         td.msg     = login;
         td.target  = inputBoxx("chat:     ");
         sendDataToServer(td);
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 22
0
 public void _regUserKek(string login, string pass, string mail)
 {
     if (login != null && pass != null && mail != null)
     {
         login = login.Replace(" ", string.Empty);
         pass  = pass.Replace(" ", string.Empty);
         mail  = mail.Replace(" ", string.Empty);
         if (login != "" && pass != "" && mail != "" && (mail.IndexOf('@') >= 0))
         {
             typedata td = new typedata();
             td.command = "reguser";
             td.data    = new string[3] {
                 login, pass, mail
             };
             sendDataToServer(td);
         }
     }
 }
Exemplo n.º 23
0
        private void authComplete()//after auth we need to get list of chats
        {
            //loginW.Owner.Visibility = System.Windows.Visibility.Visible;
            //loginW.Close();
            loginW.Dispatcher.Invoke(new Action(() => {
                loginW.Close();
            }));
            typedata td = new typedata();

            td.command = "sendgru";
            td.target  = login;
            sendDataToServer(td);
            _getFriends(login, "main");
            this.win.Dispatcher.Invoke(new Action(() =>
            {
                this.win.Title = "Bridge : " + this.login;
            }));
        }
Exemplo n.º 24
0
        public void _assignPicture(string path)
        {
            Account    account = new Account("gndlf", "322892712586893", "bdIeZOB0zvr6oWFKY0L5hu7fjU8");
            Cloudinary cloud   = new Cloudinary(account);

            var uploadparams = new ImageUploadParams()
            {
                File = new FileDescription(new Uri(path).LocalPath)
            };
            var uploadresult = cloud.Upload(uploadparams);
            //MessageBox.Show(new Uri(path).LocalPath);
            typedata td = new typedata();

            td.command = "assignpict";
            td.target  = this.login;
            td.msg     = "https://res.cloudinary.com" + uploadresult.Uri.AbsolutePath;
            sendDataToServer(td);
        }
Exemplo n.º 25
0
 private void _showUsers(typedata td)
 {
     if (this.authorized == true)
     {
         if (currentGroup == "none")
         {
             Console.WriteLine("Select chat first");
         }
         else
         {
             td.command = "sendugr";
             td.target  = currentGroup;
             sendDataToServer(td);
         }
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 26
0
 private void _sendMsg(typedata td)
 {
     if (this.authorized == true)
     {
         if (currentGroup == "none")
         {
             Console.WriteLine("Select chat first");
         }
         else
         {
             td.command = "sendmsg";
             td.msg     = inputBoxx("message:  ");
             td.data    = new string[1];
             td.data[0] = login;
             td.target  = currentGroup;
             sendDataToServer(td);
         }
     }
     else
     {
         Console.WriteLine("Unknown users cannot do this");
     }
 }
Exemplo n.º 27
0
        private void doMessage(typedata income)
        {
            //Util.logTime();
            if (income.command == "usrdata")
            {
                for (int i = 0; i < income.data.Length; i++)
                {
                    OnePeople onee = new OnePeople(this);
                    onee         = (OnePeople)primeJSON.DeserializeObject(income.data[i], typeof(OnePeople));
                    map[onee.id] = onee;
                    if (onee.id == this.login)
                    {
                        this.win.Dispatcher.Invoke(new Action(() => {
                            ImageSourceConverter conv   = new ImageSourceConverter();
                            this.win.imgInfoPict.Source = (ImageSource)conv.ConvertFrom(onee.Pict);
                            this.win.lbInfoId.Content   = onee.id;
                        }));
                    }
                }
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    foreach (oneChat item in this.win.chates)
                    {
                        item.updateIcon(this);
                    }
                    foreach (OneUser item in this.win.users)
                    {
                        item.updateIcons(this);
                    }
                    foreach (oneMsg item in this.win.msges)
                    {
                        item.updateIcons(this);
                    }
                    foreach (OnePeople item in this.win.friends)
                    {
                        item.updateIcons(this);
                    }
                }));
            }
            else
            if (income.command == "answ")
            {
                if (income.data[0] == "no")
                {
                    Console.Write("\tWhoops! ");
                    if (income.data.Length > 1)
                    {
                        Console.WriteLine(income.data[1]);
                    }
                }
                else if (income.data[0] == "yes")
                {
                    Console.WriteLine("\tAccept!");
                    if (income.msg == "authuser")
                    {
                        this.authorized   = true;
                        this.currentGroup = "none";
                        authComplete();
                    }
                    else if (income.msg == "enduser")
                    {
                        this.authorized   = false;
                        this.currentGroup = "none";
                    }
                    else if (income.msg == "leavegr")
                    {
                        //this.currentGroup = "none";
                        this.win.Dispatcher.Invoke(new Action(() => {
                            oneChat pos = null;
                            foreach (oneChat item in this.win.chatsList.Items)
                            {
                                if (item.id == this.currentGroup)
                                {
                                    pos = item;
                                    break;
                                }
                            }
                            //this.win.chatsList.Items.Remove(pos);
                            this.win.chates.Remove(pos);
                            authComplete();
                            this.win.msges.Clear();
                        }));
                    }
                    else if (income.msg == "makegr")
                    {
                    }
                }
            }
            else
            if (income.command == "switch")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.win.tabcontroll.SelectedIndex = 1;
                    foreach (oneChat item in this.win.chates)
                    {
                        if (item.id == income.target)
                        {
                            this.win.chatsList.SelectedItem = item;
                            break;
                        }
                    }
                }));
            }

            else
            if (income.command == "upddata")
            {
                if (income.msg == "sendgru")
                {
                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        oneChat selectedd = (oneChat)this.win.chatsList.SelectedItem;

                        this.listOfChates.Clear();
                        for (int i = 0; i < income.data.Length; i++)
                        {
                            typegetdata getdata = new typegetdata();
                            getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                            oneChat newchat     = new oneChat(getdata.name, this.login, this);
                            getdata.display();

                            this.listOfChates.Add(newchat);
                        }
                        if (selectedd != null)
                        {
                            if (this.listOfChates.IndexOf(selectedd) == -1)
                            {
                                this.win.chatsList.SelectedIndex = -1;
                            }
                        }
                    }

                                                          ));
                }
                else if (income.msg == "sendugr")
                {
                    if (income.target == currentGroup)
                    {
                        this.win.Dispatcher.Invoke(new Action(() =>
                        {
                            this.win.users.Clear();
                            for (int i = 0; i < income.data.Length; i++)
                            {
                                typegetdata getdata = new typegetdata();
                                getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                                OneUser us          = new OneUser(getdata.name, this);
                                if ((i == 0 && us.id == this.login) || (i > 0 && this.win.users[0].id == this.login))
                                {
                                    this.win.btnLeaveChat.Content = "Delete chat";
                                    us.isMaker = true;
                                }
                                else
                                {
                                    us.isMaker = false;
                                    this.win.btnLeaveChat.Content = "Leave chat";
                                }
                                this.win.users.Add(us);
                            }
                        }));
                    }
                }
                else if (income.msg == "sendgruws")
                {
                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        this.listOfChates.Clear();
                        for (int i = 0; i < income.data.Length; i++)
                        {
                            typegetdata getdata = new typegetdata();
                            getdata             = (typegetdata)primeJSON.DeserializeObject(income.data[i], getdata.GetType());
                            oneChat newchat     = new oneChat(getdata.name, this.login, this);
                            getdata.display();

                            this.listOfChates.Add(newchat);
                        }

                        this.win.tabcontroll.SelectedIndex = 1;
                        foreach (oneChat item in this.win.chates)
                        {
                            if (item.id == income.target)
                            {
                                this.win.chatsList.SelectedItem = item;
                                break;
                            }
                        }
                    }
                                                          ));
                }
            }
            else
            if (income.command == "updmsg")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.listOfMsg.Clear();
                    for (int i = 0; i < income.data.Length; i++)
                    {
                        typemsg tmsg  = new typemsg();
                        tmsg          = (typemsg)primeJSON.DeserializeObject(income.data[i], tmsg.GetType());
                        oneMsg newmsg = new oneMsg(tmsg.from, tmsg.msg, tmsg.time, this.login, this);

                        this.listOfMsg.Add(newmsg);

                        //win.msges.
                        //tmsg.display();
                    }
                    if (this.win.msgsList.Items.Count > 0)
                    {
                        this.win.msgsList.ScrollIntoView(this.win.msgsList.Items[this.win.msgsList.Items.Count - 1]);
                    }
                }));
            }
            else
            if (income.command == "notification")
            {
                if (income.data[0] == "newmsg")
                // Console.WriteLine($"\t\t{income.msg}");
                {
                    //MessageBox.Show(income.msg, "notification", MessageBoxButtons.OK);
                    if (income.msg == currentGroup)
                    {
                        _sendRefreshMsg(null);
                    }
                    else
                    {
                        this.win.Dispatcher.Invoke(new Action(() =>
                        {
                            int index = -1;
                            for (int i = 0; i < this.win.chates.Count; i++)
                            {
                                if (this.win.chates[i].id == income.msg)
                                {
                                    index = i;
                                }
                            }
                            if (index != -1)
                            {
                                this.win.chates[index].isNotRead = true;
                            }
                        }));
                    }

                    this.win.Dispatcher.Invoke(new Action(() =>
                    {
                        int ind    = -1;
                        object sel = this.win.chatsList.SelectedItem;
                        for (int i = 0; i < this.win.chates.Count; i++)
                        {
                            if (this.win.chates[i].id == income.msg)
                            {
                                ind = i;
                            }
                        }
                        if (ind != -1)
                        {
                            oneChat forSwap = this.win.chates[ind];
                            this.win.chates.Remove(forSwap);
                            this.win.chates.Insert(0, forSwap);
                            this.win.chatsList.SelectedItem = sel;
                        }
                    }));
                }
                else if (income.data[0] == "updateusers")
                {
                    if (income.msg == currentGroup)
                    {
                        _updateUsersInCurrent();
                    }
                }
                //income.display();
            }
            else
            if (income.command == "friends")
            {
                this.win.Dispatcher.Invoke(new Action(() =>
                {
                    this.win.friends.Clear();

                    for (int i = 0; i < income.data.Length; i++)
                    {
                        OnePeople onee = new OnePeople(this);
                        onee           = (OnePeople)primeJSON.DeserializeObject(income.data[i], typeof(OnePeople));
                        this.win.friends.Add(onee);
                    }
                }));
            }
            //income.display();
            //Console.ReadKey();
        }
Exemplo n.º 28
0
        private typedata inputMessage()
        {
            typedata td = new typedata();
            string   nowlogin;

            if (this.authorized == false)
            {
                nowlogin = "******";
            }
            else
            {
                nowlogin = login;
            }
            string startcommand = inputBoxx($"[{nowlogin},{currentGroup}]~");

            if (startcommand == "sign up")//registration
            {
                _signUp(td);
            }
            else
            if (startcommand == "log in")//log in
            {
                _logIn(td);
            }
            else
            if (startcommand == "make chat")
            {
                _makeChat(td);
            }
            else
            if (startcommand == "join chat")
            {
                _joinChat(td);
            }
            else
            if (startcommand == "leave chat")//UNSAFE
            {
                _leaveChat(td);
            }
            else
            if (startcommand == "log out")
            {
                _logOut(td);
            }
            else
            if (startcommand == "send msg")
            {
                _sendMsg(td);
            }
            else
            if (startcommand == "update msg")
            {
                _updateMsg(td);
            }
            else
            if (startcommand == "show chats")
            {
                _showChats(td);
            }
            else
            if (startcommand == "show users")
            {
                _showUsers(td);
            }
            else
            if (startcommand == "change current chat")
            {
                _changeCurrren(td);
            }
            else
            if (startcommand == "leave current chat")
            {
                _leaveCurrent(td);
            }
            if (startcommand == "exit")
            {
                _exit();
            }
            return(td);
        }