v1.5.7.0 (Summer Update)

This commit is contained in:
Regalis11
2024-06-18 16:49:51 +03:00
parent 4a63dacbce
commit 230d1b6e78
263 changed files with 7792 additions and 2845 deletions

View File

@@ -0,0 +1,40 @@
using System;
namespace Barotrauma.Extensions
{
public static class EnumExtensions
{
/// <summary>
/// Enum.HasFlag() checks if all flags matches. This method checks if any of them matches.
/// E.g. when myEnum = SomeEnum.First | SomeEnum.Second, myEnum.HasFlag(SomeEnum.First | SomeEnum.Third) returns false, because not all of the flags match, but HasAnyFlag(SomeEnum.First | SomeEnum.Third) returns true, because some of the flags match.
/// </summary>
public static bool HasAnyFlag<T>(this T type, T value) where T : Enum
{
int typeValue = Convert.ToInt32(type);
int flagValue = Convert.ToInt32(value);
return (typeValue & flagValue) != 0;
}
/// <summary>
/// Adds a flag value to an enum.
/// Note that enums are value types, so you need to use the value returned from this method.
/// </summary>
public static T AddFlag<T>(this T @enum, T flag) where T : Enum
{
int enumValue = Convert.ToInt32(@enum);
int flagValue = Convert.ToInt32(flag);
return (T)(object)(enumValue | flagValue);
}
/// <summary>
/// Removes a flag value from an enum.
/// Note that enums are value types, so you need to use the value returned from this method.
/// </summary>
public static T RemoveFlag<T>(this T @enum, T flag) where T : Enum
{
int enumValue = Convert.ToInt32(@enum);
int flagValue = Convert.ToInt32(flag);
return (T)(object)(enumValue & ~flagValue);
}
}
}

View File

@@ -0,0 +1,45 @@
#nullable enable
using System;
namespace Barotrauma.Networking
{
/// <summary>
/// Represents an account ID of a client that has not been authenticated in any way. The account ID is only based on the client's name.
/// Only used on servers that allow joining without Steam/EOS authentication (such as when playing in a local network with no internet connection).
/// </summary>
public sealed class UnauthenticatedAccountId : AccountId
{
private const string Prefix = "UNAUTHENTICATED_";
private readonly string clientName;
public override string StringRepresentation => Prefix + clientName;
public override string EosStringRepresentation => StringRepresentation;
public UnauthenticatedAccountId(string clientName)
{
this.clientName = clientName;
}
public override bool Equals(object? obj)
=> obj is UnauthenticatedAccountId otherId
&& otherId.clientName.Equals(clientName);
public override int GetHashCode()
{
return clientName.GetHashCode();
}
public new static Option<UnauthenticatedAccountId> Parse(string str)
{
if (str.IsNullOrWhiteSpace()) { return Option.None; }
if (!str.StartsWith(Prefix, StringComparison.InvariantCultureIgnoreCase))
{
return Option.None;
}
return Option.Some(new UnauthenticatedAccountId(str[Prefix.Length..]));
}
}
}

View File

@@ -18,7 +18,17 @@ namespace Barotrauma.Networking
public override string ToString() => StringRepresentation;
public static bool operator ==(Address a, Address b)
=> a.Equals(b);
{
if (a is null || b is null)
{
return a is null == b is null;
}
else
{
return a.Equals(b);
}
}
public static bool operator !=(Address a, Address b)
=> !(a == b);