InvokeHandlerNoData() public method

This function invokes the registered handler function for a message, without any message data.

public InvokeHandlerNoData ( short msgType ) : bool
msgType short The message ID of the handler to invoke.
return bool
Beispiel #1
0
 public virtual void OnDisconnected(NetworkConnection conn)
 {
     conn.InvokeHandlerNoData(MsgType.Disconnect);
 }
Beispiel #2
0
        internal virtual void Update()
        {
            if (m_ClientId == -1)
            {
                return;
            }
            switch (m_AsyncConnect)
            {
            case ConnectState.None:
            case ConnectState.Resolving:
            case ConnectState.Disconnected:
                return;

            case ConnectState.Failed:
                GenerateConnectError(11);
                m_AsyncConnect = ConnectState.Disconnected;
                return;

            case ConnectState.Resolved:
                m_AsyncConnect = ConnectState.Connecting;
                ContinueConnect();
                return;
            }
            if (m_Connection != null && (int)Time.time != m_StatResetTime)
            {
                m_Connection.ResetStats();
                m_StatResetTime = (int)Time.time;
            }
            NetworkEventType networkEventType;

            do
            {
                int num = 0;
                networkEventType = NetworkTransport.ReceiveFromHost(m_ClientId, out int _, out int channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out int receivedSize, out byte error);
                if (networkEventType != NetworkEventType.Nothing && LogFilter.logDev)
                {
                    Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEventType + " error=" + error);
                }
                switch (networkEventType)
                {
                case NetworkEventType.ConnectEvent:
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client connected");
                    }
                    if (error != 0)
                    {
                        GenerateConnectError(error);
                        return;
                    }
                    m_AsyncConnect = ConnectState.Connected;
                    m_Connection.InvokeHandlerNoData(32);
                    break;

                case NetworkEventType.DataEvent:
                    if (error != 0)
                    {
                        GenerateDataError(error);
                        return;
                    }
                    m_MsgReader.SeekZero();
                    m_Connection.TransportRecieve(m_MsgBuffer, receivedSize, channelId);
                    break;

                case NetworkEventType.DisconnectEvent:
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client disconnected");
                    }
                    m_AsyncConnect = ConnectState.Disconnected;
                    if (error != 0)
                    {
                        GenerateDisconnectError(error);
                    }
                    ClientScene.HandleClientDisconnect(m_Connection);
                    m_Connection.InvokeHandlerNoData(33);
                    break;

                default:
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Unknown network message type received: " + networkEventType);
                    }
                    break;

                case NetworkEventType.Nothing:
                    break;
                }
                if (num + 1 >= 500)
                {
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("MaxEventsPerFrame hit (" + 500 + ")");
                    }
                    break;
                }
            }while (m_ClientId != -1 && networkEventType != NetworkEventType.Nothing);
            if (m_Connection != null && m_AsyncConnect == ConnectState.Connected)
            {
                m_Connection.FlushChannels();
            }
        }
Beispiel #3
0
        internal virtual void Update()
        {
            if (m_ClientId == -1)
            {
                return;
            }

            switch (m_AsyncConnect)
            {
            case ConnectState.None:
            case ConnectState.Resolving:
            case ConnectState.Disconnected:
                return;

            case ConnectState.Failed:
                GenerateConnectError((int)NetworkError.DNSFailure);
                m_AsyncConnect = ConnectState.Disconnected;
                return;

            case ConnectState.Resolved:
                m_AsyncConnect = ConnectState.Connecting;
                ContinueConnect();
                return;

            case ConnectState.Connecting:
            case ConnectState.Connected:
            {
                break;
            }
            }

            if (m_Connection != null)
            {
                if ((int)Time.time != m_StatResetTime)
                {
                    m_Connection.ResetStats();
                    m_StatResetTime = (int)Time.time;
                }
            }

            NetworkEventType networkEvent;

            do
            {
                int  connectionId;
                int  channelId;
                int  receivedSize;
                byte error;
                int  numEvents = 0;

                networkEvent = NetworkTransport.ReceiveFromHost(m_ClientId, out connectionId, out channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out receivedSize, out error);

                if (networkEvent != NetworkEventType.Nothing)
                {
                    if (LogFilter.logDev)
                    {
                        Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEvent + " error=" + error);
                    }
                }

                switch (networkEvent)
                {
                case NetworkEventType.ConnectEvent:

                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client connected");
                    }

                    if (error != 0)
                    {
                        GenerateConnectError(error);
                        return;
                    }

                    m_AsyncConnect = ConnectState.Connected;
                    m_Connection.InvokeHandlerNoData(MsgType.Connect);
                    break;

                case NetworkEventType.DataEvent:
                    if (error != 0)
                    {
                        GenerateDataError(error);
                        return;
                    }

#if UNITY_EDITOR
                    UnityEditor.NetworkDetailStats.IncrementStat(
                        UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
                        MsgType.LLAPIMsg, "msg", 1);
#endif

                    m_MsgReader.SeekZero();
                    m_Connection.TransportRecieve(m_MsgBuffer, receivedSize, channelId);
                    break;

                case NetworkEventType.DisconnectEvent:
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client disconnected");
                    }

                    m_AsyncConnect = ConnectState.Disconnected;

                    if (error != 0)
                    {
                        if ((NetworkError)error != NetworkError.Timeout)
                        {
                            GenerateDisconnectError(error);
                        }
                    }
                    ClientScene.HandleClientDisconnect(m_Connection);
                    if (m_Connection != null)
                    {
                        m_Connection.InvokeHandlerNoData(MsgType.Disconnect);
                    }
                    break;

                case NetworkEventType.Nothing:
                    break;

                default:
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Unknown network message type received: " + networkEvent);
                    }
                    break;
                }

                if (++numEvents >= k_MaxEventsPerFrame)
                {
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("MaxEventsPerFrame hit (" + k_MaxEventsPerFrame + ")");
                    }
                    break;
                }
                if (m_ClientId == -1)
                {
                    break;
                }
            }while (networkEvent != NetworkEventType.Nothing);

            if (m_Connection != null && m_AsyncConnect == ConnectState.Connected)
            {
                m_Connection.FlushChannels();
            }
        }
Beispiel #4
0
 public virtual void OnConnected(NetworkConnection conn)
 {
     conn.InvokeHandlerNoData(32);
 }
