Inheritance: Packet
コード例 #1
0
 public string FormatMessage(string bodyHtml, Message message)
 {
     return Regex.Replace(bodyHtml, WIKIPEDIA_PAGE_LINK_PATTERN, delegate (Match match) {
         string linkUrl = match.Groups[2].Value;
         return match.Value + BuildHtmlPreview(linkUrl);
     }, RegexOptions.Singleline);
 }
コード例 #2
0
 public string FormatMessage (string bodyHtml, Message message)
 {
     return Regex.Replace(bodyHtml, YOUTUBE_LINK_PATTERN, delegate (Match match) {
         string youtubeId = match.Groups[3].Value;
         return match.Value + BuildPreviewHtml(youtubeId);
     }, RegexOptions.Singleline);
 }
コード例 #3
0
ファイル: FrmChat.cs プロジェクト: Flowdalic/realjabber
        /// <summary>Transmit RTT elements if needed.</summary>
        private bool JabberSendRTT()
        {
            bool rttSent = false;

            try
            {
                if (!rttEnabled)
                {
                    return(false);
                }

                if (!encoderRTT.IsEmpty)
                {
                    // Create the XMPP <message> with <rtt> updates, and transmit.
                    jabber.protocol.client.Message reply = new jabber.protocol.client.Message(_jabberClient.Document);
                    reply.To = JID.Bare;
                    reply.AppendChild(encoderRTT.GetEncodedRTT());
                    if (enableChatStates)
                    {
                        reply.AppendChild(reply.OwnerDocument.CreateElement("composing")); //, "http://jabber.org/protocol/chatstates"));
                    }
                    _jabberClient.Write(reply);
                    rttSent = true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("!!! Exception in JabberSendMessage(): " + ex.ToString());
            }
            return(rttSent);
        }
コード例 #4
0
        public void AnnounceClosed()
        {
            var msg = new Message(new XmlDocument()) {
                Body = "SOLVersion: 1.1; Event: CLOSE;",
            };

            mChat.SendMessage(msg);
        }
コード例 #5
0
 private void onMessage(object sender, Message msg)
 {
     Console.WriteLine(msg.Body);
     tower.Write(0);
     tower.Activate(currentPin);
     currentPin ++;
     currentPin %= 7;
 }
コード例 #6
0
 public string FormatMessage (string bodyHtml, Message message)
 {
     return Regex.Replace(bodyHtml, FLICKR_PAGE_LINK_PATTERN, delegate (Match match) {
         string url = match.Groups[2].Value;
         string photoId = match.Groups[5].Value;
         return match.Value + BuildPhotoHtml(url, photoId);
     }, RegexOptions.Singleline);
 }
コード例 #7
0
        /// <summary>
        /// Create an x:data form from the given message stanza.
        /// </summary>
        /// <param name="parent">Original stanza</param>
        public XDataForm(jabber.protocol.client.Message parent) : this(FindData(parent) as jabber.protocol.x.Data)
        {
            m_stanza = (Packet)parent.CloneNode(true);
            Data d = FindData(m_stanza);

            Debug.Assert(d != null);
            m_parent = (Element)d.ParentNode;
            m_parent.RemoveChild(d);
        }
コード例 #8
0
        public NotificationPopup(ChatSubjects subject, Message Message)
        {
            InitializeComponent();
            Subject = subject;
            MessageData = Message;
            NotificationTypeLabel.Content = Client.TitleCaseString(Enum.GetName(typeof(ChatSubjects), subject).Replace("_", " "));

            //TODO: Get name from id
            ChatPlayerItem Player = Client.AllPlayers[Message.From.User];
            using (XmlReader reader = XmlReader.Create(new StringReader(Message.Body)))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        #region Parse Popup

                        switch (reader.Name)
                        {
                            case "inviteId":
                                reader.Read();
                                InviteId = Convert.ToInt32(reader.Value);
                                break;
                            case "profileIconId":
                                reader.Read();
                                ProfileIconId = Convert.ToInt32(reader.Value);
                                break;
                            case "gameType":
                                reader.Read();
                                GameType = reader.Value;
                                break;
                            case "mapId":
                                reader.Read();
                                MapId = Convert.ToInt32(reader.Value);
                                break;
                            case "queueId":
                                reader.Read();
                                QueueId = Convert.ToInt32(reader.Value);
                                break;
                            case "gameId":
                                reader.Read();
                                GameId = Convert.ToInt32(reader.Value);
                                break;
                        }

                        #endregion Parse Popup
                    }
                }
            }

            var uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", ProfileIconId + ".png");
            ProfileImage.Source = Client.GetImage(uriSource);

            NotificationTextBox.Text = Player.Username + " has invited you to a game" + Environment.NewLine
                                     + "Hosted on " + BaseMap.GetMap(MapId).DisplayName + Environment.NewLine
                                     + "Game Type: " + Client.TitleCaseString(GameType).Replace("_", " ") + Environment.NewLine;
        }
