sharp-chat/SharpChat/ChatChannel.cs

51 lines
1.4 KiB
C#
Raw Normal View History

using System;
2022-08-30 15:00:58 +00:00
using System.Linq;
using System.Text;
namespace SharpChat {
2023-02-16 22:47:30 +00:00
public class ChatChannel {
2022-08-30 15:00:58 +00:00
public string Name { get; set; }
public string Password { get; set; } = string.Empty;
public bool IsTemporary { get; set; } = false;
public int Rank { get; set; } = 0;
public ChatUser Owner { get; set; } = null;
public bool HasPassword
=> !string.IsNullOrWhiteSpace(Password);
2023-02-08 03:32:12 +00:00
public ChatChannel() { }
2022-08-30 15:00:58 +00:00
public ChatChannel(string name) {
Name = name;
}
public string Pack() {
2023-02-07 15:01:56 +00:00
StringBuilder sb = new();
2022-08-30 15:00:58 +00:00
sb.Append(Name);
sb.Append('\t');
sb.Append(string.IsNullOrEmpty(Password) ? '0' : '1');
sb.Append('\t');
sb.Append(IsTemporary ? '1' : '0');
return sb.ToString();
}
public bool NameEquals(string name) {
return string.Equals(name, Name, StringComparison.InvariantCultureIgnoreCase);
}
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 == '_';
}
2022-08-30 15:00:58 +00:00
}
}