Example #1
0
        private void rejectInvation(string whoReject, string whoRejected)
        {
            string notification = whoReject + ": rejected your friend request !. ";

            //if receiver is online send that notification to receiver

            if (clientNames.Contains(whoRejected))
            {
                Byte[] buf = Encoding.Default.GetBytes(notification);


                int indexOfReceiver = 0;

                for (int i = 0; i < clientSockets.Count(); i++)
                {
                    if (clientSockets[i].clientName == whoRejected)
                    {
                        indexOfReceiver = i;
                        break;
                    }
                }

                Socket receiverClient = clientSockets[indexOfReceiver].socketName;

                receiverClient.Send(buf);
            }
            //if not online
            else
            {
                offlineInfo info = new offlineInfo();
                info.message           = notification;
                info.offlineClientName = whoRejected;
                offlineInfoList.Add(info);
            }
        }
Example #2
0
        private void friendInvitation(string sender, string receiver)
        {
            string notification = sender + ": wants to add you in his/her friendslist. You can accept or reject this request. \n \n";

            //if receiver is online send that notification to receiver

            if (clientNames.Contains(receiver))
            {
                Byte[] buf = Encoding.Default.GetBytes(notification);


                int indexOfReceiver = 0;

                for (int i = 0; i < clientSockets.Count(); i++)
                {
                    if (clientSockets[i].clientName == receiver)
                    {
                        indexOfReceiver = i;
                        break;
                    }
                }

                Socket receiverClient = clientSockets[indexOfReceiver].socketName;
                receiverClient.Send(buf);
            }
            //if not online
            else
            {
                offlineInfo info = new offlineInfo();
                info.message           = notification;
                info.offlineClientName = receiver;
                offlineInfoList.Add(info);
            }
        }
Example #3
0
        private void removeFriend(string whoRemove, string whoRemoved)
        {
            string notification = whoRemove + ": removed you from his/her friend list !. ";

            if (clientNames.Contains(whoRemoved))
            {
                Byte[] buf = Encoding.Default.GetBytes(notification);


                int indexOfReceiver = 0;

                for (int i = 0; i < clientSockets.Count(); i++)
                {
                    if (clientSockets[i].clientName == whoRemoved)
                    {
                        indexOfReceiver = i;
                        break;
                    }
                }

                Socket receiverClient = clientSockets[indexOfReceiver].socketName;

                receiverClient.Send(buf);
            }
            else
            {
                offlineInfo info = new offlineInfo();
                info.message           = notification;
                info.offlineClientName = whoRemoved;
                offlineInfoList.Add(info);
            }

            removeFromDb(whoRemove, whoRemoved);
        }
Example #4
0
        private void sendPrivateMessage(string sender, string receiver, string message)
        {
            string notification = message.Substring(0, message.IndexOf("."));

            notification = notification + "\n";
            if (clientNames.Contains(receiver))
            {
                Byte[] buf = Encoding.Default.GetBytes(notification);


                int indexOfReceiver = 0;

                for (int i = 0; i < clientSockets.Count(); i++)
                {
                    if (clientSockets[i].clientName == receiver)
                    {
                        indexOfReceiver = i;
                        break;
                    }
                }

                Socket receiverClient = clientSockets[indexOfReceiver].socketName;
                receiverClient.Send(buf);
            }
            else
            {
                offlineInfo info = new offlineInfo();
                info.message           = notification;
                info.offlineClientName = receiver;
                offlineInfoList.Add(info);
            }
        }