コード例 #9
0
ファイル: MessageTest.cs プロジェクト: krbysn/jabber-net
 [Test] public void Test_NullBody()
 {
     Message msg = new Message(doc);
     Assert.AreEqual(null, msg.Body);
     msg.Body = "foo";
     Assert.AreEqual("foo", msg.Body);
     msg.Body = null;
     Assert.AreEqual(null, msg.Body);
 }
コード例 #10
0
        //#############################################################################################################
        // Incoming messages

        private void jabberClient_OnMessage(object sender, jabber.protocol.client.Message msg)
        {
            // Handle messages on the same thread as UI.
            if (this.InvokeRequired)
            {
                this.Invoke(new MessageHandler(jabberClient_OnMessage), sender, msg);
            }

            bool   newWindow = false;
            string bareJID   = msg.From.Bare;
            string nickName  = null;

            if (chatNicknames.ContainsKey(bareJID))
            {
                nickName = chatNicknames[bareJID];
            }

            // Do we already have a chat window for this message?

            FrmChat chatWindow = InitializeChatWindow(msg.From, nickName);

            if (msg.Body != null)
            {
                if (!chatWindow.Visible)
                {
                    // Show chat window only when receiving first full-line message.
                    newWindow = true;
                    chatWindow.Show();
                    chatWindow.BringToFront();
                    chatWindow.WindowState = FormWindowState.Normal;
                    chatWindow.Flash();
                }
                else if (chatWindow.WindowState == FormWindowState.Minimized)
                {
                    // Flash chat window in taskbar, if minimized
                    chatWindow.Flash();
                }
                chatWindow.ReceiveFlag = true;
            }

            // Show window and handle chat message
            if (chatWindow.Visible)
            {
                chatWindow.HandleMessage(msg);
            }

            // Special behaviour if we're invited to a group chat
            if (!chatInRoster.ContainsKey(bareJID))
            {
                Console.WriteLine("NOTICE: Message from unrecogized bareJID: " + bareJID);
                if (newWindow && bareJID.EndsWith("groupchat.google.com"))
                {
                    MessageBox.Show("You have been invited to a group chat. However, group chat is not yet supported in this specific client. (XEP-0045 not implemented)");
                }
            }
        }
コード例 #11
0
ファイル: MessageTest.cs プロジェクト: bladecoding/Jabber-net
 public void Test_Create()
 {
     Message msg = new Message(doc);
     msg.Html = "foo";
     Assert.AreEqual("<message id=\""+msg.ID+"\"><html xmlns=\"http://jabber.org/protocol/xhtml-im\"><body xmlns=\"http://www.w3.org/1999/xhtml\">foo</body></html><body>foo</body></message>", msg.ToString());
     // TODO: deal with the namespace problem here
     msg.Html = "f<a href=\"http://www.jabber.org\">o</a>o";
     Assert.AreEqual("<message id=\""+msg.ID+"\"><html xmlns=\"http://jabber.org/protocol/xhtml-im\"><body xmlns=\"http://www.w3.org/1999/xhtml\">f<a href=\"http://www.jabber.org\">o</a>o</body></html><body>foo</body></message>", msg.ToString());
     Assert.AreEqual("f<a href=\"http://www.jabber.org\">o</a>o", msg.Html);
 }
