Advertisement
Guest User

Untitled

a guest
Apr 13th, 2018
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.52 KB | None | 0 0
  1. public class Account_Window : EditorWindow
  2. {
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. [ExecuteInEditMode]
  10.  
  11. static bool isInitialized = false;
  12. static string clientInstallPath;
  13. static bool signingIn = false;
  14. static string error = null;
  15. private static bool temp1234 = false;
  16.  
  17. static Account_Window window = null;
  18.  
  19. static string saved_User = "";
  20. static string saved_username = "";
  21. static string saved_password = "";
  22. private static bool sav_Signin = false;
  23. public static bool found;
  24.  
  25.  
  26. public static bool DefaultFutureProofPublishEnabled { get { return !SDKClientUtilities.IsInternalSDK(); } }
  27.  
  28. void Update()
  29. {
  30. SignIn(false);
  31. }
  32.  
  33. static string storedUsername
  34. {
  35. get
  36. {
  37. if (EditorPrefs.HasKey("sdk#username"))
  38. return EditorPrefs.GetString("sdk#username");
  39. return null;
  40. }
  41. set
  42. {
  43. EditorPrefs.SetString("sdk#username", value);
  44. if (string.IsNullOrEmpty(value))
  45. EditorPrefs.DeleteKey("sdk#username");
  46. }
  47. }
  48.  
  49. static string storedPassword
  50. {
  51. get
  52. {
  53. if (EditorPrefs.HasKey("sdk#password"))
  54. return EditorPrefs.GetString("sdk#password");
  55. return null;
  56. }
  57. set
  58. {
  59. EditorPrefs.SetString("sdk#password", value);
  60. if (string.IsNullOrEmpty(value))
  61. EditorPrefs.DeleteKey("sdk#password");
  62. }
  63. }
  64.  
  65. static string _username = null;
  66. static string _password = null;
  67.  
  68. static string username
  69. {
  70. get
  71. {
  72. if (!string.IsNullOrEmpty(_username))
  73. return _username;
  74. else
  75. _username = storedUsername;
  76. return _username;
  77. }
  78. set
  79. {
  80. _username = value;
  81. }
  82. }
  83.  
  84. static string password
  85. {
  86. get
  87. {
  88. if (!string.IsNullOrEmpty(_password))
  89. return _password;
  90. else
  91. _password = storedPassword;
  92. return _password;
  93. }
  94. set
  95. {
  96. _password = value;
  97. }
  98. }
  99.  
  100. static ApiServerEnvironment serverEnvironment
  101. {
  102. get
  103. {
  104. ApiServerEnvironment env = ApiServerEnvironment.Release;
  105. try
  106. {
  107. env = (ApiServerEnvironment)System.Enum.Parse(typeof(ApiServerEnvironment), UnityEditor.EditorPrefs.GetString("VRC_ApiServerEnvironment", env.ToString()));
  108. }
  109. catch (System.Exception e)
  110. {
  111. Debug.LogError("Invalid server environment name - " + e.ToString());
  112. }
  113.  
  114. return env;
  115. }
  116. set
  117. {
  118. UnityEditor.EditorPrefs.SetString("VRC_ApiServerEnvironment", value.ToString());
  119.  
  120. ApiModel.SetApiUrlFromEnvironment(value);
  121. }
  122. }
  123.  
  124. public static void RefreshApiUrlSetting()
  125. {
  126. // this forces the static api url variable to be reset from the server environment set in editor prefs.
  127. // needed because the static variable states get cleared when entering / exiting play mode
  128. ApiServerEnvironment env = serverEnvironment;
  129. serverEnvironment = env;
  130. }
  131.  
  132. [MenuItem("VRChat SDK/Login")]
  133. public static void CreateWindow()
  134. {
  135. Init();
  136. window = EditorWindow.GetWindow<Account_Window>("Auto Login");
  137. fixAccounts();
  138. window.Show();
  139. }
  140.  
  141. public static void Init()
  142. {
  143. if (!RemoteConfig.IsInitialized())
  144. RemoteConfig.Init();
  145.  
  146. if (isInitialized)
  147. return;
  148.  
  149. if (!APIUser.IsLoggedInWithCredentials && ApiCredentials.Load())
  150. {
  151. APIUser.Login(null, null);
  152. }
  153.  
  154.  
  155.  
  156. signingIn = false;
  157. isInitialized = true;
  158. }
  159.  
  160. [UnityEditor.Callbacks.DidReloadScripts(int.MaxValue)]
  161. static void DidReloadScripts()
  162. {
  163. RefreshApiUrlSetting();
  164. }
  165.  
  166.  
  167.  
  168. public static bool OnShowStatus()
  169. {
  170. SignIn(false);
  171.  
  172. EditorGUILayout.BeginVertical();
  173.  
  174.  
  175.  
  176. if (APIUser.IsLoggedInWithCredentials)
  177. {
  178. EditorGUILayout.PrefixLabel("Logged in as " + APIUser.CurrentUser.displayName);
  179.  
  180. }
  181.  
  182. EditorGUILayout.EndVertical();
  183.  
  184. return APIUser.IsLoggedInWithCredentials;
  185. }
  186.  
  187. static bool OnAccountGUI()
  188. {
  189. EditorGUILayout.BeginVertical();
  190.  
  191.  
  192.  
  193.  
  194. if (signingIn)
  195. {
  196. EditorGUILayout.LabelField("Signing in.");
  197. EditorGUILayout.EndVertical();
  198. return false;
  199. }
  200. else if (APIUser.IsLoggedInWithCredentials)
  201. {
  202. EditorGUILayout.PrefixLabel("Logged in as " + APIUser.CurrentUser.displayName);
  203.  
  204.  
  205. temp1234 = GUILayout.Toggle(temp1234, "Save Current User");
  206.  
  207. if (temp1234 == true)
  208. {
  209. EditorGUILayout.LabelField("If Shows Null Do not Save", EditorStyles.boldLabel);
  210. EditorGUILayout.LabelField("Press Button To Save Current Logged in User", EditorStyles.boldLabel);
  211.  
  212.  
  213. sav_Signin = true;
  214. if (GUILayout.Button(storedUsername))
  215. {
  216. writeUserData(storedUsername, storedPassword, sav_Signin);
  217. sav_Signin = false;
  218. }
  219.  
  220.  
  221.  
  222.  
  223. }
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235. }
  236. else
  237. {
  238. if (signingIn)
  239. EditorGUILayout.LabelField("Signing in.");
  240. else
  241. {
  242. Init();
  243.  
  244. username = EditorGUILayout.TextField("Username", username);
  245. password = EditorGUILayout.PasswordField("Password", password);
  246.  
  247. // EditorGUILayout.LabelField("Save Login for Quick Login", EditorStyles.boldLabel);
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. sav_Signin = GUILayout.Toggle(sav_Signin, "Saved Signin Info");
  257.  
  258. if (sav_Signin == true)
  259. {
  260. EditorGUILayout.LabelField("Current Glich Dont Save Multiple Of Same Account", EditorStyles.boldLabel);
  261. EditorGUILayout.LabelField("Account Info Can be edited in Asset/VRCSDK/Accounts", EditorStyles.boldLabel);
  262. EditorGUILayout.LabelField("Currently Impossibe to Edit Saved Password Automaticly at this time", EditorStyles.boldLabel);
  263. EditorGUILayout.LabelField("Please Edit in File of Readd account and choose lower option", EditorStyles.boldLabel);
  264. }
  265.  
  266.  
  267.  
  268. if (GUILayout.Button("Sign In"))
  269. SignIn(true);
  270.  
  271. }
  272. }
  273. {
  274.  
  275. }
  276. bool clear_users = false;
  277. EditorGUILayout.Space();
  278. EditorGUILayout.Space();
  279. EditorGUILayout.Space();
  280. EditorGUILayout.Space();
  281. EditorGUILayout.Space();
  282. EditorGUILayout.Space();
  283. EditorGUILayout.Space();
  284. EditorGUILayout.Space();
  285. EditorGUILayout.Space();
  286. EditorGUILayout.Space();
  287. EditorGUILayout.Space();
  288. EditorGUILayout.Space();
  289. if (GUILayout.Button("Logout"))
  290. {
  291.  
  292. storedUsername = username = null;
  293. storedPassword = password = null;
  294. username = null;
  295. APIUser.Logout();
  296. }
  297.  
  298. EditorGUILayout.LabelField("Quick Login", EditorStyles.boldLabel);
  299. if(EditorGUILayout.ToggleLeft("Clear Users List", clear_users) == true)
  300. {
  301. using (var testingText = new StreamWriter("Assets/VRCSDK/Accounts/Accounts.txt", false))
  302. {
  303. Debug.Log("Clearing Saved Accounts");
  304. //testingText.Write("");
  305. //testingText.Flush();
  306. testingText.Close();
  307. }
  308. }
  309. fixAccounts();
  310. StreamReader sr = new StreamReader("Assets/VRCSDK/Accounts/Accounts.txt");
  311.  
  312. string line = "";
  313. while ((line = sr.ReadLine()) != null)//Get List of usernames
  314. {
  315. if (line != "" || line != ":")
  316. {
  317. saved_User = line;
  318. string[] substrings = saved_User.Split(':');//seperate Username/passowrds
  319. // if (substrings[0] == null && substrings[1] == null)
  320. {
  321. //Debug.Log("is null");
  322. saved_User = substrings[0];
  323. saved_password = substrings[1];
  324. if(saved_User != "")
  325. {
  326. if (GUILayout.Button(saved_User))//create button for each user found
  327. {
  328. // string[] substrings = saved_User.Split(':');//seperate Username/passowrds
  329.  
  330. APIUser.Logout();
  331. SavedSignin(saved_User, saved_password);
  332. //sr.Close();
  333. }
  334. }
  335.  
  336. }
  337. }
  338.  
  339.  
  340.  
  341. }
  342. sr.Close();
  343.  
  344.  
  345.  
  346.  
  347.  
  348. // Read the file and display it line by line.
  349. //System.IO.StreamReader sr =
  350. // new System.IO.StreamReader(@"Assets/VRCSDK/Accounts/Accounts.txt");
  351.  
  352. {
  353.  
  354. }
  355.  
  356.  
  357.  
  358. // Suspend the screen.
  359. //System.Console.ReadLine();
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370. // ApiCredentials.SetUser(saved_User, saved_Password);
  371.  
  372. //}
  373.  
  374. {
  375. if (APIUser.CurrentUser == null || APIUser.CurrentUser.developerType == APIUser.DeveloperType.Internal)
  376. {
  377.  
  378.  
  379.  
  380.  
  381. if (APIUser.CurrentUser == null)
  382. {
  383. EditorGUILayout.EndVertical();
  384. return false;
  385. }
  386. }
  387. else
  388. {
  389.  
  390.  
  391.  
  392. }
  393. }
  394.  
  395.  
  396.  
  397.  
  398.  
  399. EditorGUILayout.EndVertical();
  400.  
  401. return true;
  402. }
  403.  
  404. void OnGUI()
  405. {
  406. if (VRC.Core.RemoteConfig.IsInitialized())
  407. {
  408. EditorGUILayout.LabelField("Click Account To Login To other Accounts", EditorStyles.boldLabel);
  409.  
  410. }
  411. else if (VRC.Core.RemoteConfig.HasCachedConfig())
  412. {
  413. VRC.Core.RemoteConfig.Init(false);
  414. }
  415.  
  416. OnAccountGUI();
  417. }
  418.  
  419.  
  420.  
  421. private static object syncObject = new object();
  422. private static void SignIn(bool explicitAttempt)
  423. {
  424. lock (syncObject)
  425. {
  426. if (signingIn
  427. || APIUser.IsLoggedInWithCredentials
  428. || (!explicitAttempt && string.IsNullOrEmpty(storedUsername))
  429. || (!explicitAttempt && string.IsNullOrEmpty(storedPassword)))
  430. return;
  431.  
  432. signingIn = true;
  433. }
  434.  
  435. Init();
  436.  
  437. ApiCredentials.Clear();
  438. ApiCredentials.SetUser(username, password);
  439. APIUser.Login(
  440. delegate (APIUser user)
  441. {
  442. signingIn = false;
  443. error = null;
  444. storedUsername = username;
  445. storedPassword = password;
  446. writeUserData(username, password, sav_Signin);
  447.  
  448. },
  449. delegate (string message)
  450. {
  451. signingIn = false;
  452. storedUsername = null;
  453. storedPassword = null;
  454. error = message;
  455. APIUser.Logout();
  456. VRC.Core.Logger.Log("Error logging in: " + message);
  457. }
  458. );
  459.  
  460. }
  461.  
  462.  
  463.  
  464. private static void SavedSignin(string sav_user, string sav_pass)
  465. {
  466. lock (syncObject)
  467. {
  468.  
  469.  
  470. signingIn = true;
  471. }
  472.  
  473. Init();
  474.  
  475. ApiCredentials.Clear();
  476. ApiCredentials.SetUser(sav_user, sav_pass);
  477. APIUser.Login(
  478. delegate (APIUser user)
  479. {
  480. signingIn = false;
  481. error = null;
  482. storedUsername = sav_user;
  483. storedPassword = sav_pass;
  484. writeUserData(sav_user, sav_pass, false);
  485.  
  486. // writeUserData(sav_user, sav_pass);
  487.  
  488. },
  489. delegate (string message)
  490. {
  491. signingIn = false;
  492. storedUsername = null;
  493. storedPassword = null;
  494. error = message;
  495. APIUser.Logout();
  496. VRC.Core.Logger.Log("Error logging in: " + message);
  497. EditorGUILayout.PrefixLabel("Username/Password Is Different Please Update");
  498.  
  499. }
  500. );
  501. }
  502. private void OnDestroy()
  503. {
  504. signingIn = false;
  505. isInitialized = false;
  506. }
  507.  
  508. private static void writeUserData(string user, string pass, bool write_user_data)
  509. {
  510.  
  511. found = false;
  512. if(write_user_data == true)
  513. {
  514. string guid;
  515. //private string guid;
  516.  
  517. fixAccounts();
  518.  
  519.  
  520. StreamReader sr = new StreamReader("Assets/VRCSDK/Accounts/Accounts.txt");//Verifying File Doesn't Exist already
  521. string line = "";
  522.  
  523. //Debug.Log("Found:" + found);
  524. string _username_to_write = "";
  525. string _password_to_write = "";
  526. while ((line = sr.ReadLine()) != null)//Get List of usernames
  527. {
  528. if (line != "")
  529. {
  530.  
  531. string[] substrings = line.Split(':');//seperate UsernaFme/passowrds
  532.  
  533. _username_to_write = substrings[0];
  534. _password_to_write = substrings[1];
  535. _username_to_write = UppercaseFirst(_username_to_write);
  536.  
  537. user = UppercaseFirst(user);
  538. //Debug.Log("User is formated:" + user);
  539.  
  540. //Debug.Log("Username Formatted to " + _username_to_write);
  541. if (user != _username_to_write)//if username not found Write Username
  542. {
  543. //Debug.Log(user + " Does not = " + username);
  544. found = false;
  545.  
  546.  
  547.  
  548.  
  549.  
  550. }
  551. else if (user == _username_to_write)
  552. {
  553. found = true;
  554. //Debug.Log("User Found");
  555. sr.Close();
  556. break;
  557. }
  558. }
  559. else
  560. {
  561. sr.Close();
  562. break;
  563. }
  564.  
  565. }
  566. sr.Close();
  567. if (found == false)
  568. {
  569.  
  570.  
  571. using (var testingText = new StreamWriter("Assets/VRCSDK/Accounts/Accounts.txt", true))
  572. {
  573. //Debug.Log("Writing User To Accounts File");
  574. testingText.WriteLine(UppercaseFirst(user) + ":" + pass);
  575. testingText.Flush();
  576. testingText.Close();
  577. }
  578.  
  579. }
  580.  
  581. }
  582. }
  583. static string UppercaseFirst(string s)
  584. {
  585.  
  586. s = s.ToLower();
  587. // Check for empty string.
  588. if (string.IsNullOrEmpty(s))
  589. {
  590. return string.Empty;
  591. }
  592. // Return char and concat substring.
  593. //Debug.Log(char.ToUpper(s[0]) + s.Substring(1));
  594. return char.ToUpper(s[0]) + s.Substring(1);
  595.  
  596. }
  597. public static void fixAccounts()
  598. {
  599. if (AssetDatabase.IsValidFolder("Assets/VRCSDK/Accounts") == false)
  600. {
  601. AssetDatabase.CreateFolder("Assets/VRCSDK", "Accounts");
  602. }
  603.  
  604. if (File.Exists("Assets/VRCSDK/Accounts/Accounts.txt") == true)
  605. {
  606. // Debug.Log("File Exist");
  607.  
  608. }else if (File.Exists("Assets/VRCSDK/Accounts/Accounts.txt") == false)
  609. {
  610. //Debug.Log("File Doesn't Exist");
  611. Debug.Log("Creating Files");
  612. StreamWriter writer = new StreamWriter("Assets/VRCSDK/Accounts/Accounts.txt");
  613. writer.WriteLine(":");
  614. writer.Close();
  615. }
  616. }
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement