Ejemplo n.º 1
0
        public override ClientStartData GetConnectInfo( string hash )
        {
            string uri = playUri + hash;
            var response = GetHtml( uri, classicubeNetUri );
            ClientStartData data = new ClientStartData();
            data.Username = Username;

            foreach( string line in response ) {
                int index = 0;
                // Look for <param name="x" value="x"> tags
                if( ( index = line.IndexOf( "<param", ordinal ) ) > 0 ) {
                    int nameStart = index + 13;
                    int nameEnd = line.IndexOf( '"', nameStart );
                    string paramName = line.Substring( nameStart, nameEnd - nameStart );

                    // Don't read param value by default so we avoid allocating unnecessary 'value' strings.
                    if( paramName == "server" ) {
                        data.Ip = GetParamValue( line, nameEnd );
                    } else if( paramName == "port" ) {
                        data.Port = GetParamValue( line, nameEnd );
                    } else if( paramName == "mppass" ) {
                        data.Mppass = GetParamValue( line, nameEnd );
                    }
                }
            }
            return data;
        }
Ejemplo n.º 2
0
        public bool ConnectToServer(List <ServerListEntry> publicServers, string hash)
        {
            if (String.IsNullOrEmpty(hash))
            {
                return(false);
            }

            ClientStartData data = null;

            foreach (ServerListEntry entry in publicServers)
            {
                if (entry.Hash == hash)
                {
                    data = new ClientStartData(Session.Username, entry.Mppass,
                                               entry.IPAddress, entry.Port);
                    Client.Start(data, true, ref ShouldExit);
                    return(true);
                }
            }

            // Fallback to private server handling
            try {
                data = Session.GetConnectInfo(hash);
            } catch (WebException ex) {
                ErrorHandler.LogError("retrieving server information", ex);
                return(false);
            } catch (ArgumentOutOfRangeException) {
                return(false);
            }
            Client.Start(data, true, ref ShouldExit);
            return(true);
        }
Ejemplo n.º 3
0
        public static bool Start( ClientStartData data, bool classicubeSkins )
        {
            string skinServer = classicubeSkins ? "http://www.classicube.net/static/skins/" : "http://s3.amazonaws.com/MinecraftSkins/";
            string args = data.Username + " " + data.Mppass + " " +
                data.Ip + " " + data.Port + " " + skinServer;

            UpdateResumeInfo( data, classicubeSkins );
            return Start( args );
        }
Ejemplo n.º 4
0
        void ResumeClick(int mouseX, int mouseY)
        {
            if (!resumeValid)
            {
                return;
            }
            ClientStartData data = new ClientStartData(resumeUser, resumeMppass, resumeIp, resumePort);

            Client.Start(data, resumeCCSkins, ref game.ShouldExit);
        }
Ejemplo n.º 5
0
        internal static void UpdateResumeInfo( ClientStartData data, bool classiCubeSkins )
        {
            // If the client has changed some settings in the meantime, make sure we keep the changes
            if( !Options.Load() )
                return;

            Options.Set( "launcher-username", data.Username );
            Options.Set( "launcher-ip", data.Ip );
            Options.Set( "launcher-port", data.Port );
            Options.Set( "launcher-mppass", Secure.Encode( data.Mppass, data.Username ) );
            Options.Set( "launcher-ccskins", classiCubeSkins );
            Options.Save();
        }
        void SaveToOptions(ClientStartData data, bool ccSkins)
        {
            if (!Options.Load())
            {
                return;
            }

            Options.Set("launcher-dc-username", data.RealUsername);
            Options.Set("launcher-dc-ip", data.Ip);
            Options.Set("launcher-dc-port", data.Port);
            Options.Set("launcher-dc-mppass", Secure.Encode(data.Mppass, data.RealUsername));
            Options.Set("launcher-dc-ccskins", ccSkins);
            Options.Save();
        }
Ejemplo n.º 7
0
        public static bool Start(ClientStartData data, bool classicubeSkins, ref bool shouldExit)
        {
            if ((DateTime.UtcNow - lastJoin).TotalSeconds < 1)
            {
                return(false);
            }
            lastJoin = DateTime.UtcNow;

            string skinServer = classicubeSkins ? "http://static.classicube.net/skins/" :
                                "http://s3.amazonaws.com/MinecraftSkins/";
            string args = data.Username + " " + data.Mppass + " " +
                          data.Ip + " " + data.Port + " " + skinServer;

            return(StartImpl(data, classicubeSkins, args, ref shouldExit));
        }
        ClientStartData GetStartData(string user, string mppass, string ip, string port)
        {
            SetStatus("");

            if (String.IsNullOrEmpty(user))
            {
                SetStatus("&ePlease enter a username"); return(null);
            }

            IPAddress realIp;

            if (!IPAddress.TryParse(ip, out realIp) && ip != "localhost")
            {
                SetStatus("&eInvalid ip"); return(null);
            }
            if (ip == "localhost")
            {
                ip = "127.0.0.1";
            }

            ushort realPort;

            if (!UInt16.TryParse(port, out realPort))
            {
                SetStatus("&eInvalid port"); return(null);
            }

            if (String.IsNullOrEmpty(mppass))
            {
                mppass = "******";
            }

            ClientStartData data = new ClientStartData(user, mppass, ip, port);

            if (user.ToLowerInvariant() == "rand()" || user.ToLowerInvariant() == "random()")
            {
                rnd.NextBytes(rndBytes);
                data.Username = Convert.ToBase64String(rndBytes).TrimEnd('=');
            }
            return(data);
        }
