Clients and server limit the number of chat messages included in a message if their byte size exceeds the MTU

This commit is contained in:
Joonas Rikkonen
2017-06-05 19:27:51 +03:00
parent acad7980f2
commit 46957684f3
3 changed files with 63 additions and 21 deletions
@@ -196,6 +196,34 @@ namespace Barotrauma.Networking
GameMain.Server.SendChatMessage(txt, null, c);
}
public int EstimateLengthBytesClient()
{
int length = 1 + //(byte)ServerNetObject.CHAT_MESSAGE
2 + //(UInt16)NetStateID
Encoding.UTF8.GetBytes(Text).Length + 2;
return length;
}
public int EstimateLengthBytesServer(Client c)
{
int length = 1 + //(byte)ServerNetObject.CHAT_MESSAGE
2 + //(UInt16)NetStateID
1 + //(byte)Type
Encoding.UTF8.GetBytes(Text).Length + 2;
if (Sender != null && c.inGame)
{
length += 2; //sender ID (UInt16)
}
else if (SenderName != null)
{
length += Encoding.UTF8.GetBytes(SenderName).Length + 2;
}
return length;
}
public void ServerWrite(NetOutgoingMessage msg, Client c)
{
msg.Write((byte)ServerNetObject.CHAT_MESSAGE);