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:
juanjp600
2016-08-29 20:02:46 -03:00
parent a00ceb5b9f
commit af220dbc2a
28 changed files with 29 additions and 2297 deletions
+1 -84
View File
@@ -498,89 +498,6 @@ namespace Barotrauma
}
}
}
public override bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
{
for (int i = 0; i < capacity; i++)
{
message.Write(Items[i]==null ? (ushort)0 : (ushort)Items[i].ID);
}
return true;
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime)
{
if (sendingTime < lastUpdate) return;
character.ClearInput(InputType.Use);
List<Item> droppedItems = new List<Item>();
List<Item> prevItems = new List<Item>(Items);
for (int i = 0; i<capacity; i++)
{
ushort itemId = message.ReadUInt16();
if (itemId == 0)
{
if (Items[i] != null)
{
droppedItems.Add(Items[i]);
Items[i].Drop(character, false);
}
}
else
{
Item item = Entity.FindEntityByID(itemId) as Item;
if (item == null) continue;
//item already in the right slot, no need to do anything
if (Items[i] == item) 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)
{
var owner = item.ParentInventory == null ? null : item.ParentInventory.Owner as Character;
if (owner != null && owner != character)
{
if (!character.CanAccessItem(item)) return;
}
}
//some other item already in the slot -> drop it
if (Items[i] != null) Items[i].Drop(character, false);
if (TryPutItem(item, i, false, false))
{
if (droppedItems.Contains(item)) droppedItems.Remove(item);
}
}
}
lastUpdate = sendingTime;
if (GameMain.Server == null) return;
var sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender != null && sender.Character != null)
{
foreach (Item item in droppedItems)
{
GameServer.Log(sender.Character == character ?
character.Name + " dropped " + item.Name :
sender.Character + " removed " + item.Name + " from " + character + "'s inventory", Color.Orange);
}
foreach (Item item in Items)
{
if (item == null || prevItems.Contains(item)) continue;
GameServer.Log(sender.Character == character ?
character.Name + " picked up " + item.Name :
sender.Character + " placed " + item.Name + " in " + character + "'s inventory", Color.Orange);
}
}
}
}
}