Esempio 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);
                    }
                }
            }
        }
 internal LiteNetLibFunction ProcessNetFunction(LiteNetLibFunction netFunction, NetDataReader reader, bool hookCallback)
 {
     if (netFunction == null)
     {
         return(null);
     }
     netFunction.DeserializeParameters(reader);
     if (hookCallback)
     {
         netFunction.HookCallback();
     }
     return(netFunction);
 }
Esempio n. 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 = 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);
                    }
                }
            }
        }
Esempio n. 4
0
        public void CallNetFunction(string id, long connectionId, params object[] parameters)
        {
            ushort elementId;

            if (netFunctionIds.TryGetValue(id, out elementId))
            {
                LiteNetLibFunction syncFunction = netFunctions[elementId];
                syncFunction.Call(connectionId, parameters);
            }
            else
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot call function, function [" + id + "] not found.");
                }
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void RegisterNetFunction(string id, LiteNetLibFunction netFunction)
        {
            if (netFunctionIds.ContainsKey(id))
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot register net function with existed id [" + id + "].");
                }
                return;
            }
            if (netFunctions.Count == byte.MaxValue)
            {
                if (Manager.LogError)
                {
                    Debug.LogError("[" + name + "] [" + TypeName + "] cannot register net function it's exceeds limit.");
                }
                return;
            }
            byte elementId = Convert.ToByte(netFunctions.Count);

            netFunction.Setup(this, elementId);
            netFunctions.Add(netFunction);
            netFunctionIds[id] = elementId;
        }