Esempio n. 1
0
        /// <summary>
        /// Sends an extended WHO query asking for specific information about a single user
        /// or the users in a channel, and runs a callback when we have received the response.
        /// </summary>
        public void Who(string target, WhoxFlag flags, WhoxField fields, Action <List <ExtendedWho> > callback)
        {
            if (ServerInfo.ExtendedWho)
            {
                var whox = new List <ExtendedWho>();

                // Generate random querytype for WHO query
                int queryType = RandomNumber.Next(0, 999);

                // Add the querytype field if it wasn't defined
                var _fields = fields;
                if ((fields & WhoxField.QueryType) == 0)
                {
                    _fields |= WhoxField.QueryType;
                }

                string whoQuery = string.Format("WHO {0} {1}%{2},{3}", target, flags.AsString(), _fields.AsString(), queryType);
                string queryKey = string.Format("WHO {0} {1} {2:D}", target, queryType, _fields);

                RequestManager.QueueOperation(queryKey, new RequestOperation(whox, ro =>
                {
                    callback?.Invoke((List <ExtendedWho>)ro.State);
                }));
                SendRawMessage(whoQuery);
            }
        }
Esempio n. 2
0
        public static string AsString(this WhoxFlag flag)
        {
            // nuhisradox
            var result = string.Empty;

            if ((flag & WhoxFlag.Nick) != 0)
            {
                result += 'n';
            }
            if ((flag & WhoxFlag.Username) != 0)
            {
                result += 'u';
            }
            if ((flag & WhoxFlag.Hostname) != 0)
            {
                result += 'h';
            }
            if ((flag & WhoxFlag.NumericIp) != 0)
            {
                result += 'i';
            }
            if ((flag & WhoxFlag.ServerName) != 0)
            {
                result += 's';
            }
            if ((flag & WhoxFlag.Info) != 0)
            {
                result += 'r';
            }
            if ((flag & WhoxFlag.AccountName) != 0)
            {
                result += 'a';
            }
            if ((flag & WhoxFlag.DelayedChanMembers) != 0)
            {
                result += 'd';
            }
            if ((flag & WhoxFlag.IrcOp) != 0)
            {
                result += 'o';
            }
            if ((flag & WhoxFlag.Special) != 0)
            {
                result += 'x';
            }

            if (flag == WhoxFlag.None)
            {
                result = string.Empty;
            }

            return(result);
        }