using System.Collections.Generic;
using System.Linq;
namespace ChatSharp
{
///
/// Information provided by the server about its featureset.
///
public class ServerInfo
{
internal ServerInfo()
{
// Guess for some defaults
Prefixes = new[] { "ovhaq", "@+%&~" };
SupportedChannelModes = new ChannelModes();
IsGuess = true;
ExtendedWho = false;
}
///
/// Gets the mode for a given channel user list prefix.
///
public char? GetModeForPrefix(char prefix)
{
if (Prefixes[1].IndexOf(prefix) == -1)
return null;
return Prefixes[0][Prefixes[1].IndexOf(prefix)];
}
///
/// Gets the channel modes for a given user nick.
/// Returns an empty array if user has no modes.
///
///
public List GetModesForNick(string nick)
{
var supportedPrefixes = Prefixes[1];
List modeList = new List();
List nickPrefixes = new List();
foreach (char prefix in supportedPrefixes)
{
if (nick.Contains(prefix))
{
nick.Remove(nick.IndexOf(prefix));
if (!nickPrefixes.Contains(prefix))
{
nickPrefixes.Add(prefix);
var mode = GetModeForPrefix(prefix);
if (!modeList.Contains(mode))
modeList.Add(mode);
}
}
}
return modeList;
}
///
/// ChatSharp makes some assumptions about what the server supports in order to function properly.
/// If it has not recieved a 005 message giving it accurate information, this value will be true.
///
public bool IsGuess { get; internal set; }
///
/// Nick prefixes for special modes in channel user lists
///
public string[] Prefixes { get; internal set; }
///
/// Supported channel prefixes (i.e. '#')
///
public char[] ChannelTypes { get; internal set; }
///
/// Channel modes supported by this server
///
public ChannelModes SupportedChannelModes { get; set; }
///
/// The maximum number of MODE changes possible with a single command
///
public int? MaxModesPerCommand { get; set; }
///
/// The maximum number of channels a user may join
///
public int? MaxChannelsPerUser { get; set; } // TODO: Support more than just # channels
///
/// Maximum length of user nicks on this server
///
public int? MaxNickLength { get; set; }
///
/// The limits imposed on list modes, such as +b
///
public ModeListLimit[] ModeListLimits { get; set; }
///
/// The name of the network, as identified by the server
///
public string NetworkName { get; set; }
///
/// Set to ban exception character if this server supports ban exceptions
///
public char? SupportsBanExceptions { get; set; }
///
/// Set to invite exception character if this server supports invite exceptions
///
public char? SupportsInviteExceptions { get; set; }
///
/// Set to maximum topic length for this server
///
public int? MaxTopicLength { get; set; }
///
/// Set to the maximum length of a KICK comment
///
public int? MaxKickCommentLength { get; set; }
///
/// Set to the maximum length of a channel name
///
public int? MaxChannelNameLength { get; set; }
///
/// Set to the maximum length of an away message
///
public int? MaxAwayLength { get; set; }
///
/// Server supports WHOX (WHO extension)
///
public bool ExtendedWho { get; set; }
///
/// Modes a server supports that are applicable to channels.
///
public class ChannelModes
{
internal ChannelModes()
{
// Guesses
ChannelLists = "eIbq";
ParameterizedSettings = "k";
OptionallyParameterizedSettings = "flj";
Settings = string.Empty;
ChannelUserModes = "vhoaq"; // I have no idea what I'm doing here
}
///
/// Modes that are used for lists (i.e. bans).
///
public string ChannelLists { get; internal set; }
///
/// Modes that can be set on a user of a channel (i.e. ops, voice, etc).
///
public string ChannelUserModes { get; set; }
///
/// Modes that take a parameter (i.e. +k).
///
public string ParameterizedSettings { get; internal set; }
///
/// Modes that take an optional parameter (i.e. +f).
///
public string OptionallyParameterizedSettings { get; internal set; }
///
/// Modes that change channel settings.
///
public string Settings { get; internal set; }
}
///
/// Limits imposed on channel lists, such as the maximum bans per channel.
///
public class ModeListLimit
{
internal ModeListLimit(char mode, int maximum)
{
Mode = mode;
Maximum = maximum;
}
///
/// The mode character this applies to (i.e. 'b')
///
public char Mode { get; internal set; }
///
/// The maximum entries for this list.
///
public int Maximum { get; internal set; }
}
}
}