diff --git a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/NetworkingService.cs b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/NetworkingService.cs index 7381d416d..578e5c50f 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/NetworkingService.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/LuaCs/Services/NetworkingService.cs @@ -47,7 +47,7 @@ partial class NetworkingService : INetworkingService, IEventConnectedToServer, I WriteOnlyMessage message = new WriteOnlyMessage(); message.WriteByte((byte)ClientPacketHeader.LUA_NET_MESSAGE); - message.WriteByte((byte)ClientToServer.RequestAllNetIds); + message.WriteByte((byte)ClientToServer.RequestSync); GameMain.Client.ClientPeer.Send(message, DeliveryMethod.Reliable); } diff --git a/Barotrauma/BarotraumaServer/ServerSource/LuaCs/Services/NetworkingService.cs b/Barotrauma/BarotraumaServer/ServerSource/LuaCs/Services/NetworkingService.cs index f2bed92ae..fd5bcd90c 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/LuaCs/Services/NetworkingService.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/LuaCs/Services/NetworkingService.cs @@ -56,8 +56,8 @@ partial class NetworkingService : INetworkingService, IEventClientRawNetMessageR HandleNetMessageId(netMessage, client); break; - case ClientToServer.RequestAllNetIds: - WriteAllIds(client); + case ClientToServer.RequestSync: + WriteSync(client); break; case ClientToServer.RequestSingleNetId: @@ -144,7 +144,7 @@ partial class NetworkingService : INetworkingService, IEventClientRawNetMessageR SendToClient(message, null, DeliveryMethod.Reliable); } - private void WriteAllIds(Client client) + private void WriteSync(Client client) { WriteOnlyMessage message = new WriteOnlyMessage(); message.WriteByte((byte)ServerPacketHeader.LUA_NET_MESSAGE); @@ -158,6 +158,12 @@ partial class NetworkingService : INetworkingService, IEventClientRawNetMessageR } SendToClient(message, client.Connection, DeliveryMethod.Reliable); + + // TODO: when we move to using GUIDs for everything, this should combined into a single message + foreach (INetworkSyncVar netVar in netVars.Keys) + { + SendNetVar(netVar, client.Connection); + } } public void SendToClient(IWriteMessage netMessage, NetworkConnection connection = null, DeliveryMethod deliveryMethod = DeliveryMethod.Reliable) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs index 261621bbf..834fbb6b7 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/NetworkingService.cs @@ -38,7 +38,7 @@ internal partial class NetworkingService : INetworkingService NetMessageInternalId, NetMessageNetId, RequestSingleNetId, - RequestAllNetIds, + RequestSync, } private enum ServerToClient @@ -184,11 +184,19 @@ internal partial class NetworkingService : INetworkingService } netVar.ReadNetMessage(message); + + // Sync back to all clients + if (netVar.SyncType != NetSync.ClientOneWay) + { + SendNetVar(netVar); + } }); #endif } - public void SendNetVar(INetworkSyncVar netVar) + public void SendNetVar(INetworkSyncVar netVar) => SendNetVar(netVar); + + public void SendNetVar(INetworkSyncVar netVar, NetworkConnection connection = null) { if (!netVars.TryGetValue(netVar, out NetId netId)) { diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/INetworkingService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/INetworkingService.cs index 7d6ac2930..d72b2c303 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/INetworkingService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/_Interfaces/INetworkingService.cs @@ -34,4 +34,5 @@ public interface IEntityNetworkingService Guid GetNetworkIdForInstance(INetworkSyncVar var); void RegisterNetVar(INetworkSyncVar netVar); void SendNetVar(INetworkSyncVar netVar); + void SendNetVar(INetworkSyncVar netVar, NetworkConnection connection); }