Exemple #1
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());
        }
    }
Exemple #2
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());
        }
    }