47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
|
|
namespace SharpChat {
|
|
public class ChatChannel {
|
|
public string Name { get; }
|
|
public string Password { get; set; }
|
|
public bool IsTemporary { get; set; }
|
|
public int Rank { get; set; }
|
|
public long OwnerId { get; set; }
|
|
|
|
public bool HasPassword
|
|
=> !string.IsNullOrWhiteSpace(Password);
|
|
|
|
public ChatChannel(
|
|
string name,
|
|
string? password = null,
|
|
bool isTemporary = false,
|
|
int rank = 0,
|
|
long ownerId = 0
|
|
) {
|
|
Name = name;
|
|
Password = password ?? string.Empty;
|
|
IsTemporary = isTemporary;
|
|
Rank = rank;
|
|
OwnerId = ownerId;
|
|
}
|
|
|
|
public bool NameEquals(string? name) {
|
|
return string.Equals(name, Name, StringComparison.InvariantCultureIgnoreCase);
|
|
}
|
|
|
|
public bool IsOwner(ChatUser user) {
|
|
return OwnerId > 0
|
|
&& user != null
|
|
&& OwnerId == user.UserId;
|
|
}
|
|
|
|
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 == '_';
|
|
}
|
|
}
|
|
}
|