Ejemplo n.º 1
0
        /// <summary>
        /// Al usuario B le llega un mensaje y levanta un formulario drmChat
        /// </summary>
        /// <param name="msg">Message enviado por A</param>
        public void SwitchMessage(agsXMPP.protocol.client.Message msg)
        {
            if (msg.Type == MessageType.groupchat)
            {
                return;
            }

            if (msg.Body != null)//--> es un chat
            {
                frmChat f = null;
                if (ChatForms.ContainsKey(msg.From.Bare))
                {
                    f = (frmChat)ChatForms[msg.From.Bare];
                    f.Show();
                }
                else
                {
                    RosterNode rn   = RosterControl.GetRosterItem(msg.From);
                    string     nick = msg.From.Bare;
                    if (rn != null)
                    {
                        nick = rn.Text;
                    }

                    f = new frmChat(msg.From, nick);
                    f.Show();
                    f.IncomingMessage(msg);
                }
            }
            if (msg.HasTag(typeof(Comand)))
            {
            }
        }
Ejemplo n.º 2
0
 public static bool IsContentMessage(Message msg)
 {
     //A "content message" -- that is, a message stanza whose primary meaning is contained in
     //standard messaging content such as the XMPP <body/> or any other properly-namespaced child
     //element(s) other than those defined for chat state notifications in this specification.
     return !string.IsNullOrEmpty(msg.Body) || msg.HasTag(XamlBody.TAG);
 }
Ejemplo n.º 3
0
 private void _connection_OnMessage(object sender, Message msg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new OnMessageDelegate(_connection_OnMessage), new[] { sender, msg });
         return;
     }
     if (msg.Type == MessageType.groupchat)
     {
         return;
     }
     if (msg.Type == MessageType.error)
     {
         return;
     }
     if (msg.HasTag(typeof(Data)))
     {
         Element e     = msg.SelectSingleElement(typeof(Data));
         Data    xdata = e as Data;
         if (xdata != null && xdata.Type == XDataFormType.form)
         {
             //TODO:xdata
         }
     }
     else if (msg.HasTag(typeof(agsXMPP.protocol.extensions.ibb.Data)))
     {
     }
     else
     {
         if (msg.Body != null)
         {
             RibbonFormChat formChat = null;
             if (Util.ChatFormHashtable.Contains(msg.From.Bare))
             {
                 formChat = (RibbonFormChat)Util.ChatFormHashtable[msg.From.Bare];
             }
             else
             {
                 formChat = new RibbonFormChat(_connection, msg.From, msg.From.User);
             }
             formChat.Show();
             formChat.IncomingMessage(msg);
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Handle incomming messages
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="message"></param>
 private void OnMessage(object sender, Message message)
 {
     if (!message.HasTag("event"))
     {
         return;
     }
     // Check for the activity changed data, see here: https://github.com/swissmanu/harmonyhubjs-client/blob/master/docs/protocol/startActivityFinished.md
     var eventElement = message.SelectSingleElement("event");
     var eventData = eventElement.GetData();
     if (eventData == null)
     {
         return;
     }
     foreach (var pair in eventData.Split(':'))
     {
         if (!pair.StartsWith("activityId"))
         {
             continue;
         }
         var activityId = pair.Split('=')[1];
         OnActivityChanged?.Invoke(this, activityId);
     }
 }
        /// <summary>
        /// This method will parse incoming messages and call specific handlers.
        /// </summary>
        /// <param name="sender">The sender of the message</param>
        /// <param name="message">The messsage that was received</param>
        private void receivedMessageDispatcher(Object sender, Message message)
        {
            //check whether the message is an invitation to join a chatroom and invoke the strategy
            if (message.HasTag("invite", true))
            {
                chatroom = message.From;
                MucManager manager = new MucManager(connection);
                //Wait for 3 seconds
                System.Threading.Thread.Sleep(3000);
                manager.JoinRoom(chatroom, nickname, false);
                decisionStrategy.OnJoiningGame(chatroom.ToString());
            }

            else
            {

                if (message.Body != null)
                {
                    decisionStrategy.OnMessageReceived(message);
                }

            }
        }
Ejemplo n.º 6
0
    static void Xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
    {
        if (msg.HasTag(typeof(AgIXML)))
        {
            AgIXML agiMsg = msg.SelectSingleElement(typeof(AgIXML)) as AgIXML;
            agiMsg newMsg = new agiMsg();
            newMsg.ID         = agiMsg.ID;
            newMsg.Type       = agiMsg.Type;
            newMsg.Path       = agiMsg.Path;
            newMsg.SessionID  = agiMsg.SessionID;
            newMsg.SessionKey = agiMsg.SessionKey;
            newMsg.Data       = agiMsg.Data;
            newMsg.Flags      = agiMsg.Flags;

            switch (newMsg.Type)
            {
            case "tput":
                xmppManager.world.agi.tput(newMsg);
                break;

            case "rput":
                xmppManager.world.agi.rput(newMsg);
                break;

            case "tget":
                xmppManager.world.agi.tget(newMsg);
                break;

            case "rget":
                xmppManager.world.agi.rget(newMsg);
                break;

            case "tattach":
                xmppManager.world.agi.tattach(newMsg);
                break;

            case "rattach":
                xmppManager.world.agi.rattach(newMsg);
                break;

            case "tremove":
                xmppManager.world.agi.tremove(newMsg);
                break;

            case "rremove":
                xmppManager.world.agi.rremove(newMsg);
                break;

            case "tflush":
                xmppManager.world.agi.tflush(newMsg);
                break;

            case "rflush":
                xmppManager.world.agi.rflush(newMsg);
                break;
            }
        }

        if (msg.Body != null)
        {
            messages newMsg = new messages();
            newMsg.body = msg.Body;
            newMsg.from = msg.From.User;

            int count = 0;

            while (chats.Count != 0 && count < chats.Count)
            {
                if (chats.ElementAt(count).chatWith.userID == msg.From.User)
                {
                    chats.ElementAt(count).msgChain.Add(newMsg);
                    return;
                }
                count++;
            }

            chat newchat = new chat();
            newchat.msgChain.Add(newMsg);
            newchat.chatWith.userID = msg.From.User.ToString();
            chats.Add(newchat);
            Console.WriteLine(newMsg.body.ToString());
        }
    }