Skip to content

Commit 4d7bcb4

Browse files
committed
Fixed RPC issues
1 parent 5c5eba3 commit 4d7bcb4

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,9 @@ internal void OnRemoteServerRPC(ulong hash, uint senderClientId, Stream stream)
460460

461461
internal void OnRemoteClientRPC(ulong hash, uint senderClientId, Stream stream)
462462
{
463-
if (!CachedServerRpcs.ContainsKey(GetType()) || !CachedServerRpcs[GetType()].ContainsKey(hash))
463+
if (!CachedClientRpcs.ContainsKey(GetType()) || !CachedClientRpcs[GetType()].ContainsKey(hash))
464464
{
465-
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("ServerRPC request method not found");
465+
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("ClientRPC request method not found");
466466
return;
467467
}
468468
InvokeClientRPCLocal(hash, senderClientId, stream);
@@ -551,7 +551,7 @@ internal void SendClientRPCBoxed(ulong hash, uint clientId, params object[] para
551551
}
552552
}
553553

554-
internal void SendServerRPCPerformance(ulong hash, Stream stream)
554+
internal void SendServerRPCPerformance(ulong hash, Stream messageStream)
555555
{
556556
if (!isClient)
557557
{
@@ -560,12 +560,22 @@ internal void SendServerRPCPerformance(ulong hash, Stream stream)
560560
return;
561561
}
562562

563-
if (isHost)
564-
{
565-
InvokeServerRPCLocal(hash, NetworkingManager.singleton.LocalClientId, stream);
566-
}
563+
using (PooledBitStream stream = PooledBitStream.Get())
564+
{
565+
BitWriter messageWriter = new BitWriter(stream);
566+
messageWriter.WriteUInt32Packed(networkId);
567+
messageWriter.WriteUInt16Packed(networkedObject.GetOrderIndex(this));
568+
messageWriter.WriteUInt64Packed(hash);
569+
570+
stream.CopyFrom(messageStream);
571+
572+
if (isHost)
573+
{
574+
InvokeServerRPCLocal(hash, NetworkingManager.singleton.LocalClientId, messageStream);
575+
}
567576

568-
InternalMessageHandler.Send(NetworkingManager.singleton.NetworkConfig.NetworkTransport.ServerNetId, "MLAPI_SERVER_RPC", "MLAPI_DEFAULT_MESSAGE", stream);
577+
InternalMessageHandler.Send(NetworkingManager.singleton.NetworkConfig.NetworkTransport.ServerNetId, "MLAPI_SERVER_RPC", "MLAPI_DEFAULT_MESSAGE", stream);
578+
}
569579
}
570580

571581
internal void SendClientRPCPerformance(ulong hash, List<uint> clientIds, Stream messageStream)
@@ -592,7 +602,7 @@ internal void SendClientRPCPerformance(ulong hash, List<uint> clientIds, Stream
592602
{
593603
if (isHost && NetworkingManager.singleton.ConnectedClientsList[i].ClientId == NetworkingManager.singleton.LocalClientId)
594604
{
595-
InvokeClientRPCLocal(hash, NetworkingManager.singleton.LocalClientId, stream);
605+
InvokeClientRPCLocal(hash, NetworkingManager.singleton.LocalClientId, messageStream);
596606
}
597607
else
598608
{
@@ -606,7 +616,7 @@ internal void SendClientRPCPerformance(ulong hash, List<uint> clientIds, Stream
606616
{
607617
if (isHost && clientIds[i] == NetworkingManager.singleton.LocalClientId)
608618
{
609-
InvokeClientRPCLocal(hash, NetworkingManager.singleton.LocalClientId, stream);
619+
InvokeClientRPCLocal(hash, NetworkingManager.singleton.LocalClientId, messageStream);
610620
}
611621
else
612622
{
@@ -637,7 +647,7 @@ internal void SendClientRPCPerformance(ulong hash, uint clientId, Stream message
637647

638648
if (isHost && clientId == NetworkingManager.singleton.LocalClientId)
639649
{
640-
InvokeClientRPCLocal(hash, NetworkingManager.singleton.LocalClientId, stream);
650+
InvokeClientRPCLocal(hash, NetworkingManager.singleton.LocalClientId, messageStream);
641651
}
642652
else
643653
{

0 commit comments

Comments
 (0)