public void notify(Packet packet) {
            /* od Ch 7
            if (packet.Session.Status != Session.SessionStatus.authenticated) {
                JabberServer.output.WriteLine("Dropping packet (no auth): " + packet.ToString());
                return;
            } */
            String recipient = packet.To;

            if (recipient == null) { // to server
                JabberServer.output.WriteLine("Dropping packet: " + packet.ToString());
                return;
            }

            if (recipient.Equals(JabberServer.server_name, StringComparison.OrdinalIgnoreCase )) { // to server
                JabberServer.output.WriteLine("Dropping packet: " + packet.ToString());
                return;
            }

            // Fill in sender as resource that sent message (anti-spoofing)
            packet.setFrom(packet.getSession().getJID().ToString());

            if (packet.getAttribute("type")!=null && packet.getAttribute("type").Equals("groupchat",StringComparison.OrdinalIgnoreCase)) {
                if (chatMan.isChatPacket(packet)) {
                    chatMan.handleChatMessage(packet);
                } else {
                    JabberServer.output.WriteLine("Dropping packet: " + packet.ToString());
                }
                return;
            }

            JabberServer.output.WriteLine("Delivering packet To: " + packet.To);
            deliverPacket(packet);

		}
		public void notify(Packet packet) {
            Console.WriteLine("in message handler");
			String type = packet.Type == null ? "normal" : packet.Type;
			Console.WriteLine("Received " + type + " message: " + packet.getChildValue("body"));
			Console.WriteLine("    To: " + packet.To);
			Console.WriteLine("  From: " + packet.From);
			JabberID jid = new JabberID(packet.From);

			if (jid.User != null && jid.User.EndsWith(".group")) { // groupchat message
				//void ReceiveGroupMessage(String groupJID, String userNick, String message)
				
				String user = jid.User;
				String groupJID = user.Substring(0, user.LastIndexOf(".group"));
				String userNick = jid.Resource;

				//ReceiveGroupMessage(groupJID, userNick, packet.getChildValue("body");
				RecieveGroupMessageDelegate rgmd = new RecieveGroupMessageDelegate(model.gui.ReceiveGroupMessage);
				model.gui.Invoke(rgmd, new Object[] { groupJID, userNick, packet.getChildValue("body") });
			} else { // regular message

				RecieveMessageDelegate del = new RecieveMessageDelegate(model.gui.ReceiveMessage);
				model.gui.Invoke(del, new Object[] { jid, packet.getChildValue("body") });
				//model.gui.ReceiveMessage(jid, packet.getChildValue("body"));
			}
		}
        public void notify(Packet packet) {
            Packet query = packet.getFirstChild("query");
            foreach (Packet item in query.Children) {
                String jid = item["jid"];
                String name = item["name"];
                String subscribtion = item["subscription"];
                String ask = item["ask"];						// TODO: Revise (can be null sometimes and brakes the execution)
                String group = item.getChildValue("group");
                Status status = Status.unavailable;

				if(subscribtion.Equals("none") && ask != null && ask.Equals("subscribe")) {
					status = Status.inviteSent;
				} else if (subscribtion.Equals("to")) {
					status = Status.inviteAccepted;
				} else if (subscribtion.Equals("both")) {
					status = Status.unavailable;
					model.sendPresence(model.Me.Status, model.Me.StatusMessage);
				} else if (subscribtion.Equals("none")) {//unsubscribed
					RemoveContactDelegate rcd = new RemoveContactDelegate(model.gui.RemoveContact);
					model.gui.Invoke(rcd, new Object[] { jid });

					//remove from client
					//send roster-remove
					//model.sendRosterRemove(jid);   DO NOT !!!!!!!!!!!  UNCOMMENT THIS LINE IN ANY CASE
					return;
				} else {
					return;
				}
				UpdateContactDelegate del = new UpdateContactDelegate(model.gui.UpdateContact);
				model.gui.Invoke(del, new Object[] { jid, name, group, status });                
            }
        }
        public void notify(Packet packet)
        {
            packet.To = null;
            packet.From = null;
            if (packet.getSession().getStatus() != Session.SessionStatus.authenticated)
            {
                //can not send message:user is not authenticated
                //Error Monitoring must be implemented
                MessageHandler.deliverPacket(packet);
                return;
            }
            User user = userIndex.getUser(packet.getSession());
            if (packet.Type.Equals("set"))
            {
                user.getRoster().updateRoster(packet);
                return;
            }
            if (packet.Type.Equals("get"))
            {
                packet.Type = "result";
                JabberID jidTo =packet.getSession().getJID();
                packet.To = jidTo.User + "@" + jidTo.Domain;
               // packet.From = null;
                packet.removeAttribute("from");
                packet.getChildren().Clear();
                user.getRoster().getPacket().setParent(packet);
                MessageHandler.deliverPacket(packet);
                return;
            }
            //error in packet
            MessageHandler.deliverPacket(packet);


        }
		public void notify (Packet packet) {
			JabberServer.output.WriteLine("Opening stream connection");
	
			try {
				Session session = packet.Session;	
				session.setStreamID(Authenticator.randomToken());	
//				Ова е Јава код кој не успеав да го Ц Шарпувам
//				session.setStreamID(Integer.toHexString(streamID++));
//				Милош има направено сопствена класа за претворање на стринг во хекса, уште од број до стринг да стигнев
//				byte[] rez = ??(streamID++);
//				session.StreamID = Authenticator.GetAsHexaDecimal(rez);
	
				StreamWriter output = session.Writer;


				output.Write("<?xml version='1.0' encoding='UTF-8' ?><stream:stream xmlns='jabber:client' from='");
				output.Write(JabberServer.server_name);
				output.Write("' id='");
				output.Write(session.StreamID);
				output.Write("' xmlns:stream='http://etherx.jabber.org/streams'>");
				output.Flush();
				if (packet.To.Equals(JabberServer.server_name)) {
					session.Status = Session.SessionStatus.streaming;
				}
			} catch (Exception ex) {
	//			ex.printStackTrace();
			}
		}
		public void enqueue(Packet packet) {
			lock (sync) {
				queue.Enqueue(packet);
				Monitor.PulseAll(sync);  // Java notifyAll
			}
//			Console.WriteLine(packet.ToString());

		}
 public RegisterHandler(UserIndex index) {
     userIndex = index;
     required = new Packet("iq");
     required.From = JabberServer.server_name;
     required.Type = "result";
     new Packet("username").Parent = required;
     new Packet("password").Parent = required;
     new Packet("hash").Parent = required;
 }
