Merge branch 'master' of https://github.com/Regalis11/Barotrauma into develop
This commit is contained in:
+10
-1
@@ -236,7 +236,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
else if (!packetHeader.IsConnectionInitializationStep())
|
||||
{
|
||||
if (connectedClients.Find(c => c.Connection.NetConnection == lidgrenMsg.SenderConnection) is not { Connection: LidgrenConnection conn })
|
||||
if (FindConnection(lidgrenMsg.SenderConnection) is not { } conn)
|
||||
{
|
||||
if (pendingClient != null)
|
||||
{
|
||||
@@ -264,6 +264,15 @@ namespace Barotrauma.Networking
|
||||
var packet = INetSerializableStruct.Read<PeerPacketMessage>(inc);
|
||||
callbacks.OnMessageReceived.Invoke(conn, packet.GetReadMessage(packetHeader.IsCompressed(), conn));
|
||||
}
|
||||
|
||||
LidgrenConnection? FindConnection(NetConnection ligdrenConn)
|
||||
{
|
||||
if (connectedClients.Find(c => c.Connection.NetConnection == ligdrenConn) is { Connection: LidgrenConnection conn })
|
||||
{
|
||||
return conn;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleStatusChanged(NetIncomingMessage inc)
|
||||
|
||||
+3
-6
@@ -105,11 +105,7 @@ namespace Barotrauma.Networking
|
||||
if (!started) { return; }
|
||||
|
||||
var senderInfo = INetSerializableStruct.Read<P2POwnerToServerHeader>(inc);
|
||||
if (!senderInfo.Endpoint.TryUnwrap(out var senderEndpoint))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!senderInfo.Endpoint.TryUnwrap(out var senderEndpoint)) { return; }
|
||||
var (_, packetHeader, initialization) = INetSerializableStruct.Read<PeerPacketHeaders>(inc);
|
||||
|
||||
if (packetHeader.IsServerMessage())
|
||||
@@ -179,7 +175,8 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
if (packetHeader.IsDataFragment())
|
||||
{
|
||||
var completeMessageOption = connectedClient.Defragmenter.ProcessIncomingFragment(INetSerializableStruct.Read<MessageFragment>(inc));
|
||||
var fragment = INetSerializableStruct.Read<MessageFragment>(inc);
|
||||
var completeMessageOption = connectedClient.Defragmenter.ProcessIncomingFragment(fragment);
|
||||
if (!completeMessageOption.TryUnwrap(out var completeMessage)) { return; }
|
||||
|
||||
IReadMessage msg = new ReadOnlyMessage(completeMessage.ToArray(), false, 0, completeMessage.Length, connectedClient.Connection);
|
||||
|
||||
+25
-2
@@ -97,7 +97,11 @@ namespace Barotrauma.Networking
|
||||
switch (initializationStep)
|
||||
{
|
||||
case ConnectionInitialization.AuthInfoAndVersion:
|
||||
var authPacket = INetSerializableStruct.Read<ClientAuthTicketAndVersionPacket>(inc);
|
||||
if (!INetSerializableStruct.TryRead(inc, pendingClient.AccountInfo, out ClientAuthTicketAndVersionPacket authPacket))
|
||||
{
|
||||
RemovePendingClient(pendingClient, PeerDisconnectPacket.WithReason(DisconnectReason.MalformedData));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Client.IsValidName(authPacket.Name, serverSettings))
|
||||
{
|
||||
@@ -134,7 +138,11 @@ namespace Barotrauma.Networking
|
||||
|
||||
break;
|
||||
case ConnectionInitialization.Password:
|
||||
var passwordPacket = INetSerializableStruct.Read<ClientPeerPasswordPacket>(inc);
|
||||
if (!INetSerializableStruct.TryRead(inc, pendingClient.AccountInfo, out ClientPeerPasswordPacket passwordPacket))
|
||||
{
|
||||
RemovePendingClient(pendingClient, PeerDisconnectPacket.WithReason(DisconnectReason.MalformedData));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pendingClient.PasswordSalt is null)
|
||||
{
|
||||
@@ -340,5 +348,20 @@ namespace Barotrauma.Networking
|
||||
|
||||
public abstract void Send(IWriteMessage msg, NetworkConnection conn, DeliveryMethod deliveryMethod, bool compressPastThreshold = true);
|
||||
public abstract void Disconnect(NetworkConnection conn, PeerDisconnectPacket peerDisconnectPacket);
|
||||
|
||||
private void LogMalformedMessage(NetworkConnection conn)
|
||||
{
|
||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||
{
|
||||
if (c.Connection == conn)
|
||||
{
|
||||
DebugConsole.ThrowError($"Received malformed message from {c.Name}.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
DebugConsole.ThrowError("Received malformed message from remote peer.");
|
||||
}
|
||||
protected static void LogMalformedMessage()
|
||||
=> DebugConsole.ThrowError("Received malformed message from remote peer.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user