Ejemplo n.º 1
0
        /// <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;
            }
        }
Ejemplo n.º 2
0
        /// <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;
        }