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
@@ -535,72 +535,6 @@ namespace Barotrauma.Items.Components
break;
}
}
public override bool FillNetworkData(NetworkEventType type, NetBuffer message)
{
message.Write(autoTemp);
if (GameMain.Server != null)
{
message.WriteRangedSingle(temperature, 0.0f, 10000.0f, 16);
}
message.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 8);
message.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8);
message.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
return true;
}
public override void ReadNetworkData(NetworkEventType type, NetIncomingMessage message, float sendingTime)
{
if (sendingTime < lastUpdate) return;
bool newAutoTemp;
float newTemperature = Temperature, newShutDownTemp;
float newCoolingRate, newFissionRate;
try
{
newAutoTemp = message.ReadBoolean();
if (GameMain.Server == null)
{
newTemperature = message.ReadRangedSingle(0.0f, 10000.0f, 16);
}
newShutDownTemp = message.ReadRangedSingle(0.0f, 10000.0f, 8);
newShutDownTemp = MathUtils.RoundTowardsClosest(newShutDownTemp, 100.0f);
newCoolingRate = message.ReadRangedSingle(0.0f, 100.0f, 8);
newFissionRate = message.ReadRangedSingle(0.0f, 100.0f, 8);
}
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("invalid network message", e);
#endif
return;
}
AutoTemp = newAutoTemp;
Temperature = newTemperature;
ShutDownTemp = newShutDownTemp;
CoolingRate = newCoolingRate;
FissionRate = newFissionRate;
lastUpdate = sendingTime;
if (GameMain.Server == null) return;
var sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender != null)
{
Networking.GameServer.Log(
"Reactor settings adjusted by " + sender.name+": \n"+
"Autotemp: " + (autoTemp ? "ON " : "OFF") + " Shutdown temp: " + shutDownTemp +
" Cooling rate: " + (int)coolingRate + " Fission rate: " + (int)fissionRate,
Color.Orange);
}
}
}
}