示例#1
0
        // ------ Обробка повідомлень сервера --------
        public bool AskUserForConnection(User[] userTable, IPAddress ip)
        {
            string temp = "???";
            foreach (User user in userTable)
                if (user.UserIP.Equals(ip))
                {
                    temp = user.Nickname;
                    break;
                }

            temp = ("Користувач '" + temp + "' з адресою <" + ip.ToString() + "> " +
                   "запрошує вас до конференції.\n\n");

            foreach (User user in userTable)
            {
                temp += "Нік : " + user.Nickname + " \n";
            }
            temp += "\nБажаєте приєднатись?";

            DialogResult result = MessageBox.Show(temp, "Запрошення до конференції", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                foreach (User user in userTable)
                {
                    contacts_ItemAdd(user);
                    contacts_UserUpdateStatus(user.UserIP, OnlineState.Online);
                }

                return true;
            }
            else
            {
                return false;
            }
        }
示例#2
0
        private void AcceptedConnection(object sender, ReceivedMessageEventArgs e)
        {
            User newUser = new User(e.ip, (string)e.options);
            foreach (User user in connectedUsers)
            {
                serviceServer.SendToOne(MessageType.ConnectionUserAdded, newUser, user.UserIP);
            }

            connectedUsers.Add(newUser);
            Program.main.ShowConnectionAccepted((string)e.options, e.ip);
        }
示例#3
0
        // ------- Інтерфейс користувача --------
        public void TryConnectToUser(User user)
        {
            User[] temp = new User[connectedUsers.Count + 1];

            for (int i = 0; i < connectedUsers.Count; i++)
                temp[i] = connectedUsers[i];

            temp[connectedUsers.Count] = Program.localUser;

            serviceServer.SendToOne(MessageType.ConnectionAsk, temp, user.UserIP, true);
        }
示例#4
0
 private void contacts_UserUpdateNickname(User user)
 {
     if (lbContacts.InvokeRequired)
     {
         lbContacts.Invoke(new Action<User>(contacts_UserUpdateNickname), user);
     }
     else
     {
         lbContacts.SetNickname(user.UserIP, user.Nickname);
         lbContacts.Refresh();
     }
     contacts_UserUpdateStatus(user.UserIP, OnlineState.Online);
 }
示例#5
0
        // ------ Контрол, що оброблює список контактів --------
        private void contacts_ItemRemove(User user)
        {
            if (lbContacts.InvokeRequired)
            {
                lbContacts.Invoke(new Action<User>(contacts_ItemRemove), user);
            }
            else
            {
                UserListBoxItem item = lbContacts.GetItemByIP(user.UserIP);

                if (item != null)
                {
                    lbContacts.Items.Remove(item);
                }

                lbContacts.Refresh();
            }
        }
示例#6
0
        private void contacts_ItemAdd(User user)
        {
            if (lbContacts.InvokeRequired)
            {
                lbContacts.Invoke(new Action<User>(contacts_ItemAdd), user);
            }
            else
            {
                UserListBoxItem item = lbContacts.GetItemByIP(user.UserIP);

                if (item == null)
                {
                    lbContacts.Items.Add(new UserListBoxItem(user));
                }
                else
                {
                    item.User.Nickname = user.Nickname;
                }

                lbContacts.Refresh();

                if (Program.firstExec)
                {
                    HowToCreateChat();
                }
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            main = new mainForm();
            serverPool = new ServerPool();
            settFile = new FileInfo("settings.xml");

            if (LoadSettings() == false)
            {
                firstExec = true;
                IPAddress local = LocalIPInput();
                string username = LocalUsernameInput();
                localUser = new User(local, username);
            }

            serverPool.Start();
            serverPool.LogIn();

            if (Program.firstExec)
            {
                main.FirstLogin();
            }

            Application.Run(main);

            CleanUp();
        }
示例#8
0
        static bool LoadSettings()
        {
            if (settFile.Exists)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(settFile.FullName);

                XmlElement root = doc.DocumentElement;
                XmlElement local_user = (XmlElement)root.ChildNodes[0];
                string nickname = ((XmlElement)local_user.ChildNodes[0]).InnerText;
                string ip = ((XmlElement)local_user.ChildNodes[1]).InnerText;
                localUser = new User(System.Net.IPAddress.Parse(ip), nickname);

                List<User> temp = new List<User>();
                foreach (XmlElement node in ((XmlElement)root.ChildNodes[1]).ChildNodes)
                {
                    nickname = ((XmlElement)node.ChildNodes[0]).InnerText;
                    ip = ((XmlElement)node.ChildNodes[1]).InnerText;
                    temp.Add(new User(IPAddress.Parse(ip), nickname));
                }

                main.LoadContactList(temp);
                return true;
            }
            return false;
        }
示例#9
0
 public UserListBoxItem(User user)
 {
     _user = user;
     _online = OnlineState.Unknown;
     _onlineStatus = new Bitmap(Properties.Resources.unknown);
 }