예제 #1
0
        public bool ConnectToServer(List <ServerListEntry> publicServers, string hash)
        {
            if (String.IsNullOrEmpty(hash))
            {
                return(false);
            }

            ClientStartData data = null;

            for (int i = 0; i < publicServers.Count; i++)
            {
                ServerListEntry entry = publicServers[i];
                if (entry.Hash != hash)
                {
                    continue;
                }

                data = new ClientStartData(Session.Username, entry.Mppass,
                                           entry.IPAddress, entry.Port, entry.Name);
                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);
        }
예제 #2
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( Configuration.RunningOnMono ) {
                // We also need to handle the case of running Mono through wine
                if( Configuration.RunningOnWindows ) {
                    try {
                        process = Process.Start( "mono", "\"" + path + "\" " + args );
                    } catch( Win32Exception ex ) {
                        if( !((uint)ex.ErrorCode == 0x80070002 || (uint)ex.ErrorCode == 0x80004005) )
                            throw; // File not found HRESULT, HRESULT thrown when running on wine
                        process = Process.Start( path, args );
                    }
                } else {
                    process = Process.Start( "mono", "\"" + path + "\" " + args );
                }
            } else {
                process = Process.Start( path, args );
            }
            return true;
        }
예제 #3
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);
        }
예제 #4
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 );
        }
예제 #5
0
        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();
        }
예제 #6
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));
        }
예제 #7
0
        public bool ConnectToServer(List <ServerListEntry> publicServers, string hash)
        {
            if (String.IsNullOrEmpty(hash))
            {
                return(false);
            }

            ClientStartData data = null;

            for (int i = 0; i < publicServers.Count; i++)
            {
                ServerListEntry entry = publicServers[i];
                if (entry.Hash != hash)
                {
                    continue;
                }

                data = new ClientStartData(Username, entry.Mppass,
                                           entry.IPAddress, entry.Port, entry.Name);
                Client.Start(data, true, ref ShouldExit);
                return(true);
            }

            // Fallback to private server handling
            try {
                // TODO: Rewrite to be async
                FetchServerTask task = new FetchServerTask(Username, hash);
                task.RunAsync(this);

                while (!task.Completed)
                {
                    task.Tick(); Thread.Sleep(10);
                }
                if (task.WebEx != null)
                {
                    throw task.WebEx;
                }

                data = task.Info;
            } catch (WebException ex) {
                ErrorHandler.LogError("retrieving server information", ex);
                return(false);
            } catch (ArgumentOutOfRangeException) {
                return(false);
            }
            Client.Start(data, true, ref ShouldExit);
            return(true);
        }
예제 #8
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();
        }
예제 #9
0
        static bool StartImpl(ClientStartData data, bool ccSkins, string args, ref bool shouldExit)
        {
            if (!Platform.FileExists("ClassicalSharp.exe"))
            {
                return(false);
            }

            CheckSettings(data, ccSkins, out shouldExit);
            try {
                StartProcess(args);
            } catch (Win32Exception ex) {
                if ((uint)ex.ErrorCode != 0x80004005)
                {
                    throw;                     // HRESULT when user clicks 'cancel' to 'are you sure you want to run ClassicalSharp.exe'
                }
                shouldExit = false;
                return(false);
            }
            return(true);
        }
예제 #10
0
        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);
        }
예제 #11
0
        internal static void CheckSettings(ClientStartData data, bool ccSkins, 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.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", ccSkins);
            Options.Save();
        }
예제 #12
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 (Configuration.RunningOnMono)
            {
                // We also need to handle the case of running Mono through wine
                if (Configuration.RunningOnWindows)
                {
                    try {
                        process = Process.Start("mono", "\"" + path + "\" " + args);
                    } catch (Win32Exception ex) {
                        if (!((uint)ex.ErrorCode == 0x80070002 || (uint)ex.ErrorCode == 0x80004005))
                        {
                            throw;                             // File not found HRESULT, HRESULT thrown when running on wine
                        }
                        process = Process.Start(path, args);
                    }
                }
                else
                {
                    process = Process.Start("mono", "\"" + path + "\" " + args);
                }
            }
            else
            {
                process = Process.Start(path, args);
            }
            return(true);
        }
예제 #13
0
        static bool StartImpl(ClientStartData data, bool classicubeSkins,
                              string args, ref bool shouldExit)
        {
            string path = Path.Combine(Program.AppDirectory, "ClassicalSharp.exe");

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

            CheckSettings(data, classicubeSkins, out shouldExit);
            try {
                StartProcess(path, args);
            } catch (Win32Exception ex) {
                if ((uint)ex.ErrorCode != 0x80004005)
                {
                    throw;                     // HRESULT when user clicks 'cancel' to 'are you sure you want to run ClassicalSharp.exe'
                }
                shouldExit = false;
                return(false);
            }
            return(true);
        }
예제 #14
0
        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);
        }
        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;
        }
예제 #16
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 );
 }
        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;
        }
        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();
        }