protected virtual void HandleClientCallFunction(LiteNetLibMessageHandler messageHandler) { NetDataReader reader = messageHandler.reader; FunctionReceivers receivers = (FunctionReceivers)reader.GetByte(); long connectionId = -1; if (receivers == FunctionReceivers.Target) { connectionId = (long)reader.GetPackedULong(); } LiteNetLibElementInfo info = LiteNetLibElementInfo.DeserializeInfo(reader); LiteNetLibIdentity identity; if (Assets.TryGetSpawnedObject(info.objectId, out identity)) { if (receivers == FunctionReceivers.Server) { identity.ProcessNetFunction(info, reader, true); } else { LiteNetLibFunction netFunction = identity.ProcessNetFunction(info, reader, false); // Use call with out parameters set because parameters already set while process net function if (receivers == FunctionReceivers.Target) { netFunction.CallWithoutParametersSet(connectionId); } else { netFunction.CallWithoutParametersSet(DeliveryMethod.ReliableOrdered, receivers); } } } }
protected virtual void HandleClientCallFunction(LiteNetLibMessageHandler messageHandler) { NetDataReader reader = messageHandler.reader; FunctionReceivers receivers = (FunctionReceivers)reader.GetByte(); long connectionId = -1; if (receivers == FunctionReceivers.Target) { connectionId = reader.GetPackedLong(); } LiteNetLibElementInfo info = LiteNetLibElementInfo.DeserializeInfo(reader); LiteNetLibIdentity identity; if (Assets.TryGetSpawnedObject(info.objectId, out identity)) { LiteNetLibFunction netFunction = identity.GetNetFunction(info); if (netFunction == null) { // There is no net function that player try to call (player may try to hack) return; } if (!netFunction.CanCallByEveryone && messageHandler.connectionId != identity.ConnectionId) { // The function not allowed anyone except owner client to call this net function // And the client is also not the owner client return; } if (receivers == FunctionReceivers.Server) { // Request from client to server, so hook callback at server immediately identity.ProcessNetFunction(netFunction, reader, true); } else { // Request from client to other clients, so hook callback later identity.ProcessNetFunction(netFunction, reader, false); // Use call with out parameters set because parameters already set while process net function if (receivers == FunctionReceivers.Target) { netFunction.CallWithoutParametersSet(connectionId); } else { netFunction.CallWithoutParametersSet(DeliveryMethod.ReliableOrdered, receivers); } } } }