public void HandleMessages()
        {
            NetIncomingMessage message;

            while ((message = m_Server.ReadMessage()) != null)
            {
                switch (message.MessageType)
                {
                case NetIncomingMessageType.ConnectionApproval:
                    try
                    {
                        var packet = Packet.Read(message.Data);
                        ApproveConnection(message.SenderConnection);
                        OnConnectionApproved?.Invoke(new LidgrenMessage(message));
                    }
                    catch (Exception e)
                    {
                        DenyConnection(message.SenderConnection);
                        OnConnectionDenied?.Invoke(new LidgrenMessage(message));
                    }
                    break;

                case NetIncomingMessageType.StatusChanged:
                    switch (message.SenderConnection.Status)
                    {
                    case NetConnectionStatus.Connected:
                        OnConnected?.Invoke(new LidgrenMessage(message));
                        break;

                    case NetConnectionStatus.Disconnected:
                        OnDisconnecting?.Invoke(new LidgrenMessage(message));         //not firing from lidgren
                        OnDisconnected?.Invoke(new LidgrenMessage(message));
                        break;
                    }
                    break;

                case NetIncomingMessageType.Data:
                    TriggerCallback(new LidgrenConnection(message.SenderConnection), message.Data);
                    OnReceivedData?.Invoke(new LidgrenMessage(message));
                    break;

                case NetIncomingMessageType.DebugMessage:
                    // handle debug messages
                    // (only received when compiled in DEBUG mode)
                    Console.WriteLine("DEBUG: " + message.ReadString());
                    break;

                case NetIncomingMessageType.WarningMessage:
                    Console.WriteLine("WARNING: " + message.ReadString());
                    break;

                /* .. */
                default:
                    Console.WriteLine("unhandled message with type: "
                                      + message.MessageType);
                    break;
                }
            }
        }
 protected virtual void HandleInterfaceOnConnectonDenied(INetworkLayerInterface sender, ConnectionEventArgs connectionEventArgs)
 {
     Log.Info($"Connection denied [{connectionEventArgs.Connection?.Guid}].");
     OnConnectionDenied?.Invoke(sender, connectionEventArgs);
 }
 /// <summary>
 /// Connection denied event
 /// </summary>
 private void ConnectionDeniedEvent() => OnConnectionDenied?.Invoke();