コード例 #12
0
        public void SendMessage(JID toJid, string body, MessageType type)
        {
            Message m = new Message (XmppGlobal.InternalClient.Document);

            m.To = toJid;
            m.Body = body;
            m.Type = type;

            XmppGlobal.InternalClient.Write (m);
        }
コード例 #13
0
ファイル: MessageTest.cs プロジェクト: bladecoding/Jabber-net
 public void Test_Normal()
 {
     Message msg = new Message(doc);
     Assert.AreEqual(MessageType.normal, msg.Type);
     Assert.AreEqual("", msg.GetAttribute("type"));
     msg.Type = MessageType.chat;
     Assert.AreEqual(MessageType.chat, msg.Type);
     Assert.AreEqual("chat", msg.GetAttribute("type"));
     msg.Type = MessageType.normal;
     Assert.AreEqual(MessageType.normal, msg.Type);
     Assert.AreEqual("", msg.GetAttribute("type"));
 }
コード例 #14
0
        public string FormatMessage(string bodyHtml, Message message)
        {
            string chatMessage = bodyHtml;
                        MatchCollection matchCollection = Regex.Matches(bodyHtml, WIKIPEDIA_PAGE_LINK_PATTERN); // matchCollection contains (ia) the Wikipedia-Locations and the names of the articles

                        foreach(Match match in matchCollection) // Maybe more than one article was posted in a message
                        {
                                string linkUrl = String.Format("http://{0}.wikipedia.org/wiki/{1}",  match.Groups[2], match.Groups[3]); // Groups[2] = Location , Groups[3] = Article
                                chatMessage += BuildHtmlPreview(linkUrl); // Add the WikipediaPreview to the chatMessage
                        }
                        return chatMessage; // This will be displayed in the ChatWindow
        }
コード例 #15
0
        /// <summary>
        /// When invited to a team
        /// </summary>
        /// <param name="Message"></param>
        public TeamQueuePage(Message Message, bool IsCreator)
        {
            InitializeComponent();
            MessageData = Message;
            Client.InviteListView = InviteListView;

            using (XmlReader reader = XmlReader.Create(new StringReader(Message.Body)))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        #region Parse Popup

                        switch (reader.Name)
                        {
                            case "inviteId":
                                reader.Read();
                                InviteId = Convert.ToInt64(reader.Value);
                                break;
                        }

                        #endregion Parse Popup
                    }
                }
            }

            Client.PVPNet.AcceptInviteForMatchmakingGame(InviteId.ToString());

            string ObfuscatedName = Client.GetObfuscatedChatroomName(InviteId.ToString(), ChatPrefixes.Arranging_Game);
            string JID = Client.GetChatroomJID(ObfuscatedName, "0", true);
            newRoom = Client.ConfManager.GetRoom(new jabber.JID(JID));
            newRoom.Nickname = Client.LoginPacket.AllSummonerData.Summoner.Name;
            newRoom.OnRoomMessage += newRoom_OnRoomMessage;
            newRoom.OnParticipantJoin += newRoom_OnParticipantJoin;
            newRoom.Join();

            IsOwner = IsCreator;

            if (IsCreator)
            {
                InviteButton.IsEnabled = true;
                StartGameButton.IsEnabled = true;
            }
            else
            {
                InviteButton.IsEnabled = false;
                StartGameButton.IsEnabled = false;
            }

            Client.OnMessage += Client_OnMessage;
        }
コード例 #16
0
        public void ProcessMessage(Message message)
        {
            if (!string.IsNullOrEmpty(message.Body))
            {
                if (message.From != null)
                {
                    CurrentChat = message.From.Bare;
                }

                _msg.Enqueue(message);
                _event.Set();
            }
        }
コード例 #17
0
 private void jc_OnMessage(object sender, jabber.protocol.client.Message msg)
 {
     jabber.protocol.x.Data x = msg["x", URI.XDATA] as jabber.protocol.x.Data;
     if (x != null)
     {
         muzzle.XDataForm f = new muzzle.XDataForm(msg);
         f.ShowDialog(this);
         jc.Write(f.GetResponse());
     }
     else
     {
         MessageBox.Show(this, msg.Body, msg.From, MessageBoxButtons.OK);
     }
 }
