Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Account_Window : EditorWindow
- {
- [ExecuteInEditMode]
- static bool isInitialized = false;
- static string clientInstallPath;
- static bool signingIn = false;
- static string error = null;
- private static bool temp1234 = false;
- static Account_Window window = null;
- static string saved_User = "";
- static string saved_username = "";
- static string saved_password = "";
- private static bool sav_Signin = false;
- public static bool found;
- public static bool DefaultFutureProofPublishEnabled { get { return !SDKClientUtilities.IsInternalSDK(); } }
- void Update()
- {
- SignIn(false);
- }
- static string storedUsername
- {
- get
- {
- if (EditorPrefs.HasKey("sdk#username"))
- return EditorPrefs.GetString("sdk#username");
- return null;
- }
- set
- {
- EditorPrefs.SetString("sdk#username", value);
- if (string.IsNullOrEmpty(value))
- EditorPrefs.DeleteKey("sdk#username");
- }
- }
- static string storedPassword
- {
- get
- {
- if (EditorPrefs.HasKey("sdk#password"))
- return EditorPrefs.GetString("sdk#password");
- return null;
- }
- set
- {
- EditorPrefs.SetString("sdk#password", value);
- if (string.IsNullOrEmpty(value))
- EditorPrefs.DeleteKey("sdk#password");
- }
- }
- static string _username = null;
- static string _password = null;
- static string username
- {
- get
- {
- if (!string.IsNullOrEmpty(_username))
- return _username;
- else
- _username = storedUsername;
- return _username;
- }
- set
- {
- _username = value;
- }
- }
- static string password
- {
- get
- {
- if (!string.IsNullOrEmpty(_password))
- return _password;
- else
- _password = storedPassword;
- return _password;
- }
- set
- {
- _password = value;
- }
- }
- static ApiServerEnvironment serverEnvironment
- {
- get
- {
- ApiServerEnvironment env = ApiServerEnvironment.Release;
- try
- {
- env = (ApiServerEnvironment)System.Enum.Parse(typeof(ApiServerEnvironment), UnityEditor.EditorPrefs.GetString("VRC_ApiServerEnvironment", env.ToString()));
- }
- catch (System.Exception e)
- {
- Debug.LogError("Invalid server environment name - " + e.ToString());
- }
- return env;
- }
- set
- {
- UnityEditor.EditorPrefs.SetString("VRC_ApiServerEnvironment", value.ToString());
- ApiModel.SetApiUrlFromEnvironment(value);
- }
- }
- public static void RefreshApiUrlSetting()
- {
- // this forces the static api url variable to be reset from the server environment set in editor prefs.
- // needed because the static variable states get cleared when entering / exiting play mode
- ApiServerEnvironment env = serverEnvironment;
- serverEnvironment = env;
- }
- [MenuItem("VRChat SDK/Login")]
- public static void CreateWindow()
- {
- Init();
- window = EditorWindow.GetWindow<Account_Window>("Auto Login");
- fixAccounts();
- window.Show();
- }
- public static void Init()
- {
- if (!RemoteConfig.IsInitialized())
- RemoteConfig.Init();
- if (isInitialized)
- return;
- if (!APIUser.IsLoggedInWithCredentials && ApiCredentials.Load())
- {
- APIUser.Login(null, null);
- }
- signingIn = false;
- isInitialized = true;
- }
- [UnityEditor.Callbacks.DidReloadScripts(int.MaxValue)]
- static void DidReloadScripts()
- {
- RefreshApiUrlSetting();
- }
- public static bool OnShowStatus()
- {
- SignIn(false);
- EditorGUILayout.BeginVertical();
- if (APIUser.IsLoggedInWithCredentials)
- {
- EditorGUILayout.PrefixLabel("Logged in as " + APIUser.CurrentUser.displayName);
- }
- EditorGUILayout.EndVertical();
- return APIUser.IsLoggedInWithCredentials;
- }
- static bool OnAccountGUI()
- {
- EditorGUILayout.BeginVertical();
- if (signingIn)
- {
- EditorGUILayout.LabelField("Signing in.");
- EditorGUILayout.EndVertical();
- return false;
- }
- else if (APIUser.IsLoggedInWithCredentials)
- {
- EditorGUILayout.PrefixLabel("Logged in as " + APIUser.CurrentUser.displayName);
- temp1234 = GUILayout.Toggle(temp1234, "Save Current User");
- if (temp1234 == true)
- {
- EditorGUILayout.LabelField("If Shows Null Do not Save", EditorStyles.boldLabel);
- EditorGUILayout.LabelField("Press Button To Save Current Logged in User", EditorStyles.boldLabel);
- sav_Signin = true;
- if (GUILayout.Button(storedUsername))
- {
- writeUserData(storedUsername, storedPassword, sav_Signin);
- sav_Signin = false;
- }
- }
- }
- else
- {
- if (signingIn)
- EditorGUILayout.LabelField("Signing in.");
- else
- {
- Init();
- username = EditorGUILayout.TextField("Username", username);
- password = EditorGUILayout.PasswordField("Password", password);
- // EditorGUILayout.LabelField("Save Login for Quick Login", EditorStyles.boldLabel);
- sav_Signin = GUILayout.Toggle(sav_Signin, "Saved Signin Info");
- if (sav_Signin == true)
- {
- EditorGUILayout.LabelField("Current Glich Dont Save Multiple Of Same Account", EditorStyles.boldLabel);
- EditorGUILayout.LabelField("Account Info Can be edited in Asset/VRCSDK/Accounts", EditorStyles.boldLabel);
- EditorGUILayout.LabelField("Currently Impossibe to Edit Saved Password Automaticly at this time", EditorStyles.boldLabel);
- EditorGUILayout.LabelField("Please Edit in File of Readd account and choose lower option", EditorStyles.boldLabel);
- }
- if (GUILayout.Button("Sign In"))
- SignIn(true);
- }
- }
- {
- }
- bool clear_users = false;
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- if (GUILayout.Button("Logout"))
- {
- storedUsername = username = null;
- storedPassword = password = null;
- username = null;
- APIUser.Logout();
- }
- EditorGUILayout.LabelField("Quick Login", EditorStyles.boldLabel);
- if(EditorGUILayout.ToggleLeft("Clear Users List", clear_users) == true)
- {
- using (var testingText = new StreamWriter("Assets/VRCSDK/Accounts/Accounts.txt", false))
- {
- Debug.Log("Clearing Saved Accounts");
- //testingText.Write("");
- //testingText.Flush();
- testingText.Close();
- }
- }
- fixAccounts();
- StreamReader sr = new StreamReader("Assets/VRCSDK/Accounts/Accounts.txt");
- string line = "";
- while ((line = sr.ReadLine()) != null)//Get List of usernames
- {
- if (line != "" || line != ":")
- {
- saved_User = line;
- string[] substrings = saved_User.Split(':');//seperate Username/passowrds
- // if (substrings[0] == null && substrings[1] == null)
- {
- //Debug.Log("is null");
- saved_User = substrings[0];
- saved_password = substrings[1];
- if(saved_User != "")
- {
- if (GUILayout.Button(saved_User))//create button for each user found
- {
- // string[] substrings = saved_User.Split(':');//seperate Username/passowrds
- APIUser.Logout();
- SavedSignin(saved_User, saved_password);
- //sr.Close();
- }
- }
- }
- }
- }
- sr.Close();
- // Read the file and display it line by line.
- //System.IO.StreamReader sr =
- // new System.IO.StreamReader(@"Assets/VRCSDK/Accounts/Accounts.txt");
- {
- }
- // Suspend the screen.
- //System.Console.ReadLine();
- // ApiCredentials.SetUser(saved_User, saved_Password);
- //}
- {
- if (APIUser.CurrentUser == null || APIUser.CurrentUser.developerType == APIUser.DeveloperType.Internal)
- {
- if (APIUser.CurrentUser == null)
- {
- EditorGUILayout.EndVertical();
- return false;
- }
- }
- else
- {
- }
- }
- EditorGUILayout.EndVertical();
- return true;
- }
- void OnGUI()
- {
- if (VRC.Core.RemoteConfig.IsInitialized())
- {
- EditorGUILayout.LabelField("Click Account To Login To other Accounts", EditorStyles.boldLabel);
- }
- else if (VRC.Core.RemoteConfig.HasCachedConfig())
- {
- VRC.Core.RemoteConfig.Init(false);
- }
- OnAccountGUI();
- }
- private static object syncObject = new object();
- private static void SignIn(bool explicitAttempt)
- {
- lock (syncObject)
- {
- if (signingIn
- || APIUser.IsLoggedInWithCredentials
- || (!explicitAttempt && string.IsNullOrEmpty(storedUsername))
- || (!explicitAttempt && string.IsNullOrEmpty(storedPassword)))
- return;
- signingIn = true;
- }
- Init();
- ApiCredentials.Clear();
- ApiCredentials.SetUser(username, password);
- APIUser.Login(
- delegate (APIUser user)
- {
- signingIn = false;
- error = null;
- storedUsername = username;
- storedPassword = password;
- writeUserData(username, password, sav_Signin);
- },
- delegate (string message)
- {
- signingIn = false;
- storedUsername = null;
- storedPassword = null;
- error = message;
- APIUser.Logout();
- VRC.Core.Logger.Log("Error logging in: " + message);
- }
- );
- }
- private static void SavedSignin(string sav_user, string sav_pass)
- {
- lock (syncObject)
- {
- signingIn = true;
- }
- Init();
- ApiCredentials.Clear();
- ApiCredentials.SetUser(sav_user, sav_pass);
- APIUser.Login(
- delegate (APIUser user)
- {
- signingIn = false;
- error = null;
- storedUsername = sav_user;
- storedPassword = sav_pass;
- writeUserData(sav_user, sav_pass, false);
- // writeUserData(sav_user, sav_pass);
- },
- delegate (string message)
- {
- signingIn = false;
- storedUsername = null;
- storedPassword = null;
- error = message;
- APIUser.Logout();
- VRC.Core.Logger.Log("Error logging in: " + message);
- EditorGUILayout.PrefixLabel("Username/Password Is Different Please Update");
- }
- );
- }
- private void OnDestroy()
- {
- signingIn = false;
- isInitialized = false;
- }
- private static void writeUserData(string user, string pass, bool write_user_data)
- {
- found = false;
- if(write_user_data == true)
- {
- string guid;
- //private string guid;
- fixAccounts();
- StreamReader sr = new StreamReader("Assets/VRCSDK/Accounts/Accounts.txt");//Verifying File Doesn't Exist already
- string line = "";
- //Debug.Log("Found:" + found);
- string _username_to_write = "";
- string _password_to_write = "";
- while ((line = sr.ReadLine()) != null)//Get List of usernames
- {
- if (line != "")
- {
- string[] substrings = line.Split(':');//seperate UsernaFme/passowrds
- _username_to_write = substrings[0];
- _password_to_write = substrings[1];
- _username_to_write = UppercaseFirst(_username_to_write);
- user = UppercaseFirst(user);
- //Debug.Log("User is formated:" + user);
- //Debug.Log("Username Formatted to " + _username_to_write);
- if (user != _username_to_write)//if username not found Write Username
- {
- //Debug.Log(user + " Does not = " + username);
- found = false;
- }
- else if (user == _username_to_write)
- {
- found = true;
- //Debug.Log("User Found");
- sr.Close();
- break;
- }
- }
- else
- {
- sr.Close();
- break;
- }
- }
- sr.Close();
- if (found == false)
- {
- using (var testingText = new StreamWriter("Assets/VRCSDK/Accounts/Accounts.txt", true))
- {
- //Debug.Log("Writing User To Accounts File");
- testingText.WriteLine(UppercaseFirst(user) + ":" + pass);
- testingText.Flush();
- testingText.Close();
- }
- }
- }
- }
- static string UppercaseFirst(string s)
- {
- s = s.ToLower();
- // Check for empty string.
- if (string.IsNullOrEmpty(s))
- {
- return string.Empty;
- }
- // Return char and concat substring.
- //Debug.Log(char.ToUpper(s[0]) + s.Substring(1));
- return char.ToUpper(s[0]) + s.Substring(1);
- }
- public static void fixAccounts()
- {
- if (AssetDatabase.IsValidFolder("Assets/VRCSDK/Accounts") == false)
- {
- AssetDatabase.CreateFolder("Assets/VRCSDK", "Accounts");
- }
- if (File.Exists("Assets/VRCSDK/Accounts/Accounts.txt") == true)
- {
- // Debug.Log("File Exist");
- }else if (File.Exists("Assets/VRCSDK/Accounts/Accounts.txt") == false)
- {
- //Debug.Log("File Doesn't Exist");
- Debug.Log("Creating Files");
- StreamWriter writer = new StreamWriter("Assets/VRCSDK/Accounts/Accounts.txt");
- writer.WriteLine(":");
- writer.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement