Exemplo n.º 1
0
        /// <summary>
        /// Login User, Use the user credentials to login and retrieve the session ID.
        /// </summary>
        /// <param name="username">Input username here. Example: "username"</param>
        /// <param name="password">Input password here. Example: "pass1234"</param>
        /// <returns>Status of exceptions or success</returns>
        private MinecraftSession Authenticate(string inputUsername = "", string inputPassword = "")
        {
            if (!OnlineMode) {
                return new MinecraftSession () {
                    Username = OfflineName
                };
            }

            var session = new MinecraftAuthentication ().Login (inputUsername, inputPassword);

            if (session != null)
                session.OriginalUsername = inputUsername;

            return session;
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var craftalyst = new Context ();

            craftalyst.AppName = "Craftalyst 1337 Launcher";
            craftalyst.AppVersion = "0.0.1a6";
            craftalyst.AppId = "CraftalystLauncher";

            string username = "";
            string password = "";
            MinecraftSession session = null;

            while (true) {
                Console.WriteLine ();
                Console.WriteLine ("Craftalyst {0}", Context.Version);
                Console.WriteLine ("Warning: The server play.tirrin.com will control what software components are downloaded and from where.");
                Console.WriteLine ("         Only use Craftalyst with servers you trust.");
                Console.WriteLine ();
                Console.WriteLine ("(C) 2014 rezonaut");
                Console.Write ("Minecraft Login : "******"       Password : "******"Invalid Login: "******"Let's do this!");
            Console.WriteLine ();

            Instance instance = craftalyst.GetOrCreateInstance("CraftalystTest", new InstanceDescription() {
                Version = "1.6.4-forge",
                Name = "Tirrin",
                Description = "Client instance for Tirrin server",
                SyncUrl = "http://play.tirrin.com:8080/craftalyst",
                SyncConfigs = new List<string>(),
                Mods = new List<ModDescription>(),
                ConfigVersion = 0
            });

            var mc = instance.CreateMinecraft();
            mc.Start(session);
        }
Exemplo n.º 3
0
        public void Login()
        {
            LoginDialog login = new LoginDialog ();
            SavedCredentials saved = null;
            string credsFileName = Path.Combine(Instance.GameFolder, "credentials.json");

            if (File.Exists(credsFileName)) {
                using (var sr = new StreamReader(credsFileName))
                    saved = SavedCredentials.Parse(sr.ReadToEnd());
            }

            if (saved != null) {
                login.Username = saved.AutoLoginUser;

                var savedCreds = saved.Credentials.Where(x => x.UserName == saved.AutoLoginUser).FirstOrDefault();
                if (savedCreds != null) {
                    login.Password = savedCreds.Password;
                    login.RememberCredentials = true;
                }
            }

            while (true) {
                int response = login.Run ();

                if (response == (int)Gtk.ResponseType.Ok) {

                    var auth = new MinecraftAuthentication ();
                    string message = "Invalid login!";

                    try {
                        Session = auth.Login (login.Username, login.Password);
                    } catch (Exception e) {
                        Session = null;
                        message = e.Message;
                    }

                    if (Session == null || Session.AccessToken == null) {
                        MessageBox (message);
                        continue;
                    }

                    break;
                } else if (response == (int)Gtk.ResponseType.Cancel) {
                    Gtk.Application.Quit();
                    Environment.Exit(0);
                }
            }

            saved = new SavedCredentials() {
                AutoLoginUser = login.Username,
                Credentials = new List<SavedCredential>()
            };

            if (login.RememberCredentials) {
                saved.Credentials = new List<SavedCredential>() {
                    new SavedCredential() {
                        UserName = login.Username,
                        Password = login.Password
                    }
                };
            }

            Directory.CreateDirectory(Path.GetDirectoryName(credsFileName));
            using (StreamWriter sw = new StreamWriter(credsFileName))
                sw.Write(saved.ToJson());

            login.Hide ();
            login.Destroy();
        }