Beispiel #1
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);
                    }
                }
            }
        }
Beispiel #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);
                        }
                    }
                }
            }
        }
Beispiel #3
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);
                    }
                }
            }
        }
        public LiteNetLibFunction ProcessNetFunction(LiteNetLibElementInfo info, NetDataReader reader, bool hookCallback)
        {
            if (info.objectId != ObjectId)
            {
                return(null);
            }
            var elementId = info.elementId;

            if (elementId >= 0 && elementId < netFunctions.Count)
            {
                var netFunction = netFunctions[elementId];
                netFunction.DeserializeParameters(reader);
                if (hookCallback)
                {
                    netFunction.HookCallback();
                }
                return(netFunction);
            }
            else
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot process net function, functionId [" + info.elementId + "] not found.");
                }
            }
            return(null);
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
 internal LiteNetLibSyncList GetSyncList(LiteNetLibElementInfo info)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.elementId >= 0 && info.elementId < syncLists.Count)
     {
         return(syncLists[info.elementId]);
     }
     return(null);
 }
 internal LiteNetLibSyncList ProcessSyncList(LiteNetLibElementInfo info, NetDataReader reader)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.behaviourIndex >= Behaviours.Length)
     {
         return(null);
     }
     return(Behaviours[info.behaviourIndex].ProcessSyncList(info, reader));
 }
 internal LiteNetLibFunction ProcessNetFunction(LiteNetLibElementInfo info, NetDataReader reader, bool hookCallback)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.behaviourIndex >= Behaviours.Length)
     {
         return(null);
     }
     return(Behaviours[info.behaviourIndex].ProcessNetFunction(info, reader, hookCallback));
 }
Beispiel #9
0
 internal LiteNetLibFunction GetNetFunction(LiteNetLibElementInfo info)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.elementId >= 0 && info.elementId < netFunctions.Count)
     {
         return(netFunctions[info.elementId]);
     }
     return(null);
 }
Beispiel #10
0
 internal LiteNetLibSyncField ProcessSyncField(LiteNetLibElementInfo info, NetDataReader reader, bool isInitial)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.behaviourIndex >= Behaviours.Length)
     {
         return(null);
     }
     return(Behaviours[info.behaviourIndex].ProcessSyncField(info, reader, isInitial));
 }
Beispiel #11
0
        internal LiteNetLibSyncField ProcessSyncField(LiteNetLibElementInfo info, NetDataReader reader, bool isInitial)
        {
            LiteNetLibSyncField syncField = GetSyncField(info);

            if (syncField == null)
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot process sync field, fieldId [" + info.elementId + "] not found.");
                }
                return(null);
            }
            syncField.Deserialize(reader, isInitial);
            return(syncField);
        }
Beispiel #12
0
        internal LiteNetLibSyncList ProcessSyncList(LiteNetLibElementInfo info, NetDataReader reader)
        {
            LiteNetLibSyncList syncList = GetSyncList(info);

            if (syncList == null)
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot process sync list, fieldId [" + info.elementId + "] not found.");
                }
                return(null);
            }
            syncList.DeserializeOperation(reader);
            return(syncList);
        }
Beispiel #13
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);
                    }
                }
            }
        }
 internal LiteNetLibSyncList GetSyncList(LiteNetLibElementInfo info)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.elementId >= 0 && info.elementId < SyncLists.Count)
     {
         return(SyncLists[info.elementId]);
     }
     if (Manager.LogError)
     {
         Logging.LogError(LogTag, $"Cannot find sync list: {info.elementId}.");
     }
     return(null);
 }
 internal LiteNetLibFunction GetNetFunction(LiteNetLibElementInfo info)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.elementId >= 0 && info.elementId < NetFunctions.Count)
     {
         return(NetFunctions[info.elementId]);
     }
     if (Manager.LogError)
     {
         Logging.LogError(LogTag, $"Cannot find net function: {info.elementId}.");
     }
     return(null);
 }
Beispiel #16
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);
            }
        }
Beispiel #17
0
 internal LiteNetLibSyncField GetSyncField(LiteNetLibElementInfo info)
 {
     if (info.objectId != ObjectId)
     {
         return(null);
     }
     if (info.elementId >= 0 && info.elementId < SyncFields.Count)
     {
         return(SyncFields[info.elementId]);
     }
     if (Manager.LogError)
     {
         Logging.LogError(LogTag, "Cannot find sync field [" + info.elementId + "].");
     }
     return(null);
 }
Beispiel #18
0
        internal LiteNetLibFunction ProcessNetFunction(LiteNetLibElementInfo info, NetDataReader reader, bool hookCallback)
        {
            LiteNetLibFunction netFunction = GetNetFunction(info);

            if (netFunction == null)
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot process net function, functionId [" + info.elementId + "] not found.");
                }
                return(null);
            }
            netFunction.DeserializeParameters(reader);
            if (hookCallback)
            {
                netFunction.HookCallback();
            }
            return(netFunction);
        }
Beispiel #19
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);
                        }
                    }
                }
            }
        }
        public LiteNetLibSyncList ProcessSyncList(LiteNetLibElementInfo info, NetDataReader reader)
        {
            if (info.objectId != ObjectId)
            {
                return(null);
            }
            var elementId = info.elementId;

            if (elementId >= 0 && elementId < syncLists.Count)
            {
                var syncList = syncLists[elementId];
                syncList.DeserializeOperation(reader);
                return(syncList);
            }
            else
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot process sync field, fieldId [" + elementId + "] not found.");
                }
            }
            return(null);
        }
 internal LiteNetLibSyncList ProcessSyncList(LiteNetLibElementInfo info, NetDataReader reader)
 {
     return(ProcessSyncList(GetSyncList(info), reader));
 }
 internal LiteNetLibFunction ProcessNetFunction(LiteNetLibElementInfo info, NetDataReader reader, bool hookCallback)
 {
     return(ProcessNetFunction(GetNetFunction(info), reader, hookCallback));
 }
 internal LiteNetLibSyncField ProcessSyncField(LiteNetLibElementInfo info, NetDataReader reader, bool isInitial)
 {
     return(ProcessSyncField(GetSyncField(info), reader, isInitial));
 }
 protected void SerializeForSend(NetDataWriter writer)
 {
     LiteNetLibElementInfo.SerializeInfo(GetInfo(), writer);
     SerializeParameters(writer);
 }
 private void SerializeForSend(NetDataWriter writer)
 {
     LiteNetLibElementInfo.SerializeInfo(GetInfo(), writer);
     Serialize(writer);
 }
Beispiel #26
0
 public static void SerializeInfo(LiteNetLibElementInfo info, NetDataWriter writer)
 {
     writer.PutPackedUInt(info.objectId);
     writer.PutPackedUInt((uint)info.elementId);
 }