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
@@ -141,60 +141,5 @@ namespace Barotrauma.Items.Components
}
}
public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetBuffer message)
{
foreach (Connection c in Connections)
{
Wire[] wires = Array.FindAll(c.Wires, w => w != null);
message.WriteRangedInteger(0, Connection.MaxLinked, wires.Length);
for (int i = 0 ; i < wires.Length; i++)
{
message.Write(wires[i].Item.ID);
}
}
return true;
}
public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message, float sendingTime)
{
if (GameMain.Server != null)
{
var sender = GameMain.Server.ConnectedClients.Find(c => c.Connection == message.SenderConnection);
if (sender != null)
{
Networking.GameServer.Log(item.Name + " rewired by " + sender.name, Color.Orange);
}
}
System.Diagnostics.Debug.WriteLine("connectionpanel update");
foreach (Connection c in Connections)
{
//int wireCount = c.Wires.Length;
c.ClearConnections();
int wireCount = message.ReadRangedInteger(0, Connection.MaxLinked);
for (int i = 0; i < wireCount; i++)
{
ushort wireId = message.ReadUInt16();
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
if (wireItem == null) continue;
Wire wireComponent = wireItem.GetComponent<Wire>();
if (wireComponent == null) continue;
c.Wires[i] = wireComponent;
wireComponent.Connect(c, false);
var otherConnection = c.Wires[i].OtherConnection(c);
Networking.GameServer.Log(
item.Name+" ("+ c.Name + ") -> " +
(otherConnection == null ? "none" : otherConnection.Item.Name+" ("+(otherConnection.Name)+")"), Color.Orange);
}
c.UpdateRecipients();
}
}
}
}