コード例 #18
0
        public void _他の入札者によって価格が変更された場合に新しい価格の通知を受ける()
        {
            mListener.Expect(listener =>  {
                listener.CurrentPrice(192, 7, PriceSource.FromOtherBidder);
            })
                .Repeat.Times(1);

            var m = new Message(new XmlDocument()) {
                Body = "SOLVersion: 1.1; Event: PRICE; CurrentPrice: 192; Increment: 7; Bidder: Someone else;",
            };

            mTranslator.ProcessMessage(UnusedChat, m);

            mListener.VerifyAllExpectations();
        }
コード例 #19
0
        public void _Closeメッセージを受け取ったらオークションのCloseを通知する()
        {
            mListener.Expect(listener => {
                listener.AuctionClosed();
            })
            .Repeat.Once();

            var m = new Message(new XmlDocument()) {
                Body = "SOLVersion: 1.1; Event: CLOSE;",
            };

            mTranslator.ProcessMessage(UnusedChat, m);

            mListener.VerifyAllExpectations();
        }
コード例 #20
0
        public void _Sniperによって価格が変更された場合に新しい価格の通知を受ける()
        {
            mListener.Expect(listener =>  {
                listener.CurrentPrice(234, 5, PriceSource.FromSniper);
            })
                .Repeat.Times(1);

            var m = new Message(new XmlDocument()) {
                Body = string.Format("SOLVersion: 1.1; Event: PRICE; CurrentPrice: 234; Increment: 5; Bidder: {0};", SniperId.User),
            };

            mTranslator.ProcessMessage(UnusedChat, m);

            mListener.VerifyAllExpectations();
        }
コード例 #21
0
        private void newRoom_OnRoomMessage(object sender, Message msg)
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {

                if (msg.Body != "This room is not anonymous")
                {
                    TextRange tr = new TextRange(ChatTextThing.Document.ContentEnd, ChatTextThing.Document.ContentEnd);
                    tr.Text = msg.From.Resource + ": ";
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);
                    tr = new TextRange(ChatTextThing.Document.ContentEnd, ChatTextThing.Document.ContentEnd);
                    tr.Text = msg.InnerText.Replace("<![CDATA[", "").Replace("]]>", "") + Environment.NewLine;
                    tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
                }
            }));
        }
コード例 #22
0
        internal static void ChatClient_OnMessage(object sender, jabber.protocol.client.Message msg)
        {
            MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                if (OnMessage != null)
                {
                    OnMessage(sender, msg);
                }

                if (msg.Subject != null)
                {
                    ChatSubjects subject = (ChatSubjects)Enum.Parse(typeof(ChatSubjects), msg.Subject, true);

                    if (subject == ChatSubjects.PRACTICE_GAME_INVITE ||
                        subject == ChatSubjects.GAME_INVITE)
                    {
                        MainWin.FlashWindow();
                        NotificationPopup pop   = new NotificationPopup(subject, msg);
                        pop.Height              = 230;
                        pop.HorizontalAlignment = HorizontalAlignment.Right;
                        pop.VerticalAlignment   = VerticalAlignment.Bottom;
                        NotificationGrid.Children.Add(pop);
                    }
                    else if (subject == ChatSubjects.GAME_MSG_OUT_OF_SYNC)
                    {
                        MessageOverlay messageOver         = new MessageOverlay();
                        messageOver.MessageTitle.Content   = "Game no longer exists";
                        messageOver.MessageTextBox.Text    = "The game you are looking for no longer exists.";
                        Client.OverlayContainer.Content    = messageOver.Content;
                        Client.OverlayContainer.Visibility = Visibility.Visible;
                    }
                }
            }));

            //On core thread
            if (msg.Subject != null)
            {
                return;
            }

            if (AllPlayers.ContainsKey(msg.From.User) && !String.IsNullOrWhiteSpace(msg.Body))
            {
                ChatPlayerItem chatItem = AllPlayers[msg.From.User];
                chatItem.Messages.Add(chatItem.Username + "|" + msg.Body);
                MainWin.FlashWindow();
            }
        }
