Changed entity ids from int to ushort, inventory sync bugfixes

This commit is contained in:
Regalis
2015-10-21 18:58:36 +03:00
parent 0233579e37
commit 313d16d886
20 changed files with 155 additions and 78 deletions
@@ -534,7 +534,7 @@ namespace Barotrauma
//message.WriteRangedSingle(MathHelper.Clamp(raycastTimer, 0.0f, RaycastInterval), 0.0f, RaycastInterval, 8); //message.WriteRangedSingle(MathHelper.Clamp(raycastTimer, 0.0f, RaycastInterval), 0.0f, RaycastInterval, 8);
//message.WriteRangedSingle(MathHelper.Clamp(coolDownTimer, 0.0f, attackCoolDown * 2.0f), 0.0f, attackCoolDown * 2.0f, 8); //message.WriteRangedSingle(MathHelper.Clamp(coolDownTimer, 0.0f, attackCoolDown * 2.0f), 0.0f, attackCoolDown * 2.0f, 8);
message.Write(targetEntity==null ? -1 : (targetEntity as Entity).ID); message.Write(targetEntity==null ? (ushort)0 : (targetEntity as Entity).ID);
} }
public override void ReadNetworkData(NetIncomingMessage message) public override void ReadNetworkData(NetIncomingMessage message)
@@ -548,7 +548,7 @@ namespace Barotrauma
Vector2 targetPosition = Vector2.Zero; Vector2 targetPosition = Vector2.Zero;
int targetID; ushort targetID;
try try
{ {
@@ -571,7 +571,7 @@ namespace Barotrauma
//raycastTimer = message.ReadRangedSingle(0.0f, RaycastInterval, 8); //raycastTimer = message.ReadRangedSingle(0.0f, RaycastInterval, 8);
//coolDownTimer = message.ReadRangedSingle(0.0f, attackCoolDown*2.0f, 8); //coolDownTimer = message.ReadRangedSingle(0.0f, attackCoolDown*2.0f, 8);
targetID = message.ReadInt32(); targetID = message.ReadUInt16();
} }
catch { return; } catch { return; }
@@ -583,8 +583,7 @@ namespace Barotrauma
//this.raycastTimer = raycastTimer; //this.raycastTimer = raycastTimer;
//this.coolDownTimer = coolDownTimer; //this.coolDownTimer = coolDownTimer;
if (targetID > -1) if (targetID > 0) targetEntity = Entity.FindEntityByID(targetID) as IDamageable;
targetEntity = Entity.FindEntityByID(targetID) as IDamageable;
} }
} }
@@ -17,7 +17,7 @@ namespace Barotrauma
public Job Job; public Job Job;
private List<int> pickedItems; private List<ushort> pickedItems;
private Vector2[] headSpriteRange; private Vector2[] headSpriteRange;
@@ -30,7 +30,7 @@ namespace Barotrauma
public bool StartItemsGiven; public bool StartItemsGiven;
public List<int> PickedItemIDs public List<ushort> PickedItemIDs
{ {
get { return pickedItems; } get { return pickedItems; }
} }
@@ -72,7 +72,7 @@ namespace Barotrauma
headSpriteRange = new Vector2[2]; headSpriteRange = new Vector2[2];
pickedItems = new List<int>(); pickedItems = new List<ushort>();
//ID = -1; //ID = -1;
@@ -218,7 +218,7 @@ namespace Barotrauma
HeadSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1); HeadSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1);
StartItemsGiven = ToolBox.GetAttributeBool(element, "startitemsgiven", false); StartItemsGiven = ToolBox.GetAttributeBool(element, "startitemsgiven", false);
pickedItems = new List<int>(); pickedItems = new List<ushort>();
string pickedItemString = ToolBox.GetAttributeString(element, "items", ""); string pickedItemString = ToolBox.GetAttributeString(element, "items", "");
if (!string.IsNullOrEmpty(pickedItemString)) if (!string.IsNullOrEmpty(pickedItemString))
@@ -226,7 +226,7 @@ namespace Barotrauma
string[] itemIds = pickedItemString.Split(','); string[] itemIds = pickedItemString.Split(',');
foreach (string s in itemIds) foreach (string s in itemIds)
{ {
pickedItems.Add(int.Parse(s)); pickedItems.Add((ushort)int.Parse(s));
} }
} }
+5 -2
View File
@@ -685,11 +685,14 @@ namespace Barotrauma
//limb.body.SetTransform(limb.SimPosition + newMovement * 0.1f, limb.Rotation); //limb.body.SetTransform(limb.SimPosition + newMovement * 0.1f, limb.Rotation);
} }
correctionMovement = Vector2.Normalize(newMovement) * MathHelper.Clamp(dist*5.0f, 0.1f, 5.0f); correctionMovement =
Vector2.Lerp(targetMovement, Vector2.Normalize(newMovement) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
} }
else else
{ {
correctionMovement = Vector2.Normalize(newMovement) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f); correctionMovement =
Vector2.Lerp(targetMovement, Vector2.Normalize(newMovement) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f; if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
} }
} }
@@ -2,6 +2,9 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking;
using Lidgren.Network;
using System.Collections.Generic;
namespace Barotrauma namespace Barotrauma
{ {
@@ -292,5 +295,71 @@ namespace Barotrauma
} }
} }
public override bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
{
for (int i = 0; i < 5; i++ )
{
message.Write(items[i]==null ? (ushort)0 : (ushort)items[i].ID);
}
for (int i = 5; i < capacity; i++)
{
if (items[i] == null) continue;
message.Write((ushort)items[i].ID);
}
return true;
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
{
for (int i = 0; i<5; i++)
{
ushort itemId = message.ReadUInt16();
if (itemId==0)
{
if (items[i] != null) items[i].Drop(character, false);
}
else
{
Item item = Entity.FindEntityByID(itemId) as Item;
if (item == null) continue;
TryPutItem(item, i, false);
}
}
List<ushort> newItemIDs = new List<ushort>();
try
{
while (message.Position <= message.LengthBits - (sizeof(ushort) * 8))
{
newItemIDs.Add(message.ReadUInt16());
}
}
catch
{
return;
}
for (int i = 5; i < capacity; i++)
{
if (items[i] == null) continue;
if (!newItemIDs.Contains(items[i].ID))
{
items[i].Drop(null, false);
continue;
}
}
foreach (ushort itemId in newItemIDs)
{
Item item = Entity.FindEntityByID(itemId) as Item;
if (item == null) continue;
TryPutItem(item, LimbSlot.Any, false);
}
}
} }
} }
@@ -228,7 +228,7 @@ namespace Barotrauma.Items.Components
{ {
if (itemIds == null) return; if (itemIds == null) return;
for (int i = 0; i < itemIds.Length; i++) for (ushort i = 0; i < itemIds.Length; i++)
{ {
Item item = MapEntity.FindEntityByID(itemIds[i]) as Item; Item item = MapEntity.FindEntityByID(itemIds[i]) as Item;
if (item == null) continue; if (item == null) continue;
@@ -247,17 +247,17 @@ namespace Barotrauma.Items.Components
string[] itemIdStrings = containedString.Split(','); string[] itemIdStrings = containedString.Split(',');
itemIds = new int[itemIdStrings.Length]; itemIds = new ushort[itemIdStrings.Length];
for (int i = 0; i < itemIdStrings.Length; i++) for (int i = 0; i < itemIdStrings.Length; i++)
{ {
int id = -1; ushort id = 0;
if (!int.TryParse(itemIdStrings[i], out id)) continue; if (!ushort.TryParse(itemIdStrings[i], out id)) continue;
itemIds[i] = id; itemIds[i] = id;
} }
} }
int[] itemIds; ushort[] itemIds;
public override XElement Save(XElement parentElement) public override XElement Save(XElement parentElement)
{ {
@@ -266,7 +266,7 @@ namespace Barotrauma.Items.Components
string[] itemIdStrings = new string[inventory.items.Length]; string[] itemIdStrings = new string[inventory.items.Length];
for (int i = 0; i < inventory.items.Length; i++) for (int i = 0; i < inventory.items.Length; i++)
{ {
itemIdStrings[i] = (inventory.items[i]==null) ? "-1" : inventory.items[i].ID.ToString(); itemIdStrings[i] = (inventory.items[i]==null) ? "0" : inventory.items[i].ID.ToString();
} }
componentElement.Add(new XAttribute("contained", string.Join(",",itemIdStrings))); componentElement.Add(new XAttribute("contained", string.Join(",",itemIdStrings)));
@@ -28,7 +28,7 @@ namespace Barotrauma.Items.Components
private List<StatusEffect> effects; private List<StatusEffect> effects;
public readonly int[] wireId; public readonly ushort[] wireId;
public bool IsPower public bool IsPower
{ {
@@ -79,7 +79,7 @@ namespace Barotrauma.Items.Components
effects = new List<StatusEffect>(); effects = new List<StatusEffect>();
wireId = new int[MaxLinked]; wireId = new ushort[MaxLinked];
foreach (XElement subElement in element.Elements()) foreach (XElement subElement in element.Elements())
{ {
@@ -93,7 +93,9 @@ namespace Barotrauma.Items.Components
} }
if (index == -1) break; if (index == -1) break;
wireId[index] = ToolBox.GetAttributeInt(subElement, "w", -1); int id = ToolBox.GetAttributeInt(subElement, "w", 0);
if (id<0) id = 0;
wireId[index] = (ushort)id;
break; break;
@@ -441,7 +443,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < MaxLinked; i++) for (int i = 0; i < MaxLinked; i++)
{ {
if (wireId[i] == -1) continue; if (wireId[i] == 0) continue;
Item wireItem = MapEntity.FindEntityByID(wireId[i]) as Item; Item wireItem = MapEntity.FindEntityByID(wireId[i]) as Item;
@@ -146,7 +146,7 @@ namespace Barotrauma.Items.Components
for (int i = 0; i < wireCount; i++) for (int i = 0; i < wireCount; i++)
{ {
int wireId = message.ReadInt32(); ushort wireId = message.ReadUInt16();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item; Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue; if (wireItem == null) continue;
+17 -14
View File
@@ -5,6 +5,7 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Barotrauma.Networking; using Barotrauma.Networking;
using System; using System;
using System.Collections.Generic;
namespace Barotrauma namespace Barotrauma
{ {
@@ -193,7 +194,7 @@ namespace Barotrauma
{ {
if (Owner!=null) if (Owner!=null)
{ {
int[] data = { draggingItem.ID, -1 }; ushort[] data = { draggingItem.ID, 0 };
new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true, data); new NetworkEvent(NetworkEventType.InventoryUpdate, Owner.ID, true, data);
} }
@@ -288,25 +289,27 @@ namespace Barotrauma
spriteBatch.DrawString(GUI.Font, (int)item.Condition + " %", new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.Red); spriteBatch.DrawString(GUI.Font, (int)item.Condition + " %", new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), Color.Red);
} }
public bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data) public virtual bool FillNetworkData(NetworkEventType type, NetOutgoingMessage message, object data)
{ {
for (int i = 0; i<capacity; i++) for (int i = 0; i<capacity; i++)
{ {
message.Write((items[i] == null) ? -1 : items[i].ID); if (items[i] == null) continue;
message.Write((ushort)items[i].ID);
} }
return true; return true;
} }
public void ReadNetworkData(NetworkEventType type, NetIncomingMessage message) public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message)
{ {
int[] newItemIDs = new int[capacity]; List<ushort> newItemIDs = new List<ushort>();
try try
{ {
for (int i = 0; i<capacity; i++)
while (message.Position <= message.LengthBits - (sizeof(ushort) * 8))
{ {
newItemIDs[i] = message.ReadInt32(); newItemIDs.Add(message.ReadUInt16());
} }
} }
catch catch
@@ -316,20 +319,20 @@ namespace Barotrauma
for (int i = 0; i < capacity; i++) for (int i = 0; i < capacity; i++)
{ {
if (newItemIDs[i] == -1) if (items[i] == null) continue;
if (!newItemIDs.Contains(items[i].ID))
{ {
if (items[i] == null) continue;
items[i].Drop(null, false); items[i].Drop(null, false);
continue; continue;
} }
}
Item item = Entity.FindEntityByID(newItemIDs[i]) as Item; foreach (ushort itemId in newItemIDs)
{
Item item = Entity.FindEntityByID(itemId) as Item;
if (item == null) continue; if (item == null) continue;
TryPutItem(item, i, false); TryPutItem(item, item.AllowedSlots, false);
} }
} }
} }
} }
+1 -1
View File
@@ -1101,7 +1101,7 @@ namespace Barotrauma
} }
Item item = new Item(rect, ip); Item item = new Item(rect, ip);
item.ID = int.Parse(element.Attribute("ID").Value); item.ID = (ushort)int.Parse(element.Attribute("ID").Value);
item.linkedToID = new List<int>(); item.linkedToID = new List<int>();
+5 -4
View File
@@ -7,15 +7,16 @@ namespace Barotrauma
{ {
class Entity class Entity
{ {
private static Dictionary<int, Entity> dictionary = new Dictionary<int, Entity>(); private static Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>();
private int id;
private ushort id;
protected AITarget aiTarget; protected AITarget aiTarget;
//protected float soundRange; //protected float soundRange;
//protected float sightRange; //protected float sightRange;
public int ID public ushort ID
{ {
get { return id; } get { return id; }
set set
@@ -73,7 +74,7 @@ namespace Barotrauma
/// <summary> /// <summary>
/// Find an entity based on the ID /// Find an entity based on the ID
/// </summary> /// </summary>
public static Entity FindEntityByID(int ID) public static Entity FindEntityByID(ushort ID)
{ {
Entity matchingEntity; Entity matchingEntity;
dictionary.TryGetValue(ID, out matchingEntity); dictionary.TryGetValue(ID, out matchingEntity);
+1 -1
View File
@@ -607,7 +607,7 @@ namespace Barotrauma
int.Parse(element.Attribute("height").Value)); int.Parse(element.Attribute("height").Value));
Gap g = new Gap(rect); Gap g = new Gap(rect);
g.ID = int.Parse(element.Attribute("ID").Value); g.ID = (ushort)int.Parse(element.Attribute("ID").Value);
g.linkedToID = new List<int>(); g.linkedToID = new List<int>();
//int i = 0; //int i = 0;
+1 -1
View File
@@ -468,7 +468,7 @@ namespace Barotrauma
h.volume = ToolBox.GetAttributeFloat(element, "pressure", 0.0f); h.volume = ToolBox.GetAttributeFloat(element, "pressure", 0.0f);
h.ID = int.Parse(element.Attribute("ID").Value); h.ID = (ushort)int.Parse(element.Attribute("ID").Value);
} }
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message, object data) public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message, object data)
+1 -1
View File
@@ -515,7 +515,7 @@ namespace Barotrauma
e.linkedTo.Clear(); e.linkedTo.Clear();
foreach (int i in e.linkedToID) foreach (ushort i in e.linkedToID)
{ {
MapEntity linked = FindEntityByID(i) as MapEntity; MapEntity linked = FindEntityByID(i) as MapEntity;
+1 -1
View File
@@ -609,7 +609,7 @@ namespace Barotrauma
if (ep.Name == name) if (ep.Name == name)
{ {
s = new Structure(rect, (StructurePrefab)ep); s = new Structure(rect, (StructurePrefab)ep);
s.ID = int.Parse(element.Attribute("ID").Value); s.ID = (ushort)int.Parse(element.Attribute("ID").Value);
break; break;
} }
} }
+2 -2
View File
@@ -149,7 +149,7 @@ namespace Barotrauma
} }
base.Remove(); base.Remove();
ID = -5; ID = ushort.MaxValue;
} }
//drawing ---------------------------------------------------- //drawing ----------------------------------------------------
@@ -635,7 +635,7 @@ namespace Barotrauma
GameMain.LightManager.OnMapLoaded(); GameMain.LightManager.OnMapLoaded();
ID = int.MaxValue-10; ID = ushort.MaxValue-10;
loaded = this; loaded = this;
} }
+1 -1
View File
@@ -312,7 +312,7 @@ namespace Barotrauma
WayPoint w = new WayPoint(rect); WayPoint w = new WayPoint(rect);
w.ID = int.Parse(element.Attribute("ID").Value); w.ID = (ushort)int.Parse(element.Attribute("ID").Value);
w.spawnType = (SpawnType)Enum.Parse(typeof(SpawnType), w.spawnType = (SpawnType)Enum.Parse(typeof(SpawnType),
ToolBox.GetAttributeString(element, "spawn", "None")); ToolBox.GetAttributeString(element, "spawn", "None"));
+6 -6
View File
@@ -347,7 +347,7 @@ namespace Barotrauma.Networking
} }
else if (gameStarted) else if (gameStarted)
{ {
new NetworkEvent(myCharacter.ID, true); myCharacter.SendNetworkEvent(true);
} }
} }
@@ -525,7 +525,7 @@ namespace Barotrauma.Networking
List<Character> crew = new List<Character>(); List<Character> crew = new List<Character>();
int count = inc.ReadInt32(); int count = inc.ReadByte();
for (int n = 0; n < count; n++) for (int n = 0; n < count; n++)
{ {
int id = inc.ReadInt32(); int id = inc.ReadInt32();
@@ -631,7 +631,7 @@ namespace Barotrauma.Networking
msg.Write((byte)PacketTypes.CharacterInfo); msg.Write((byte)PacketTypes.CharacterInfo);
msg.Write(characterInfo.Name); msg.Write(characterInfo.Name);
msg.Write(characterInfo.Gender == Gender.Male); msg.Write(characterInfo.Gender == Gender.Male);
msg.Write(characterInfo.HeadSpriteId); msg.Write((byte)characterInfo.HeadSpriteId);
var jobPreferences = GameMain.NetLobbyScreen.JobPreferences; var jobPreferences = GameMain.NetLobbyScreen.JobPreferences;
int count = Math.Min(jobPreferences.Count, 3); int count = Math.Min(jobPreferences.Count, 3);
@@ -647,10 +647,10 @@ namespace Barotrauma.Networking
private Character ReadCharacterData(NetIncomingMessage inc, bool isMyCharacter) private Character ReadCharacterData(NetIncomingMessage inc, bool isMyCharacter)
{ {
string newName = inc.ReadString(); string newName = inc.ReadString();
int ID = inc.ReadInt32(); ushort ID = inc.ReadUInt16();
bool isFemale = inc.ReadBoolean(); bool isFemale = inc.ReadBoolean();
int headSpriteID = inc.ReadInt32(); int headSpriteID = inc.ReadByte();
Vector2 position = new Vector2(inc.ReadFloat(), inc.ReadFloat()); Vector2 position = new Vector2(inc.ReadFloat(), inc.ReadFloat());
@@ -719,7 +719,7 @@ namespace Barotrauma.Networking
{ {
case 0: case 0:
msg.Write((byte)PacketTypes.NetworkEvent); msg.Write((byte)PacketTypes.NetworkEvent);
msg.Write((byte)NetworkEventType.UpdateEntity); msg.Write((byte)NetworkEventType.EntityUpdate);
msg.Write(Rand.Int(MapEntity.mapEntityList.Count)); msg.Write(Rand.Int(MapEntity.mapEntityList.Count));
break; break;
case 1: case 1:
+5 -7
View File
@@ -297,7 +297,7 @@ namespace Barotrauma.Networking
{ {
if (gameStarted) if (gameStarted)
{ {
if (myCharacter != null) new NetworkEvent(myCharacter.ID, true); if (myCharacter != null) myCharacter.SendNetworkEvent(true);
foreach (Character c in Character.CharacterList) foreach (Character c in Character.CharacterList)
{ {
@@ -305,7 +305,7 @@ namespace Barotrauma.Networking
if (c.SimPosition == Vector2.Zero || c.SimPosition.Length() < 100.0f) if (c.SimPosition == Vector2.Zero || c.SimPosition.Length() < 100.0f)
{ {
new NetworkEvent(c.ID, false); c.SendNetworkEvent(false);
} }
} }
} }
@@ -678,8 +678,6 @@ namespace Barotrauma.Networking
} }
else else
{ {
if (server.ConnectionsCount>0) if (server.ConnectionsCount>0)
{ {
server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0); server.SendMessage(message, recipientConnections, NetDeliveryMethod.Unreliable, 0);
@@ -777,7 +775,7 @@ namespace Barotrauma.Networking
//msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes); //msg.Write(GameMain.NetLobbyScreen.GameDuration.TotalMinutes);
msg.Write((myCharacter == null) ? connectedClients.Count : connectedClients.Count + 1); msg.Write((myCharacter == null) ? (byte)connectedClients.Count : (byte)(connectedClients.Count + 1));
foreach (Client client in connectedClients) foreach (Client client in connectedClients)
{ {
msg.Write(client.ID); msg.Write(client.ID);
@@ -1036,7 +1034,7 @@ namespace Barotrauma.Networking
{ {
name = message.ReadString(); name = message.ReadString();
gender = message.ReadBoolean() ? Gender.Male : Gender.Female; gender = message.ReadBoolean() ? Gender.Male : Gender.Female;
headSpriteId = message.ReadInt32(); headSpriteId = message.ReadByte();
} }
catch catch
{ {
@@ -1072,7 +1070,7 @@ namespace Barotrauma.Networking
message.Write(character.ID); message.Write(character.ID);
message.Write(character.Info.Gender == Gender.Female); message.Write(character.Info.Gender == Gender.Female);
message.Write(character.Info.HeadSpriteId); message.Write((byte)character.Info.HeadSpriteId);
message.Write(character.SimPosition.X); message.Write(character.SimPosition.X);
message.Write(character.SimPosition.Y); message.Write(character.SimPosition.Y);
+18 -16
View File
@@ -1,11 +1,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using Lidgren.Network; using Lidgren.Network;
using System;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
enum NetworkEventType enum NetworkEventType
{ {
UpdateEntity = 0, EntityUpdate = 0,
KillCharacter = 1, KillCharacter = 1,
UpdateComponent = 2, UpdateComponent = 2,
DropItem = 3, DropItem = 3,
@@ -13,17 +14,19 @@ namespace Barotrauma.Networking
PickItem = 5, PickItem = 5,
UpdateProperty = 6, UpdateProperty = 6,
WallDamage = 7, WallDamage = 7,
SelectCharacter = 8
SelectCharacter = 8,
EntityUpdateLarge = 9
} }
class NetworkEvent class NetworkEvent
{ {
public static List<NetworkEvent> events = new List<NetworkEvent>(); public static List<NetworkEvent> events = new List<NetworkEvent>();
private static bool[] isImportant = { false, true, false, true, true, true, true, true, true }; private static bool[] isImportant = { false, true, false, true, true, true, true, true, true, false };
private static bool[] overridePrevious = { true, false, true, false, false, false, true, true, true }; private static bool[] overridePrevious = { true, false, true, false, false, false, true, true, true, true };
private int id; private ushort id;
private NetworkEventType eventType; private NetworkEventType eventType;
@@ -33,7 +36,7 @@ namespace Barotrauma.Networking
//private NetOutgoingMessage message; //private NetOutgoingMessage message;
public int ID public ushort ID
{ {
get { return id; } get { return id; }
} }
@@ -53,12 +56,12 @@ namespace Barotrauma.Networking
get { return eventType; } get { return eventType; }
} }
public NetworkEvent(int id, bool isClient) public NetworkEvent(ushort id, bool isClient)
: this(NetworkEventType.UpdateEntity, id, isClient) : this(NetworkEventType.EntityUpdate, id, isClient)
{ {
} }
public NetworkEvent(NetworkEventType type, int id, bool isClient, object data = null) public NetworkEvent(NetworkEventType type, ushort id, bool isClient, object data = null)
{ {
if (isClient) if (isClient)
{ {
@@ -109,12 +112,12 @@ namespace Barotrauma.Networking
public static bool ReadData(NetIncomingMessage message) public static bool ReadData(NetIncomingMessage message)
{ {
NetworkEventType eventType; NetworkEventType eventType;
int id; ushort id;
try try
{ {
eventType = (NetworkEventType)message.ReadByte(); eventType = (NetworkEventType)message.ReadByte();
id = message.ReadInt32(); id = message.ReadUInt16();
} }
catch catch
{ {
@@ -129,16 +132,15 @@ namespace Barotrauma.Networking
return false; return false;
} }
//System.Diagnostics.Debug.WriteLine("Networkevent entity: "+e.ToString());
//System.Diagnostics.Debug.WriteLine("new message: " + eventType +" - "+e);
try try
{ {
e.ReadNetworkData(eventType, message); e.ReadNetworkData(eventType, message);
} }
catch catch (Exception exception)
{ {
DebugConsole.ThrowError("Received invalid network message"); #if DEBUG
DebugConsole.ThrowError("Received invalid network message", exception);
#endif
return false; return false;
} }
Binary file not shown.