Пример #1
0
        protected internal void SendRpcInternal(Type invokeClass, string rpcName, NetworkWriter writer, int channelId, bool excludeOwner)
        {
            // this was in Weaver before
            if (!Server || !Server.Active)
            {
                throw new InvalidOperationException("RPC Function " + rpcName + " called on Client.");
            }
            // This cannot use Server.active, as that is not specific to this object.
            if (!IsServer)
            {
                if (logger.WarnEnabled())
                {
                    logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
                }
                return;
            }

            // construct the message
            var message = new RpcMessage
            {
                netId          = NetId,
                componentIndex = ComponentIndex,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, rpcName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            // The public facing parameter is excludeOwner in [ClientRpc]
            // so we negate it here to logically align with SendToReady.
            bool includeOwner = !excludeOwner;

            NetIdentity.SendToObservers(message, includeOwner, channelId);
        }