Release v0.15.12.0

This commit is contained in:
Joonas Rikkonen
2021-10-27 18:50:57 +03:00
parent bf95e82d80
commit 234fb6bc06
450 changed files with 26042 additions and 10457 deletions
@@ -89,7 +89,7 @@ namespace Barotrauma.Networking
private static int ReadIncomingMsgs()
{
Task<int> readTask = readStream?.ReadAsync(tempBytes, 0, tempBytes.Length, readCancellationToken.Token);
TimeSpan ts = TimeSpan.FromMilliseconds(100);
TimeSpan timeOut = TimeSpan.FromMilliseconds(100);
for (int i = 0; i < 150; i++)
{
if (shutDown)
@@ -99,7 +99,7 @@ namespace Barotrauma.Networking
return -1;
}
if ((readTask?.IsCompleted ?? true) || (readTask?.Wait(ts) ?? true))
if ((readTask?.IsCompleted ?? true) || (readTask?.Wait(timeOut) ?? true))
{
break;
}
@@ -1,4 +1,5 @@
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
using Barotrauma.Items.Components;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
@@ -28,6 +29,7 @@ namespace Barotrauma
public bool SpawnIfInventoryFull = true;
public bool IgnoreLimbSlots = false;
public InvSlotType Slot = InvSlotType.None;
private readonly Action<Item> onSpawned;
@@ -73,7 +75,8 @@ namespace Barotrauma
{
Condition = Condition
};
if (!Inventory.Owner.Removed && !Inventory.TryPutItem(spawnedItem, null, spawnedItem.AllowedSlots))
var slot = Slot != InvSlotType.None ? Slot.ToEnumerable() : spawnedItem.AllowedSlots;
if (!Inventory.Owner.Removed && !Inventory.TryPutItem(spawnedItem, null, slot))
{
if (IgnoreLimbSlots)
{
@@ -264,7 +267,7 @@ namespace Barotrauma
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, position, sub, onSpawned, condition));
}
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null, Action<Item> onSpawned = null, bool spawnIfInventoryFull = true, bool ignoreLimbSlots = false)
public void AddToSpawnQueue(ItemPrefab itemPrefab, Inventory inventory, float? condition = null, Action<Item> onSpawned = null, bool spawnIfInventoryFull = true, bool ignoreLimbSlots = false, InvSlotType slot = InvSlotType.None)
{
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; }
if (itemPrefab == null)
@@ -277,7 +280,8 @@ namespace Barotrauma
spawnQueue.Enqueue(new ItemSpawnInfo(itemPrefab, inventory, onSpawned, condition)
{
SpawnIfInventoryFull = spawnIfInventoryFull,
IgnoreLimbSlots = ignoreLimbSlots
IgnoreLimbSlots = ignoreLimbSlots,
Slot = slot
});
}
@@ -23,6 +23,10 @@ namespace Barotrauma.Networking
TeamChange,
ObjectiveManagerState,
AddToCrew,
UpdateExperience,
UpdateTalents,
UpdateMoney,
UpdatePermanentStats,
}
public readonly Entity Entity;
@@ -23,9 +23,12 @@ namespace Barotrauma.Networking
/// </summary>
public int? WallSectionIndex { get; set; }
/// <summary>
/// Same as calling <see cref="OrderChatMessage.OrderChatMessage(Order, string, int, string, ISpatialEntity, Character, Character)"/>, but the text parameter is set using <see cref="Order.GetChatMessage(string, string, bool, string)"/>
/// </summary>
public OrderChatMessage(Order order, string orderOption, int priority, ISpatialEntity targetEntity, Character targetCharacter, Character sender)
: this(order, orderOption, priority,
order?.GetChatMessage(targetCharacter?.Name, sender?.CurrentHull?.DisplayName, givingOrderToSelf: targetCharacter == sender, orderOption: orderOption),
order?.GetChatMessage(targetCharacter?.Name, sender?.CurrentHull?.DisplayName, givingOrderToSelf: targetCharacter == sender, orderOption: orderOption, priority: priority),
targetEntity, targetCharacter, sender)
{
@@ -19,6 +19,8 @@ namespace Barotrauma.Networking
Double ReadDouble();
UInt32 ReadVariableUInt32();
String ReadString();
Microsoft.Xna.Framework.Color ReadColorR8G8B8();
Microsoft.Xna.Framework.Color ReadColorR8G8B8A8();
int ReadRangedInteger(int min, int max);
Single ReadRangedSingle(Single min, Single max, int bitCount);
byte[] ReadBytes(int numberOfBytes);
@@ -15,6 +15,8 @@ namespace Barotrauma.Networking
void Write(UInt64 val);
void Write(Single val);
void Write(Double val);
void WriteColorR8G8B8(Microsoft.Xna.Framework.Color val);
void WriteColorR8G8B8A8(Microsoft.Xna.Framework.Color val);
void WriteVariableUInt32(UInt32 val);
void Write(string val);
void WriteRangedInteger(int val, int min, int max);
@@ -5,6 +5,7 @@ using Barotrauma.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Xna.Framework;
namespace Barotrauma.Networking
{
@@ -138,6 +139,26 @@ namespace Barotrauma.Networking
byte[] bytes = BitConverter.GetBytes(val);
WriteBytes(ref buf, ref bitPos, bytes, 0, 8);
}
internal static void WriteColorR8G8B8(ref byte[] buf, ref int bitPos, Microsoft.Xna.Framework.Color val)
{
EnsureBufferSize(ref buf, bitPos + 24);
Write(ref buf, ref bitPos, val.R);
Write(ref buf, ref bitPos, val.G);
Write(ref buf, ref bitPos, val.B);
}
internal static void WriteColorR8G8B8A8(ref byte[] buf, ref int bitPos, Microsoft.Xna.Framework.Color val)
{
EnsureBufferSize(ref buf, bitPos + 32);
Write(ref buf, ref bitPos, val.R);
Write(ref buf, ref bitPos, val.G);
Write(ref buf, ref bitPos, val.B);
Write(ref buf, ref bitPos, val.A);
}
internal static void Write(ref byte[] buf, ref int bitPos, string val)
{
if (string.IsNullOrEmpty(val))
@@ -217,7 +238,7 @@ namespace Barotrauma.Networking
{
byte retval = NetBitWriter.ReadByte(buf, 1, bitPos);
bitPos++;
return (retval > 0 ? true : false);
return retval > 0;
}
internal static void ReadPadBits(byte[] buf, ref int bitPos)
@@ -299,6 +320,23 @@ namespace Barotrauma.Networking
return BitConverter.ToDouble(bytes, 0);
}
internal static Microsoft.Xna.Framework.Color ReadColorR8G8B8(byte[] buf, ref int bitPos)
{
byte r = ReadByte(buf, ref bitPos);
byte g = ReadByte(buf, ref bitPos);
byte b = ReadByte(buf, ref bitPos);
return new Color(r, g, b, (byte)255);
}
internal static Microsoft.Xna.Framework.Color ReadColorR8G8B8A8(byte[] buf, ref int bitPos)
{
byte r = ReadByte(buf, ref bitPos);
byte g = ReadByte(buf, ref bitPos);
byte b = ReadByte(buf, ref bitPos);
byte a = ReadByte(buf, ref bitPos);
return new Color(r, g, b, a);
}
internal static UInt32 ReadVariableUInt32(byte[] buf, ref int bitPos)
{
int bitLength = buf.Length * 8;
@@ -482,6 +520,16 @@ namespace Barotrauma.Networking
MsgWriter.Write(ref buf, ref seekPos, val);
}
public void WriteColorR8G8B8(Color val)
{
MsgWriter.WriteColorR8G8B8(ref buf, ref seekPos, val);
}
public void WriteColorR8G8B8A8(Color val)
{
MsgWriter.WriteColorR8G8B8A8(ref buf, ref seekPos, val);
}
public void WriteVariableUInt32(UInt32 val)
{
MsgWriter.WriteVariableUInt32(ref buf, ref seekPos, val);
@@ -624,14 +672,28 @@ namespace Barotrauma.Networking
}
}
buf = new byte[decompressedData.Length];
Array.Copy(decompressedData, 0, buf, 0, decompressedData.Length);
try
{
Array.Copy(decompressedData, 0, buf, 0, decompressedData.Length);
}
catch (ArgumentException e)
{
throw new ArgumentException($"Failed to copy the incoming compressed buffer. Source buffer length: {decompressedData.Length}, start position: {0}, length: {decompressedData.Length}, destination buffer length: {buf.Length}.", e);
}
lengthBits = decompressedData.Length * 8;
DebugConsole.Log("Decompressing message: " + inLength + " to " + LengthBytes);
}
else
{
buf = new byte[inBuf.Length];
Array.Copy(inBuf, startPos, buf, 0, inLength);
try
{
Array.Copy(inBuf, startPos, buf, 0, inLength);
}
catch (ArgumentException e)
{
throw new ArgumentException($"Failed to copy the incoming uncompressed buffer. Source buffer length: {inBuf.Length}, start position: {startPos}, length: {inLength}, destination buffer length: {buf.Length}.", e);
}
lengthBits = inLength * 8;
}
seekPos = 0;
@@ -702,6 +764,17 @@ namespace Barotrauma.Networking
return MsgReader.ReadString(buf, ref seekPos);
}
public Color ReadColorR8G8B8()
{
return MsgReader.ReadColorR8G8B8(buf, ref seekPos);
}
public Color ReadColorR8G8B8A8()
{
return MsgReader.ReadColorR8G8B8A8(buf, ref seekPos);
}
public int ReadRangedInteger(int min, int max)
{
return MsgReader.ReadRangedInteger(buf, ref seekPos, min, max);
@@ -845,6 +918,16 @@ namespace Barotrauma.Networking
MsgWriter.Write(ref buf, ref seekPos, val);
}
public void WriteColorR8G8B8(Color val)
{
MsgWriter.WriteColorR8G8B8(ref buf, ref seekPos, val);
}
public void WriteColorR8G8B8A8(Color val)
{
MsgWriter.WriteColorR8G8B8A8(ref buf, ref seekPos, val);
}
public void WriteVariableUInt32(UInt32 val)
{
MsgWriter.WriteVariableUInt32(ref buf, ref seekPos, val);
@@ -936,6 +1019,16 @@ namespace Barotrauma.Networking
return MsgReader.ReadString(buf, ref seekPos);
}
public Color ReadColorR8G8B8()
{
return MsgReader.ReadColorR8G8B8(buf, ref seekPos);
}
public Color ReadColorR8G8B8A8()
{
return MsgReader.ReadColorR8G8B8A8(buf, ref seekPos);
}
public int ReadRangedInteger(int min, int max)
{
return MsgReader.ReadRangedInteger(buf, ref seekPos, min, max);
@@ -26,6 +26,9 @@ namespace Barotrauma.Networking
//any respawn items left in the shuttle are removed when the shuttle despawns
private readonly List<Item> respawnItems = new List<Item>();
//characters who spawned during the last respawn
private readonly List<Character> respawnedCharacters = new List<Character>();
public bool UsingShuttle
{
get { return RespawnShuttle != null; }
@@ -277,11 +280,17 @@ namespace Barotrauma.Networking
hull.BallastFlora?.Kill();
}
Dictionary<Character, Vector2> characterPositions = new Dictionary<Character, Vector2>();
foreach (Character c in Character.CharacterList)
{
if (c.Submarine != RespawnShuttle) { continue; }
if (!respawnedCharacters.Contains(c))
{
characterPositions.Add(c, c.WorldPosition);
continue;
}
#if CLIENT
if (Character.Controlled == c) Character.Controlled = null;
if (Character.Controlled == c) { Character.Controlled = null; }
#endif
c.Kill(CauseOfDeathType.Unknown, null, true);
c.Enabled = false;
@@ -298,6 +307,11 @@ namespace Barotrauma.Networking
RespawnShuttle.SetPosition(new Vector2(Level.Loaded.StartPosition.X, Level.Loaded.Size.Y + RespawnShuttle.Borders.Height));
RespawnShuttle.Velocity = Vector2.Zero;
foreach (var characterPosition in characterPositions)
{
characterPosition.Key.TeleportTo(characterPosition.Value);
}
}
partial void RespawnCharactersProjSpecific(Vector2? shuttlePos);
@@ -507,7 +507,7 @@ namespace Barotrauma.Networking
}
[Serialize(800, true)]
private int LinesPerLogFile
public int LinesPerLogFile
{
get
{
@@ -892,8 +892,15 @@ namespace Barotrauma.Networking
get;
set;
}
// we do not serialize this value because it relies on a default setting
public int MaxMissionCount { get; set; } = CampaignSettings.DefaultMaxMissionCount;
private int maxMissionCount = CampaignSettings.DefaultMaxMissionCount;
[Serialize(CampaignSettings.DefaultMaxMissionCount, true)]
public int MaxMissionCount
{
get { return maxMissionCount; }
set { maxMissionCount = MathHelper.Clamp(value, CampaignSettings.MinMissionCountLimit, CampaignSettings.MaxMissionCountLimit); }
}
public void SetPassword(string password)
{