internal static void Update()
 {
     // local or remote connection?
     if (isLocalClient)
     {
         // process internal messages so they are applied at the correct time
         while (localClientPacketQueue.Count > 0)
         {
             BufferHolder packet = localClientPacketQueue.Dequeue();
             if (packet.writer)
             {
                 NetworkWriter writer = (NetworkWriter)packet.data;
                 OnDataReceived(writer.ToArraySegment());
                 NetworkWriterPool.Recycle(writer);
             }
             else
             {
                 OnDataReceived(new ArraySegment <byte>((byte[])packet.data));
             }
         }
     }
     else
     {
         // only update things while connected
         if (active && connectState == ConnectState.Connected)
         {
             NetworkTime.UpdateClient();
         }
     }
 }
Exemple #2
0
 internal virtual void Update()
 {
     // only update things while connected
     if (active && connectState == ConnectState.Connected)
     {
         NetworkTime.UpdateClient(this);
     }
 }
Exemple #3
0
 internal static void Update()
 {
     // local or remote connection?
     if (connection is ULocalConnectionToServer localConnection)
     {
         localConnection.Update();
     }
     else
     {
         // only update things while connected
         if (active && connectState == ConnectState.Connected)
         {
             NetworkTime.UpdateClient();
         }
     }
 }
Exemple #4
0
        static void OnConnected()
        {
            if (connection != null)
            {
                // reset network time stats
                NetworkTime.Reset();

                // the handler may want to send messages to the client
                // thus we should set the connected state before calling the handler
                connectState = ConnectState.Connected;
                NetworkTime.UpdateClient();
                connection.InvokeHandler(new ConnectMessage(), -1);
            }
            else
            {
                logger.LogError("Skipped Connect message handling because connection is null.");
            }
        }
Exemple #5
0
        void OnConnected()
        {
            if (m_Connection != null)
            {
                // reset network time stats
                NetworkTime.Reset();

                // the handler may want to send messages to the client
                // thus we should set the connected state before calling the handler
                connectState = ConnectState.Connected;
                NetworkTime.UpdateClient(this);
                m_Connection.InvokeHandlerNoData((short)MsgType.Connect);
            }
            else
            {
                Debug.LogError("Skipped Connect message handling because m_Connection is null.");
            }
        }
Exemple #6
0
 internal static void Update()
 {
     // local or remote connection?
     if (isLocalClient)
     {
         // process internal messages so they are applied at the correct time
         while (localClientPacketQueue.Count > 0)
         {
             byte[] packet = localClientPacketQueue.Dequeue();
             OnDataReceived(packet);
         }
     }
     else
     {
         // only update things while connected
         if (active && connectState == ConnectState.Connected)
         {
             NetworkTime.UpdateClient();
         }
     }
 }
Exemple #7
0
        internal virtual void Update()
        {
            if (m_ClientId == -1)
            {
                return;
            }

            // don't do anything if we aren't fully connected
            // -> we don't check Client.Connected because then we wouldn't
            //    process the last disconnect message.
            if (connectState != ConnectState.Connecting &&
                connectState != ConnectState.Connected)
            {
                return;
            }

            if (connectState == ConnectState.Connected)
            {
                NetworkTime.UpdateClient(this);
            }
        }
 internal static void Update()
 {
     // local or remote connection?
     if (isLocalClient)
     {
         // process internal messages so they are applied at the correct time
         while (localClientPacketQueue.Count > 0)
         {
             byte[] packet = localClientPacketQueue.Dequeue();
             // TODO avoid serializing and deserializng the message
             // just pass it as is
             OnDataReceived(new ArraySegment <byte>(packet), Channels.DefaultReliable);
         }
     }
     else
     {
         // only update things while connected
         if (active && connectState == ConnectState.Connected)
         {
             NetworkTime.UpdateClient();
         }
     }
 }
