Finalize networking service

This commit is contained in:
Evil Factory
2026-02-08 15:03:03 -03:00
parent ce4cd1fefd
commit 705137e993
4 changed files with 21 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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))
{

View File

@@ -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);
}