Client reads lobby chat from server
This commit is contained in:
@@ -36,6 +36,7 @@ namespace Barotrauma.Networking
|
|||||||
private string saltedPw;
|
private string saltedPw;
|
||||||
|
|
||||||
private UInt32 lastRecvChatMsgID = 0; //last message the server received from this client
|
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>();
|
private List<ChatMessage> chatMsgQueue = new List<ChatMessage>();
|
||||||
|
|
||||||
public byte ID
|
public byte ID
|
||||||
@@ -526,7 +527,15 @@ namespace Barotrauma.Networking
|
|||||||
switch (objHeader)
|
switch (objHeader)
|
||||||
{
|
{
|
||||||
case ServerNetObject.CHAT_MESSAGE:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,6 +546,7 @@ namespace Barotrauma.Networking
|
|||||||
NetOutgoingMessage outmsg = client.CreateMessage();
|
NetOutgoingMessage outmsg = client.CreateMessage();
|
||||||
outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
outmsg.Write((byte)ClientPacketHeader.UPDATE_LOBBY);
|
||||||
|
|
||||||
|
outmsg.Write(lastSentChatMsgID);
|
||||||
ChatMessage removeMsg;
|
ChatMessage removeMsg;
|
||||||
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
|
while ((removeMsg=chatMsgQueue.Find(cMsg => cMsg.ID <= lastRecvChatMsgID)) != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -544,13 +544,19 @@ namespace Barotrauma.Networking
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UInt32 ID = inc.ReadUInt32();
|
||||||
|
if (ID > c.lastRecvChatMsgID)
|
||||||
|
{
|
||||||
|
c.lastRecvChatMsgID = ID;
|
||||||
|
}
|
||||||
|
|
||||||
ClientNetObject objHeader;
|
ClientNetObject objHeader;
|
||||||
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
while ((objHeader=(ClientNetObject)inc.ReadByte()) != ClientNetObject.END_OF_MESSAGE)
|
||||||
{
|
{
|
||||||
switch (objHeader)
|
switch (objHeader)
|
||||||
{
|
{
|
||||||
case ClientNetObject.CHAT_MESSAGE:
|
case ClientNetObject.CHAT_MESSAGE:
|
||||||
UInt32 ID = inc.ReadUInt32();
|
ID = inc.ReadUInt32();
|
||||||
string msg = inc.ReadString();
|
string msg = inc.ReadString();
|
||||||
if (c.lastSentChatMsgID<ID)
|
if (c.lastSentChatMsgID<ID)
|
||||||
{
|
{
|
||||||
@@ -591,6 +597,25 @@ namespace Barotrauma.Networking
|
|||||||
NetOutgoingMessage outmsg = server.CreateMessage();
|
NetOutgoingMessage outmsg = server.CreateMessage();
|
||||||
outmsg.Write((byte)ServerPacketHeader.UPDATE_LOBBY);
|
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
|
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);
|
server.SendMessage(outmsg,c.Connection,NetDeliveryMethod.Unreliable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ namespace Barotrauma
|
|||||||
private GUIListBox playerList;
|
private GUIListBox playerList;
|
||||||
|
|
||||||
private GUIListBox subList, modeList, chatBox;
|
private GUIListBox subList, modeList, chatBox;
|
||||||
|
public GUIListBox ChatBox
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return chatBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private GUIButton[] traitorProbabilityButtons;
|
private GUIButton[] traitorProbabilityButtons;
|
||||||
private GUITextBlock traitorProbabilityText;
|
private GUITextBlock traitorProbabilityText;
|
||||||
|
|||||||
Reference in New Issue
Block a user