예제 #1
0
        /// <summary>
        /// Tries to parse a string to get an IRC identity.
        ///
        /// IRC identities are formatted as nickname!username@hostname.
        /// </summary>
        /// <param name="string">The string to parse.</param>
        /// <param name="identity">The identity, or <c>null</c> if parsing fails.</param>
        /// <returns><c>true</c> if parsing completed successfully.</returns>
        public static bool TryParse(IrcString @string, out IrcIdentity identity)
        {
            IrcString[] parts; identity = null;
            if (@string == null)
            {
                goto invalid;
            }
            identity = new IrcIdentity();

            parts = @string.Split((byte)'@');
            if (parts.Length >= 2)
            {
                identity.Hostname = parts[1]; @string = parts[0];
            }

            parts = @string.Split((byte)'!');
            if (parts.Length >= 2)
            {
                identity.Username = parts[1]; @string = parts[0];
            }

            identity.Nickname = @string;

            string errorMessage;

            if (!IrcValidation.ValidateIdentity(identity, out errorMessage))
            {
                goto invalid;
            }
            return(true);

invalid:
            identity = null; return(false);
        }
예제 #2
0
 protected virtual void OnCtcpReplyReceived(IrcIdentity sender, IrcString recipient, IrcString command,
                                            IrcString[] parameters, IrcString rawParameter)
 {
     switch ((string)command)
     {
     case "PING":
         if (parameters.Length >= 1)
         {
             int timestamp;
             if (int.TryParse(parameters[0], out timestamp))
             {
                 int delay = CtcpPingGetTimeDifference(timestamp, CtcpPingGetTimestamp());
                 OnGotPingReply(new PingReplyEventArgs(sender, delay));
             }
         }
         break;
     }
 }
예제 #3
0
        protected virtual void OnCtcpCommandReceived(IrcIdentity sender, IrcString recipient, IrcString command,
                                                     IrcString[] parameters, IrcString rawParameter)
        {
            switch ((string)command)
            {
            case "ACTION":
                OnGotChatAction(new ChatMessageEventArgs(sender, recipient, rawParameter));
                break;

            case "DCC":
                if (parameters.Length >= 1)
                {
                    OnDccCommandReceived(sender, recipient, parameters[0], parameters.Skip(1).ToArray());
                }
                break;

            case "PING":
                if (parameters.Length >= 1 && !IrcValidation.IsChannelName(recipient))
                {
                    CtcpReply(sender.Nickname, "PING", new IrcString[] { parameters[0] });
                }
                break;

            case "TIME":
                if (!IrcValidation.IsChannelName(recipient))
                {
                    CtcpReply(sender.Nickname, "TIME", new IrcString[] { CtcpTimeGetNow().ToString
                                                                             ("ddd MMM dd HH:mm:ss yyyy", DateTimeFormatInfo.InvariantInfo) });
                }
                break;

            case "VERSION":
                if (!IrcValidation.IsChannelName(recipient))
                {
                    CtcpReply(sender.Nickname, "VERSION", new[] { ClientVersion });
                }
                break;
            }
        }
예제 #4
0
 protected virtual void OnDccCommandReceived(IrcIdentity sender, IrcString recipient,
                                             IrcString command, IrcString[] parameters)
 {
 }