MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SendRpc

Function SendRpc

Source/Engine/Networking/NetworkReplicator.cpp:776–840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

774}
775
776void SendRpc(RpcSendItem& e)
777{
778 ScriptingObject* obj = e.Object.Get();
779 if (!obj)
780 return;
781 auto it = Objects.Find(obj->GetID());
782 if (it == Objects.End())
783 {
784#if !BUILD_RELEASE
785 if (!DespawnedObjects.Contains(obj->GetID()))
786 LOG(Error, "Cannot invoke RPC method '{0}.{1}' on object '{2}' that is not registered in networking (use 'NetworkReplicator.AddObject').", e.Name.First.ToString(), e.Name.Second.ToString(), obj->GetID());
787#endif
788 return;
789 }
790 auto& item = it->Item;
791 if (e.ArgsData.Length() > MAX_uint16)
792 {
793 LOG(Error, "Too much data for object RPC method '{}.{}' on object '{}' ({} bytes provided while limit is {}).", e.Name.First.ToString(), e.Name.Second.ToString(), obj->GetID(), e.ArgsData.Length(), MAX_uint16);
794 return;
795 }
796 const NetworkManagerMode mode = NetworkManager::Mode;
797 NetworkPeer* peer = NetworkManager::Peer;
798
799 bool toServer;
800 if (e.Info.Server && mode == NetworkManagerMode::Client)
801 {
802 // Client -> Server
803#if USE_NETWORK_REPLICATOR_LOG
804 if (e.Targets.Length() != 0)
805 NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Server RPC '{}.{}' called with non-empty list of targets is not supported (only server will receive it)", e.Name.First.ToString(), e.Name.Second.ToString());
806#endif
807 toServer = true;
808 }
809 else if (e.Info.Client && (mode == NetworkManagerMode::Server || mode == NetworkManagerMode::Host))
810 {
811 // Server -> Client(s)
812 BuildCachedTargets(NetworkManager::Clients, item.TargetClientIds, e.Targets, NetworkManager::LocalClientId);
813 if (CachedTargets.IsEmpty())
814 return;
815 toServer = false;
816 }
817 else
818 return;
819
820 // Send RPC message
821 //NETWORK_REPLICATOR_LOG(Info, "[NetworkReplicator] Rpc {}.{} object ID={}", e.Name.First.ToString(), e.Name.Second.ToString(), item.ToString());
822 NetworkMessageObjectRpc msgData;
823 msgData.OwnerFrame = ++RpcId;
824 Guid objectId = item.ObjectId;
825 Guid parentId = item.ParentId;
826 {
827 // Remap local client object ids into server ids
828 IdsRemappingTable.KeyOf(objectId, &objectId);
829 IdsRemappingTable.KeyOf(parentId, &parentId);
830 }
831 NetworkMessage msg = peer->BeginSendMessage();
832 msg.WriteStructure(msgData);
833 msg.WriteNetworkId(objectId);

Callers 1

Calls 14

BuildCachedTargetsFunction · 0.85
SendInPartsFunction · 0.85
GetIDMethod · 0.80
BeginSendMessageMethod · 0.80
WriteNetworkIdMethod · 0.80
WriteNetworkNameMethod · 0.80
GetMethod · 0.45
FindMethod · 0.45
EndMethod · 0.45
ContainsMethod · 0.45
ToStringMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected