Пример #1
0
        public bool Connect(Client client)
        {
            if (!clients.ContainsValue(CurrentCallback) && !SearchClientsByName(client.Name))
            {
                lock (padLock)
                {
                    clients.Add(client, CurrentCallback);
                    listOfClients.Add(client);

                    foreach (Client key in clients.Keys)
                    {
                        IChatCallback callback = clients[key];
                        try
                        {
                            callback.RefreshClients(listOfClients);
                            callback.UserJoin(client);
                        }
                        catch
                        {
                            clients.Remove(key);
                            return false;
                        }
                    }
                }
                return false;
            }
            return true;
        }
Пример #2
0
        //DG TODO: change foreach loop and if statement into a containskey method from dictioanry
        public void Disconnect(Client client)
        {
            foreach (Client cl in clients.Keys)
                if (client.Name == cl.Name)
                {
                    lock (padLock)
                    {
                        this.clients.Remove(cl);
                        this.listOfClients.Remove(cl);

                        foreach (IChatCallback callback in clients.Values)
                        {
                            callback.RefreshClients(this.listOfClients);
                            callback.UserLeave(client);
                        }
                    }
                    return;
                }
        }
Пример #3
0
 //DG TODO:  possibly rename or have it return a boolean  (ex; check client for data)
 public void IsWriting(Client client)
 {
     lock (padLock)
     {
         foreach (IChatCallback callback in clients.Values)
         {
             callback.IsWritingCallback(client);
         }
     }
 }