diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 70633b7e0..f7cb530a2 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -36,6 +36,7 @@ namespace Barotrauma.Networking private string saltedPw; private UInt32 lastRecvChatMsgID = 0; //last message the server received from this client + private UInt32 lastSentChatMsgID = 0; //last message the server has sent to this client private List chatMsgQueue = new List(); public byte ID @@ -526,7 +527,15 @@ namespace Barotrauma.Networking switch (objHeader) { case ServerNetObject.CHAT_MESSAGE: - //TODO: READ CHAT MESSAGES FROM SERVER + UInt32 ID = inc.ReadUInt32(); + ChatMessageType type = (ChatMessageType)inc.ReadByte(); + string senderName = inc.ReadString(); + string msg = inc.ReadString(); + if (ID > lastSentChatMsgID) + { + AddChatMessage(msg, type, senderName); + lastSentChatMsgID = ID; + } break; } } @@ -537,6 +546,7 @@ namespace Barotrauma.Networking NetOutgoingMessage outmsg = client.CreateMessage(); outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY); + outmsg.Write(lastSentChatMsgID); ChatMessage removeMsg; while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null) { diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 5a73b3cd9..78001e38d 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -544,13 +544,19 @@ namespace Barotrauma.Networking return; } + UInt32 ID = inc.ReadUInt32(); + if (ID > c.lastRecvChatMsgID) + { + c.lastRecvChatMsgID = ID; + } + ClientNetObject objHeader; while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE) { switch (objHeader) { case ClientNetObject.CHAT_MESSAGE: - UInt32 ID = inc.ReadUInt32(); + ID = inc.ReadUInt32(); string msg = inc.ReadString(); if (c.lastSentChatMsgID c.lastRecvChatMsgID) + { + outmsg.Write((byte)ServerNetObject.CHAT_MESSAGE); + outmsg.Write(cMsg.ID); + outmsg.Write((byte)cMsg.Type); + outmsg.Write(cMsg.SenderName); + outmsg.Write(cMsg.Text); + } + } + } + } + outmsg.Write((byte)ServerNetObject.END_OF_MESSAGE); server.SendMessage(outmsg,c.Connection,NetDeliveryMethod.Unreliable); } diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 230b52420..9e8539d79 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -21,6 +21,13 @@ namespace Barotrauma private GUIListBox playerList; private GUIListBox subList, modeList, chatBox; + public GUIListBox ChatBox + { + get + { + return chatBox; + } + } private GUIButton[] traitorProbabilityButtons; private GUITextBlock traitorProbabilityText;