Merge branch 'master' of https://github.com/Regalis11/Barotrauma into develop
This commit is contained in:
@@ -785,6 +785,7 @@ namespace Barotrauma
|
||||
AssignRelayToServer("simulatedduplicateschance", false);
|
||||
AssignRelayToServer("simulatedlongloadingtime", false);
|
||||
AssignRelayToServer("storeinfo", false);
|
||||
AssignRelayToServer("sendrawpacket", false);
|
||||
#endif
|
||||
|
||||
commands.Add(new Command("clientlist", "", (string[] args) => { }));
|
||||
@@ -3273,6 +3274,36 @@ namespace Barotrauma
|
||||
LocationType.Prefabs.Select(lt => lt.Identifier.Value).ToArray()
|
||||
};
|
||||
}));
|
||||
|
||||
commands.Add(new Command("sendrawpacket", "sendrawpacket [data]: Send a string of hex values as raw binary data to the server", (string[] args) =>
|
||||
{
|
||||
if (GameMain.NetworkMember is null)
|
||||
{
|
||||
ThrowError("Not connected to a server");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
ThrowError("No data provided");
|
||||
return;
|
||||
}
|
||||
|
||||
string dataString = string.Join(" ", args);
|
||||
|
||||
try
|
||||
{
|
||||
byte[] bytes = ToolBox.HexStringToBytes(dataString);
|
||||
IWriteMessage msg = new WriteOnlyMessage();
|
||||
foreach (byte b in bytes) { msg.WriteByte(b); }
|
||||
GameMain.Client?.ClientPeer?.DebugSendRawMessage(msg);
|
||||
NewMessage($"Sent {bytes.Length} byte(s)", Color.Green);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ThrowError("Failed to parse the data", e);
|
||||
}
|
||||
}));
|
||||
#endif
|
||||
|
||||
commands.Add(new Command("limbscale", "Define the limbscale for the controlled character. Provide id or name if you want to target another character. Note: the changes are not saved!", (string[] args) =>
|
||||
|
||||
@@ -231,6 +231,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
#if DEBUG
|
||||
public abstract void ForceTimeOut();
|
||||
|
||||
public abstract void DebugSendRawMessage(IWriteMessage msg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+3
@@ -287,6 +287,9 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
netClient?.ServerConnection?.ForceTimeOut();
|
||||
}
|
||||
|
||||
public override void DebugSendRawMessage(IWriteMessage msg)
|
||||
=> ForwardToLidgren(msg, DeliveryMethod.Reliable);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -423,6 +423,9 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
timeout = 0.0f;
|
||||
}
|
||||
|
||||
public override void DebugSendRawMessage(IWriteMessage msg)
|
||||
=> ForwardToRemotePeer(msg, DeliveryMethod.Reliable);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+18
-8
@@ -142,8 +142,12 @@ namespace Barotrauma.Networking
|
||||
if (remotePeer is null) { return; }
|
||||
if (remotePeer.PendingDisconnect.IsSome()) { return; }
|
||||
|
||||
var peerPacketHeaders = INetSerializableStruct.Read<PeerPacketHeaders>(inc);
|
||||
|
||||
if (!INetSerializableStruct.TryRead(inc, remotePeer.AccountInfo, out PeerPacketHeaders peerPacketHeaders))
|
||||
{
|
||||
CommunicateDisconnectToRemotePeer(remotePeer, PeerDisconnectPacket.WithReason(DisconnectReason.MalformedData));
|
||||
return;
|
||||
}
|
||||
|
||||
PacketHeader packetHeader = peerPacketHeaders.PacketHeader;
|
||||
|
||||
if (packetHeader.IsConnectionInitializationStep())
|
||||
@@ -178,13 +182,11 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
remotePeer.AuthStatus = RemotePeer.AuthenticationStatus.AuthenticationPending;
|
||||
|
||||
var packet = INetSerializableStruct.Read<ClientAuthTicketAndVersionPacket>(inc);
|
||||
|
||||
void failAuth()
|
||||
if (!INetSerializableStruct.TryRead(inc, remotePeer.AccountInfo, out ClientAuthTicketAndVersionPacket packet))
|
||||
{
|
||||
CommunicateDisconnectToRemotePeer(remotePeer, PeerDisconnectPacket.WithReason(DisconnectReason.AuthenticationFailed));
|
||||
failAuth();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!packet.AuthTicket.TryUnwrap(out var authenticationTicket))
|
||||
{
|
||||
failAuth();
|
||||
@@ -221,6 +223,11 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
remotePeer.UnauthedMessages.Clear();
|
||||
});
|
||||
|
||||
void failAuth()
|
||||
{
|
||||
CommunicateDisconnectToRemotePeer(remotePeer, PeerDisconnectPacket.WithReason(DisconnectReason.AuthenticationFailed));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime)
|
||||
@@ -381,7 +388,7 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
OnInitializationComplete();
|
||||
|
||||
PeerPacketMessage packet = INetSerializableStruct.Read<PeerPacketMessage>(inc);
|
||||
var packet = INetSerializableStruct.Read<PeerPacketMessage>(inc);
|
||||
IReadMessage msg = new ReadOnlyMessage(packet.Buffer, packetHeader.IsCompressed(), 0, packet.Length, ServerConnection);
|
||||
callbacks.OnMessageReceived.Invoke(msg);
|
||||
}
|
||||
@@ -552,6 +559,9 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
//TODO: reimplement?
|
||||
}
|
||||
|
||||
public override void DebugSendRawMessage(IWriteMessage msg)
|
||||
=> ForwardToServerProcess(msg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -520,5 +520,32 @@ namespace Barotrauma
|
||||
|
||||
static string ColorString(string text, Color color) => $"‖color:{color.ToStringHex()}‖{text}‖end‖";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string of hex values to a byte array.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// 04 03 4b 50 -> { 4, 3, 75, 80 }
|
||||
/// </example>
|
||||
/// <param name="raw"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] HexStringToBytes(string raw)
|
||||
{
|
||||
string value = string.Join(string.Empty, raw.Split(" "));
|
||||
List<byte> bytes = new List<byte>();
|
||||
for (int i = 0; i < value.Length; i += 2)
|
||||
{
|
||||
string hex = value.Substring(i, 2);
|
||||
byte b = Convert.ToByte(hex, 16);
|
||||
bytes.Add(b);
|
||||
|
||||
static bool IsHexChar(char c) => c is
|
||||
>= '0' and <= '9' or
|
||||
>= 'A' and <= 'F' or
|
||||
>= 'a' and <= 'f';
|
||||
}
|
||||
|
||||
return bytes.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user