Beispiel #5
0
        internal virtual void Update()
        {
            if (m_ClientId == -1)
            {
                return;
            }

            switch (m_AsyncConnect)
            {
            case ConnectState.None:
            case ConnectState.Resolving:
            case ConnectState.Disconnected:
                return;

            case ConnectState.Failed:
                GenerateConnectError((int)NetworkError.DNSFailure);
                m_AsyncConnect = ConnectState.Disconnected;
                return;

            case ConnectState.Resolved:
                m_AsyncConnect = ConnectState.Connecting;
                ContinueConnect();
                return;

            case ConnectState.Connecting:
            case ConnectState.Connected:
            {
                break;
            }
            }

            int numEvents = 0;
            NetworkEventType networkEvent;

            do
            {
                int  connectionId;
                int  channelId;
                int  receivedSize;
                byte error;

                networkEvent = NetworkTransport.ReceiveFromHost(m_ClientId, out connectionId, out channelId, m_MsgBuffer, (ushort)m_MsgBuffer.Length, out receivedSize, out error);
                if (m_Connection != null)
                {
                    m_Connection.lastError = (NetworkError)error;
                }

                if (networkEvent != NetworkEventType.Nothing)
                {
                    if (LogFilter.logDev)
                    {
                        Debug.Log("Client event: host=" + m_ClientId + " event=" + networkEvent + " error=" + error);
                    }
                }

                switch (networkEvent)
                {
                case NetworkEventType.ConnectEvent:

                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client connected");
                    }

                    if (error != 0)
                    {
                        GenerateConnectError(error);
                        return;
                    }

                    m_AsyncConnect = ConnectState.Connected;
                    m_Connection.InvokeHandlerNoData((short)MsgType.Connect);
                    break;

                case NetworkEventType.DataEvent:
                    if (error != 0)
                    {
                        GenerateDataError(error);
                        return;
                    }

#if UNITY_EDITOR
                    UnityEditor.NetworkDetailStats.IncrementStat(
                        UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
                        (short)MsgType.LLAPIMsg, "msg", 1);
#endif
                    // create a buffer with exactly 'receivedSize' size for the handlers so we don't need to read
                    // a size header (saves bandwidth)
                    byte[] data = new byte[receivedSize];
                    Array.Copy(m_MsgBuffer, data, receivedSize);

                    m_Connection.TransportReceive(data, channelId);
                    break;

                case NetworkEventType.DisconnectEvent:
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Client disconnected");
                    }

                    m_AsyncConnect = ConnectState.Disconnected;

                    if (error != 0)
                    {
                        if ((NetworkError)error != NetworkError.Timeout)
                        {
                            GenerateDisconnectError(error);
                        }
                    }
                    ClientScene.HandleClientDisconnect(m_Connection);
                    if (m_Connection != null)
                    {
                        m_Connection.InvokeHandlerNoData((short)MsgType.Disconnect);
                    }
                    break;

                case NetworkEventType.Nothing:
                    break;

                default:
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Unknown network message type received: " + networkEvent);
                    }
                    break;
                }

                if (++numEvents >= k_MaxEventsPerFrame)
                {
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("MaxEventsPerFrame hit (" + k_MaxEventsPerFrame + ")");
                    }
                    break;
                }
                if (m_ClientId == -1)
                {
                    break;
                }
            }while (networkEvent != NetworkEventType.Nothing);
        }
Beispiel #6
0
 /// <summary>
 ///   <para>This virtual function can be overridden to perform custom functionality for disconnected network connections.</para>
 /// </summary>
 /// <param name="conn"></param>
 public virtual void OnDisconnected(NetworkConnection conn)
 {
     conn.InvokeHandlerNoData((short)33);
 }
 private bool AddExternalConnectionInternal(NetworkConnection conn)
 {
     if (conn.connectionId < 0)
     {
         return false;
     }
     if ((conn.connectionId < connections.Count) && (connections[conn.connectionId] != null))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("AddExternalConnection failed, already connection for id:" + conn.connectionId);
         }
         return false;
     }
     if (LogFilter.logDebug)
     {
         Debug.Log("AddExternalConnection external connection " + conn.connectionId);
     }
     this.m_SimpleServerSimple.SetConnectionAtIndex(conn);
     this.m_ExternalConnections.Add(conn.connectionId);
     conn.InvokeHandlerNoData(0x20);
     return true;
 }
 private void OnDisconnected(NetworkConnection conn)
 {
     conn.InvokeHandlerNoData(0x21);
     for (int i = 0; i < conn.playerControllers.Count; i++)
     {
         if ((conn.playerControllers[i].gameObject != null) && LogFilter.logWarn)
         {
             Debug.LogWarning("Player not destroyed when connection disconnected.");
         }
     }
     if (LogFilter.logDebug)
     {
         Debug.Log("Server lost client:" + conn.connectionId);
     }
     conn.RemoveObservers();
     conn.Dispose();
 }
 private void OnConnected(NetworkConnection conn)
 {
     if (LogFilter.logDebug)
     {
         Debug.Log("Server accepted client:" + conn.connectionId);
     }
     conn.SetMaxDelay(this.m_MaxDelay);
     conn.InvokeHandlerNoData(0x20);
     SendCrc(conn);
 }