Ejemplo n.º 9
0
        internal static void CheckSettings(ClientStartData data, bool classiCubeSkins, out bool shouldExit)
        {
            shouldExit = false;
            // Make sure if the client has changed some settings in the meantime, we keep the changes
            if (!Options.Load())
            {
                return;
            }
            shouldExit = Options.GetBool(OptionsKey.AutoCloseLauncher, false);
            if (data == null)
            {
                return;
            }

            Options.Set("launcher-username", data.RealUsername);
            Options.Set("launcher-ip", data.Ip);
            Options.Set("launcher-port", data.Port);
            Options.Set("launcher-mppass", Secure.Encode(data.Mppass, data.RealUsername));
            Options.Set("launcher-ccskins", classiCubeSkins);
            Options.Save();
        }
Ejemplo n.º 10
0
        static bool StartImpl(ClientStartData data, bool classicubeSkins,
                              string args, ref bool shouldExit)
        {
            Process process = null;
            string  path    = Path.Combine(Program.AppDirectory, "ClassicalSharp.exe");

            if (!File.Exists(path))
            {
                return(false);
            }

            CheckSettings(data, classicubeSkins, out shouldExit);
            if (Type.GetType("Mono.Runtime") != null)
            {
                process = Process.Start("mono", "\"" + path + "\" " + args);
            }
            else
            {
                process = Process.Start(path, args);
            }
            return(true);
        }
        void StartClient(int mouseX, int mouseY)
        {
            string address = Get(1);
            int    index   = address.LastIndexOf(':');

            if (index <= 0 || index == address.Length - 1)
            {
                SetStatus("&eInvalid address"); return;
            }

            string          ipPart   = address.Substring(0, index);
            string          portPart = address.Substring(index + 1, address.Length - index - 1);
            ClientStartData data     = GetStartData(Get(0), Get(2), ipPart, portPart);

            if (data == null)
            {
                return;
            }

            bool ccSkins = ((LauncherBooleanWidget)widgets[skinsIndex]).Value;

            SaveToOptions(data, ccSkins);
            Client.Start(data, ccSkins, ref game.ShouldExit);
        }
Ejemplo n.º 12
0
        public bool ConnectToServer( List<ServerListEntry> publicServers, string hash )
        {
            if( String.IsNullOrEmpty( hash ) ) return false;

            ClientStartData data = null;
            foreach( ServerListEntry entry in publicServers ) {
                if( entry.Hash == hash ) {
                    data = new ClientStartData( Session.Username, entry.Mppass,
                                               entry.IPAddress, entry.Port );
                    Client.Start( data, true );
                    return true;
                }
            }

            // Fallback to private server handling
            try {
                data = Session.GetConnectInfo( hash );
            } catch( WebException ex ) {
                ErrorHandler.LogError( "retrieving server information", ex );
                return false;
            }
            Client.Start( data, true );
            return true;
        }
Ejemplo n.º 13
0
        void StartClient( int mouseX, int mouseY )
        {
            SetStatus( "" );

            if( String.IsNullOrEmpty( Get( 3 ) ) ) {
                SetStatus( "&ePlease enter a username" ); return;
            }

            string address = Get( 4 );
            int index = address.LastIndexOf( ':' );
            if( index <= 0 || index == address.Length - 1 ) {
                SetStatus( "&eInvalid address" ); return;
            }

            string ipPart = address.Substring( 0, index ); IPAddress ip;
            if( !IPAddress.TryParse( ipPart, out ip ) && ipPart != "localhost" ) {
                SetStatus( "&eInvalid ip" ); return;
            }
            if( ipPart == "localhost" ) ipPart = "127.0.0.1";

            string portPart = address.Substring( index + 1, address.Length - index - 1 ); ushort port;
            if( !UInt16.TryParse( portPart, out port ) ) {
                SetStatus( "&eInvalid port" ); return;
            }

            string mppass = Get( 5 );
            if( String.IsNullOrEmpty( mppass ) ) mppass = "******";
            ClientStartData data = new ClientStartData( Get( 3 ), mppass, ipPart, portPart );
            Client.Start( data, ccSkins );
        }