Exemplo n.º 1
0
        /// <summary>
        /// Gets a <see cref="IrcChannelUserModes"/> instance from prefixes preceding a name in a NAMES reply.
        /// </summary>
        internal static IrcChannelUserModes GetUserMode(string prefixes, IrcNetworkParameters parameters)
        {
            var mode = IrcChannelUserModes.Normal;

            foreach (char c in prefixes)
            {
                mode |= parameters.ChannelModes.UserPrefixes[c];
            }

            return(mode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the prefixes and actual name from a prefixed channel user name.
        /// </summary>
        private static ModifiedName SplitName(string prefixedName, IrcNetworkParameters parameters)
        {
            int index = 0;

            while (parameters.ChannelModes.UserPrefixes.ContainsKey(prefixedName[index]))
            {
                index++;
            }

            if (index == 0)
            {
                return(new ModifiedName(prefixedName, string.Empty));
            }

            string prefixes = prefixedName.Substring(0, index);
            string name     = prefixedName.Substring(index);

            return(new ModifiedName(name, prefixes));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempts to find what the real name of an <see cref="IrcChannel"/> is from the specified channel name which might include modes.
        /// </summary>
        /// <remarks>
        /// The channel name may begin with the mode char associated with the user (e.g. @#example)
        /// Some networks send multiple mode chars. (e.g. @+#example)
        /// There is no way to distinguish a voiced user (+#example) from a weird but legal channel name (+#example).
        /// Thus, this method is not guaranteed to return an accurate result.
        /// </remarks>
        internal static ModifiedName GuessChannelName(string nameWithMode, IrcNetworkParameters parameters)
        {
            int prefixIndex = nameWithMode.IndexOf(StandardChannelPrefix);

            if (prefixIndex == -1)
            {
                do
                {
                    prefixIndex++;
                } while (!parameters.IsChannelPrefix(nameWithMode[prefixIndex]));
            }

            if (prefixIndex == 0)
            {
                return(new ModifiedName(nameWithMode, string.Empty));
            }

            string modes = nameWithMode.Substring(0, prefixIndex);
            string name  = nameWithMode.Substring(prefixIndex);

            return(new ModifiedName(name, modes));
        }