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

View File

@@ -236,8 +236,13 @@ namespace Barotrauma.Items.Components
public void ServerRead(Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
{
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
IsActive = msg.ReadBoolean();
float flowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
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)

View File

@@ -433,7 +433,11 @@ namespace Barotrauma.Items.Components
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;
item.CreateServerEvent(this);

View File

@@ -563,11 +563,18 @@ namespace Barotrauma.Items.Components
public void ServerRead(NetIncomingMessage msg, Client c)
{
AutoTemp = msg.ReadBoolean();
ShutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 8);
bool autoTemp = msg.ReadBoolean();
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);
FissionRate = msg.ReadRangedSingle(0.0f, 100.0f, 8);
if (!item.CanClientAccess(c)) return;
AutoTemp = autoTemp;
ShutDownTemp = shutDownTemp;
CoolingRate = coolingRate;
FissionRate = fissionRate;
//need to create a server event to notify all clients of the changed state
unsentChanges = true;

View File

@@ -488,7 +488,11 @@ namespace Barotrauma.Items.Components
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)
{

View File

@@ -1356,6 +1356,11 @@ namespace Barotrauma
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)
{
bool hasRequiredSkills = true;