diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs index 0fba6f5c5..bad788bc1 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs @@ -172,13 +172,17 @@ namespace Barotrauma.Items.Components if (draggingConnected.Connect(this, !alreadyConnected, true)) { - GameServer.Log(item.Name + " rewired by " + Character.Controlled.Name, ServerLog.MessageType.ItemInteraction); - var otherConnection = draggingConnected.OtherConnection(this); - - GameServer.Log(item.Name + " rewired by " + Character.Controlled.Name + ": " + - Name + " -> " + - (otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.ItemInteraction); + if (otherConnection == null) + { + GameServer.Log(Character.Controlled + " connected a wire to " + + 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; } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs index 9704cd3db..b3f4b4daa 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs @@ -143,14 +143,15 @@ namespace Barotrauma.Items.Components public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { - int[] wireCounts = new int[Connections.Count]; - Wire[,] wires = new Wire[Connections.Count, Connection.MaxLinked]; + List[] wires = new List[Connections.Count]; //read wire IDs for each connection for (int i = 0; i < Connections.Count; i++) { - wireCounts[i] = msg.ReadRangedInteger(0, Connection.MaxLinked); - for (int j = 0; j < wireCounts[i]; j++) + wires[i] = new List(); + + int wireCount = msg.ReadRangedInteger(0, Connection.MaxLinked); + for (int j = 0; j < wireCount; j++) { ushort wireId = msg.ReadUInt16(); @@ -160,7 +161,7 @@ namespace Barotrauma.Items.Components Wire wireComponent = wireItem.GetComponent(); if (wireComponent != null) { - wires[i, j] = wireComponent; + wires[i].Add(wireComponent); } } } @@ -170,67 +171,82 @@ namespace Barotrauma.Items.Components //check if the character can access this connectionpanel //and all the wires they're trying to connect 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) // -> we need to check if the client has access to it if (!Connections.Any(connection => connection.Wires.Contains(wire))) { if (!wire.Item.CanClientAccess(c)) return; - } + } } } - //update the connections + //go through existing wire links for (int i = 0; i < Connections.Count; i++) { - Wire[] prevWires = new Wire[Connections[i].Wires.Length]; - Array.Copy(Connections[i].Wires, prevWires, prevWires.Length); - - Connections[i].ClearConnections(); - - for (int j = 0; j < wireCounts[i]; j++) + for (int j = 0; j < Connection.MaxLinked; 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 " + - 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); - } + GameServer.Log(c.Character.Name + " disconnected a wire from " + + Connections[i].Item.Name + " (" + Connections[i].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; + } + + } + } + + //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); } - - //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); } } - } public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs index 78477ed5a..c55837842 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs @@ -304,18 +304,18 @@ namespace Barotrauma.Items.Components { 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[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction); } 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); } 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); } }