示例#1
0
文件: Session.cs 项目: pkt30/OscarLib
 /// <summary>
 /// Raises the <see cref="OscarLib_DirectIMReceived"/> event
 /// </summary>
 /// <param name="message">The <see cref="DirectIM"/> received</param>
 protected internal void OnDirectIMReceived(DirectIM message)
 {
     if (this.DirectIMReceived != null)
     {
         this.DirectIMReceived(this, message);
     }
 }
示例#2
0
文件: Main.cs 项目: pkt30/OscarLib
 private void sess_DirectIMReceived(Session sess, DirectIM message)
 {
     Console.WriteLine("DirectIM Message from {1}: {0}", message.Message, message.ScreenName);
     sess.Messages.SendMessage(message.ScreenName, "Your momma!", OutgoingMessageFlags.None);
 }
示例#3
0
        /// <summary>
        /// Sends an instant message
        /// </summary>
        /// <param name="screenName">The screenname to receive the IM</param>
        /// <param name="message">The message to send</param>
        /// <param name="flags">A <see cref="OutgoingMessageFlags"/> enumeration specifying what
        /// additional information should be sent with the message</param>
        /// <param name="attachments">A list of <see cref="Attachment"/>s to send with the message</param>
        /// <remarks>
        /// <para>Delivery confirmation results or sending errors will be returned in the <see cref="MessageDeliveryUpdate"/> event.</para>
        /// <para>If any attachments are specified in the <paramref name="attachments"/> list, this method will
        /// attempt to open a Direct Connection, a peer-to-peer connection that could expose the local
        /// IP address to the other participant in the conversation.  If a Direct Connection cannot be established,
        /// this method will not attempt to send the message without the attachments.  The <see cref="Session.DirectIMSessionCancelled"/>
        /// event will be raised, and the client should attempt to send the message without attachments manually.</para></remarks>
        /// <exception cref="NotLoggedInException">Thrown when the <see cref="Session"/> is not logged in</exception>
        public Cookie SendMessage(String screenName, String message, OutgoingMessageFlags flags,
		                          List<Attachment> attachments)
        {
            if (!parent.LoggedIn)
            {
                throw new NotLoggedInException();
            }

            // See if there is an existing Direct Connection for this screen name.
            // If there is, send the message by it.  If there isn't and there are
            // attachments to send along, create a new DC
            DirectIMConnection conn = parent.Connections.GetDirectIMByScreenname(screenName);
            if (conn != null || (attachments != null && attachments.Count > 0))
            {
                // Make sure the connection hasn't been disconnected on the other side
                if (conn != null && conn.Connected == false)
                {
                    // If there are no attachments, it can be sent through the server,
                    // otherwise the DC will attempt reconnection
                    if (attachments == null || attachments.Count == 0)
                    {
                        // No attachments, just send it through the server
                        return SendMessageThroughServer(screenName, message, flags);
                    }
                }

                if (conn == null)
                {
                    conn = parent.Connections.CreateNewDirectIMConnection(DirectConnectionMethod.Direct,
                                                                          DirectConnectRole.Initiator);
                    RequestDirectConnectionInvite(conn);
                }

                DirectIM dim = new DirectIM(screenName, conn);
                dim.Cookie = Cookie.CreateCookieForSending();
                dim.Attachments = attachments;
                dim.Message = message;
                dim.IsAutoResponse = (flags & OutgoingMessageFlags.AutoResponse) != 0;
                conn.SendMessage(dim);

                return dim.Cookie;
            }
            else
            {
                return SendMessageThroughServer(screenName, message, flags);
            }
        }