Removed Fill/ReadNetworkData
These functions needed to be replaced because they rely heavily on reliability. Instead, new functions called (Write/Read)Data(Server/Client) will be added. Separating client and server code into completely separate functions will help ensure that proper security checks are performed.
This commit is contained in:
@@ -385,75 +385,6 @@ namespace Barotrauma
|
||||
|
||||
item.Sprite.Draw(spriteBatch, new Vector2(rect.X + rect.Width / 2, rect.Y + rect.Height / 2), item.Color);
|
||||
}
|
||||
|
||||
public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
message.Write((ushort)(Items[i]==null ? 0 : Items[i].ID));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime)
|
||||
{
|
||||
if (sendingTime < lastUpdate) return;
|
||||
|
||||
//List<ushort> newItemIDs = new List<ushort>();
|
||||
//List<Item> droppedItems = new List<Item>();
|
||||
List<Item> prevItems = new List<Item>(Items);
|
||||
|
||||
Client sender = GameMain.Server == null ? null : GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
ushort itemId = message.ReadUInt16();
|
||||
if (itemId == 0)
|
||||
{
|
||||
if (Items[i] != null) Items[i].Drop();
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = Entity.FindEntityByID(itemId) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
//if the item is in the inventory of some other character and said character isn't dead/unconscious,
|
||||
//don't let this character pick it up
|
||||
if (GameMain.Server != null)
|
||||
{
|
||||
if (sender == null || sender.Character == null) return;
|
||||
|
||||
if (!sender.Character.CanAccessItem(item)) continue;
|
||||
}
|
||||
|
||||
TryPutItem(item, i, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdate = sendingTime;
|
||||
|
||||
if (GameMain.Server == null) return;
|
||||
if (sender != null && sender.Character != null)
|
||||
{
|
||||
foreach (Item item in Items)
|
||||
{
|
||||
if (item == null) continue;
|
||||
if (!prevItems.Contains(item))
|
||||
{
|
||||
GameServer.Log(sender.Character + " placed " + item.Name + " in " + Owner, Color.Orange);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Item item in prevItems)
|
||||
{
|
||||
if (item == null) continue;
|
||||
if (!Items.Contains(item))
|
||||
{
|
||||
GameServer.Log(sender.Character + " removed " + item.Name + " from " + Owner.ToString(), Color.Orange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user