コード例 #23
0
ファイル: MessageTest.cs プロジェクト: bladecoding/Jabber-net
 public void Test_Escape()
 {
     Message msg = new Message(doc);
     msg.Body = "&";
     Assert.AreEqual("<message id=\""+msg.ID+"\"><body>&amp;</body></message>", msg.ToString());
     msg.RemoveChild(msg["body"]);
     Assert.AreEqual("<message id=\""+msg.ID+"\"></message>", msg.ToString());
     try
     {
         msg.Html = "&";
         Assert.Fail("should have thrown an exception");
     }
     catch
     {
         Assert.IsTrue(true, "Threw exception, as expected");
     }
 }
コード例 #24
0
        public bool TryPoll(TimeSpan inTimeout, TimeSpan inWait, out Message outItem)
        {
            outItem = null;

            var endTime = DateTime.Now.Add(inTimeout);

            while (DateTime.Now < endTime) {
                lock (mLock) {
            //                    if (mMessages.TryDequeue(out outItem)) {
                    if (mMessages.Any()) {
                        outItem = mMessages.Dequeue();
                        return true;
                    }

                    Monitor.Wait(mLock, inWait);
                }
            }

            return false;
        }
コード例 #25
0
ファイル: FrmChat.cs プロジェクト: Flowdalic/realjabber
        /// <summary>Process the contents of an XMPP message</summary>
        public void HandleMessage(jabber.protocol.client.Message msg)
        {
            //Console.WriteLine(msg.OuterXml.ToString());
            if (rttEnabled)
            {
                // Did we receive a <rtt> element?
                XmlElement rttBlock = (XmlElement)msg["rtt"];
                if (rttBlock != null)
                {
                    // Create a new real time mesage if not already created
                    RealTimeMessage rttMessage = m_chat.GetRealTimeMessage(msg.From.Bare);
                    if (rttMessage == null)
                    {
                        rttMessage = m_chat.NewRealTimeMessage(_jabberClient.Document, (string)msg.From.Bare, Color.DarkBlue);
                        rttMessage.Decoder.TextUpdated      += new RealTimeText.Decoder.TextUpdatedHandler(decoder_TextDecoded);
                        rttMessage.Decoder.SyncStateChanged += new RealTimeText.Decoder.SyncStateChangedHandler(decoder_SyncStateChanged);
                    }
                    // Process <rtt> element
                    rttMessage.Decoder.Decode(rttBlock);

                    // Highlight frozen text differently (stalled due to missing message)
                    rttMessage.Color = rttMessage.Decoder.InSync ? Color.DarkBlue : Color.LightGray;

                    // If key press intervals are disabled, decode immediately
                    if (!encoderRTT.KeyIntervalsEnabled)
                    {
                        rttMessage.Decoder.FullDecodeNow();
                        UpdateConversationWindow();
                    }
                }
            }

            if (msg.Body != null)
            {
                // Completed line of text
                AppendConversation(msg.From.Bare, msg.Body, Color.DarkBlue);
            }
        }
コード例 #26
0
ファイル: FrmChat.cs プロジェクト: Flowdalic/realjabber
        /// <summary>Transmit a message. Either a regular message, or real time text update, or both.</summary>
        private void JabberSendMessage(string body)
        {
            try
            {
                if (body == null)
                {
                    return;
                }

                // Create the XMPP <message>
                jabber.protocol.client.Message reply = new jabber.protocol.client.Message(_jabberClient.Document);
                reply.To = JID.Bare;

                // Add <rtt> element if needed (flush final RTT element with full message delivery)
                if (rttEnabled)
                {
                    encoderRTT.Encode(SendBox.Text, SendBox.SelectionStart);
                    if (!encoderRTT.IsEmpty)
                    {
                        reply.AppendChild(encoderRTT.GetEncodedRTT());
                    }
                    encoderRTT.NextMsg();
                }

                // Add the <body> element
                reply.Body = body;
                if (enableChatStates)
                {
                    reply.AppendChild(reply.OwnerDocument.CreateElement("active")); //, "http://jabber.org/protocol/chatstates"));
                }
                _jabberClient.Write(reply);
            }
            catch (Exception ex)
            {
                Console.WriteLine("!!! Exception in JabberSendMessage(): " + ex.ToString());
            }
        }
