Server limits chatmessage length and the number of chatmessages written in one packet
This commit is contained in:
@@ -735,6 +735,24 @@ namespace Barotrauma
|
||||
GameMain.Server.CreateEntityEvent(wall);
|
||||
}
|
||||
break;
|
||||
case "spamchatmessages":
|
||||
int msgCount = 1000;
|
||||
if (commands.Length > 1) int.TryParse(commands[1], out msgCount);
|
||||
int msgLength = 50;
|
||||
if (commands.Length > 2) int.TryParse(commands[2], out msgLength);
|
||||
|
||||
for (int i = 0; i < msgCount; i++)
|
||||
{
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
GameMain.Server.SendChatMessage(ToolBox.RandomSeed(msgLength), ChatMessageType.Default);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameMain.Client.SendChatMessage(ToolBox.RandomSeed(msgLength));
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case "cleanbuild":
|
||||
GameMain.Config.MusicVolume = 0.5f;
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Barotrauma
|
||||
|
||||
public bool CaretEnabled;
|
||||
|
||||
private int? maxTextWidth;
|
||||
private int? maxTextLength;
|
||||
|
||||
public GUITextBlock.TextGetterHandler TextGetter
|
||||
{
|
||||
@@ -42,14 +42,13 @@ namespace Barotrauma
|
||||
set { textBlock.Wrap = value; }
|
||||
}
|
||||
|
||||
public int? MaxTextWidth
|
||||
public int? MaxTextLength
|
||||
{
|
||||
get { return maxTextWidth; }
|
||||
get { return maxTextLength; }
|
||||
set
|
||||
{
|
||||
textBlock.OverflowClip = value != null && (int)value > textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z;
|
||||
|
||||
maxTextWidth = value;
|
||||
textBlock.OverflowClip = true;
|
||||
maxTextLength = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,9 +141,14 @@ namespace Barotrauma
|
||||
{
|
||||
if (!Wrap)
|
||||
{
|
||||
int maxWidth = MaxTextWidth == null ? (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z) : (int)MaxTextWidth;
|
||||
|
||||
if (Font.MeasureString(textBlock.Text).X > maxWidth)
|
||||
if (maxTextLength != null)
|
||||
{
|
||||
if (Text.Length > maxTextLength)
|
||||
{
|
||||
Text = textBlock.Text.Substring(0, (int)maxTextLength);
|
||||
}
|
||||
}
|
||||
else if (Font.MeasureString(textBlock.Text).X > (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z))
|
||||
{
|
||||
Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
|
||||
enum ChatMessageType
|
||||
{
|
||||
Default, Error, Dead, Server, Radio, Private
|
||||
@@ -14,6 +13,8 @@ namespace Barotrauma.Networking
|
||||
|
||||
class ChatMessage
|
||||
{
|
||||
public const int MaxLength = 150;
|
||||
|
||||
public const float SpeakRange = 2000.0f;
|
||||
|
||||
public static Color[] MessageColor =
|
||||
@@ -138,6 +139,12 @@ namespace Barotrauma.Networking
|
||||
{
|
||||
UInt16 ID = msg.ReadUInt16();
|
||||
string txt = msg.ReadString();
|
||||
|
||||
if (txt.Length > MaxLength)
|
||||
{
|
||||
txt = txt.Substring(0, MaxLength);
|
||||
}
|
||||
|
||||
if (NetIdUtils.IdMoreRecent(ID, c.lastSentChatMsgID))
|
||||
{
|
||||
//this chat message is new to the server
|
||||
|
||||
@@ -841,11 +841,13 @@ namespace Barotrauma.Networking
|
||||
outmsg.Write(c.lastSentEntityEventID);
|
||||
|
||||
c.chatMsgQueue.RemoveAll(cMsg => !NetIdUtils.IdMoreRecent(cMsg.NetStateID, c.lastRecvChatMsgID));
|
||||
foreach (ChatMessage cMsg in c.chatMsgQueue)
|
||||
|
||||
int maxChatMsgsPerPacket = 50;
|
||||
for (int i = 0; i < c.chatMsgQueue.Count && i < maxChatMsgsPerPacket; i++)
|
||||
{
|
||||
cMsg.ServerWrite(outmsg, c);
|
||||
}
|
||||
|
||||
c.chatMsgQueue[i].ServerWrite(outmsg, c);
|
||||
}
|
||||
|
||||
//don't send position updates to characters who are still midround syncing
|
||||
//characters or items spawned mid-round don't necessarily exist at the client's end yet
|
||||
if (!c.NeedsMidRoundSync)
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Barotrauma.Networking
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.TopLeft, Alignment.Left, "", inGameHUD);
|
||||
chatMsgBox.Font = GUI.SmallFont;
|
||||
chatMsgBox.MaxTextWidth = chatBox.Rect.Width * 2;
|
||||
chatMsgBox.MaxTextLength = ChatMessage.MaxLength;
|
||||
chatMsgBox.Padding = Vector4.Zero;
|
||||
chatMsgBox.OnEnterPressed = EnterChatMessage;
|
||||
chatMsgBox.OnTextChanged = TypingChatMessage;
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace Barotrauma
|
||||
|
||||
chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, "", chatFrame);
|
||||
textBox = new GUITextBox(new Rectangle(0, 25, 0, 25), Alignment.Bottom, "", chatFrame);
|
||||
textBox.MaxTextWidth = textBox.Rect.Width * 2;
|
||||
textBox.MaxTextLength = ChatMessage.MaxLength;
|
||||
textBox.Font = GUI.SmallFont;
|
||||
|
||||
//player info panel ------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user