Client reads lobby chat from server
This commit is contained in:
@@ -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<ChatMessage> chatMsgQueue = new List<ChatMessage>();
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<ID)
|
||||
{
|
||||
@@ -591,6 +597,25 @@ namespace Barotrauma.Networking
|
||||
NetOutgoingMessage outmsg = server.CreateMessage();
|
||||
outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
|
||||
outmsg.Write(c.lastSentChatMsgID); //send this to client so they know which messages weren't received by the server
|
||||
foreach (GUIComponent gc in GameMain.NetLobbyScreen.ChatBox.children)
|
||||
{
|
||||
if (gc is GUITextBlock)
|
||||
{
|
||||
if (gc.UserData is ChatMessage)
|
||||
{
|
||||
ChatMessage cMsg = (ChatMessage)gc.UserData;
|
||||
if (cMsg.ID > 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user