Unstable 0.17.1.0

This commit is contained in:
Markus Isberg
2022-03-17 01:25:04 +09:00
parent 3974067915
commit 6d410cc1b7
302 changed files with 5878 additions and 3317 deletions
@@ -115,7 +115,7 @@ namespace Barotrauma.Networking
}
else
{
orderMessageInfo.TargetCharacter?.SetOrder(order);
orderMessageInfo.TargetCharacter?.SetOrder(order, orderMessageInfo.IsNewOrder);
}
}
}
@@ -125,7 +125,8 @@ namespace Barotrauma.Networking
Order order = null;
if (orderMessageInfo.TargetPosition != null)
{
order = new Order(orderPrefab, orderOption, orderMessageInfo.Priority, Order.OrderType.Current, null, orderMessageInfo.TargetPosition, orderGiver: senderCharacter);
order = new Order(orderPrefab, orderOption, orderMessageInfo.TargetPosition, orderGiver: senderCharacter)
.WithManualPriority(orderMessageInfo.Priority);
}
else if (orderMessageInfo.WallSectionIndex != null)
{
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO.Pipes;
using System.Linq;
namespace Barotrauma.Networking
{
@@ -12,6 +13,9 @@ namespace Barotrauma.Networking
public static void Start(ProcessStartInfo processInfo)
{
CrashString = null;
CrashReportFilePath = null;
writePipe = new AnonymousPipeServerStream(PipeDirection.Out, System.IO.HandleInheritability.Inheritable);
readPipe = new AnonymousPipeServerStream(PipeDirection.In, System.IO.HandleInheritability.Inheritable);
@@ -42,8 +46,8 @@ namespace Barotrauma.Networking
public static void ClosePipes()
{
writePipe?.Close();
readPipe?.Close();
writePipe?.Dispose(); writePipe = null;
readPipe?.Dispose(); readPipe = null;
shutDown = true;
}
@@ -54,5 +58,20 @@ namespace Barotrauma.Networking
PrivateShutDown();
}
public static string CrashString { get; private set; }
public static string CrashReportFilePath { get; private set; }
public static LocalizedString CrashMessage
=> string.IsNullOrEmpty(CrashReportFilePath)
? TextManager.Get("ServerProcessClosed")
: TextManager.GetWithVariable("ServerProcessCrashed", "[reportfilepath]", CrashReportFilePath);
static partial void HandleCrashString(string str)
{
DebugConsole.ThrowError($"The server has crashed: {str}");
CrashReportFilePath = str.Split("||").FirstOrDefault() ?? "servercrashreport.log";
CrashString = str;
}
}
}
@@ -5,7 +5,7 @@ namespace Barotrauma
{
partial class EntitySpawner : Entity, IServerSerializable
{
public void ClientRead(ServerNetObject type, IReadMessage message, float sendingTime)
public void ClientEventRead(IReadMessage message, float sendingTime)
{
bool remove = message.ReadBoolean();
@@ -666,7 +666,7 @@ namespace Barotrauma.Networking
if (ChildServerRelay.Process?.HasExited ?? true)
{
Disconnect();
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), TextManager.Get("ServerProcessClosed"));
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
msgBox.Buttons[0].OnClicked += ReturnToPreviousMenu;
}
}
@@ -937,6 +937,9 @@ namespace Barotrauma.Networking
case ServerPacketHeader.MEDICAL:
campaign?.MedicalClinic?.ClientRead(inc);
break;
case ServerPacketHeader.MONEY:
campaign?.ClientReadMoney(inc);
break;
case ServerPacketHeader.READY_CHECK:
ReadyCheck.ClientRead(inc);
break;
@@ -1203,7 +1206,7 @@ namespace Barotrauma.Networking
if (disconnectReason == DisconnectReason.ServerCrashed && IsServerOwner)
{
msg = TextManager.Get("ServerProcessCrashed");
msg = TextManager.GetWithVariable("ServerProcessCrashed", "[reportfilepath]", ChildServerRelay.CrashReportFilePath);
}
}
@@ -2240,10 +2243,11 @@ namespace Barotrauma.Networking
}
}
readonly List<IServerSerializable> debugEntityList = new List<IServerSerializable>();
private void ReadIngameUpdate(IReadMessage inc)
{
List<IServerSerializable> entities = new List<IServerSerializable>();
debugEntityList.Clear();
float sendingTime = inc.ReadSingle() - 0.0f;//TODO: reimplement inc.SenderConnection.RemoteTimeOffset;
ServerNetObject? prevObjHeader = null;
@@ -2284,15 +2288,15 @@ namespace Barotrauma.Networking
uint msgLength = inc.ReadVariableUInt32();
int msgEndPos = (int)(inc.BitPosition + msgLength * 8);
var entity = Entity.FindEntityByID(id) as IServerSerializable;
var entity = Entity.FindEntityByID(id) as IServerPositionSync;
if (msgEndPos > inc.LengthBits)
{
DebugConsole.ThrowError($"Error while reading a position update for the entity \"({entity?.ToString() ?? "null"})\". Message length exceeds the size of the buffer.");
return;
}
entities.Add(entity);
if (entity != null && (entity is Item || entity is Character || entity is Submarine))
debugEntityList.Add(entity);
if (entity != null)
{
if (entity is Item != isItem)
{
@@ -2307,7 +2311,7 @@ namespace Barotrauma.Networking
}
else
{
entity.ClientRead(objHeader.Value, inc, sendingTime);
entity.ClientReadPosition(inc, sendingTime);
}
}
@@ -2321,7 +2325,7 @@ namespace Barotrauma.Networking
break;
case ServerNetObject.ENTITY_EVENT:
case ServerNetObject.ENTITY_EVENT_INITIAL:
if (!entityEventManager.Read(objHeader.Value, inc, sendingTime, entities))
if (!entityEventManager.Read(objHeader.Value, inc, sendingTime, debugEntityList))
{
return;
}
@@ -2340,7 +2344,6 @@ namespace Barotrauma.Networking
prevBytePos = inc.BytePosition;
}
}
catch (Exception ex)
{
List<string> errorLines = new List<string>
@@ -2359,7 +2362,7 @@ namespace Barotrauma.Networking
objHeader == ServerNetObject.ENTITY_EVENT || objHeader == ServerNetObject.ENTITY_EVENT_INITIAL ||
objHeader == ServerNetObject.ENTITY_POSITION || prevObjHeader == ServerNetObject.ENTITY_POSITION)
{
foreach (IServerSerializable ent in entities)
foreach (IServerSerializable ent in debugEntityList)
{
if (ent == null)
{
@@ -2480,7 +2483,7 @@ namespace Barotrauma.Networking
outmsg.Write(GameMain.NetLobbyScreen.CampaignCharacterDiscarded);
}
Character.Controlled?.ClientWrite(outmsg);
Character.Controlled?.ClientWriteInput(outmsg);
GameMain.GameScreen.Cam?.ClientWrite(outmsg);
entityEventManager.Write(outmsg, clientPeer?.ServerConnection);
@@ -2711,7 +2714,7 @@ namespace Barotrauma.Networking
}
}
public override void CreateEntityEvent(INetSerializable entity, object[] extraData)
public override void CreateEntityEvent(INetSerializable entity, NetEntityEvent.IData extraData = null)
{
if (!(entity is IClientSerializable clientSerializable))
{
@@ -2770,7 +2773,7 @@ namespace Barotrauma.Networking
if (ChildServerRelay.Process != null)
{
int checks = 0;
while (ChildServerRelay.Process != null && !ChildServerRelay.Process.HasExited)
while (ChildServerRelay.Process is { HasExited: false })
{
if (checks > 10)
{
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
namespace Barotrauma.Networking
{
@@ -41,16 +42,16 @@ namespace Barotrauma.Networking
thisClient = client;
}
public void CreateEvent(IClientSerializable entity, object[] extraData = null)
public void CreateEvent(IClientSerializable entity, NetEntityEvent.IData extraData = null)
{
if (GameMain.Client?.Character == null) { return; }
if (!ValidateEntity(entity)) { return; }
var newEvent = new ClientEntityEvent(entity, (UInt16)(ID + 1))
{
CharacterStateID = GameMain.Client.Character.LastNetworkUpdateID
};
var newEvent = new ClientEntityEvent(
entity,
eventId: (UInt16)(ID + 1),
characterStateId: GameMain.Client.Character.LastNetworkUpdateID);
if (extraData != null) { newEvent.SetData(extraData); }
for (int i = events.Count - 1; i >= 0; i--)
@@ -144,6 +145,7 @@ namespace Barotrauma.Networking
entities.Clear();
msg.ReadPadBits();
UInt16 firstEventID = msg.ReadUInt16();
int eventCount = msg.ReadByte();
@@ -172,7 +174,6 @@ namespace Barotrauma.Networking
DebugConsole.NewMessage("received msg " + thisEventID + " (null entity)",
Microsoft.Xna.Framework.Color.Orange);
}
msg.ReadPadBits();
entities.Add(null);
if (thisEventID == (UInt16)(lastReceivedID + 1)) { lastReceivedID++; }
continue;
@@ -207,7 +208,6 @@ namespace Barotrauma.Networking
}
msg.BitPosition += msgLength * 8;
msg.ReadPadBits();
}
else
{
@@ -239,22 +239,22 @@ namespace Barotrauma.Networking
//msg.BitPosition = (int)(msgPosition + msgLength * 8);
}
}
catch (Exception e)
{
string errorMsg = "Failed to read event for entity \"" + entity.ToString() + "\" (" + e.Message + ")! (MidRoundSyncing: " + thisClient.MidRoundSyncing + ")\n" + e.StackTrace.CleanupStackTrace();
string errorMsg = $"Failed to read event {thisEventID} for entity \"{entity}\"" +
$"{(entity is Entity { ID: var entityId } ? $", id {entityId}" : "")} ";
DebugConsole.ThrowError(errorMsg, e);
errorMsg += $"({e.Message})! (MidRoundSyncing: {thisClient.MidRoundSyncing})\n{e.StackTrace.CleanupStackTrace()}";
errorMsg += "\nPrevious entities:";
for (int j = entities.Count - 2; j >= 0; j--)
{
errorMsg += "\n" + (entities[j] == null ? "NULL" : entities[j].ToString());
}
DebugConsole.ThrowError("Failed to read event for entity \"" + entity.ToString() + "\"!", e);
GameAnalyticsManager.AddErrorEventOnce("ClientEntityEventManager.Read:ReadFailed" + entity.ToString(),
GameAnalyticsManager.ErrorSeverity.Error, errorMsg);
msg.BitPosition = (int)(msgPosition + msgLength * 8);
msg.ReadPadBits();
}
}
}
@@ -272,7 +272,7 @@ namespace Barotrauma.Networking
protected void ReadEvent(IReadMessage buffer, IServerSerializable entity, float sendingTime)
{
entity.ClientRead(ServerNetObject.ENTITY_EVENT, buffer, sendingTime);
entity.ClientEventRead(buffer, sendingTime);
}
public void Clear()
@@ -4,20 +4,21 @@ namespace Barotrauma.Networking
{
class ClientEntityEvent : NetEntityEvent
{
private IClientSerializable serializable;
private readonly IClientSerializable serializable;
public UInt16 CharacterStateID;
public readonly UInt16 CharacterStateID;
public ClientEntityEvent(IClientSerializable entity, UInt16 id)
: base(entity, id)
public ClientEntityEvent(IClientSerializable entity, UInt16 eventId, UInt16 characterStateId)
: base(entity, eventId)
{
serializable = entity;
CharacterStateID = characterStateId;
}
public void Write(IWriteMessage msg)
{
msg.Write(CharacterStateID);
serializable.ClientWrite(msg, Data);
serializable.ClientEventWrite(msg, Data);
}
}
}
@@ -84,7 +84,7 @@ namespace Barotrauma.Networking
if (ownerKey != 0 && (ChildServerRelay.Process?.HasExited ?? true))
{
Close();
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), TextManager.Get("ServerProcessClosed"));
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
msgBox.Buttons[0].OnClicked += (btn, obj) => { GameMain.MainMenuScreen.Select(); return false; };
return;
}
@@ -193,7 +193,7 @@ namespace Barotrauma.Networking
if (ChildServerRelay.HasShutDown || (ChildServerRelay.Process?.HasExited ?? true))
{
Close();
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), TextManager.Get("ServerProcessClosed"));
var msgBox = new GUIMessageBox(TextManager.Get("ConnectionLost"), ChildServerRelay.CrashMessage);
msgBox.Buttons[0].OnClicked += (btn, obj) => { GameMain.MainMenuScreen.Select(); return false; };
return;
}
@@ -71,7 +71,7 @@ namespace Barotrauma.Networking
}, delay: delay);
}
public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
public void ClientEventRead(IReadMessage msg, float sendingTime)
{
bool respawnPromptPending = false;
var newState = (State)msg.ReadRangedInteger(0, Enum.GetNames(typeof(State)).Length);