Exemplo n.º 1
0
        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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected virtual void HandleClientUpdateSyncField(LiteNetLibMessageHandler messageHandler)
        {
            // Field updated at owner-client, if this is server then multicast message to other clients
            if (!IsServer)
            {
                return;
            }
            NetDataReader         reader = messageHandler.reader;
            LiteNetLibElementInfo info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity    identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                LiteNetLibSyncField syncField = identity.Behaviours[info.behaviourIndex].GetSyncField(info);
                // Sync field at server also have to be client multicast to allow it to multicast to other clients
                if (syncField != null && syncField.syncMode == LiteNetLibSyncField.SyncMode.ClientMulticast)
                {
                    // If this is not host, set data then pass to other clients because host already set data
                    if (!identity.IsOwnerClient)
                    {
                        syncField.Deserialize(reader, false);
                    }
                    // Send to other clients
                    foreach (long connectionId in GetConnectionIds())
                    {
                        if (identity.IsSubscribedOrOwning(connectionId))
                        {
                            syncField.SendUpdate(false, connectionId);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected virtual void HandleClientCallFunction(LiteNetLibMessageHandler messageHandler)
        {
            var reader = messageHandler.reader;
            FunctionReceivers receivers = (FunctionReceivers)reader.GetByte();
            long connectId = 0;

            if (receivers == FunctionReceivers.Target)
            {
                connectId = (long)reader.GetPackedULong();
            }
            var info = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                if (receivers == FunctionReceivers.Server)
                {
                    identity.ProcessNetFunction(info, reader, true);
                }
                else
                {
                    var netFunction = identity.ProcessNetFunction(info, reader, false);
                    if (receivers == FunctionReceivers.Target)
                    {
                        netFunction.Call(connectId);
                    }
                    else
                    {
                        netFunction.Call(receivers);
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected virtual void HandleServerCallFunction(LiteNetLibMessageHandler messageHandler)
        {
            NetDataReader         reader = messageHandler.reader;
            LiteNetLibElementInfo info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity    identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                identity.ProcessNetFunction(info, reader, true);
            }
        }
Exemplo n.º 5
0
        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);
                    }
                }
            }
        }
Exemplo n.º 6
0
        protected virtual void HandleServerUpdateSyncList(LiteNetLibMessageHandler messageHandler)
        {
            // List updated at server, if this is host (client and server) then skip it.
            if (IsServer)
            {
                return;
            }
            NetDataReader         reader = messageHandler.reader;
            LiteNetLibElementInfo info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity    identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                identity.ProcessSyncList(info, reader);
            }
        }
Exemplo n.º 7
0
        protected virtual void HandleClientUpdateSyncField(LiteNetLibMessageHandler messageHandler)
        {
            // Field updated at owner-client, if this is server then multicast message to other clients
            if (!IsServer)
            {
                return;
            }
            NetDataReader         reader = messageHandler.reader;
            LiteNetLibElementInfo info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity    identity;

            if (Assets.TryGetSpawnedObject(info.objectId, out identity))
            {
                LiteNetLibSyncField syncField = identity.GetSyncField(info);
                // Sync field at server also have to be client multicast to allow it to multicast to other clients
                if (syncField != null && syncField.syncMode == LiteNetLibSyncField.SyncMode.ClientMulticast)
                {
                    // If this is server but it is not host, set data (deserialize) then pass to other clients
                    // If this is host don't set data because it's already did (in LiteNetLibSyncField class)
                    if (!identity.IsOwnerClient)
                    {
                        syncField.Deserialize(reader, false);
                    }
                    // Send to other clients
                    foreach (long connectionId in GetConnectionIds())
                    {
                        // Don't send the update to owner client because it was updated before send update to server
                        if (connectionId == messageHandler.connectionId)
                        {
                            continue;
                        }
                        // Send update to clients except owner client
                        if (identity.IsSubscribedOrOwning(connectionId))
                        {
                            syncField.SendUpdate(false, connectionId);
                        }
                    }
                }
            }
        }