Checking if a client can access an item in the itemcomponent serialization methods

This commit is contained in:
Regalis
2016-12-09 16:56:17 +02:00
parent bea523187b
commit fa712e0102
5 changed files with 33 additions and 8 deletions
@@ -236,8 +236,13 @@ namespace Barotrauma.Items.Components
public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c) public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
{ {
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f; float flowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
IsActive = msg.ReadBoolean(); bool isActive = msg.ReadBoolean();
if (!item.CanClientAccess(c)) return;
FlowPercentage = flowPercentage;
IsActive = isActive;
} }
public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null) public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)
@@ -433,7 +433,11 @@ namespace Barotrauma.Items.Components
public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c) public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
{ {
IsActive = msg.ReadBoolean(); bool isActive = msg.ReadBoolean();
if (!item.CanClientAccess(c)) return;
IsActive = isActive;
isActiveTickBox.Selected = IsActive; isActiveTickBox.Selected = IsActive;
item.CreateServerEvent(this); item.CreateServerEvent(this);
@@ -563,11 +563,18 @@ namespace Barotrauma.Items.Components
public void ServerRead(NetIncomingMessage msg, Client c) public void ServerRead(NetIncomingMessage msg, Client c)
{ {
AutoTemp = msg.ReadBoolean(); bool autoTemp = msg.ReadBoolean();
ShutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 8); float shutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 8);
float coolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
float fissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
CoolingRate = msg.ReadRangedSingle(0.0f, 100.0f, 8); if (!item.CanClientAccess(c)) return;
FissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
AutoTemp = autoTemp;
ShutDownTemp = shutDownTemp;
CoolingRate = coolingRate;
FissionRate = fissionRate;
//need to create a server event to notify all clients of the changed state //need to create a server event to notify all clients of the changed state
unsentChanges = true; unsentChanges = true;
@@ -488,7 +488,11 @@ namespace Barotrauma.Items.Components
public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c) public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
{ {
AutoPilot = msg.ReadBoolean(); bool autoPilot = msg.ReadBoolean();
if (!item.CanClientAccess(c)) return;
AutoPilot = autoPilot;
if (!AutoPilot) if (!AutoPilot)
{ {
+5
View File
@@ -1356,6 +1356,11 @@ namespace Barotrauma
return Vector2.Distance(WorldPosition, worldPosition) < PickDistance; return Vector2.Distance(WorldPosition, worldPosition) < PickDistance;
} }
public bool CanClientAccess(Client c)
{
return c != null && c.Character != null && c.Character.CanAccessItem(this);
}
public bool Pick(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false) public bool Pick(Character picker, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceActionKey=false)
{ {
bool hasRequiredSkills = true; bool hasRequiredSkills = true;