Skip to content

Commit

Permalink
Fixed message fragmentation issues caused by initial lobby syncing. T…
Browse files Browse the repository at this point in the history
…he size of the initial message exceeds MTU if the host has a large number of subs, and apparently Lidgren doesn't attempt to handle fragmenting by default when sending the messages with the unreliable delivery method. Now the initial syncing message is sent only once with the reliable delivery method which should be able to handle fragmented messages.
  • Loading branch information
Regalis11 committed Jun 4, 2017
1 parent 55cb56d commit 72ecba8
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Barotrauma/Source/Networking/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ private void ClientWriteIngame(Client c)

private void ClientWriteLobby(Client c)
{
bool isInitialUpdate = false;

NetOutgoingMessage outmsg = server.CreateMessage();
outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);

Expand All @@ -939,6 +941,7 @@ private void ClientWriteLobby(Client c)
outmsg.Write(c.lastRecvGeneralUpdate < 1);
if (c.lastRecvGeneralUpdate < 1)
{
isInitialUpdate = true;
ClientWriteInitial(c, outmsg);
}
outmsg.Write((GameMain.NetLobbyScreen.SubList.SelectedData as Submarine).Name);
Expand Down Expand Up @@ -987,12 +990,27 @@ private void ClientWriteLobby(Client c)

outmsg.Write((byte)ServerNetObject.END_OF_MESSAGE);

if (outmsg.LengthBytes > config.MaximumTransmissionUnit)
if (isInitialUpdate)
{
DebugConsole.ThrowError("Maximum packet size exceeded (" + outmsg.LengthBytes + " > " + config.MaximumTransmissionUnit + ")");
//the initial update may be very large if the host has a large number
//of submarine files, so the message may have to be fragmented

//unreliable messages don't play nicely with fragmenting, so we'll send the message reliably
server.SendMessage(outmsg, c.Connection, NetDeliveryMethod.ReliableUnordered);

//and assume the message was received, so we don't have to keep resending
//these large initial messages until the client acknowledges receiving them
c.lastRecvGeneralUpdate++;
}
else
{
if (outmsg.LengthBytes > config.MaximumTransmissionUnit)
{
DebugConsole.ThrowError("Maximum packet size exceeded (" + outmsg.LengthBytes + " > " + config.MaximumTransmissionUnit + ")");
}

server.SendMessage(outmsg, c.Connection, NetDeliveryMethod.Unreliable);
server.SendMessage(outmsg, c.Connection, NetDeliveryMethod.Unreliable);
}
}

public bool StartGameClicked(GUIButton button, object obj)
Expand Down

0 comments on commit 72ecba8

Please sign in to comment.