コード例 #1
0
        private void Call()
        {
            string targetLogin = connection[0];

            if (String.IsNullOrEmpty(targetLogin))
            {
                connection.SendMessage(CommandSet.Error, ErrorMessageID.UnknownError);
                return;
            }
            bool isFriend;

            lock (ThreadSync.Lock)
            {
                isFriend = IsFriend(targetLogin);
            }
            if (!isFriend)
            {
                connection.SendMessage(CommandSet.Error, ErrorMessageID.NotInContacts);
                return;
            }
            bool isOnline;

            lock (ThreadSync.Lock)
            {
                isOnline = UserCollection.IsOnline(targetLogin);
            }
            if (!isOnline)
            {
                connection.SendMessage(CommandSet.Call, ErrorMessageID.UserOffline);
                return;
            }
            User targetUser;

            try
            {
                targetUser = UserCollection.GetUserByLogin(targetLogin);
            }
            catch
            {
                connection.SendMessage(CommandSet.Error, ErrorMessageID.UnknownError);
                return;
            }
            if (targetUser.IsBusy)
            {
                connection.SendMessage(CommandSet.Call, ErrorMessageID.UserBusy);
                return;
            }
            connection.SendMessage(CommandSet.Call, targetUser.GetIPString(), targetUser.Firstport, targetUser.SecondPort);
        }
コード例 #2
0
        private void Invite()
        {
            string targetLogin = connection[0];

            if (String.IsNullOrEmpty(targetLogin) || targetLogin == Login)
            {
                connection.SendMessage(CommandSet.Error, ErrorMessageID.UnknownError);
                return;
            }
            string message = connection[1];

            if (message.Trim().Length == 0) // pozbywamy się pustych wiadomości
            {
                message = String.Empty;
            }
            string result;

            lock (ThreadSync.Lock)
            {
                result = Database.AddInvitation(this, targetLogin, message);
            }
            if (result != ErrorMessageID.OK)
            {
                connection.SendMessage(CommandSet.Error, result);
                return;
            }
            try
            {
                User targetUser = UserCollection.GetUserByLogin(targetLogin);
                targetUser.NewInvitation(this, message);
            }
            catch
            {
                Debug.WriteLine("Użytkownik " + targetLogin + " nie jest online");
            }
            connection.SendMessage(CommandSet.OK);
        }
コード例 #3
0
        private void AcceptInvite()
        {
            string inviterLogin = connection[0];

            lock (ThreadSync.Lock)
            {
                if (!Database.RemoveInvitation(inviterLogin, Login))
                {
                    return;
                }
                Database.AddContact(inviterLogin, Login);
                Database.AddContact(Login, inviterLogin);
            }
            try
            {
                User targetUser = UserCollection.GetUserByLogin(inviterLogin);
                targetUser.InvitationAccepted(this);
            }
            catch
            {
                // jeśli użytkownik nie jest online to nie robimy nic
            }
            SendContacts();
        }