Esempio n. 8
0
		public Packet(Packet parent, String element, String nmspace, Dictionary<String, String> atts) {
			Element = (element);
			Namespace = (nmspace);
			Parent = (parent);
			if (atts != null) {
				attributes = atts;
			} else {
				clearAttributes();
			}
			
		}
        static public void setError(Packet packet, int code, String message)
        {
            packet.Type = "error";
            if (message == null)
            {
                message = getCode(code);
            }

            Packet e = new Packet("error",message);
            e["code"] = Convert.ToString(code);
            e.Parent = packet;
        }
        /// <summary>
        /// Главниот дел - хендлерот за пакети
        /// </summary>
        /// <param name="packet"></param>
        public void notify(Packet packet)
        {
		
            String type = packet.Type;
            Packet query = packet.getFirstChild("query");
            username = query.getChildValue("username");
            iq.setID(packet.getID());
            iq.Session = packet.Session;
            iq.getChildren().Clear();
            iq.Type = "result";

            reply = new Packet("query");
            reply.setAttribute("xmlns", "jabber:iq:auth");
            reply.Parent = iq;

            user = userIndex.getUser(username);
            if (user == null)
            {
                sendErrorPacket(404, "User not found");
                return;
            }

            if (userIndex.sessionIndex.ContainsValue(user) == true)
            {
                sendErrorPacket(404, "User already Logged In");
                return;
            }
            

            if (type.Equals("get"))
            {
                sendGetPacket();
                return;
            }
            else if (type.Equals("set"))
            {
                session = packet.Session;
					 if (session.Status != Session.SessionStatus.streaming) {
						 sendErrorPacket(400, "Server name does not match");
						 return;
					 }
                resource = query.getChildValue("resource");
                if (resource == null)
                {
                    sendErrorPacket(404, "You must send resource");
                    return;
                }
                handleSetPacket(query);
                return;
            }
        }
        public void notify(Packet packet) {
			try {
				if (packet.ID.StartsWith("auth_get")) {
					Packet query = packet.getFirstChild("query");
					String token = query.getChildValue("token");
                    int sequence = Convert.ToInt32(query.getChildValue("sequence"));
                    String hash = auth.getZeroKHash(sequence, Encoding.UTF8.GetBytes(token), Encoding.UTF8.GetBytes(jabberModel.Password));
                    jabberModel.addResultHandler("0k_auth_" + Convert.ToString(counter), this);
                    StreamWriter output = packet.Session.Writer;
                    output.Write("<iq type='set' id='0k_auth_");
                    output.Write(Convert.ToString(counter++));
                    output.Write("'><query xmlns='jabber:iq:auth'><username>");
                    output.Write(jabberModel.User);
                    output.Write("</username><resource>");
                    output.Write(jabberModel.Resource);                    
                    output.Write("</resource><hash>");
                    output.Write(hash);
                    output.Write("</hash></query></iq>");
                    output.Flush();
                } else if (packet.Type.Equals("result")) {
					Console.WriteLine("Auth Handler passed");
					packet.Session.Status = Session.SessionStatus.authenticated;
					AuthenticateDelegate ad = new AuthenticateDelegate(jabberModel.gui.Authenticated);
					jabberModel.gui.Invoke(ad);
                } else if (packet.Type.Equals("error")) {
                    Console.WriteLine("Failed to authenticate: " + packet.getChildValue("error"));
					AuthenticationFailedDelegate afd = new AuthenticationFailedDelegate(jabberModel.gui.AuthenticationFailed);
					jabberModel.gui.Invoke(afd);
                }

                else

                {

                    Console.WriteLine("Unknown result: " + packet.ToString());

                }

            }

            catch (IOException ex)

            {

                Console.WriteLine(ex.StackTrace);

            }

        }
