Build 0.21.6.0 (1.0 pre-patch)

This commit is contained in:
Regalis11
2023-01-31 18:08:26 +02:00
parent e1c04bc31d
commit cf9ecd35b3
231 changed files with 4479 additions and 2276 deletions
@@ -12,7 +12,7 @@ namespace Barotrauma.Networking
public readonly Either<Address, AccountId> AddressOrAccountId;
public readonly string Reason;
public DateTime? ExpirationTime;
public Option<SerializableDateTime> ExpirationTime;
public readonly UInt32 UniqueIdentifier;
}
@@ -197,7 +197,7 @@ namespace Barotrauma.Networking
public T GetVote<T>(VoteType voteType)
{
return (votes[(int)voteType] is T) ? (T)votes[(int)voteType] : default(T);
return (votes[(int)voteType] is T t) ? t : default;
}
public void SetVote(VoteType voteType, object value)
@@ -34,7 +34,7 @@
interface IServerPositionSync : IServerSerializable
{
#if SERVER
void ServerWritePosition(IWriteMessage msg, Client c);
void ServerWritePosition(ReadWriteMessage tempBuffer, Client c);
#endif
#if CLIENT
void ClientReadPosition(IReadMessage msg, float sendingTime);
@@ -160,7 +160,8 @@ namespace Barotrauma
{ typeof(Identifier), new ReadWriteBehavior<Identifier>(ReadIdentifier, WriteIdentifier) },
{ typeof(AccountId), new ReadWriteBehavior<AccountId>(ReadAccountId, WriteAccountId) },
{ typeof(Color), new ReadWriteBehavior<Color>(ReadColor, WriteColor) },
{ typeof(Vector2), new ReadWriteBehavior<Vector2>(ReadVector2, WriteVector2) }
{ typeof(Vector2), new ReadWriteBehavior<Vector2>(ReadVector2, WriteVector2) },
{ typeof(SerializableDateTime), new ReadWriteBehavior<SerializableDateTime>(ReadSerializableDateTime, WriteSerializableDateTime) }
};
private static readonly ImmutableDictionary<Predicate<Type>, Func<Type, IReadWriteBehavior>> BehaviorFactories = new Dictionary<Predicate<Type>, Func<Type, IReadWriteBehavior>>
@@ -512,6 +513,41 @@ namespace Barotrauma
WriteSingle(y, attribute, msg, bitField);
}
private static readonly Range<Int64> ValidTickRange
= new Range<Int64>(
start: DateTime.MinValue.Ticks,
end: DateTime.MaxValue.Ticks);
private static readonly Range<Int16> ValidTimeZoneMinuteRange
= new Range<Int16>(
start: (Int16)TimeSpan.FromHours(-12).TotalMinutes,
end: (Int16)TimeSpan.FromHours(14).TotalMinutes);
private static SerializableDateTime ReadSerializableDateTime(
IReadMessage inc, NetworkSerialize attribute, ReadOnlyBitField bitField)
{
var ticks = inc.ReadInt64();
var timezone = inc.ReadInt16();
if (!ValidTickRange.Contains(ticks))
{
throw new Exception($"Incoming SerializableDateTime ticks out of range (ticks: {ticks}, timezone: {timezone})");
}
if (!ValidTimeZoneMinuteRange.Contains(timezone))
{
throw new Exception($"Incoming SerializableDateTime timezone out of range (ticks: {ticks}, timezone: {timezone})");
}
return new SerializableDateTime(new DateTime(ticks),
new SerializableTimeZone(TimeSpan.FromMinutes(timezone)));
}
private static void WriteSerializableDateTime(
SerializableDateTime dateTime, NetworkSerialize attribute, IWriteMessage msg, WriteOnlyBitField bitField)
{
msg.WriteInt64(dateTime.Ticks);
msg.WriteInt16((Int16)(dateTime.TimeZone.Value.Ticks / TimeSpan.TicksPerMinute));
}
private static bool IsRanged(float minValue, float maxValue) => minValue > float.MinValue || maxValue < float.MaxValue;
private static bool IsRanged(int minValue, int maxValue) => minValue > int.MinValue || maxValue < int.MaxValue;
@@ -99,6 +99,19 @@ namespace Barotrauma.Networking
EntityEventInitial
}
[NetworkSerialize]
readonly record struct EntityPositionHeader(
bool IsItem,
UInt32 PrefabUintIdentifier,
UInt16 EntityId) : INetSerializableStruct
{
public static EntityPositionHeader FromEntity(Entity entity)
=> new (
IsItem: entity is Item,
PrefabUintIdentifier: entity is MapEntity me ? me.Prefab.UintIdentifier : 0,
EntityId: entity.ID);
}
enum TraitorMessageType
{
Server,
@@ -171,6 +171,8 @@ namespace Barotrauma.Networking
public bool ShouldCreateAnalyticsEvent
=> DisconnectReason is not (
DisconnectReason.Disconnected
or DisconnectReason.ServerShutdown
or DisconnectReason.ServerFull
or DisconnectReason.Banned
or DisconnectReason.Kicked
or DisconnectReason.TooManyFailedLogins
@@ -300,7 +302,7 @@ namespace Barotrauma.Networking
public ServerContentPackage() { }
public ServerContentPackage(ContentPackage contentPackage, DateTime referenceTime)
public ServerContentPackage(ContentPackage contentPackage, SerializableDateTime referenceTime)
{
Name = contentPackage.Name;
Hash = contentPackage.Hash;
@@ -1093,7 +1093,7 @@ namespace Barotrauma.Networking
for (int i = 0; i < count; i++)
{
int index = msg.ReadUInt16();
if (index < 0 || index >= subList.Count) { continue; }
if (index >= subList.Count) { continue; }
string submarineName = subList[index].Name;
HiddenSubs.Add(submarineName);
}
@@ -8,7 +8,7 @@ namespace Barotrauma
{
public enum VoteState { None = 0, Started = 1, Running = 2, Passed = 3, Failed = 4 };
private IReadOnlyDictionary<T, int> GetVoteCounts<T>(VoteType voteType, IEnumerable<Client> voters)
private static IReadOnlyDictionary<T, int> GetVoteCounts<T>(VoteType voteType, IEnumerable<Client> voters)
{
Dictionary<T, int> voteList = new Dictionary<T, int>();
@@ -29,7 +29,7 @@ namespace Barotrauma
return voteList;
}
public T HighestVoted<T>(VoteType voteType, List<Client> voters)
public static T HighestVoted<T>(VoteType voteType, IEnumerable<Client> voters)
{
if (voteType == VoteType.Sub && !GameMain.NetworkMember.ServerSettings.AllowSubVoting) { return default; }
if (voteType == VoteType.Mode && !GameMain.NetworkMember.ServerSettings.AllowModeVoting) { return default; }