Exemple #9
0
        // NetworkLateUpdate called after any Update/FixedUpdate/LateUpdate
        // (we add this to the UnityEngine in NetworkLoop)
        internal static void NetworkLateUpdate()
        {
            // local connection?
            if (connection is LocalConnectionToServer localConnection)
            {
                localConnection.Update();
            }
            // remote connection?
            else
            {
                // only update things while connected
                if (active && connectState == ConnectState.Connected)
                {
                    NetworkTime.UpdateClient();
                }
            }

            // process all incoming messages after updating the world
            if (Transport.activeTransport != null)
            {
                Transport.activeTransport.ClientLateUpdate();
            }
        }
Exemple #10
0
 internal static void Update()
 {
     // local or remote connection?
     if (isLocalClient)
     {
         // process internal messages so they are applied at the correct time
         while (localClientPacketQueue.Count > 0)
         {
             byte[] packet = localClientPacketQueue.Dequeue();
             // Treat host player messages exactly like connected client
             // to avoid deceptive / misleading behavior differences
             OnDataReceived(new ArraySegment <byte>(packet), Channels.DefaultReliable);
         }
     }
     else
     {
         // only update things while connected
         if (active && connectState == ConnectState.Connected)
         {
             NetworkTime.UpdateClient();
         }
     }
 }
Exemple #11
0
        internal virtual void Update()
        {
            if (m_ClientId == -1)
            {
                return;
            }

            // don't do anything if we aren't fully connected
            // -> we don't check Client.Connected because then we wouldn't
            //    process the last disconnect message.
            if (connectState != ConnectState.Connecting &&
                connectState != ConnectState.Connected)
            {
                return;
            }

            // pause message handling while a scene load is in progress
            //
            // problem:
            //   if we handle packets (calling the msgDelegates) while a
            //   scene load is in progress, then all the handled data and state
            //   will be lost as soon as the scene load is finished, causing
            //   state bugs.
            //
            // solution:
            //   don't handle messages until scene load is finished. the
            //   transport layer will queue it automatically.
            if (pauseMessageHandling)
            {
                Debug.Log("NetworkClient.Update paused during scene load...");
                return;
            }

            if (connectState == ConnectState.Connected && Time.time - lastPingTime >= pingFrequency)
            {
                NetworkPingMessage pingMessage = NetworkTime.GetPing();
                Send((short)MsgType.Ping, pingMessage);
                lastPingTime = Time.time;
            }

            // any new message?
            // -> calling it once per frame is okay, but really why not just
            //    process all messages and make it empty..
            TransportEvent transportEvent;

            byte[] data;
            while (Transport.layer.ClientGetNextMessage(out transportEvent, out data))
            {
                switch (transportEvent)
                {
                case TransportEvent.Connected:
                    //Debug.Log("NetworkClient loop: Connected");

                    if (m_Connection != null)
                    {
                        // reset network time stats
                        NetworkTime.Reset(pingWindowSize);

                        // the handler may want to send messages to the client
                        // thus we should set the connected state before calling the handler
                        connectState = ConnectState.Connected;
                        m_Connection.InvokeHandlerNoData((short)MsgType.Connect);
                    }
                    else
                    {
                        Debug.LogError("Skipped Connect message handling because m_Connection is null.");
                    }

                    break;

                case TransportEvent.Data:
                    //Debug.Log("NetworkClient loop: Data: " + BitConverter.ToString(data));

                    if (m_Connection != null)
                    {
                        m_Connection.TransportReceive(data);
                    }
                    else
                    {
                        Debug.LogError("Skipped Data message handling because m_Connection is null.");
                    }

                    break;

                case TransportEvent.Disconnected:
                    //Debug.Log("NetworkClient loop: Disconnected");
                    connectState = ConnectState.Disconnected;

                    //GenerateDisconnectError(error); TODO which one?
                    ClientScene.HandleClientDisconnect(m_Connection);
                    if (m_Connection != null)
                    {
                        m_Connection.InvokeHandlerNoData((short)MsgType.Disconnect);
                    }
                    break;
                }
            }
        }
 private static void OnRemoteUpdated()
 {
     NetworkTime.UpdateClient();
 }