/// <summary> /// Checks to see if the user has at least the given prefix SYMBOL (true if his highest prefix is higher or equal to this prefix) /// </summary> /// <param name="svr"></param> /// <param name="prefix"></param> /// <returns></returns> public bool AtLeast(IrcClient.ServerInfoType svr, char prefix) { int targetPosition = svr.PREFIX_symbols.IndexOf(prefix); if (targetPosition <= 0 || Prefixes.Length == 0) { return(false); } int myPosition = svr.PREFIX_symbols.IndexOf(Prefixes[0]); if (myPosition < 0) { return(false); } return(myPosition <= targetPosition); }
/// <summary> /// Inserts a prefix (mode symbol) into this client's prefix list for the given channel and svrInfo class (must have PREFIX_symbols set by server) /// </summary> /// <param name="svrInfo"></param> /// <param name="channelName"></param> /// <param name="prefix"></param> internal void InsertPrefix(IrcClient.ServerInfoType svrInfo, String channelName, char prefix) { String currentList; lock (prefixes) { if (prefixes.ToString().Contains(prefix)) { return; } else if (prefixes.Length == 0) { prefixes.Append(prefix); } else { if (svrInfo.PREFIX_symbols == null) { throw new Exception("Internal IRCClient error: PREFIX_symbols is NULL"); } if (!svrInfo.PREFIX_symbols.Contains(prefix)) { throw new Exception("Internal IRCClient error: PREFIX_symbols does not contain prefix which was inserted: " + prefix); } /// Find the first prefix in the current list (newList) whose value is less than this new prefix, and insert at that position /// Or append it to the end if we never find one for (int i = 0; i < prefixes.Length; ++i) { if (svrInfo.PREFIX_symbols.IndexOf(prefix) < svrInfo.PREFIX_symbols.IndexOf(prefixes[i])) { prefixes.Insert(i, prefix); break; } else if (i + 1 == prefixes.Length) // If we've reached the end and still haven't found one of lower value, then this one belongs at the end { prefixes.Append(prefix); return; } } } } }