More sanity checks to make sure clients aren't doing something they're not allowed to:

- AICharacter, hull, structure and submarine updates from clients are ignored
- character updates from anyone else than the client controlling the character are ignored
- players can't pick/drop items from anyone else's inventory (unless the target is unconscious/stunned/cuffed)
- server has authority over reactor temperature
This commit is contained in:
Regalis
2016-08-16 17:56:33 +03:00
parent 8a2ad8eb64
commit 6c5452570e
11 changed files with 175 additions and 106 deletions
+21 -9
View File
@@ -1217,7 +1217,7 @@ namespace Barotrauma
return closest;
}
public bool IsInsideTrigger(Vector2 worldPosition)
{
foreach (Rectangle trigger in prefab.Triggers)
@@ -1716,7 +1716,7 @@ namespace Barotrauma
return true;
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
public override bool ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
{
data = null;
@@ -1725,6 +1725,15 @@ namespace Barotrauma
switch (type)
{
case NetworkEventType.DropItem:
if (GameMain.Server != null)
{
Client sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender == null || sender.Character == null || !sender.Character.CanAccessItem(this))
{
return false;
}
}
Drop(null, false);
if (body != null)
{
@@ -1733,22 +1742,23 @@ namespace Barotrauma
}
break;
case NetworkEventType.PhysicsBodyPosition:
//clients don't have authority over item positions
if (GameMain.Server != null) return false;
if (body != null) body.ReadNetworkData(message, sendingTime);
FindHull();
break;
case NetworkEventType.ItemFixed:
byte requirementIndex = message.ReadByte();
data = requirementIndex;
if (requirementIndex >= FixRequirements.Count) return;
if (requirementIndex >= FixRequirements.Count) return false;
FixRequirements[requirementIndex].Fixed = true;
break;
case NetworkEventType.InventoryUpdate:
var itemContainers = GetComponents<ItemContainer>();
if (itemContainers == null || !itemContainers.Any()) return;
if (itemContainers == null || !itemContainers.Any()) return false;
int containerCount = message.ReadRangedInteger(1, ItemContainer.MaxInventoryCount);
for (int i = 0; i < containerCount;i++ )
@@ -1763,7 +1773,7 @@ namespace Barotrauma
data = componentIndex;
if (componentIndex < 0 || componentIndex > components.Count - 1) return;
if (componentIndex < 0 || componentIndex > components.Count - 1) return false;
components[componentIndex].NetworkUpdateSent = true;
components[componentIndex].ReadNetworkData(type, message, sendingTime);
@@ -1787,12 +1797,12 @@ namespace Barotrauma
}
catch
{
return;
return false;
}
var allProperties = GetProperties<InGameEditable>();
ObjectProperty property = allProperties.Find(op => op.Name == propertyName);
if (property == null) return;
if (property == null) return false;
try
{
@@ -1815,11 +1825,13 @@ namespace Barotrauma
catch
{
return;
return false;
}
break;
}
return true;
}
public override void Remove()