Fixed crashing when a client clears connections of a wire (because the logging attempted to access Character.Controlled instead of the client's character), fixed the (completely broken) ConnectionPanel.ServerRead
This commit is contained in:
@@ -172,13 +172,17 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
if (draggingConnected.Connect(this, !alreadyConnected, true))
|
if (draggingConnected.Connect(this, !alreadyConnected, true))
|
||||||
{
|
{
|
||||||
GameServer.Log(item.Name + " rewired by " + Character.Controlled.Name, ServerLog.MessageType.ItemInteraction);
|
|
||||||
|
|
||||||
var otherConnection = draggingConnected.OtherConnection(this);
|
var otherConnection = draggingConnected.OtherConnection(this);
|
||||||
|
if (otherConnection == null)
|
||||||
GameServer.Log(item.Name + " rewired by " + Character.Controlled.Name + ": " +
|
{
|
||||||
Name + " -> " +
|
GameServer.Log(Character.Controlled + " connected a wire to " +
|
||||||
(otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.ItemInteraction);
|
Item.Name + " (" + Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameServer.Log(Character.Controlled + " connected a wire from " +
|
||||||
|
Item.Name + " (" + Name + ") to " + otherConnection.item.Name + " (" + otherConnection.Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
Wires[index] = draggingConnected;
|
Wires[index] = draggingConnected;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,14 +143,15 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
|
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
|
||||||
{
|
{
|
||||||
int[] wireCounts = new int[Connections.Count];
|
List<Wire>[] wires = new List<Wire>[Connections.Count];
|
||||||
Wire[,] wires = new Wire[Connections.Count, Connection.MaxLinked];
|
|
||||||
|
|
||||||
//read wire IDs for each connection
|
//read wire IDs for each connection
|
||||||
for (int i = 0; i < Connections.Count; i++)
|
for (int i = 0; i < Connections.Count; i++)
|
||||||
{
|
{
|
||||||
wireCounts[i] = msg.ReadRangedInteger(0, Connection.MaxLinked);
|
wires[i] = new List<Wire>();
|
||||||
for (int j = 0; j < wireCounts[i]; j++)
|
|
||||||
|
int wireCount = msg.ReadRangedInteger(0, Connection.MaxLinked);
|
||||||
|
for (int j = 0; j < wireCount; j++)
|
||||||
{
|
{
|
||||||
ushort wireId = msg.ReadUInt16();
|
ushort wireId = msg.ReadUInt16();
|
||||||
|
|
||||||
@@ -160,7 +161,7 @@ namespace Barotrauma.Items.Components
|
|||||||
Wire wireComponent = wireItem.GetComponent<Wire>();
|
Wire wireComponent = wireItem.GetComponent<Wire>();
|
||||||
if (wireComponent != null)
|
if (wireComponent != null)
|
||||||
{
|
{
|
||||||
wires[i, j] = wireComponent;
|
wires[i].Add(wireComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,9 +171,9 @@ namespace Barotrauma.Items.Components
|
|||||||
//check if the character can access this connectionpanel
|
//check if the character can access this connectionpanel
|
||||||
//and all the wires they're trying to connect
|
//and all the wires they're trying to connect
|
||||||
if (!item.CanClientAccess(c)) return;
|
if (!item.CanClientAccess(c)) return;
|
||||||
foreach (Wire wire in wires)
|
for (int i = 0; i < Connections.Count; i++)
|
||||||
{
|
{
|
||||||
if (wire != null)
|
foreach (Wire wire in wires[i])
|
||||||
{
|
{
|
||||||
//wire not found in any of the connections yet (client is trying to connect a new wire)
|
//wire not found in any of the connections yet (client is trying to connect a new wire)
|
||||||
// -> we need to check if the client has access to it
|
// -> we need to check if the client has access to it
|
||||||
@@ -183,54 +184,69 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the connections
|
//go through existing wire links
|
||||||
for (int i = 0; i < Connections.Count; i++)
|
for (int i = 0; i < Connections.Count; i++)
|
||||||
{
|
{
|
||||||
Wire[] prevWires = new Wire[Connections[i].Wires.Length];
|
for (int j = 0; j < Connection.MaxLinked; j++)
|
||||||
Array.Copy(Connections[i].Wires, prevWires, prevWires.Length);
|
|
||||||
|
|
||||||
Connections[i].ClearConnections();
|
|
||||||
|
|
||||||
for (int j = 0; j < wireCounts[i]; j++)
|
|
||||||
{
|
{
|
||||||
if (wires[i, j] == null)
|
Wire existingWire = Connections[i].Wires[j];
|
||||||
|
if (existingWire == null) continue;
|
||||||
|
|
||||||
|
//existing wire not in the list of new wires -> disconnect it
|
||||||
|
if (!wires[i].Contains(existingWire))
|
||||||
{
|
{
|
||||||
if (prevWires[j] != null)
|
existingWire.RemoveConnection(item);
|
||||||
|
|
||||||
|
if (existingWire.Connections[0] == null && existingWire.Connections[1] == null)
|
||||||
{
|
{
|
||||||
if (prevWires[j].Connections[0] != null && prevWires[j].Connections[1] != null)
|
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
||||||
{
|
Connections[i].Item.Name + " (" + Connections[i].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
|
||||||
prevWires[j].Connections[0].Item.Name + " (" + prevWires[j].Connections[0].Name + ") to " +
|
|
||||||
prevWires[j].Connections[1].Item.Name + " (" + prevWires[j].Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
|
||||||
}
|
|
||||||
else if (prevWires[j].Connections[0] != null)
|
|
||||||
{
|
|
||||||
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
|
||||||
prevWires[j].Connections[0].Item.Name + " (" + prevWires[j].Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
|
|
||||||
}
|
|
||||||
else if (prevWires[j].Connections[1] != null)
|
|
||||||
{
|
|
||||||
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
|
||||||
prevWires[j].Connections[1].Item.Name + " (" + prevWires[j].Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
else if (existingWire.Connections[0] != null)
|
||||||
|
{
|
||||||
|
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
||||||
|
Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
|
}
|
||||||
|
else if (existingWire.Connections[1] != null)
|
||||||
|
{
|
||||||
|
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
||||||
|
Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections[i].Wires[j] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//already connected, no need to do anything
|
|
||||||
if (wires[i, j] == prevWires[j]) continue;
|
|
||||||
|
|
||||||
Connections[i].Wires[j] = wires[i,j];
|
|
||||||
wires[i, j].Connect(Connections[i], true);
|
|
||||||
|
|
||||||
var otherConnection = Connections[i].Wires[j].OtherConnection(Connections[i]);
|
|
||||||
|
|
||||||
GameServer.Log(item.Name + " rewired by " + c.Character.Name+ ": " +
|
|
||||||
Connections[i].Name + " -> " +
|
|
||||||
(otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.ItemInteraction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go through new wires
|
||||||
|
for (int i = 0; i < Connections.Count; i++)
|
||||||
|
{
|
||||||
|
foreach (Wire newWire in wires[i])
|
||||||
|
{
|
||||||
|
//already connected, no need to do anything
|
||||||
|
if (Connections[i].Wires.Contains(newWire)) continue;
|
||||||
|
|
||||||
|
Connections[i].TryAddLink(newWire);
|
||||||
|
newWire.Connect(Connections[i]);
|
||||||
|
|
||||||
|
var otherConnection = newWire.OtherConnection(Connections[i]);
|
||||||
|
|
||||||
|
if (otherConnection == null)
|
||||||
|
{
|
||||||
|
GameServer.Log(c.Character.Name + " connected a wire to " +
|
||||||
|
Connections[i].Item.Name + " (" + Connections[i].Name + ")",
|
||||||
|
ServerLog.MessageType.ItemInteraction);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameServer.Log(c.Character.Name + " connected a wire from " +
|
||||||
|
Connections[i].Item.Name + " (" + Connections[i].Name + ") to " +
|
||||||
|
(otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"),
|
||||||
|
ServerLog.MessageType.ItemInteraction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
|
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
|
||||||
|
|||||||
@@ -304,18 +304,18 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
if (connections[0] != null && connections[1] != null)
|
if (connections[0] != null && connections[1] != null)
|
||||||
{
|
{
|
||||||
GameServer.Log(Character.Controlled.Name + " disconnected a wire from " +
|
GameServer.Log(user.Name + " disconnected a wire from " +
|
||||||
connections[0].Item.Name + " (" + connections[0].Name + ") to "+
|
connections[0].Item.Name + " (" + connections[0].Name + ") to "+
|
||||||
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
}
|
}
|
||||||
else if (connections[0] != null)
|
else if (connections[0] != null)
|
||||||
{
|
{
|
||||||
GameServer.Log(Character.Controlled.Name + " disconnected a wire from " +
|
GameServer.Log(user.Name + " disconnected a wire from " +
|
||||||
connections[0].Item.Name + " (" + connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
|
connections[0].Item.Name + " (" + connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
}
|
}
|
||||||
else if (connections[1] != null)
|
else if (connections[1] != null)
|
||||||
{
|
{
|
||||||
GameServer.Log(Character.Controlled.Name + " disconnected a wire from " +
|
GameServer.Log(user.Name + " disconnected a wire from " +
|
||||||
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user