コード例 #27
0
ファイル: Client.cs プロジェクト: ErikMelton/JustUlted
        internal static void ChatClient_OnMessage(object sender, jabber.protocol.client.Message msg)
        {
            if (msg.Subject != null)
            {
                MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    ChatSubjects subject = (ChatSubjects)Enum.Parse(typeof(ChatSubjects), msg.Subject, true);
                    //NotificationPopup pop = new NotificationPopup(subject, msg);
                    //pop.Height = 230;
                    //pop.HorizontalAlignment = HorizontalAlignment.Right;
                    //pop.VerticalAlignment = VerticalAlignment.Bottom;
                    //Client.NotificationGrid.Children.Add(pop);
                }));

                return;
            }

            if (AllPlayers.ContainsKey(msg.From.User) && !String.IsNullOrWhiteSpace(msg.Body))
            {
                ChatPlayerItem chatItem = AllPlayers[msg.From.User];
                chatItem.Messages.Add(chatItem.Username + "|" + msg.Body);
                MainWin.FlashWindow();
            }
        }
コード例 #28
0
        /// <summary>
        /// Invite a user to join the room.
        /// </summary>
        /// <param name="invitee">The JID of the person to invite</param>
        /// <param name="reason">The reason for the invite, or null for none.</param>
        public void Invite(JID invitee, string reason)
        {
            if (m_state != STATE.running)
                throw new InvalidOperationException("Must be in running state to send invite: " + m_state.ToString());

            if (invitee == null)
                throw new ArgumentNullException("invitee");
            /*
            <message
            from='[email protected]/desktop'
            to='*****@*****.**'>
              <x xmlns='http://jabber.org/protocol/muc#user'>
            <invite to='*****@*****.**'>
              <reason>
            Hey Hecate, this is the place for all good witches!
              </reason>
            </invite>
              </x>
            </message>
             */
            Message m = new Message(m_manager.Stream.Document);
            m.To = m_room;
            UserX x = new UserX(m_manager.Stream.Document);
            x.AddInvite(invitee, reason);
            m.AddChild(x);
            m_manager.Write(m);
        }
コード例 #29
0
        private void m_stream_OnProtocol(object sender, System.Xml.XmlElement rp)
        {
            // There isn't always a from address.  iq:roster, for example.
            string af = rp.GetAttribute("from");
            if (af == "")
                return;
            JID from = new JID(af);
            if (from.Bare != (string)m_room)
                return;  // not for this room.

            switch (rp.LocalName)
            {
            case "presence":
                Presence p = (Presence)rp;
                if (p.Error != null)
                {
                    m_state = STATE.error;
                    if (OnPresenceError != null)
                        OnPresenceError(this, p);
                    return;
                }

                ParticipantCollection.Modification mod = ParticipantCollection.Modification.NONE;
                RoomParticipant party = m_participants.Modify(p, out mod);

                // if this is ours
                if (p.From == m_jid)
                {
                    switch (m_state)
                    {
                    case STATE.join:
                        OnJoinPresence(p);
                        break;
                    case STATE.leaving:
                        OnLeavePresence(p);
                        break;
                    case STATE.running:
                        if (p.Type == PresenceType.unavailable)
                            OnLeavePresence(p);
                        break;
                    }
                }
                else
                {
                    switch (mod)
                    {
                    case ParticipantCollection.Modification.NONE:
                        if (OnParticipantPresenceChange != null)
                            OnParticipantPresenceChange(this, party);
                        break;
                    case ParticipantCollection.Modification.JOIN:
                        if (OnParticipantJoin != null)
                            OnParticipantJoin(this, party);
                        break;
                    case ParticipantCollection.Modification.LEAVE:
                        if (OnParticipantLeave != null)
                            OnParticipantLeave(this, party);
                        break;
                    }
                }
                break;
            case "message":
                Message m = (Message)rp;
                if (m.Type == MessageType.groupchat)
                {
                    if (m.Subject != null)
                    {
                        if (OnSubjectChange != null)
                            OnSubjectChange(this, m);
                        m_subject = m;
                    }
                    else if (m.From == m_jid)
                    {
                        if (OnSelfMessage != null)
                            OnSelfMessage(this, m);
                    }
                    else
                    {
                        if (OnRoomMessage != null)
                            OnRoomMessage(this, m);
                    }
                }
                else
                {
                    if (m.From.Resource == null)
                    {
                        // room notification of some kind
                        if (OnAdminMessage != null)
                            OnAdminMessage(this, m);
                    }
                    else
                    {
                        if (OnPrivateMessage != null)
                            OnPrivateMessage(this, m);
                    }
                }
                break;
            case "iq":
                // TODO: IQs the room sends to us.
                break;
            }
        }
