Exemplo n.º 1
0
 public ClientHandler lookupClient(ChatBuddy client)
 {
     lock (this._clients)
     {
         return((ClientHandler)this._clients[client.getID()]);
     }
 }
Exemplo n.º 2
0
        public void updateChatBuddy(ChatBuddy cb)
        {
            string status = cb.getStatus();

            if (status.Equals(RuntimeConstants.CAN_CHAT) || status.Equals(RuntimeConstants.CANNOT_CHAT))
            {
                System.Collections.IEnumerator ie = this._clientInterface.listBox1.Items.GetEnumerator();
                ie.MoveNext();
                while (ie.Current != null)
                {
                    if (((ChatBuddy)ie.Current).getID().Equals(cb.getID()))
                    {
                        ((ChatBuddy)ie.Current).setStatus(status);
                        break;
                    }
                    ie.MoveNext();
                }
            }
            else if (status.Equals(RuntimeConstants.NEW_BUDDY))
            {
                this._clientInterface.listBox1.Items.Add(cb);
            }
            else if (status.Equals(RuntimeConstants.BUDDY_DISCONNECTING))
            {
                System.Collections.IEnumerator ie = this._clientInterface.listBox1.Items.GetEnumerator();
                ie.MoveNext();
                while (ie.Current != null)
                {
                    if (((ChatBuddy)ie.Current).getID().Equals(cb.getID()))
                    {
                        this._clientInterface.listBox1.Items.Remove(ie.Current);
                        break;
                    }
                    ie.MoveNext();
                }
            }
        }
        public static void chatBuddiesUpdate(XmlTextWriter xtw, string id, bool client, string messageID, ChatBuddy chatBuddy)
        {
            xtw.WriteStartDocument();
            //open pvctd tag
            xtw.WriteStartElement("pvctd", "columbia-psl-memento-pervasive-hermes");
            //open message element
            xtw.WriteStartElement("message");
            //open connect element of message
            xtw.WriteStartElement("chatBuddiesUpdate");



            xtw.WriteStartElement("chatBuddy");

            xtw.WriteStartElement("ip");
            xtw.WriteString(chatBuddy.getIP());
            xtw.WriteEndElement();
            xtw.WriteStartElement("chatName");
            xtw.WriteString(chatBuddy.getChatName());
            xtw.WriteEndElement();
            xtw.WriteStartElement("status");
            xtw.WriteString(chatBuddy.getStatus());
            xtw.WriteEndElement();
            xtw.WriteStartElement("clientID");
            xtw.WriteString(chatBuddy.getID());
            xtw.WriteEndElement();
            xtw.WriteEndElement();


            //**********

            //close
            xtw.WriteEndElement();
            //close message
            xtw.WriteEndElement();

            //open time element
            xtw.WriteStartElement("time");
            xtw.WriteString(System.DateTime.Now.ToString());
            xtw.WriteEndElement();
            //open id
            xtw.WriteStartElement("id");
            xtw.WriteString(id);
            xtw.WriteEndElement();

            //clientID or serverID
            if (client)
            {
                xtw.WriteStartElement("clientID");
            }
            else
            {
                xtw.WriteStartElement("serverID");
            }
            xtw.WriteString(id);
            xtw.WriteEndElement();

            //close it all up
            xtw.WriteEndElement();
            xtw.WriteEndDocument();
            xtw.Flush();
        }
        public static void confirmConnect(XmlTextWriter xtw, string id, bool client, string messageID, string clientID, ArrayList chatBuddies, string serverID)
        {
            xtw.WriteStartDocument();
            //open pvctd tag
            xtw.WriteStartElement("pvctd", "columbia-psl-memento-pervasive-hermes");
            //open message element
            xtw.WriteStartElement("message");
            //open connect element of message
            xtw.WriteStartElement("confirmConnect");

            //open and close all your internal elements here
            xtw.WriteStartElement("clientID");
            xtw.WriteString(clientID);
            xtw.WriteEndElement();

            xtw.WriteStartElement("chatBuddies");

            //we add a chat buddy for each one in the list of chat buddies

            object[] buddies = chatBuddies.ToArray();
            xtw.WriteAttributeString("chatBuddiesCount", buddies.Length.ToString());
            //xtw.WriteAttributeString("chatBuddies", "buddyCount", "columbia-psl-memento-pervasive-hermes", buddies.Length.ToString());
            //xtw.WriteEndAttribute();

            if (buddies.Length > 0)
            {
                for (int i = 0; i < buddies.Length; i++)
                {
                    ChatBuddy chatBuddy = (ChatBuddy)buddies[i];
                    xtw.WriteStartElement("chatBuddy");
                    xtw.WriteStartElement("ip");
                    xtw.WriteString(chatBuddy.getIP());
                    xtw.WriteEndElement();
                    xtw.WriteStartElement("chatName");
                    xtw.WriteString(chatBuddy.getChatName());
                    xtw.WriteEndElement();
                    xtw.WriteStartElement("status");
                    xtw.WriteString(chatBuddy.getStatus());
                    xtw.WriteEndElement();
                    xtw.WriteStartElement("clientID");
                    xtw.WriteString(chatBuddy.getID());
                    xtw.WriteEndElement();
                    xtw.WriteEndElement();
                }
            }

            xtw.WriteEndElement();
            //serverID element
            xtw.WriteStartElement("serverID");
            xtw.WriteString(serverID);
            xtw.WriteEndElement();
            //**********

            //close
            xtw.WriteEndElement();
            //close message
            xtw.WriteEndElement();

            //open time element
            xtw.WriteStartElement("time");
            xtw.WriteString(System.DateTime.Now.ToString());
            xtw.WriteEndElement();
            //open id
            xtw.WriteStartElement("id");
            xtw.WriteString(id);
            xtw.WriteEndElement();

            //clientID or serverID
            if (client)
            {
                xtw.WriteStartElement("clientID");
            }
            else
            {
                xtw.WriteStartElement("serverID");
            }
            xtw.WriteString(id);
            xtw.WriteEndElement();

            //close it all up
            xtw.WriteEndElement();
            xtw.WriteEndDocument();
            xtw.Flush();
        }