Пример #1
0
 internal void UpdateClient(NetworkClient client)
 {
     if (UnityEngine.Time.time - lastPingTime >= PingFrequency)
     {
         var pingMessage = new NetworkPingMessage(LocalTime());
         client.Connection.Send(pingMessage);
         lastPingTime = UnityEngine.Time.time;
     }
 }
Пример #2
0
 internal static void UpdateClient()
 {
     if (Time.time - lastPingTime >= PingFrequency)
     {
         NetworkPingMessage pingMessage = new NetworkPingMessage(LocalTime());
         NetworkClient.Send(pingMessage);
         lastPingTime = Time.time;
     }
 }
Пример #3
0
 internal static void UpdateClient()
 {
     if (Time.time - lastPingTime >= PingFrequency)
     {
         NetworkPingMessage pingMessage = new NetworkPingMessage(localTime);
         NetworkClient.Send(pingMessage, Channels.Unreliable);
         lastPingTime = Time.time;
     }
 }
Пример #4
0
 internal static void UpdateClient(NetworkClient networkClient)
 {
     if (Time.time - lastPingTime >= PingFrequency)
     {
         NetworkPingMessage pingMessage = GetPing();
         networkClient.Send((short)MsgType.Ping, pingMessage);
         lastPingTime = Time.time;
     }
 }
Пример #5
0
 internal static void UpdateClient()
 {
     // localTime (double) instead of Time.time for accuracy over days
     if (localTime - lastPingTime >= PingFrequency)
     {
         NetworkPingMessage pingMessage = new NetworkPingMessage(localTime);
         NetworkClient.Send(pingMessage, Channels.Unreliable);
         lastPingTime = localTime;
     }
 }
Пример #6
0
        // executed at the server when we receive a ping message
        // reply with a pong containing the time from the client
        // and time from the server
        internal static void OnServerPing(NetworkConnection conn, NetworkPingMessage message)
        {
            // Debug.Log("OnPingServerMessage  conn=" + conn);
            NetworkPongMessage pongMessage = new NetworkPongMessage
            {
                clientTime = message.clientTime,
                serverTime = localTime
            };

            conn.Send(pongMessage, Channels.Unreliable);
        }
Пример #7
0
        // executed at the server when we receive a ping message
        // reply with a pong containing the time from the client
        // and time from the server
        internal static void OnServerPing(NetworkConnection conn, NetworkPingMessage msg)
        {
            // Debug.Log("OnPingServerMessage  conn=" + conn);

            NetworkPongMessage pongMsg = new NetworkPongMessage
            {
                clientTime = msg.clientTime,
                serverTime = LocalTime()
            };

            conn.Send(pongMsg, Channels.DefaultUnreliable);
        }
Пример #8
0
 internal void UpdateClient(NetworkClient client)
 {
     if (UnityEngine.Time.time - lastPingTime >= PingFrequency)
     {
         var pingMessage = new NetworkPingMessage
         {
             clientTime = LocalTime()
         };
         client.Connection.Send(pingMessage, Channel.Unreliable);
         lastPingTime = UnityEngine.Time.time;
     }
 }
Пример #9
0
        // executed at the server when we receive a ping message
        // reply with a pong containing the time from the client
        // and time from the server
        internal static void OnServerPing(NetworkConnection conn, NetworkPingMessage msg)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("OnPingServerMessage  conn=" + conn);
            }

            NetworkPongMessage pongMsg = new NetworkPongMessage
            {
                clientTime = msg.clientTime,
                serverTime = LocalTime()
            };

            conn.Send(pongMsg);
        }
Пример #10
0
        // executed at the server when we receive a ping message
        // reply with a pong containing the time from the client
        // and time from the server
        internal void OnServerPing(INetworkConnection conn, NetworkPingMessage msg)
        {
            if (logger.LogEnabled())
            {
                logger.Log("OnPingServerMessage  conn=" + conn);
            }

            var pongMsg = new NetworkPongMessage
            {
                clientTime = msg.clientTime,
                serverTime = LocalTime()
            };

            conn.Send(pongMsg);
        }
Пример #11
0
        // executed at the server when we receive a ping message
        // reply with a pong containing the time from the client
        // and time from the server
        internal static void OnServerPing(NetworkMessage netMsg)
        {
            NetworkPingMessage pingMsg = netMsg.ReadMessage <NetworkPingMessage>();

            if (LogFilter.Debug)
            {
                Debug.Log("OnPingServerMessage  conn=" + netMsg.conn);
            }

            NetworkPongMessage pongMsg = new NetworkPongMessage
            {
                clientTime = pingMsg.value,
                serverTime = LocalTime()
            };

            netMsg.conn.Send((short)MsgType.Pong, pongMsg);
        }
Пример #12
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;
                }
            }
        }