Esempio n. 12
0
		public void notify(Packet packet) {
			if(jabberModel == null) {
				Console.WriteLine("IQHandler Error - jabberModel==null");
				/// TODO Не постои ваков метод!?
				/// jabberModel = JabberModel.getModel();
			}
			if(packet.ID != null) {
				PacketListener listener = jabberModel.removeResultHandler(packet.ID);
				if(listener != null) {
					listener.notify(packet);
					return;
			}
			}

		}
        // TODO : deliverPacketToAll()

		public static void deliverPacket(Packet packet) {
            try {
              String recipient = packet.To;
              StreamWriter output;

              if (recipient == null){
                output = packet.getSession().getWriter();
                if (output == null){
                    JabberServer.output.WriteLine("Undeliverable packet " + packet.ToString());
                    return;
                }
              } else {
                  if (userIndex.containsUser(recipient))
                 {
                      output = userIndex.getWriter(recipient);
                 }
                 else
                  {
                      return;
                  }
//				JabberServer.output.WriteLine("String"+userIndex.getUser(recipient).ToString());
              }
              if (output != null){
                JabberServer.output.WriteLine("Delivering packet: " + packet.ToString());
                output.Write(packet.ToString());    // smeneto od DarkoA
                output.Flush();                     // smeneto od DarkoA
              } else {
                  //begin change by marko
                  if (!packet.Element.Equals("presence") || (packet["type"] != null && (packet["type"].Equals("subscribe") || packet["type"].Equals("subscribed") || packet["type"].Equals("unsubscribe") || packet["type"].Equals("unsubscribed"))))
                  {     //update presence packets (available & unavailable) don't need to be stored for offline use
                      JabberServer.output.WriteLine("Store & forward: " + packet.ToString());
                      User user = userIndex.getUser(new JabberID(recipient).getUser());
                      user.storeMessage(packet);
                  }
                  //end change by marko
              }
			} catch (Exception ex){
				JabberServer.output.WriteLine(ex.StackTrace);

				
                JabberServer.output.WriteLine("MessageHandler: ", ex);
            }

		}
		public bool isChatPacket(Packet packet) {
			JabberID recipient;
			if (packet.To == null) {
				return false;
			}
			recipient = new JabberID(packet.To);
			
			//try {
			//    recipient = new JabberID(packet.To);
			//} catch (Exception ex) {
			//    return false;
			//}
			
			String user = recipient.User;
			if (user == null) {
				return false;
			}
			return user.EndsWith(".group") && recipient.equalsDomain(JabberServer.server_name);
		}
		public void notify(Packet packet) {
			String recipient = packet.To;

			if (recipient.Equals(JabberServer.server_name, StringComparison.OrdinalIgnoreCase)) {
				return;
			}

			Session session = sessionIndex[recipient];

			if (session != null) {
				session.Writer.Write(packet);
				session.Writer.Flush();
			} else {
				return;
			}



		}
		public void notify(Packet packet) {
            if (packet.Session.Status != Session.SessionStatus.authenticated) {
                //Log.info("PresenceHandler: Not authenticated" + packet.ToString());
                //send an error message Not Authenticated!;

                packet.To = null;
                packet.From = null;
                //ErrorTool.setError(packet, 401, "You must be authenticated to send presence");
                MessageHandler.deliverPacket(packet);
            } else if (chatMan.isChatPacket(packet)) {
                //Log.trace("PresenceHandler: groupchat presence");
                chatMan.handleChatPresence(packet);
            } else {
                //Log.trace("PresenceHandler: delivering presence packet " + packet.ToString());
                // Od Marko
                User user = userIndex.getUser(packet.getSession().getJID().getUser());
                user.getRoster().updatePresence(packet);
            }        
        }
		public void notify(Packet packet) {
			try {
				if(packet.Type.Equals("result")) {
					voidDel vd = new voidDel(jaberModel.gui.Registered);
					jaberModel.gui.Invoke(vd);
				} else {
					String message = null;
					if(packet.Type.Equals("error")) {
						Packet err = packet.getFirstChild("error");
						message = err["code"] + " : " + err.getValue();

						RegisterFailedDelegate rfd = new RegisterFailedDelegate(jaberModel.gui.RegistrationFailed);
						jaberModel.gui.Invoke(rfd, new Object[] {message});
					}
					Console.WriteLine(message);
				}
			} catch(Exception ex) {
				Console.WriteLine(ex.ToString());
			}
		}
		public void handleChatPresence(Packet packet) {
			JabberID recipient = new JabberID(packet.To);
			if (!isChatPacket(packet)) {
				return;
			}

			Group group = this[recipient.User];
			String nick = recipient.Resource;
			String jid = packet.From;
			if (String.IsNullOrEmpty(nick)) {
				sendEmptyNicknameError(packet);
				return;
			}


			if (group.nick2jid.ContainsKey(nick)) {
				if (group.nick2jid[nick] == packet.From) {

					updatePresence(group, packet);
				} else {
					sendConflictingNicknameError(packet);
				}
			} else {
				if(group.jid2nick.ContainsKey(jid)) {

					sendConflictingUserError(packet);
					
				} else {
					joinGroup(group, packet);
				}
			}
		}
		public void deliverToGroup(Group group, Packet packet) {
			foreach (KeyValuePair<String, String> kvp in group.jid2nick) {
				String rec = kvp.Key;
				packet.To = rec;
				MessageHandler.deliverPacket(packet);
			}
		}
		public void serverMessage(Group group, String msg) {
			Packet packet = new Packet("message");
			packet.From = group.JabberID;
			packet.Type = "groupchat";

			Packet body = new Packet("body", msg);
			body.Parent = packet;
			deliverToGroup(group, packet);
		}
		public void handleChatMessage(Packet packet) {
			JabberID recipient = new JabberID(packet.To);
			Group group = this[recipient.User];

			packet.From = group.JabberID + "/" + group.jid2nick[packet.From];

			if (recipient.Resource == null) {
				deliverToGroup(group, packet);

			} else {
				packet.To = group.nick2jid[recipient.Resource];
				MessageHandler.deliverPacket(packet);
			}
		}
		public void sendEmptyNicknameError(Packet packet) {
			try {
				Packet presence = new Packet("presence");
				presence.From = packet.To;
				presence.To = packet.From;

				Packet ePacket = new Packet("error");
				ePacket["code"] = 405.ToString();
				ePacket.Children.Add("Not allowed : nickname must not be empty");
				ePacket.Parent = presence;
				packet.Session.Writer.Write(presence.ToString());
				packet.Session.Writer.Flush();
			} catch (Exception ex) {
			}
		}
		public void sendConflictingUserError(Packet packet) {
			try {
				Packet presence = new Packet("presence");
				presence.From = packet.To;
				presence.To = packet.From;

				Packet ePacket = new Packet("error");
				ePacket["code"] = 409.ToString();
				ePacket.Children.Add("Conflict: cannot sign in twice in the same group");
				ePacket.Parent = presence;
				packet.Session.Writer.Write(presence.ToString());
				packet.Session.Writer.Flush();
			} catch(Exception ex) {
			}
		}
		public void sendConflictingNicknameError(Packet packet) {
			try {
				Packet presence = new Packet("presence");
				presence.From = packet.To;
				presence.To = packet.From;

				Packet ePacket = new Packet("error");
				ePacket["code"] = 409.ToString();
				ePacket.Children.Add("Conflict: nickname taken");
				ePacket.Parent = presence;
				packet.Session.Writer.Write(presence.ToString());
				packet.Session.Writer.Flush();
			} catch (Exception ex) {			
			}
		}
		public void updatePresence(Group group, Packet packet) {
			String sender = packet.From;
			packet.From = group.JabberID + "/" + group.jid2nick[sender];

			deliverToGroup(group, packet);
			group.jid2presence[sender] = packet;

			if (packet.Type == null) {
				return;
			}
			//try {
			//    String t = packet.Type;
			//} catch (Exception ex) {
			//    return;
			//}

			if (packet.Type == "unavailable") {
				removeUser(group, sender);
			}
		}
