public bool TryRemoveConnection(IProxyConnection connection)
 {
     Tuple<int, int> result;
     return EntityIDMapping.TryRemove(connection, out result);
 }
        /// <summary>
        ///   Get the minecraft protocol server of a given minecraft server.
        /// </summary>
        /// <param name="proxyConnection"> The connection this server relates to. </param>
        /// <param name="serverEndPoint"> The current version of the Remote server info. </param>
        public void GetServerVersion(IProxyConnection proxyConnection, RemoteServerInfo serverEndPoint)
        {
            var args = new PluginResultEventArgs<RemoteServerInfo>(serverEndPoint, proxyConnection);

            PluginManager.TriggerPlugin.GetServerVersion(args);

            args.EnsureSuccess ();

            if (serverEndPoint.MinecraftVersion == 0)
            {
                //Look up configuration

                ProxyConfigurationSection settings = ProxyConfigurationSection.Settings;

                IEnumerable<ServerElement> serverList =
                    settings.Server.OfType<ServerElement> ().Where(
                        m => m.EndPoint == serverEndPoint.EndPoint.ToString ());

                ServerElement server = serverList.FirstOrDefault ();

                if (server != null) serverEndPoint.MinecraftVersion = server.MinecraftVersion;
                    //Use default
                else serverEndPoint.MinecraftVersion = ProtocolInformation.MaxSupportedServerVersion;
            }
        }
        /// <summary>
        ///   Returns true if the online mode is enabled for a specific user or not.
        /// </summary>
        /// <param name="proxyConnection"> The proxy connection which should be checked </param>
        /// <returns> true if the online mode is enabled, otherwise false. </returns>
        public bool OnlineModeEnabled(IProxyConnection proxyConnection)
        {
            var args = new PluginResultEventArgs<bool?>(null, proxyConnection);
            PluginManager.TriggerPlugin.IsOnlineModeEnabled(args);


            if (args.Result == null)
                return OnlineMode;
            return (bool) args.Result;
        }
        /// <summary>
        ///   Get a new server end point for a given proxy connection to.
        /// </summary>
        /// <param name="proxyConnection"> The proxy connection which need a new server connection. </param>
        /// <returns> A RemoteServerInfo object which contains important information about the new backend server. </returns>
        public RemoteServerInfo GetServerEndPoint(IProxyConnection proxyConnection)
        {
            ProxyConfigurationSection settings = ProxyConfigurationSection.Settings;

            IOrderedEnumerable<ServerElement> server =
                settings.Server.OfType<ServerElement> ().Where(
                    m => m.IsDefault || (!string.IsNullOrEmpty(m.DnsName) && proxyConnection.Host.StartsWith(m.DnsName)))
                    .OrderBy(m => m.IsDefault);

            ServerElement possibleResult = server.FirstOrDefault ();
            RemoteServerInfo result = possibleResult == null
                                          ? null
                                          : new RemoteServerInfo(possibleResult.Name,
                                                                 Extensions.ParseEndPoint(possibleResult.EndPoint),
                                                                 possibleResult.MinecraftVersion)
                                                {
                                                    KickMessage = possibleResult.KickMessage
                                                };

            var args = new PluginResultEventArgs<RemoteServerInfo>(result, proxyConnection);
            PluginManager.TriggerPlugin.OnPlayerServerSelection(args);
            args.EnsureSuccess ();
            return args.Result;
        }
 /// <summary>
 ///   Create a new instance of the UserEventArgs class with the specific connection
 /// </summary>
 /// <param name="connection"> The connection this event data belongs to </param>
 public UserEventArgs(IProxyConnection connection)
 {
     Connection = connection;
 }
 /// <summary>
 ///   Creates a new instance of the <see cref="PacketReceivedEventArgs" /> class
 /// </summary>
 /// <param name="packet"> The packet which should be redirected </param>
 /// <param name="connection"> The connection this packet belongs to </param>
 public PacketReceivedEventArgs(Packet packet, IProxyConnection connection)
 {
     Packet = packet;
     Connection = connection;
 }