diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 0598ce9c2..8fcfff3f1 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -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; diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index 2c89b42e3..c5350f007 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -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); } diff --git a/Subsurface/Source/Networking/ChatMessage.cs b/Subsurface/Source/Networking/ChatMessage.cs index fd6b561e9..c640dfa93 100644 --- a/Subsurface/Source/Networking/ChatMessage.cs +++ b/Subsurface/Source/Networking/ChatMessage.cs @@ -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 diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index a4622a6b5..8e5d5df8e 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -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) diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index 74c558539..0505eda01 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -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; diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 9d5ab90ff..c6ee7700d 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -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 ------------------------------------------------------------