Esempio n. 26
0
        }//UpdatePresense

        public void updateSubscribers(Packet packet)
        {//checked, works!
            if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) != null)
            {
                foreach (object obj in (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Keys)
                {
                    Subscriber sub = (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers[obj] as Subscriber;
                    if (sub.subscription.Equals("to") || sub.subscription.Equals("both"))//inform only subscribers!
                    {
                        packet.To = obj as String;
                        MessageHandler.deliverPacket(packet);
                    }
                }
            }
        }//Update subscribers
Esempio n. 27
0
        }//getPacket

        public void updateRoster(Packet packet)
        {
            //Extract the query packet
            Packet rosterQuery = packet.getFirstChild("query");
            rosterQuery.setAttribute("xmlns", "jabber:iq:roster");
            foreach (object rosterItems in rosterQuery.getChildren())
            {
                //for each <item> packet in the query
                Object child = rosterItems;
                if (child is Packet)
                {
                    Packet itemPacket = child as Packet;
                    String subJID = itemPacket.getAttribute("jid");



                    //create Subscriber object if needed
                    //Subscriber sendersSubscriberItem = this.subscribers[subJID] as Subscriber;
                    if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) == null)
                    {
                        Server.JabberServer.RosterHashtable[this.user] = new UserRoster();
                    }
                    Subscriber sub = (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers[subJID] as Subscriber;
                    if (sub == null)
                    {
                        sub = new Subscriber();
                        sub.subscription = "none";
                        sub.ask = null;
                        (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Add(subJID, sub);
                    }

                    if (itemPacket.getAttribute("subscription") != null)
                    {
                        //signal to remove
                        if (itemPacket.getAttribute("subscription").Equals("remove"))
                        {
                            //remove from subscribers item
                            JabberID otherID = new JabberID(subJID);
                            (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Remove(otherID.ToString());
                            if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.ContainsKey(subJID))
                            {
                                //remove <item> packet
                                (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.Remove(subJID);
                            }

                            if ((Server.JabberServer.RosterHashtable[otherID.User] as UserRoster) == null)
                            {
                                Server.JabberServer.RosterHashtable[otherID.User] = new UserRoster();
                            }
                            //set only subscription=none from other item
                            sub = ((Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).subscribers[this.user + "@" + Server.JabberServer.server_name]) as Subscriber;
                            if (sub == null)
                            {
                                sub = new Subscriber();
                            }
                            sub.subscription = "none";
                            sub.ask = null;
                            (Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).subscribers[this.user + "@" + Server.JabberServer.server_name] = sub;
                            //(Server.JabberServer.RosterHashtable[subJID] as UserRoster).subscribers.Add(subJID, sendersSubscriberItem);
                            //}
                            if ((Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).items.ContainsKey(this.user + "@" + Server.JabberServer.server_name))
                            {
                                //update <item> packet
                                //itemPacket.removeAttribute("subscription");

                                Packet mypacket = (Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).items[this.user + "@" + Server.JabberServer.server_name] as Packet;
                                mypacket.setAttribute("subscription", "none");
                                mypacket.setAttribute("ask", null);
                                (Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).items[this.user + "@" + Server.JabberServer.server_name] = mypacket;
                            }
                        }



                    }
                    else
                    {

                        //update <item> with the subscriber info for roster push
                        itemPacket.setAttribute("subscription", sub.subscription);
                        itemPacket.setAttribute("ask", sub.ask);

                        //Packet test = items[subJID];
                        if (!(Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.ContainsKey(subJID))
                        {
                            //store updated <item> packet
                            (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.Add(subJID, itemPacket);
                        }
                        else
                        {
                            (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items[subJID] = itemPacket;
                        }
                    }
                }
            }
            //Roster push
            packet.Type = "set";
            JabberID jidTo = packet.getSession().getJID();
            packet.To = jidTo.User + "@" + jidTo.Domain;
            packet.removeAttribute("from");
            //needs to be verified
            MessageHandler.deliverPacket(packet);
        }//update roster
Esempio n. 28
0
        }//Update subscribers


        public Packet getPacket()
        {
            Packet packet = new Packet("query");
            packet.setAttribute("xmlns", "jabber:iq:roster");
            //works, checked!:
            if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) != null)
            {
                foreach (object obj in (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.Values)
                {
                    ((Packet)obj).Parent = packet;
                }
                return packet;
            }
            else return packet;
        }//getPacket
Esempio n. 29
0
        }//update roster
        public void informSubscriber()
        {
            //needs to be checked!
            if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) != null)
            {
                foreach (object obj in (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Keys)
                {
                    Subscriber sub = (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers[obj] as Subscriber;
                    if (sub.subscription.Equals("from") || sub.subscription.Equals("both"))//inform sender of his subscribers status!
                    {
                        JabberID myid = new JabberID(obj.ToString());//other's subscribers id
                        if (myid.Domain.Equals(Server.JabberServer.server_name))//if from this server
                        {
                            //new code!
                           
                            
                            
                            
                            
                            
                            if (Server.JabberServer.getUserIndex().getUser(myid.User).getSessions().Values==null)
                            {
                                // if Server.JabberServer.getUserIndex().getUser(myid.User).getSessions()
                                //user is offline
                                Packet presencePacket = new Packet("presence");
                                presencePacket.From = myid.ToString();
                                presencePacket.To = new JabberID(this.user + "@" + Server.JabberServer.server_name).ToString();
                                presencePacket.setAttribute("type", "unavailable");
                                MessageHandler.deliverPacket(presencePacket);

                            }// if (Server.JabberServer.getUserIndex().getUser(myid.User).getSessions().Values!=null)
                            else
                            {
                                foreach (Object obj2 in (Server.JabberServer.getUserIndex().getUser(myid.User).getSessions().Values))
                                {//for each active session
                                    Session sess = obj2 as Session;
 
                                    Packet presencePacket = new Packet("presence");
                                    presencePacket.From = myid.ToString();
                                    presencePacket.To = new JabberID(this.user + "@" + Server.JabberServer.server_name).ToString();
                                    if (sess.getPresence().isAvailible())
                                    {
                                        presencePacket.setAttribute("type", "available");
                                        if(sess.getPresence().getShow()!=null)
                                            presencePacket.Children.Add(new Packet("show",sess.getPresence().getShow()));
 
                                        
                                        if(sess.getPresence().getStatus()!=null)
                                            presencePacket.Children.Add(new Packet("status",sess.getPresence().getStatus()));


                                        if (sess.getPresence().getPriority() != null)
                                            presencePacket.Children.Add(new Packet("priority", sess.getPresence().getPriority()));
 
                                        //other info may be added!
                                    }
                                    else
                                        presencePacket.setAttribute("type", "unavailable");
                                    MessageHandler.deliverPacket(presencePacket);

                                }//for each active session
                            
                              
                            }

                        }//  if(myid.Domain.Equals(Server.JabberServer.server_name))
                        else
                        {
                            //generate probe for S2S communication!@TODO
                        }
                        
                    }//if (sub.subscription.Equals("from") || sub.subscription.Equals("both"))
                }//foreach (object obj in (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Keys)

            }//if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) != null)


        }
		public void joinGroup(Group group, Packet packet) {
			JabberID jid = new JabberID(packet.To);
			String sender = packet.From;

			group.jid2nick.Add(sender, jid.Resource);
			group.nick2jid.Add(jid.Resource, sender);
			updatePresence(group, packet);

			foreach (KeyValuePair<String, Packet> pair in group.jid2presence) {
				Packet p = pair.Value;
				if (p.From != jid.ToString()) {
					p.To = sender;
					MessageHandler.deliverPacket(p);
				}
			}
			serverMessage(group, jid.Resource + " has joined the group");
		}