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:
@@ -93,13 +93,28 @@ namespace Barotrauma
|
||||
dictionary.Add(id, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the state of the entity into the message
|
||||
/// </summary>
|
||||
/// <param name="data">some data that was saved when the networkevent was created</param>
|
||||
/// <returns>false if something went wrong when filling the message, true if the msg is ready to be sent</returns>
|
||||
public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public virtual void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
||||
|
||||
/// <summary>
|
||||
/// Updates the state of the entity based on the data in the message
|
||||
/// </summary>
|
||||
|
||||
/// <param name="sendingTime"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns>false if the message is not valid (client trying to change something they're not authorized to, corrupt data, etc) and should be ignored</returns>
|
||||
public virtual bool ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
||||
{
|
||||
data = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -831,11 +831,13 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime, out object data)
|
||||
public override bool ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime, out object data)
|
||||
{
|
||||
data = null;
|
||||
|
||||
if (sendingTime < lastNetworkUpdate) return;
|
||||
if (GameMain.Server != null) return false;
|
||||
|
||||
if (sendingTime < lastNetworkUpdate) return false;
|
||||
|
||||
float newVolume = this.volume;
|
||||
float newOxygen = this.OxygenPercentage;
|
||||
@@ -851,7 +853,7 @@ namespace Barotrauma
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.Log("Failed to read network message for Hull {" + ID + "}! " + e.Message);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Volume = newVolume;
|
||||
@@ -901,8 +903,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
var toBeRemoved = fireSources.FindAll(fs => !newFireSources.Contains(fs));
|
||||
for (int i = toBeRemoved.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -911,6 +911,8 @@ namespace Barotrauma
|
||||
fireSources = newFireSources;
|
||||
|
||||
lastNetworkUpdate = sendingTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -793,11 +793,13 @@ 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;
|
||||
|
||||
if (sendingTime < lastUpdate) return;
|
||||
if (GameMain.Server != null) return false;
|
||||
|
||||
if (sendingTime < lastUpdate) return false;
|
||||
|
||||
// int sectionCount = message.ReadByte();
|
||||
|
||||
@@ -812,6 +814,8 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
lastUpdate = sendingTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -550,14 +550,16 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
||||
public override bool ReadNetworkData(Networking.NetworkEventType type, NetIncomingMessage message, float sendingTime, out object data)
|
||||
{
|
||||
data = null;
|
||||
|
||||
if (GameMain.Server != null) return false;
|
||||
|
||||
Vector2 newTargetPosition, newSpeed;
|
||||
try
|
||||
{
|
||||
if (sendingTime <= lastNetworkUpdate) return;
|
||||
if (sendingTime <= lastNetworkUpdate) return false;
|
||||
|
||||
newTargetPosition = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
newSpeed = new Vector2(message.ReadFloat(), message.ReadFloat());
|
||||
@@ -568,10 +570,10 @@ namespace Barotrauma
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("invalid network message", e);
|
||||
#endif
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!newSpeed.IsValid() || !newTargetPosition.IsValid()) return;
|
||||
if (!newSpeed.IsValid() || !newTargetPosition.IsValid()) return false;
|
||||
|
||||
//newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime);
|
||||
|
||||
@@ -579,6 +581,8 @@ namespace Barotrauma
|
||||
subBody.Velocity = newSpeed;
|
||||
|
||||
lastNetworkUpdate = sendingTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user