Changed lobby & chatMsg IDs to from uint to ushort, added a utility class that handles the wrap around of IDs

This commit is contained in:
Regalis
2017-02-05 22:55:19 +02:00
parent 9bda79036a
commit 4b8d1054b1
7 changed files with 94 additions and 42 deletions

View File

@@ -47,9 +47,9 @@ namespace Barotrauma.Networking
private set;
}
public static UInt32 LastID = 0;
public static UInt16 LastID = 0;
public UInt32 NetStateID
public UInt16 NetStateID
{
get;
set;
@@ -138,9 +138,9 @@ namespace Barotrauma.Networking
static public void ServerRead(NetIncomingMessage msg, Client c)
{
UInt32 ID = msg.ReadUInt32();
UInt16 ID = msg.ReadUInt16();
string txt = msg.ReadString();
if (c.lastSentChatMsgID < ID)
if (NetIdUtils.IdMoreRecent(ID, c.lastSentChatMsgID))
{
//this chat message is new to the server
GameMain.Server.SendChatMessage(txt, null, c);
@@ -169,7 +169,7 @@ namespace Barotrauma.Networking
static public void ClientRead(NetIncomingMessage msg)
{
UInt32 ID = msg.ReadUInt32();
UInt16 ID = msg.ReadUInt16();
ChatMessageType type = (ChatMessageType)msg.ReadByte();
string txt = msg.ReadString();
@@ -189,7 +189,7 @@ namespace Barotrauma.Networking
senderName = msg.ReadString();
}
if (ID > LastID)
if (NetIdUtils.IdMoreRecent(ID, LastID))
{
GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter);
LastID = ID;