Clients can't send wire positions to the server

This commit is contained in:
Regalis
2017-05-03 21:28:09 +03:00
parent ab4e8cee83
commit 464078e565
2 changed files with 7 additions and 32 deletions
@@ -227,7 +227,7 @@ namespace Barotrauma.Items.Components
if (wires[i, j] == null) continue; if (wires[i, j] == null) continue;
Connections[i].Wires[j] = wires[i,j]; Connections[i].Wires[j] = wires[i,j];
wires[i, j].Connect(Connections[i], false); wires[i, j].Connect(Connections[i], true);
var otherConnection = Connections[i].Wires[j].OtherConnection(Connections[i]); var otherConnection = Connections[i].Wires[j].OtherConnection(Connections[i]);
@@ -11,7 +11,7 @@ using System.Xml.Linq;
namespace Barotrauma.Items.Components namespace Barotrauma.Items.Components
{ {
class Wire : ItemComponent, IDrawableComponent, IServerSerializable, IClientSerializable class Wire : ItemComponent, IDrawableComponent, IServerSerializable
{ {
class WireSection class WireSection
{ {
@@ -202,10 +202,6 @@ namespace Barotrauma.Items.Components
{ {
item.CreateServerEvent(this); item.CreateServerEvent(this);
} }
else if (GameMain.Client != null)
{
item.CreateClientEvent(this);
}
//the wire is active if only one end has been connected //the wire is active if only one end has been connected
IsActive = connections[0] == null ^ connections[1] == null; IsActive = connections[0] == null ^ connections[1] == null;
} }
@@ -716,7 +712,7 @@ namespace Barotrauma.Items.Components
base.RemoveComponentSpecific(); base.RemoveComponentSpecific();
} }
public void ClientWrite(NetBuffer msg, object[] extraData = null) public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
{ {
msg.Write((byte)Math.Min(nodes.Count, 255)); msg.Write((byte)Math.Min(nodes.Count, 255));
for (int i = 0; i < Math.Min(nodes.Count, 255); i++) for (int i = 0; i < Math.Min(nodes.Count, 255); i++)
@@ -726,7 +722,7 @@ namespace Barotrauma.Items.Components
} }
} }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{ {
nodes.Clear(); nodes.Clear();
@@ -738,7 +734,6 @@ namespace Barotrauma.Items.Components
nodePositions[i] = new Vector2(msg.ReadFloat(), msg.ReadFloat()); nodePositions[i] = new Vector2(msg.ReadFloat(), msg.ReadFloat());
} }
if (!item.CanClientAccess(c)) return;
if (nodePositions.Any(n => !MathUtils.IsValid(n))) return; if (nodePositions.Any(n => !MathUtils.IsValid(n))) return;
nodes = nodePositions.ToList(); nodes = nodePositions.ToList();
@@ -747,25 +742,5 @@ namespace Barotrauma.Items.Components
Drawable = nodes.Any(); Drawable = nodes.Any();
} }
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
{
ClientWrite(msg, extraData);
}
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
nodes.Clear();
int nodeCount = msg.ReadByte();
for (int i = 0; i < nodeCount; i++)
{
Vector2 newNode = new Vector2(msg.ReadFloat(), msg.ReadFloat());
if (MathUtils.IsValid(newNode)) nodes.Add(newNode);
}
UpdateSections();
Drawable = nodes.Any();
}
} }
} }