ircsharp/IrcTokens/Hostmask.cs

70 lines
1.6 KiB
C#
Raw Normal View History

using System;
namespace IrcTokens
2020-04-20 00:52:41 +00:00
{
/// <summary>
/// Represents the three parts of a hostmask. Parse with the constructor.
/// </summary>
public class Hostmask : IEquatable<Hostmask>
2020-04-20 00:52:41 +00:00
{
public string NickName { get; set; }
public string UserName { get; set; }
public string HostName { get; set; }
public override string ToString()
{
return _source;
}
2020-04-20 00:52:41 +00:00
public override int GetHashCode()
{
return _source.GetHashCode(StringComparison.Ordinal);
}
2020-04-20 21:24:59 +00:00
public bool Equals(Hostmask other)
2020-04-20 21:24:59 +00:00
{
if (other == null)
{
2020-04-20 21:24:59 +00:00
return false;
}
2020-04-20 21:24:59 +00:00
return _source == other._source;
}
public override bool Equals(object obj)
{
return Equals(obj as Hostmask);
2020-04-20 21:24:59 +00:00
}
2020-04-20 00:52:41 +00:00
private readonly string _source;
2020-04-20 21:24:59 +00:00
2020-04-20 00:52:41 +00:00
public Hostmask(string source)
{
if (source == null)
{
return;
}
2020-04-20 00:52:41 +00:00
_source = source;
if (source.Contains('@', StringComparison.Ordinal))
2020-04-20 00:52:41 +00:00
{
var split = source.Split('@');
NickName = split[0];
HostName = split[1];
}
else
{
NickName = source;
}
2020-04-20 21:24:59 +00:00
if (NickName.Contains('!', StringComparison.Ordinal))
2020-04-20 00:52:41 +00:00
{
var userSplit = NickName.Split('!');
NickName = userSplit[0];
UserName = userSplit[1];
}
}
}
2020-04-20 21:24:59 +00:00
}