Esempio n. 1
0
        protected virtual void HandleServerCallFunction(LiteNetLibMessageHandler messageHandler)
        {
            var reader = messageHandler.reader;
            var info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity identity;

            if (Assets.SpawnedObjects.TryGetValue(info.objectId, out identity))
            {
                identity.ProcessNetFunction(info, reader, true);
            }
        }
Esempio n. 2
0
        protected virtual void HandleServerUpdateTime(LiteNetLibMessageHandler messageHandler)
        {
            // Server updated at server, if this is hot (client and server) then skip it.
            if (IsServer)
            {
                return;
            }
            float time = messageHandler.reader.GetFloat();

            ServerTimeOffset = time - Time.unscaledTime;
        }
Esempio n. 3
0
        protected virtual void HandleServerDestroyObject(LiteNetLibMessageHandler messageHandler)
        {
            // Object spawned at server, if this is host (client and server) then skip it.
            if (IsServer)
            {
                return;
            }
            var message = messageHandler.ReadMessage <ServerDestroyObjectMessage>();

            Assets.NetworkDestroy(message.objectId);
        }
Esempio n. 4
0
        protected virtual void HandleServerSpawnObject(LiteNetLibMessageHandler messageHandler)
        {
            // Object spawned at server, if this is host (client and server) then skip it.
            if (IsServer)
            {
                return;
            }
            var message = messageHandler.ReadMessage <ServerSpawnObjectMessage>();

            Assets.NetworkSpawn(message.assetId, message.position, message.objectId, message.connectId);
        }
        private void ReadPacket(NetPeer peer, NetDataReader reader, Dictionary <short, MessageHandlerDelegate> registerDict)
        {
            var msgType = reader.GetShort();
            MessageHandlerDelegate handlerDelegate;

            if (registerDict.TryGetValue(msgType, out handlerDelegate))
            {
                var messageHandler = new LiteNetLibMessageHandler(msgType, peer, reader);
                handlerDelegate.Invoke(messageHandler);
            }
        }
Esempio 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;
            }
            var reader = messageHandler.reader;
            var info   = LiteNetLibElementInfo.DeserializeInfo(reader);
            LiteNetLibIdentity identity;

            if (Assets.SpawnedObjects.TryGetValue(info.objectId, out identity))
            {
                identity.ProcessSyncList(info, reader);
            }
        }
Esempio n. 7
0
        protected virtual void HandleClientReady(LiteNetLibMessageHandler messageHandler)
        {
            var peer           = messageHandler.peer;
            var spawnedObjects = Assets.SpawnedObjects.Values;

            foreach (var spawnedObject in spawnedObjects)
            {
                if (Assets.SceneObjects.ContainsKey(spawnedObject.ObjectId))
                {
                    SendServerSpawnSceneObject(peer, spawnedObject);
                }
                else
                {
                    SendServerSpawnObject(peer, spawnedObject);
                }
                spawnedObject.SendInitSyncFields(peer);
                spawnedObject.SendInitSyncLists(peer);
            }
            SpawnPlayer(peer);
        }