40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
namespace SharpChat;
|
|
|
|
public class Channel(
|
|
string name,
|
|
string password = "",
|
|
bool isTemporary = false,
|
|
int rank = 0,
|
|
string ownerId = ""
|
|
) {
|
|
public string Name { get; } = name ?? throw new ArgumentNullException(nameof(name));
|
|
public string Password { get; set; } = password ?? string.Empty;
|
|
public bool IsTemporary { get; set; } = isTemporary;
|
|
public int Rank { get; set; } = rank;
|
|
public string OwnerId { get; set; } = ownerId;
|
|
|
|
public bool HasPassword
|
|
=> !string.IsNullOrWhiteSpace(Password);
|
|
|
|
public bool NameEquals(string name) {
|
|
return string.Equals(name, Name, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool IsOwner(User user) {
|
|
return string.IsNullOrEmpty(OwnerId)
|
|
&& user != null
|
|
&& OwnerId == user.UserId;
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
return Name.GetHashCode();
|
|
}
|
|
|
|
public static bool CheckName(string name) {
|
|
return !string.IsNullOrWhiteSpace(name) && name.All(CheckNameChar);
|
|
}
|
|
|
|
public static bool CheckNameChar(char c) {
|
|
return char.IsLetter(c) || char.IsNumber(c) || c == '-' || c == '_';
|
|
}
|
|
}
|