Client LuaCsForBarotrauma
AccountInfo.cs
1 #nullable enable
2 using System.Collections.Immutable;
3 using System.Linq;
4 
5 namespace Barotrauma.Networking
6 {
7  [NetworkSerialize]
8  readonly struct AccountInfo : INetSerializableStruct
9  {
10  public static readonly AccountInfo None = new AccountInfo(Option<AccountId>.None());
11 
15  public readonly Option<AccountId> AccountId;
16 
21  public readonly ImmutableArray<AccountId> OtherMatchingIds;
22 
23  public bool IsNone => AccountId.IsNone() && OtherMatchingIds.Length == 0;
24 
25  public AccountInfo(AccountId accountId, params AccountId[] otherIds) : this(Option<AccountId>.Some(accountId), otherIds) { }
26 
27  public AccountInfo(Option<AccountId> accountId, params AccountId[] otherIds)
28  {
29  AccountId = accountId;
30  OtherMatchingIds = otherIds.Where(id => !accountId.ValueEquals(id)).ToImmutableArray();
31  }
32 
33  public bool Matches(AccountId accountId)
34  => AccountId.ValueEquals(accountId) || OtherMatchingIds.Contains(accountId);
35 
36  public override bool Equals(object? obj)
37  => obj switch
38  {
39  AccountInfo otherInfo => AccountId == otherInfo.AccountId && OtherMatchingIds.All(otherInfo.OtherMatchingIds.Contains),
40  _ => false
41  };
42 
43  public override int GetHashCode()
44  => AccountId.GetHashCode();
45 
46  public static bool operator ==(AccountInfo a, AccountInfo b)
47  => a.Equals(b);
48 
49  public static bool operator !=(AccountInfo a, AccountInfo b) => !(a == b);
50  }
51 }
readonly ImmutableArray< AccountId > OtherMatchingIds
Other user IDs that this user might be closely tied to, such as the owner of the current copy of Baro...
Definition: AccountInfo.cs:21
AccountInfo(AccountId accountId, params AccountId[] otherIds)
Definition: AccountInfo.cs:25
bool Matches(AccountId accountId)
readonly Option< AccountId > AccountId
The primary ID for a given user
Definition: AccountInfo.cs:15
static readonly AccountInfo None
Definition: AccountInfo.cs:10
override bool Equals(object? obj)
static bool operator==(AccountInfo a, AccountInfo b)
AccountInfo(Option< AccountId > accountId, params AccountId[] otherIds)
Definition: AccountInfo.cs:27
static bool operator!=(AccountInfo a, AccountInfo b)