コード例 #30
0
 /// <summary>
 /// Sends a message to everyone currently in the room.
 /// </summary>
 /// <param name="body">The message text to send.</param>
 public void PublicMessage(string body)
 {
     if (m_state != STATE.running)
         throw new InvalidOperationException("Must be in running state to send message: " + m_state.ToString());
     /*
     <message
     to='*****@*****.**'
     type='groupchat'>
       <body>Harpier cries: 'tis time, 'tis time.</body>
     </message>
      */
     if (body == null)
         throw new ArgumentNullException("body");
     Message m = new Message(m_manager.Stream.Document);
     m.To = m_room;
     m.Type = MessageType.groupchat;
     m.Body = body;
     m_manager.Write(m);
 }
コード例 #31
0
        /// <summary>
        /// Sends a private message to a single user in the room.
        /// </summary>
        /// <param name="nick">The nickname of the user to send a private message to.</param>
        /// <param name="body">The message body to send.</param>
        public void PrivateMessage(string nick, string body)
        {
            if (m_state != STATE.running)
                throw new InvalidOperationException("Must be in running state to send message: " + m_state.ToString());

            /*
            <message
            to='[email protected]/firstwitch'
            type='chat'>
              <body>I'll give thee a wind.</body>
            </message>
             */
            if (nick == null)
                throw new ArgumentNullException("nick");
            if (body == null)
                throw new ArgumentNullException("body");

            Message m = new Message(m_manager.Stream.Document);
            m.To = new JID(m_room.User, m_room.Server, nick);
            m.Type = MessageType.chat;
            m.Body = body;
            m_manager.Write(m);
        }
コード例 #32
0
 // FIXME: I don't really like this method being here.
 public void AppendMessage(Message msg)
 {
     AppendMessage(true, msg);
 }
