| 774 | } |
| 775 | |
| 776 | void 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); |
no test coverage detected