Beispiel #1
0
 public void IsWriting(Client client)
 {
     lock (syncObj)
     {
         foreach (IChatCallback callback in clients.Values)
         {
             callback.IsWritingCallback(client);
         }
     }
 }
Beispiel #2
0
 public void Disconnect(Client client)
 {
     foreach (Client c in clients.Keys)
     {
         if (client.Name == c.Name)
         {
             lock (syncObj)
             {
                 clients.Remove(c);
                 clientList.Remove(c);
                 foreach (IChatCallback callback in clients.Values)
                 {
                     callback.RefreshClients(clientList);
                     callback.UserLeave(client);
                 }
             }
             return;
         }
     }
 }
Beispiel #3
0
        public bool SendFile(FileMessage fileMsg, Client receiver)
        {
            foreach (Client rcvr in clients.Keys)
            {
                if (rcvr.Name == receiver.Name)
                {
                    Message msg = new Message();
                    msg.Sender = fileMsg.Sender;
                    msg.Content = "I'M SENDING FILE.. " + fileMsg.FileName;

                    IChatCallback rcvrCallback = clients[rcvr];
                    rcvrCallback.ReceiveWhisper(msg, receiver);
                    rcvrCallback.ReceiverFile(fileMsg, receiver);

                    foreach (Client sender in clients.Keys)
                    {
                        if (sender.Name == fileMsg.Sender)
                        {
                            IChatCallback sndrCallback = clients[sender];
                            sndrCallback.ReceiveWhisper(msg, receiver);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
Beispiel #4
0
        public void Whisper(Message msg, Client receiver)
        {
            foreach (Client rec in clients.Keys)
            {
                if (rec.Name == receiver.Name)
                {
                    IChatCallback callback = clients[rec];
                    callback.ReceiveWhisper(msg, rec);

                    foreach (Client sender in clients.Keys)
                    {
                        if (sender.Name == msg.Sender)
                        {
                            IChatCallback senderCallback = clients[sender];
                            senderCallback.ReceiveWhisper(msg, rec);
                            return;
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public bool Connect(Client client)
        {
            if (!clients.ContainsValue(CurrentCallback) && !SearchClientsByName(client.Name))
            {
                lock (syncObj)
                {
                    clients.Add(client, CurrentCallback);
                    clientList.Add(client);

                    foreach (Client key in clients.Keys)
                    {
                        IChatCallback callback = clients[key];
                        try
                        {
                            callback.RefreshClients(clientList);
                            callback.UserJoin(client);
                        }
                        catch
                        {
                            clients.Remove(key);
                            return false;
                        }

                    }

                }
                return true;
            }
            return false;
        }
Beispiel #6
0
        public bool Connect(Client client)
        {
            lock (syncObj)
            {
                var calback = CurrentCallback;
                if (_clients.ContainsValue(CurrentCallback) || SearchClientsByName(client.Name))
                {
                    calback.Error("Currently login is busy, enter new login");
                    return false;
                }
                _clients.Add(client, CurrentCallback);

                foreach (var key in _clients.Keys)
                {
                    var callback = _clients[key];
                    try
                    {
                        if (key.Name.Equals(client.Name))
                        {
                            callback.Conected();
                            callback.RefreshClients(_clients.Keys.ToList());
                        }
                        else
                        {
                            callback.UserJoin(client);
                        }
                    }
                    catch
                    {
                        _clients.Remove(key);
                        return false;
                    }
                }
                return true;
            }
        }
Beispiel #7
0
 public void Disconnect(Client client)
 {
     lock (syncObj)
     {
         var cl = GetClientByName(client.Name);
         if (cl.Key == null) return;
         _clients.Remove(cl.Key);
         foreach (var callback in _clients.Values)
         {
             callback.UserLeave(client);
         }
     }
 }