コード例 #33
0
        protected void AppendMessage(bool incoming, Message msg)
        {
            string iconPath = null;
            string from = null;
            JID fromJid = null;

            if (msg.From == null) {
                from = m_Account.UserDisplayName;
                fromJid = m_Account.Jid;
            } else {
                if (this is MucHandler) {
                    // FIXME: Abstract this...
                    var participant = ((MucHandler)this).Room.Participants[msg.From];
                    if (participant != null) {
                        fromJid = (!String.IsNullOrEmpty(participant.RealJID)) ? participant.RealJID : participant.NickJID;
                        from = participant.Nick;
                    } else {
                        fromJid = msg.From;
                        from = msg.From.Resource;
                    }
                } else if (this is ChatHandler && ((ChatHandler)this).IsMucMessage) {
                    fromJid = msg.From;
                    from = msg.From.Resource;
                } else {
                    fromJid = msg.From;
                    from = m_Account.GetDisplayName(msg.From);
                }
            }

            foreach (XmlNode child in msg) {
                if (child.NamespaceURI == Namespace.ChatStates) {
                    TypingState state = TypingState.None;
                    if (child.LocalName == "active") {
                        state = TypingState.Active;
                    } else if (child.LocalName == "composing") {
                        state = TypingState.Composing;
                    } else if (child.LocalName == "paused") {
                        state = TypingState.Paused;
                    } else if (child.LocalName == "inactive") {
                        state = TypingState.Inactive;
                    } else if (child.LocalName == "gone") {
                        state = TypingState.Gone;
                    } else {
                        Console.WriteLine(String.Format("Unknown chatstate from {0}: {1}", from, child.LocalName));
                    }

                    var typingContent = new ChatContentTyping(m_Account, fromJid, from, null, state);
                    OnNewContent(typingContent);
                }
            }

            if (msg.Body != null || msg.Html != null) {
                string body = null;

                if (!String.IsNullOrEmpty(msg.Html)) {
                    body = HtmlSanitizer.Sanitize(msg.Html, true);
                } else {
                    body = Util.EscapeHtml(msg.Body);
                    body = Util.Linkify(body);
                    body = body.Replace("  ", " &nbsp;");
                    body = body.Replace("\t", " &nbsp;&nbsp;&nbsp;");
                    body = body.Replace("\r\n", "<br/>");
                    body = body.Replace("\n", "<br/>");
                }

                var guiService = ServiceManager.Get<GuiService>();
                foreach (var formatter in guiService.MessageDisplayFormatters) {
                    if (formatter.SupportsMessage(body, msg)) {
                        body = formatter.FormatMessage(body, msg);
                        if (formatter.StopAfter) {
                            break;
                        }
                    }
                }

                DateTime date = DateTime.Now;

                var nsmgr = new XmlNamespaceManager(msg.OwnerDocument.NameTable);
                nsmgr.AddNamespace("delay", "jabber:x:delay");
                var delay = (XmlElement)msg.SelectSingleNode("delay:x", nsmgr);
                if (delay != null) {
                    string stamp = delay.GetAttribute("stamp");
                    // CCYYMMDDThh:mm:ss
                    date = DateTime.ParseExact(stamp, @"yyyyMMdd\THH:mm:ss", null).ToLocalTime();
                }

                var content = new ChatContentMessage(m_Account, fromJid, from, msg.To, date);
                content.IsOutgoing = !incoming;
                content.MessageHtml = body;

                OnNewContent(content);
            }
        }
コード例 #34
0
ファイル: Client.cs プロジェクト: Battler624/LegendaryClient
 internal static void Message(string To, string Message, ChatSubjects Subject)
 {
     Message msg = new Message(ChatClient.Document);
     msg.Type = MessageType.normal;
     msg.To = To + "@pvp.net";
     msg.Subject = ((ChatSubjects)Subject).ToString();
     msg.Body = Message;
     ChatClient.Write(msg);
 }
コード例 #35
0
        private void muc_OnInvite(object sender, jabber.protocol.client.Message msg)
        {
            Room r = sender as Room;

            r.Join();
        }
コード例 #36
0
ファイル: MucHandler.cs プロジェクト: newcreation/synapse
 void HandleOnSubjectChange(object sender, Message msg)
 {
     // FIXME: Show who set the subject. Handle null subject.
     base.AppendStatus(String.Format("Subject is now: {0}", m_Room.Subject));
 }
コード例 #37
0
ファイル: MucHandler.cs プロジェクト: newcreation/synapse
 void HandleOnSelfMessage(object sender, Message msg)
 {
     base.AppendMessage(false, msg);
 }
コード例 #38
0
ファイル: MucHandler.cs プロジェクト: newcreation/synapse
 void HandleOnRoomMessage(object sender, Message msg)
 {
     base.AppendMessage(true, msg);
 }
コード例 #39
0
ファイル: MucHandler.cs プロジェクト: newcreation/synapse
 void HandleOnAdminMessage(object sender, Message msg)
 {
     // FIXME: When does this happen?
     base.AppendStatus("Admin Message: " + msg.Body);
 }
コード例 #40
0
 void InternalClient_OnMessage(object sender, jabber.protocol.client.Message msg)
 {
     OnGotMessage(new MessageEventArgs(msg));
 }