v0.13.0.11

This commit is contained in:
Joonas Rikkonen
2021-04-22 17:33:08 +03:00
parent 0697d7fc64
commit 8bb31f2893
391 changed files with 17271 additions and 5949 deletions
@@ -8,7 +8,18 @@ namespace Barotrauma.Networking
{
public enum ChatMessageType
{
Default, Error, Dead, Server, Radio, Private, Console, MessageBox, Order, ServerLog, ServerMessageBox, ServerMessageBoxInGame
Default = 0,
Error = 1,
Dead = 2,
Server = 3,
Radio = 4,
Private = 5,
Console = 6,
MessageBox = 7,
Order = 8,
ServerLog = 9,
ServerMessageBox = 10,
ServerMessageBoxInGame = 11
}
public enum PlayerConnectionChangeType { None = 0, Joined = 1, Kicked = 2, Disconnected = 3, Banned = 4 }
@@ -82,7 +93,7 @@ namespace Barotrauma.Networking
{
get
{
return string.IsNullOrWhiteSpace(SenderName) ? TranslatedText : SenderName + ": " + TranslatedText;
return string.IsNullOrWhiteSpace(SenderName) ? TranslatedText : NetworkMember.ClientLogName(SenderClient, SenderName) + ": " + TranslatedText;
}
}
@@ -13,6 +13,7 @@ namespace Barotrauma.Networking
public string Name; public UInt16 NameID;
public byte ID;
public UInt64 SteamID;
public UInt64 OwnerSteamID;
public string Language;
@@ -14,15 +14,6 @@ namespace Barotrauma.Networking
public static string MasterServerUrl = GameMain.Config.MasterServerUrl;
//if a Character is further than this from the sub and the players, the server will disable it
//(in display units)
public const float DisableCharacterDist = 22000.0f;
public const float DisableCharacterDistSqr = DisableCharacterDist * DisableCharacterDist;
//the character needs to get this close to be re-enabled
public const float EnableCharacterDist = 20000.0f;
public const float EnableCharacterDistSqr = EnableCharacterDist * EnableCharacterDist;
public const float MaxPhysicsBodyVelocity = 64.0f;
public const float MaxPhysicsBodyAngularVelocity = 16.0f;
@@ -18,7 +18,8 @@ namespace Barotrauma.Networking
Combine,
ExecuteAttack,
Upgrade,
AssignCampaignInteraction
AssignCampaignInteraction,
ObjectiveManagerOrderState,
}
public readonly Entity Entity;
@@ -30,7 +30,8 @@ namespace Barotrauma.Networking
ERROR, //tell the server that an error occurred
CREW,
READY_CHECK
READY_CHECK,
READY_TO_SPAWN
}
enum ClientNetObject
@@ -172,7 +173,7 @@ namespace Barotrauma.Networking
#endif
protected ServerSettings serverSettings;
protected TimeSpan updateInterval;
protected DateTime updateTimer;
@@ -236,9 +237,9 @@ namespace Barotrauma.Networking
return radioComponent.HasRequiredContainedItems(sender, addMessage: false);
}
public void AddChatMessage(string message, ChatMessageType type, string senderName = "", Character senderCharacter = null, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
public void AddChatMessage(string message, ChatMessageType type, string senderName = "", Client senderClient = null, Character senderCharacter = null, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
{
AddChatMessage(ChatMessage.Create(senderName, message, type, senderCharacter, changeType: changeType));
AddChatMessage(ChatMessage.Create(senderName, message, type, senderCharacter, senderClient, changeType: changeType));
}
public virtual void AddChatMessage(ChatMessage message)
@@ -251,6 +252,18 @@ namespace Barotrauma.Networking
}
}
public static string ClientLogName(Client client, string name = null)
{
if (client == null) { return name; }
string retVal = "‖";
if (client.Karma < 40.0f)
{
retVal += "color:#ff9900;";
}
retVal += "metadata:" + (client.SteamID != 0 ? client.SteamID.ToString() : client.ID.ToString()) + "‖" + (name ?? client.Name).Replace("‖", "") + "‖end‖";
return retVal;
}
public virtual void KickPlayer(string kickedName, string reason) { }
public virtual void BanPlayer(string kickedName, string reason, bool range = false, TimeSpan? duration = null) { }
@@ -1,4 +1,6 @@
namespace Barotrauma.Networking
using System;
namespace Barotrauma.Networking
{
partial class OrderChatMessage : ChatMessage
{
@@ -13,26 +15,87 @@
//additional instructions (power up, fire at will, etc)
public readonly string OrderOption;
public readonly int OrderPriority;
/// <summary>
/// Used when the order targets a wall
/// </summary>
public int? WallSectionIndex { get; set; }
public OrderChatMessage(Order order, string orderOption, ISpatialEntity targetEntity, Character targetCharacter, Character sender)
: this(order, orderOption,
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),
targetEntity, targetCharacter, sender)
{
}
public OrderChatMessage(Order order, string orderOption, string text, ISpatialEntity targetEntity, Character targetCharacter, Character sender)
public OrderChatMessage(Order order, string orderOption, int priority, string text, ISpatialEntity targetEntity, Character targetCharacter, Character sender)
: base(sender?.Name, text, ChatMessageType.Order, sender, GameMain.NetworkMember.ConnectedClients.Find(c => c.Character == sender))
{
Order = order;
OrderOption = orderOption;
OrderPriority = priority;
TargetCharacter = targetCharacter;
TargetEntity = targetEntity;
}
private void WriteOrder(IWriteMessage msg)
{
msg.Write((byte)Order.PrefabList.IndexOf(Order.Prefab));
msg.Write(TargetCharacter == null ? (UInt16)0 : TargetCharacter.ID);
msg.Write(TargetEntity is Entity ? (TargetEntity as Entity).ID : (UInt16)0);
// The option of a Dismiss order is written differently so we know what order we target
// now that the game supports multiple current orders simultaneously
if (Order.Prefab.Identifier != "dismissed")
{
msg.Write((byte)Array.IndexOf(Order.Prefab.Options, OrderOption));
}
else
{
if (!string.IsNullOrEmpty(OrderOption))
{
msg.Write(true);
string[] dismissedOrder = OrderOption.Split('.');
msg.Write((byte)dismissedOrder.Length);
if (dismissedOrder.Length > 0)
{
string dismissedOrderIdentifier = dismissedOrder[0];
var orderPrefab = Order.GetPrefab(dismissedOrderIdentifier);
msg.Write((byte)Order.PrefabList.IndexOf(orderPrefab));
if (dismissedOrder.Length > 1)
{
string dismissedOrderOption = dismissedOrder[1];
msg.Write((byte)Array.IndexOf(orderPrefab.Options, dismissedOrderOption));
}
}
}
else
{
// If the order option is not specified for a Dismiss order,
// we dismiss all current orders for the character
msg.Write(false);
}
}
msg.Write((byte)OrderPriority);
msg.Write((byte)Order.TargetType);
if (Order.TargetType == Order.OrderTargetType.Position && TargetEntity is OrderTarget orderTarget)
{
msg.Write(true);
msg.Write(orderTarget.Position.X);
msg.Write(orderTarget.Position.Y);
msg.Write(orderTarget.Hull == null ? (UInt16)0 : orderTarget.Hull.ID);
}
else
{
msg.Write(false);
if (Order.TargetType == Order.OrderTargetType.WallSection)
{
msg.Write((byte)(WallSectionIndex ?? Order.WallSectionIndex ?? 0));
}
}
}
}
}
@@ -136,8 +136,7 @@ namespace Barotrauma.Networking
EnsureBufferSize(ref buf, bitPos + 64);
byte[] bytes = BitConverter.GetBytes(val);
WriteBytes(ref buf, ref bitPos, bytes, 0, bytes.Length);
bitPos += 64;
WriteBytes(ref buf, ref bitPos, bytes, 0, 8);
}
internal static void Write(ref byte[] buf, ref int bitPos, string val)
{
@@ -155,14 +154,14 @@ namespace Barotrauma.Networking
internal static int WriteVariableUInt32(ref byte[] buf, ref int bitPos, uint value)
{
int retval = 1;
uint num1 = (uint)value;
while (num1 >= 0x80)
uint remainingValue = (uint)value;
while (remainingValue >= 0x80)
{
Write(ref buf, ref bitPos, (byte)(num1 | 0x80));
num1 = num1 >> 7;
Write(ref buf, ref bitPos, (byte)(remainingValue | 0x80));
remainingValue = remainingValue >> 7;
retval++;
}
Write(ref buf, ref bitPos, (byte)num1);
Write(ref buf, ref bitPos, (byte)remainingValue);
return retval;
}
@@ -304,19 +303,19 @@ namespace Barotrauma.Networking
{
int bitLength = buf.Length * 8;
int num1 = 0;
int num2 = 0;
int result = 0;
int shift = 0;
while (bitLength - bitPos >= 8)
{
byte num3 = ReadByte(buf, ref bitPos);
num1 |= (num3 & 0x7f) << num2;
num2 += 7;
if ((num3 & 0x80) == 0)
return (uint)num1;
byte chunk = ReadByte(buf, ref bitPos);
result |= (chunk & 0x7f) << shift;
shift += 7;
if ((chunk & 0x80) == 0)
return (uint)result;
}
// ouch; failed to find enough bytes; malformed variable length number?
return (uint)num1;
return (uint)result;
}
internal static String ReadString(byte[] buf, ref int bitPos)
@@ -329,7 +328,7 @@ namespace Barotrauma.Networking
if ((ulong)(bitLength - bitPos) < ((ulong)byteLen * 8))
{
// not enough data
return null;
return null;
}
if ((bitPos & 7) == 0)
@@ -21,6 +21,12 @@ namespace Barotrauma.Networking
protected set;
}
public UInt64 OwnerSteamID
{
get;
protected set;
}
public string EndPointString
{
get;
@@ -44,5 +50,15 @@ namespace Barotrauma.Networking
//is received by the server.
return false;
}
public bool SetOwnerSteamIDIfUnknown(UInt64 id)
{
//we know that for both Lidgren and SteamP2P, the
//owner id isn't known until the auth ticket is
//processed, so this method is the same for both
if (OwnerSteamID != 0) { return false; }
OwnerSteamID = id;
return true;
}
}
}
@@ -10,6 +10,7 @@ namespace Barotrauma.Networking
public SteamP2PConnection(string name, UInt64 steamId)
{
SteamID = steamId;
OwnerSteamID = 0;
EndPointString = SteamManager.SteamIDUInt64ToString(SteamID);
Name = name;
Heartbeat();
@@ -24,7 +24,7 @@ namespace Barotrauma.Networking
//items created during respawn
//any respawn items left in the shuttle are removed when the shuttle despawns
private List<Item> respawnItems = new List<Item>();
private readonly List<Item> respawnItems = new List<Item>();
public bool UsingShuttle
{
@@ -55,6 +55,14 @@ namespace Barotrauma.Networking
public State CurrentState { get; private set; }
public bool UseRespawnPrompt
{
get
{
return GameMain.GameSession?.GameMode is CampaignMode && Level.Loaded != null && Level.Loaded?.Type != LevelData.LevelType.Outpost;
}
}
private float maxTransportTime;
private float updateReturnTimer;
@@ -70,6 +78,8 @@ namespace Barotrauma.Networking
{
RespawnShuttle = new Submarine(shuttleInfo, true);
RespawnShuttle.PhysicsBody.FarseerBody.OnCollision += OnShuttleCollision;
//set crush depth slightly deeper than the main sub's
RespawnShuttle.RealWorldCrushDepth = Math.Max(RespawnShuttle.RealWorldCrushDepth, Submarine.MainSub.RealWorldCrushDepth * 1.2f);
//prevent wifi components from communicating between the respawn shuttle and other subs
List<WifiComponent> wifiComponents = new List<WifiComponent>();
@@ -293,10 +303,10 @@ namespace Barotrauma.Networking
RespawnShuttle.Velocity = Vector2.Zero;
}
partial void RespawnCharactersProjSpecific();
public void RespawnCharacters()
partial void RespawnCharactersProjSpecific(Vector2? shuttlePos);
public void RespawnCharacters(Vector2? shuttlePos)
{
RespawnCharactersProjSpecific();
RespawnCharactersProjSpecific(shuttlePos);
}
public Vector2 FindSpawnPos()
@@ -628,6 +628,13 @@ namespace Barotrauma.Networking
set;
}
[Serialize(false, true)]
public bool LockAllDefaultWires
{
get;
set;
}
[Serialize(true, true)]
public bool AllowFriendlyFire
{
@@ -872,6 +879,13 @@ namespace Barotrauma.Networking
private set;
}
[Serialize(true, true)]
public bool RadiationEnabled
{
get;
set;
}
public void SetPassword(string password)
{
if (string.IsNullOrEmpty(password))
@@ -139,7 +139,21 @@ namespace Barotrauma.Steam
}
return success;
}
public static bool StoreStats()
{
if (!isInitialized || !Steamworks.SteamClient.IsValid) { return false; }
DebugConsole.Log("Storing Steam stats...");
bool success = Steamworks.SteamUserStats.StoreStats();
if (!success)
{
#if DEBUG
DebugConsole.NewMessage("Failed to store Steam stats.");
#endif
}
return success;
}
public static void Update(float deltaTime)
{
if (!isInitialized) { return; }
@@ -6,8 +6,8 @@ namespace Barotrauma.Networking
{
static partial class VoipConfig
{
public const int MAX_COMPRESSED_SIZE = 120; //amount of bytes we expect each 60ms of audio to fit in
public const int MAX_COMPRESSED_SIZE = 40; //amount of bytes we expect each 20ms of audio to fit in
public static readonly TimeSpan SEND_INTERVAL = new TimeSpan(0,0,0,0,120);
public static readonly TimeSpan SEND_INTERVAL = new TimeSpan(0,0,0,0,20);
}
}