Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.17 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. using CodeStage.AntiCheat.ObscuredTypes;
  7.  
  8. public class AS_CanvasUI : MonoBehaviour
  9. {
  10. /*
  11. * --- TODO: CUSTOMIZE ---
  12. *
  13. * Called upon Successful Login - Add any custom logic here
  14. * You could load a level, initialize some characters or
  15. * download additional info. The latter can be done by an
  16. * AS_AccountManagementGUI instance.
  17. */
  18.  
  19.  
  20. private string finalUsername;
  21. private string finalPassword;
  22. private ObscuredInt accountID;
  23. public GameObject loading;
  24. public InputField clanTagField;
  25.  
  26. public static AS_CanvasUI singleton;
  27.  
  28. public bool useUI = true;
  29.  
  30. public void OnSuccessfulLogin(int id, bool ui = true)
  31. {
  32. accountID = id;
  33. if (useUI)
  34. {
  35. //this.Log(LogType.Log, "Successfully Logged In User with id: " + id + " - Add any custom Logic Here!");
  36. loginState = AS_LoginState.LoginSuccessful;
  37. }
  38. ObscuredPrefs.SetInt("loginID", id);
  39. //Application.LoadLevel ("MultiplayerScene");
  40. accountInfo.customInfo = new AS_CustomInfo();
  41. accountInfo.TryToDownload (id, AccountInfoDownloaded);
  42. /*if (accountManagementGUI)
  43. {
  44. accountManagementGUI.enabled = true;
  45. accountManagementGUI.Init(id);
  46. }*/
  47. }
  48.  
  49. public void AccountInfoUploaded (string message)
  50. {
  51. accountInfo.TryToDownload (accountID, AccountInfoDownloaded);
  52. }
  53.  
  54. void UploadUnlockedCamos(int index, string weaponName)
  55. {
  56. List<CamoManager.CamoType> unlockedCamos = new List<CamoManager.CamoType>();
  57. foreach (CamoManager.CamoType t in System.Enum.GetValues (typeof(CamoManager.CamoType))) {
  58. if (t != CamoManager.CamoType.None) {
  59. if (ObscuredPrefs.GetInt(weaponName + "_HASCAMO_" + (int)t) == 1)
  60. {
  61. unlockedCamos.Add(t);
  62. }
  63. }
  64. }
  65. accountInfo.customInfo.weaponInfo[index].camos = new int[unlockedCamos.Count];
  66. for (int j = 0; j < unlockedCamos.Count; j++)
  67. {
  68. accountInfo.customInfo.weaponInfo[index].camos[j] = (int)unlockedCamos[j];
  69. }
  70. }
  71.  
  72. void UploadUnlockedSights(int index, string weaponName)
  73. {
  74. List<AttachmentManager.SightType> unlocked = new List<AttachmentManager.SightType>();
  75. foreach (AttachmentManager.SightType t in System.Enum.GetValues (typeof(AttachmentManager.SightType))) {
  76. if (t != AttachmentManager.SightType.None) {
  77. if (ObscuredPrefs.GetInt(weaponName + "_SIGHT_" + (int)t) == 1)
  78. {
  79. unlocked.Add(t);
  80. }
  81. }
  82. }
  83. accountInfo.customInfo.weaponInfo[index].sights = new int[unlocked.Count];
  84. for (int j = 0; j < unlocked.Count; j++)
  85. {
  86. accountInfo.customInfo.weaponInfo[index].sights[j] = (int)unlocked[j];
  87. }
  88. }
  89.  
  90. void UploadUnlockedBarrels(int index, string weaponName)
  91. {
  92. List<AttachmentManager.BarrelType> unlocked = new List<AttachmentManager.BarrelType>();
  93. foreach (AttachmentManager.BarrelType t in System.Enum.GetValues (typeof(AttachmentManager.BarrelType))) {
  94. if (t != AttachmentManager.BarrelType.None) {
  95. if (ObscuredPrefs.GetInt(weaponName + "_BARREL_" + (int)t) == 1)
  96. {
  97. unlocked.Add(t);
  98. }
  99. }
  100. }
  101. accountInfo.customInfo.weaponInfo[index].barrels = new int[unlocked.Count];
  102. for (int j = 0; j < unlocked.Count; j++)
  103. {
  104. accountInfo.customInfo.weaponInfo[index].barrels[j] = (int)unlocked[j];
  105. }
  106. }
  107.  
  108. void UploadUnlockedAccessories(int index, string weaponName)
  109. {
  110. List<AttachmentManager.AccessoryType> unlocked = new List<AttachmentManager.AccessoryType>();
  111. foreach (AttachmentManager.AccessoryType t in System.Enum.GetValues (typeof(AttachmentManager.AccessoryType))) {
  112. if (t != AttachmentManager.AccessoryType.None) {
  113. if (ObscuredPrefs.GetInt(weaponName + "_ACCESSORY_" + (int)t) == 1)
  114. {
  115. unlocked.Add(t);
  116. }
  117. }
  118. }
  119. accountInfo.customInfo.weaponInfo[index].accessories = new int[unlocked.Count];
  120. for (int j = 0; j < unlocked.Count; j++)
  121. {
  122. accountInfo.customInfo.weaponInfo[index].accessories[j] = (int)unlocked[j];
  123. }
  124. }
  125.  
  126. void UploadCamosOnLoadouts(int index, string weaponName, bool blank = false)
  127. {
  128. // 3 loadouts total
  129. accountInfo.customInfo.weaponInfo[index].camosOnLoadouts = new int[3];
  130. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  131. {
  132. accountInfo.customInfo.weaponInfo[index].camosOnLoadouts[activeLoadout] = blank ? 0 : ObscuredPrefs.GetInt(activeLoadout + "" + weaponName + "_CAMO");
  133. }
  134. }
  135.  
  136. void UploadSightsOnLoadouts(int index, string weaponName, bool blank = false)
  137. {
  138. // 3 loadouts total
  139. accountInfo.customInfo.weaponInfo[index].sightsOnLoadouts = new int[3];
  140. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  141. {
  142. accountInfo.customInfo.weaponInfo[index].sightsOnLoadouts[activeLoadout] = blank ? 0 : ObscuredPrefs.GetInt(activeLoadout + "" + weaponName + "_SIGHT");
  143. }
  144. }
  145.  
  146. void UploadBarrelsOnLoadouts(int index, string weaponName, bool blank = false)
  147. {
  148. // 3 loadouts total
  149. accountInfo.customInfo.weaponInfo[index].barrelsOnLoadouts = new int[3];
  150. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  151. {
  152. accountInfo.customInfo.weaponInfo[index].barrelsOnLoadouts[activeLoadout] = blank ? 0 : ObscuredPrefs.GetInt(activeLoadout + "" + weaponName + "_BARREL");
  153. }
  154. }
  155.  
  156. void UploadAccessoriesOnLoadouts(int index, string weaponName, bool blank = false)
  157. {
  158. // 3 loadouts total
  159. accountInfo.customInfo.weaponInfo[index].accessoriesOnLoadouts = new int[3];
  160. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  161. {
  162. accountInfo.customInfo.weaponInfo[index].accessoriesOnLoadouts[activeLoadout] = blank ? 0 : ObscuredPrefs.GetInt(activeLoadout + "" + weaponName + "_ACCESSORY");
  163. }
  164. }
  165.  
  166. public void EditClanTag(string tag)
  167. {
  168. ObscuredPrefs.SetString("clantag", tag);
  169. }
  170.  
  171. void UploadBlankInfo()
  172. {
  173. accountInfo.customInfo.bfAccountInfo.money = 2000;
  174. accountInfo.customInfo.bfAccountInfo.xp = 0;
  175. accountInfo.customInfo.bfAccountInfo.deviceID = SystemInfo.deviceUniqueIdentifier;
  176.  
  177. // Make sure, when adding new weapons, to ALWAYS add them to the end of the array or it will break
  178.  
  179. string[] weapons = new string[18];
  180. weapons [0] = "M4A1";
  181. weapons [1] = "AK-12";
  182. weapons [2] = "FAMAS";
  183. weapons [3] = "M40A5";
  184. weapons [4] = "SAIGA 12K";
  185. weapons [5] = "SCAR-H";
  186. weapons [6] = "MPX";
  187. weapons [7] = "AS VAL";
  188. weapons [8] = "SRR-61";
  189. weapons [9] = "MG4";
  190. weapons [10] = "RPG-7V2";
  191. weapons [11] = "MP412 REX";
  192. weapons [12] = "COMPACT .45";
  193. weapons [13] = "BUTTERFLY KNIFE";
  194. weapons [14] = "G18";
  195. weapons [15] = "M320 HE";
  196. weapons [16] = "M320 DART";
  197. weapons [17] = "870 MCS";
  198.  
  199.  
  200. accountInfo.customInfo.weaponInfo = new BF_WeaponInfo[weapons.Length];
  201.  
  202. for (int i = 0; i < weapons.Length; i++)
  203. {
  204. accountInfo.customInfo.weaponInfo[i] = new BF_WeaponInfo (0, 0, new int[3], new int[3], new int[3], new int[3], new int[1], new int[1], new int[1], new int[1]);
  205. PlayerScript.WeaponType weaponType = GunStats.singleton.WeaponNameToWeaponType(weapons[i]);
  206. accountInfo.customInfo.weaponInfo[i].weapon = (int)weaponType;
  207. accountInfo.customInfo.weaponInfo[i].unlockedWeapon = 0;
  208.  
  209. accountInfo.customInfo.weaponInfo[i].camos = new int[1];
  210. accountInfo.customInfo.weaponInfo[i].sights = new int[1];
  211. accountInfo.customInfo.weaponInfo[i].barrels= new int[1];
  212. accountInfo.customInfo.weaponInfo[i].accessories = new int[1];
  213.  
  214. UploadCamosOnLoadouts(i, weapons[i], true);
  215. UploadSightsOnLoadouts(i, weapons[i], true);
  216. UploadBarrelsOnLoadouts(i, weapons[i], true);
  217. UploadAccessoriesOnLoadouts(i, weapons[i], true);
  218. }
  219.  
  220. string[] throwables = new string[4];
  221. throwables [0] = "M67 FRAG";
  222. throwables [1] = "M84 FLASHBANG";
  223. throwables [2] = "M18 SMOKE GRENADE";
  224. throwables [3] = "THROWING KNIFE";
  225.  
  226. accountInfo.customInfo.throwableInfo = new BF_ThrowableInfo[throwables.Length];
  227.  
  228. for (int i = 0; i < throwables.Length; i++)
  229. {
  230. accountInfo.customInfo.throwableInfo[i] = new BF_ThrowableInfo (0, 0);
  231. PlayerScript.WeaponType weaponType = GunStats.singleton.WeaponNameToWeaponType(throwables[i]);
  232. accountInfo.customInfo.throwableInfo[i].weapon = (int)weaponType;
  233. accountInfo.customInfo.throwableInfo[i].unlockedWeapon = 0;
  234. }
  235.  
  236. DownloadInfoFromServer(false);
  237. Intro.SetDefaults(true);
  238. accountInfo.TryToUpload (accountID, FinishedUpdating);
  239. }
  240.  
  241. void UploadCurrentInfo()
  242. {
  243. accountInfo.customInfo.bfAccountInfo.money = ObscuredPrefs.GetInt (CreditsManager.creditsPrefsKey);
  244. accountInfo.customInfo.bfAccountInfo.xp = ObscuredPrefs.GetInt (XPManager.xpSaveKey);
  245. accountInfo.customInfo.bfAccountInfo.deviceID = SystemInfo.deviceUniqueIdentifier;
  246.  
  247. // Make sure, when adding new weapons, to ALWAYS add them to the end of the array or it will break
  248.  
  249. string[] weapons = new string[18];
  250. weapons [0] = "M4A1";
  251. weapons [1] = "AK-12";
  252. weapons [2] = "FAMAS";
  253. weapons [3] = "M40A5";
  254. weapons [4] = "SAIGA 12K";
  255. weapons [5] = "SCAR-H";
  256. weapons [6] = "MPX";
  257. weapons [7] = "AS VAL";
  258. weapons [8] = "SRR-61";
  259. weapons [9] = "MG4";
  260. weapons [10] = "RPG-7V2";
  261. weapons [11] = "MP412 REX";
  262. weapons [12] = "COMPACT .45";
  263. weapons [13] = "BUTTERFLY KNIFE";
  264. weapons [14] = "G18";
  265. weapons [15] = "M320 HE";
  266. weapons [16] = "M320 DART";
  267. weapons [17] = "870 MCS";
  268.  
  269.  
  270. accountInfo.customInfo.weaponInfo = new BF_WeaponInfo[weapons.Length];
  271.  
  272. for (int i = 0; i < weapons.Length; i++)
  273. {
  274. accountInfo.customInfo.weaponInfo[i] = new BF_WeaponInfo (0, 0, new int[3], new int[3], new int[3], new int[3], new int[1], new int[1], new int[1], new int[1]);
  275. PlayerScript.WeaponType weaponType = GunStats.singleton.WeaponNameToWeaponType(weapons[i]);
  276. accountInfo.customInfo.weaponInfo[i].weapon = (int)weaponType;
  277. accountInfo.customInfo.weaponInfo[i].unlockedWeapon = ObscuredPrefs.GetInt("UNLOCKED_" + weapons[i]);
  278.  
  279. if (PlayerPrefs.GetInt("streamer") == 1)
  280. {
  281. ObscuredPrefs.SetInt(weapons[i] + "_HASCAMO_" + (int)CamoManager.CamoType.Mobcrush, 1);
  282. }
  283. else{
  284. ObscuredPrefs.SetInt(weapons[i] + "_HASCAMO_" + (int)CamoManager.CamoType.Mobcrush, 0);
  285. }
  286.  
  287. if (PlayerPrefs.GetString("clan").ToLower() == "sxc")
  288. {
  289. ObscuredPrefs.SetInt(weapons[i] + "_HASCAMO_" + (int)CamoManager.CamoType.SxC, 1);
  290. }
  291. else{
  292. ObscuredPrefs.SetInt(weapons[i] + "_HASCAMO_" + (int)CamoManager.CamoType.SxC, 0);
  293. }
  294.  
  295. UploadUnlockedCamos(i, weapons[i]);
  296. UploadUnlockedSights(i, weapons[i]);
  297. UploadUnlockedBarrels(i, weapons[i]);
  298. UploadUnlockedAccessories(i, weapons[i]);
  299.  
  300. UploadCamosOnLoadouts(i, weapons[i]);
  301. UploadSightsOnLoadouts(i, weapons[i]);
  302. UploadBarrelsOnLoadouts(i, weapons[i]);
  303. UploadAccessoriesOnLoadouts(i, weapons[i]);
  304. }
  305.  
  306. string[] throwables = new string[4];
  307. throwables [0] = "M67 FRAG";
  308. throwables [1] = "M84 FLASHBANG";
  309. throwables [2] = "M18 SMOKE GRENADE";
  310. throwables [3] = "THROWING KNIFE";
  311.  
  312. accountInfo.customInfo.throwableInfo = new BF_ThrowableInfo[throwables.Length];
  313.  
  314. for (int i = 0; i < throwables.Length; i++)
  315. {
  316. accountInfo.customInfo.throwableInfo[i] = new BF_ThrowableInfo (0, 0);
  317. PlayerScript.WeaponType weaponType = GunStats.singleton.WeaponNameToWeaponType(throwables[i]);
  318. accountInfo.customInfo.throwableInfo[i].weapon = (int)weaponType;
  319. accountInfo.customInfo.throwableInfo[i].unlockedWeapon = ObscuredPrefs.GetInt("UNLOCKED_" + weapons[i]);
  320. }
  321.  
  322. accountInfo.TryToUpload (accountID, FinishedUpdating);
  323. }
  324.  
  325. void DownloadUnlockedCamos(int index, string weaponName)
  326. {
  327. foreach (CamoManager.CamoType t in System.Enum.GetValues (typeof(CamoManager.CamoType))) {
  328. if (t != CamoManager.CamoType.None) {
  329. ObscuredPrefs.SetInt(weaponName + "_HASCAMO_" + (int)t, accountInfo.customInfo.weaponInfo[index].camos.Contains((int)t) ? 1 : 0);
  330. }
  331. }
  332. }
  333.  
  334. void DownloadUnlockedSights(int index, string weaponName)
  335. {
  336. foreach (AttachmentManager.SightType t in System.Enum.GetValues (typeof(AttachmentManager.SightType))) {
  337. if (t != AttachmentManager.SightType.None) {
  338. ObscuredPrefs.SetInt(weaponName + "_SIGHT_" + (int)t, accountInfo.customInfo.weaponInfo[index].sights.Contains((int)t) ? 1 : 0);
  339. }
  340. }
  341. }
  342.  
  343. void DownloadUnlockedBarrels(int index, string weaponName)
  344. {
  345. foreach (AttachmentManager.BarrelType t in System.Enum.GetValues (typeof(AttachmentManager.BarrelType))) {
  346. if (t != AttachmentManager.BarrelType.None) {
  347. ObscuredPrefs.SetInt(weaponName + "_BARREL_" + (int)t, accountInfo.customInfo.weaponInfo[index].barrels.Contains((int)t) ? 1 : 0);
  348. }
  349. }
  350. }
  351.  
  352. void DownloadUnlockedAccessories(int index, string weaponName)
  353. {
  354. foreach (AttachmentManager.AccessoryType t in System.Enum.GetValues (typeof(AttachmentManager.AccessoryType))) {
  355. if (t != AttachmentManager.AccessoryType.None) {
  356. ObscuredPrefs.SetInt(weaponName + "_ACCESSORY_" + (int)t, accountInfo.customInfo.weaponInfo[index].accessories.Contains((int)t) ? 1 : 0);
  357. }
  358. }
  359. }
  360.  
  361. void DownloadCamosOnLoadouts(int index, string weaponName)
  362. {
  363. // 3 loadouts total
  364. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  365. {
  366. int camo = accountInfo.customInfo.weaponInfo[index].camosOnLoadouts[activeLoadout];
  367. if (camo == (int)CamoManager.CamoType.None || ObscuredPrefs.GetInt(weaponName + "_HASCAMO_" + camo) == 1)
  368. {
  369. ObscuredPrefs.SetInt(activeLoadout + "" + weaponName + "_CAMO", camo);
  370. }
  371. else
  372. {
  373. ObscuredPrefs.SetInt(activeLoadout + "" + weaponName + "_CAMO", 0);
  374. }
  375. }
  376. }
  377.  
  378. void DownloadSightsOnLoadouts(int index, string weaponName)
  379. {
  380. // 3 loadouts total
  381. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  382. {
  383. ObscuredPrefs.SetInt(activeLoadout + "" + weaponName + "_SIGHT", accountInfo.customInfo.weaponInfo[index].sightsOnLoadouts[activeLoadout]);
  384. }
  385. }
  386.  
  387. void DownloadBarrelsOnLoadouts(int index, string weaponName)
  388. {
  389. // 3 loadouts total
  390. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  391. {
  392. ObscuredPrefs.SetInt(activeLoadout + "" + weaponName + "_BARREL", accountInfo.customInfo.weaponInfo[index].barrelsOnLoadouts[activeLoadout]);
  393. }
  394. }
  395.  
  396. void DownloadAccessoriesOnLoadouts(int index, string weaponName)
  397. {
  398. // 3 loadouts total
  399. for (int activeLoadout = 0; activeLoadout < 3; activeLoadout++)
  400. {
  401. ObscuredPrefs.SetInt(activeLoadout + "" + weaponName + "_ACCESSORY", accountInfo.customInfo.weaponInfo[index].accessoriesOnLoadouts[activeLoadout]);
  402. }
  403. }
  404.  
  405. void DownloadInfoFromServer(bool uploadAfter = true)
  406. {
  407. ObscuredPrefs.SetInt (CreditsManager.creditsPrefsKey, accountInfo.customInfo.bfAccountInfo.money);
  408. ObscuredPrefs.SetInt (XPManager.xpSaveKey, accountInfo.customInfo.bfAccountInfo.xp);
  409. ObscuredPrefs.SetInt("PastXP", accountInfo.customInfo.bfAccountInfo.xp);
  410. accountInfo.customInfo.bfAccountInfo.deviceID = SystemInfo.deviceUniqueIdentifier;
  411.  
  412. string[] weapons = new string[18];
  413. weapons [0] = "M4A1";
  414. weapons [1] = "AK-12";
  415. weapons [2] = "FAMAS";
  416. weapons [3] = "M40A5";
  417. weapons [4] = "SAIGA 12K";
  418. weapons [5] = "SCAR-H";
  419. weapons [6] = "MPX";
  420. weapons [7] = "AS VAL";
  421. weapons [8] = "SRR-61";
  422. weapons [9] = "MG4";
  423. weapons [10] = "RPG-7V2";
  424. weapons [11] = "MP412 REX";
  425. weapons [12] = "COMPACT .45";
  426. weapons [13] = "BUTTERFLY KNIFE";
  427. weapons [14] = "G18";
  428. weapons [15] = "M320 HE";
  429. weapons [16] = "M320 DART";
  430. weapons [17] = "870 MCS";
  431.  
  432. for (int i = 0; i < accountInfo.customInfo.weaponInfo.Length; i++)
  433. {
  434. ObscuredPrefs.SetInt("UNLOCKED_" + weapons[i], accountInfo.customInfo.weaponInfo[i].unlockedWeapon);
  435.  
  436. DownloadUnlockedCamos(i, weapons[i]);
  437. DownloadUnlockedSights(i, weapons[i]);
  438. DownloadUnlockedBarrels(i, weapons[i]);
  439. DownloadUnlockedAccessories(i, weapons[i]);
  440.  
  441. DownloadCamosOnLoadouts(i, weapons[i]);
  442. DownloadSightsOnLoadouts(i, weapons[i]);
  443. DownloadBarrelsOnLoadouts(i, weapons[i]);
  444. DownloadAccessoriesOnLoadouts(i, weapons[i]);
  445.  
  446. if (PlayerPrefs.GetInt("streamer") == 1)
  447. {
  448. ObscuredPrefs.SetInt(weapons[i] + "_HASCAMO_" + (int)CamoManager.CamoType.Mobcrush, 1);
  449. }
  450. else{
  451. ObscuredPrefs.SetInt(weapons[i] + "_HASCAMO_" + (int)CamoManager.CamoType.Mobcrush, 0);
  452. }
  453.  
  454. }
  455.  
  456.  
  457. string[] throwables = new string[4];
  458. throwables [0] = "M67 FRAG";
  459. throwables [1] = "M84 FLASHBANG";
  460. throwables [2] = "M18 SMOKE GRENADE";
  461. throwables [3] = "THROWING KNIFE";
  462.  
  463. for (int i = 0; i < accountInfo.customInfo.throwableInfo.Length; i++)
  464. {
  465. ObscuredPrefs.SetInt("UNLOCKED_" + throwables[i], accountInfo.customInfo.throwableInfo[i].unlockedWeapon);
  466. }
  467.  
  468. if (uploadAfter)
  469. {
  470. accountInfo.TryToUpload (accountID, FinishedUpdating);
  471. }
  472. }
  473.  
  474. public void FinishedUpdating(string message)
  475. {
  476. if (CamoCaseManager.singleton)
  477. {
  478. CamoCaseManager.singleton.SetCases(accountInfo.customInfo.bfAccountInfo.cases);
  479. }
  480. if (LoadoutManager.Instance)
  481. {
  482. LoadoutManager.Instance.SetGold(accountInfo.customInfo.bfAccountInfo.gold);
  483. LoadoutManager.Instance.WeaponPurchased();
  484. }
  485. if (GoldManager.singleton)
  486. {
  487. GoldManager.singleton.SetGold(accountInfo.customInfo.bfAccountInfo.gold);
  488. }
  489. if (CreditsManager.singleton)
  490. {
  491. CreditsManager.singleton.FinishedUploadingCredits();
  492. }
  493. if (useUI)
  494. {
  495. Application.LoadLevel ("MultiplayerScene");
  496. }
  497. }
  498.  
  499. public void AccountInfoDownloaded (string message)
  500. {
  501. accountInfo.customInfo.bfAccountInfo.gold += ObscuredPrefs.GetInt("goldtoadd");
  502. accountInfo.customInfo.bfAccountInfo.v = PNetworkManager.version;
  503. switch (Application.platform)
  504. {
  505. case RuntimePlatform.IPhonePlayer:
  506. accountInfo.customInfo.bfAccountInfo.platform = "iOS";
  507. break;
  508. case RuntimePlatform.Android:
  509. accountInfo.customInfo.bfAccountInfo.platform = "Android";
  510. break;
  511. case RuntimePlatform.OSXEditor:
  512. accountInfo.customInfo.bfAccountInfo.platform = "Android";
  513. break;
  514. default:
  515. accountInfo.customInfo.bfAccountInfo.platform = "";
  516. break;
  517. }
  518. if (ObscuredPrefs.GetInt("goldtoadd") > 0)
  519. {
  520. accountInfo.customInfo.bfAccountInfo.totalGoldBought += ObscuredPrefs.GetInt("goldtoadd");
  521. }
  522. ObscuredPrefs.SetInt("cases", accountInfo.customInfo.bfAccountInfo.cases);
  523. ObscuredPrefs.SetInt("goldtoadd", 0);
  524.  
  525. // These lines are to fool hackers
  526. PlayerPrefs.SetInt("gold", accountInfo.customInfo.bfAccountInfo.gold);
  527. PlayerPrefs.SetInt("credits", accountInfo.customInfo.bfAccountInfo.money);
  528.  
  529. if (accountInfo.customInfo.bfAccountInfo.hacker)
  530. {
  531. ObscuredPrefs.SetBool("hacker", accountInfo.customInfo.bfAccountInfo.hacker);
  532. }
  533.  
  534. PlayerPrefs.SetInt("streamer", accountInfo.customInfo.bfAccountInfo.streamer?1:0);
  535. PlayerPrefs.SetString("clan", accountInfo.customInfo.bfAccountInfo.clan);
  536.  
  537. if (accountInfo.customInfo.bfAccountInfo.deviceID == "error")
  538. {
  539. Debug.Log("ERROR!!! :(");
  540. // There was an error deserializing the custom info XML, so upload correct data
  541. UploadCurrentInfo();
  542. }
  543. else if (accountInfo.customInfo.bfAccountInfo.deviceID == "") {
  544. // First time logging in after making new account
  545. //UploadCurrentInfo();
  546. UploadBlankInfo();
  547. }
  548. else if (accountInfo.GetFieldValue("username").ToLower() != ObscuredPrefs.GetString ("username").ToLower())
  549. {
  550. // Not first time logging in after making new account
  551. // Switching accounts or first time logging into existing account after installing app
  552. DownloadInfoFromServer();
  553. }
  554. else if ((accountInfo.customInfo.bfAccountInfo.deviceID != SystemInfo.deviceUniqueIdentifier ||
  555. accountInfo.customInfo.bfAccountInfo.xp > ObscuredPrefs.GetInt(XPManager.xpSaveKey))) {
  556. Debug.Log("LENGTH: " + accountInfo.customInfo.weaponInfo.Length);
  557. // Not first time logging in
  558. // Not switching accounts
  559. // Logging in from a different device (or same device with glitch) or account has more XP than device
  560. if (accountInfo.customInfo.weaponInfo.Length > 10)
  561. {
  562. DownloadInfoFromServer();
  563. }
  564. else{
  565. UploadCurrentInfo();
  566. //UploadBlankInfo();
  567. }
  568. } else if (accountInfo.customInfo.bfAccountInfo.deviceID == SystemInfo.deviceUniqueIdentifier) {
  569. // Normal log in to old account with same device
  570.  
  571. // Update account info with local info
  572. UploadCurrentInfo();
  573. }
  574. if (useUI)
  575. {
  576. ObscuredPrefs.SetString ("username", finalUsername);
  577. ObscuredPrefs.SetString ("password", finalPassword);
  578. }
  579. ObscuredPrefs.Save();
  580. }
  581.  
  582. // Messages to the user
  583. /// <summary>
  584. /// Make sure there's a child with that name in every canvas group
  585. /// </summary>
  586. public string guiMessageTextName = "GUI Message";
  587. /// <summary>
  588. /// Gui messages disappear after this time. Set negative or 0 to keep indefinitely.
  589. /// </summary>
  590. public float guiMessageTime = 5;
  591.  
  592. // The parent groups of the different login states
  593. public CanvasGroup loginParent, registrationParent, recoveryParent;
  594.  
  595. public InputField usernameField, passwordField, recoveryField;
  596. /// <summary>
  597. /// Container to place all the registration fields. The list is populated online by quering the server.
  598. /// </summary>
  599. public GridLayoutGroup registrationFieldsContainer;
  600.  
  601. /// <summary>
  602. /// A prefab to serve as a registration input field
  603. /// </summary>
  604. public GameObject inputFieldPrefab;
  605.  
  606. /// <summary>
  607. /// Only need to set this if using Password Recovery (from Setup)
  608. /// </summary>
  609. public Button recoveryButton;
  610.  
  611. Text guiMessageText;
  612. AS_AccountInfo accountInfo = new AS_AccountInfo();
  613. AS_MySQLField passwordConfirm, emailConfirm;
  614. AS_AccountManagementGUI accountManagementGUI;
  615.  
  616. // Shut everything off
  617. void Awake()
  618. {
  619. singleton = this;
  620. loginState = AS_LoginState.Idle;
  621. }
  622.  
  623. // Check if we're good to go, and load up the first screen
  624. void Start()
  625. {
  626. if (useUI)
  627. {
  628. accountManagementGUI = GetComponentInChildren<AS_AccountManagementGUI> ();
  629.  
  630. if (!loginParent || !registrationParent || !recoveryParent
  631. || !registrationFieldsContainer || !inputFieldPrefab) {
  632. this.Log (LogType.Exception, "Unassigned variables - make sure you have assigned all the variables in this object");
  633. return;
  634. }
  635. if ((!recoveryButton||!recoveryField) && AS_Preferences.enablePasswordRecovery) {
  636. this.Log (LogType.Exception, "You haven't assigned the Recovery button and/or field. Either disable password recovery from Setup, or assign a button and a field.");
  637. return;
  638. } else if ((recoveryButton || recoveryField) && !AS_Preferences.enablePasswordRecovery) {
  639. this.Log(LogType.Warning, "You have assigned a Recovery button and/or field, but haven't enabled password recovery in the setup. Disabling the button & field");
  640. if (recoveryButton)
  641. recoveryButton.gameObject.SetActive(false);
  642. if (recoveryField)
  643. recoveryField.gameObject.SetActive(false);
  644. }
  645. loginState = AS_LoginState.LoginPrompt;
  646. passwordField.text = ObscuredPrefs.GetString ("password");
  647. usernameField.text = ObscuredPrefs.GetString ("username");
  648. clanTagField.text = ObscuredPrefs.GetString("clantag");
  649. if (PlayerPrefs.GetInt("autologin") == 1)
  650. {
  651. PlayerPrefs.SetInt("autologin", 0);
  652. OnLoginRequested();
  653. }
  654. }
  655. }
  656.  
  657. public string guiMessage { set {
  658. if (!guiMessageText)
  659. return;
  660. guiMessageText.text = value;
  661. if(guiMessageTime > 0)
  662. {
  663. StopCoroutine("ClearGUIText");
  664. StartCoroutine ("ClearGUIText", guiMessageText);
  665. } } }
  666.  
  667. // If the state changes update messages / load level
  668. AS_LoginState _loginState = AS_LoginState.Idle;
  669. AS_LoginState loginState
  670. {
  671. get { return _loginState; }
  672. set
  673. {
  674. if (value == loginState)
  675. return;
  676. switch (value)
  677. {
  678. case AS_LoginState.Idle:
  679. ToggleCanvasGroup(null);
  680. break;
  681.  
  682. case AS_LoginState.LoginPrompt:
  683. if (accountManagementGUI)
  684. accountManagementGUI.enabled = false;
  685. ToggleCanvasGroup(loginParent);
  686. break;
  687.  
  688. case AS_LoginState.Registering:
  689. ToggleCanvasGroup(registrationParent);
  690. break;
  691.  
  692. case AS_LoginState.RecoverPassword:
  693. ToggleCanvasGroup(recoveryParent);
  694. break;
  695.  
  696. case AS_LoginState.LoginSuccessful:
  697. ToggleCanvasGroup(null);
  698. loading.SetActive(true);
  699. // ToggleCanvasGroup(accountManagementParent);
  700. break;
  701. }
  702. guiMessage = "";
  703. _loginState = value;
  704. }
  705. }
  706.  
  707.  
  708. #region Button Accessors
  709. public void OnLoginRequested()
  710. {
  711. string username = usernameField.text;
  712. string password = passwordField.text;
  713. finalUsername = username;
  714. finalPassword = password;
  715. username.TryToLogin(password, LoginAttempted);
  716. }
  717.  
  718. public void OnLogoutRequested()
  719. {
  720. loginState = AS_LoginState.LoginPrompt;
  721. }
  722.  
  723. public void OnRegistrationRequested()
  724. {
  725. // When the form is downloaded, RegistrationFormDownloaded is called
  726. accountInfo.TryToDownloadRegistrationForm(RegistrationFormDownloaded);
  727. // Equivalent to:
  728. // StartCoroutine ( AS_Login.TryToDownloadRegistrationForm (accountInfo, RegistrationFormDownloaded) );
  729.  
  730. guiMessage = "Loading..";
  731. }
  732.  
  733. public void OnRegistrationCancelled()
  734. {
  735. loginState = AS_LoginState.LoginPrompt;
  736. }
  737. public void OnRegistrationSubmitted()
  738. {
  739. // Offline field check
  740. string errorMessage = "";
  741. if (!AS_Login.CheckFields (accountInfo, passwordConfirm.stringValue, emailConfirm.stringValue, ref errorMessage)) {
  742. guiMessage = errorMessage;
  743. return;
  744. }
  745.  
  746. // Online check with the given database
  747. guiMessage = "Attempting to Register..";
  748. accountInfo.TryToRegister(RegistrationAttempted);
  749. // Equivalent to:
  750. // StartCoroutine ( AS_Login.TryToRegister( accountInfo, RegistrationAttempted ) ) ;
  751.  
  752. }
  753.  
  754. public void OnRecoveryRequested()
  755. {
  756. loginState = AS_LoginState.RecoverPassword;
  757. }
  758. public void OnRecoveryCancelled()
  759. {
  760. loginState = AS_LoginState.LoginPrompt;
  761. }
  762. public void OnRecoverySubmitted()
  763. {
  764. recoveryField.text.TryToRecoverPassword(PasswordRecoveryAttempted);
  765. // Equivalent to:
  766. // StartCoroutine(AS_Login.TryToRecoverPassword ( emailPasswordRecovery, PasswordRecoveryAttempted ) );
  767.  
  768. guiMessage = "Processing your request..";
  769. }
  770. #endregion
  771.  
  772. #region Callbacks
  773. // Called by the AttemptLogin coroutine when it's finished executing
  774. public void LoginAttempted(string callbackMessage)
  775. {
  776.  
  777.  
  778. // If our log in failed,
  779. if (callbackMessage.IsAnError())
  780. {
  781. string [] s = callbackMessage.Split( new string[] { "Error: " }, StringSplitOptions.RemoveEmptyEntries);
  782. guiMessage = s.Length >= 1 ? s[0] : callbackMessage;
  783. this.Log( LogType.Error, callbackMessage);
  784. return;
  785. }
  786.  
  787. // Otherwise,
  788. int accountId = Convert.ToInt32(callbackMessage);
  789. OnSuccessfulLogin(accountId);
  790.  
  791. }
  792. // Used by the AttemptDownloadRegistrationForm when it's finished executing
  793. void RegistrationFormDownloaded(string callbackMessage)
  794. {
  795.  
  796. if (callbackMessage.IsAnError())
  797. {
  798. this.Log( LogType.Error, callbackMessage);
  799. guiMessage = callbackMessage;
  800. return;
  801. }
  802.  
  803. PopulateRegistrationGroup ();
  804.  
  805. loginState = AS_LoginState.Registering;
  806.  
  807. // What you want to appear in the registration GUI
  808. guiMessage = "Please fill in the required fields.";
  809.  
  810. }
  811.  
  812. // Called by the AttemptRegistration coroutine when it's finished executing
  813. public void RegistrationAttempted(string callbackMessage)
  814. {
  815.  
  816. guiMessage = callbackMessage;
  817.  
  818. // If our registration failed,
  819. if (callbackMessage.IsAnError())
  820. {
  821. this.Log( LogType.Error, callbackMessage);
  822. return;
  823. }
  824.  
  825. // Otherwise, success
  826. loginState = AS_LoginState.LoginPrompt;
  827.  
  828. guiMessage = callbackMessage;
  829.  
  830. }
  831.  
  832. // Called by the AttemptPasswordRecovery coroutine when it's finished executing
  833. public void PasswordRecoveryAttempted(string callbackMessage)
  834. {
  835.  
  836. guiMessage = callbackMessage;
  837. // If our registration failed,
  838. if (callbackMessage.IsAnError())
  839. {
  840. this.Log( LogType.Error, callbackMessage);
  841. return;
  842. }
  843.  
  844. // Otherwise,
  845. loginState = AS_LoginState.LoginPrompt;
  846.  
  847. guiMessage = callbackMessage;
  848.  
  849. }
  850. #endregion
  851.  
  852. #region Helpers
  853. /// <summary>
  854. /// Toggles on a specific Canvas Group - and the rest off
  855. /// </summary>
  856. private void ToggleCanvasGroup(CanvasGroup groupToToggle)
  857. {
  858. if (groupToToggle) {
  859. groupToToggle.gameObject.SetActive(true);
  860. guiMessageText = FindGUIMessage (groupToToggle.transform);
  861. }
  862. else
  863. guiMessageText = null;
  864.  
  865. foreach (CanvasGroup cG in gameObject.GetComponentsInChildren<CanvasGroup>())
  866. {
  867. cG.alpha = cG == groupToToggle ? 1 : 0;
  868. cG.blocksRaycasts = cG == groupToToggle;
  869. }
  870. }
  871.  
  872. /// <summary>
  873. /// Finds the GUI message in the hierarchy of the given transform
  874. /// </summary>
  875. private Text FindGUIMessage(Transform parent)
  876. {
  877. foreach (Text text in parent.GetComponentsInChildren<Text>()) {
  878.  
  879. if (text.name.CompareTo(guiMessageTextName) != 0)
  880. continue;
  881. return text;
  882. }
  883.  
  884. this.Log(LogType.Exception, "Couldn't find a Text component named '" +guiMessageTextName+"' as a child of '" + parent.name +"'. Make sure you add one.");
  885.  
  886. return null;
  887. }
  888.  
  889. IEnumerator ClearGUIText(Text text)
  890. {
  891. if (!text)
  892. yield break;
  893. yield return new WaitForSeconds(guiMessageTime);
  894. if (text)
  895. text.text = "";
  896. }
  897.  
  898. AS_InputField CreateInputField(AS_MySQLField field)
  899. {
  900. GameObject temp = GameObject.Instantiate (inputFieldPrefab) as GameObject;
  901.  
  902. // Place it in the container
  903. temp.transform.SetParent (registrationFieldsContainer.transform, false);
  904.  
  905. // Grab its AS_InputField component (or add it)
  906. AS_InputField inputField = temp.GetComponent<AS_InputField> ();
  907. if (!inputField)
  908. inputField = temp.AddComponent<AS_InputField> ();
  909.  
  910. inputField.Initialize (field);
  911. return inputField;
  912. }
  913.  
  914. void PopulateRegistrationGroup()
  915. {
  916. // Clean up first
  917. for (int c = 0; c < registrationFieldsContainer.transform.childCount; c++)
  918. Destroy(registrationFieldsContainer.transform.GetChild (c).gameObject);
  919.  
  920. // Registration Info has the fields the user should fill in
  921. foreach (AS_MySQLField field in accountInfo.fields)
  922. {
  923.  
  924. // Id is an auto-increment unique identifier
  925. // and custom info is not specified during registration
  926. if (field.name.ToLower() == "id" | field.name.ToLower() == "custominfo" | field.name.ToLower() == "isactive" | field.name.ToLower() == "unbanned")
  927. continue;
  928.  
  929. // For any other field, create an InputField prefab
  930.  
  931. // Initialize it
  932. AS_InputField inputField = CreateInputField(field);
  933.  
  934. // User requires one more space for PWD & Confirm to allign
  935. if (field.name.ToLower().Contains("username"))
  936. {
  937. AS_MySQLField dummyField = new AS_MySQLField();
  938. dummyField.name = "<b>Bold *</b>: Required Field";
  939. AS_InputField dummy = CreateInputField(dummyField);
  940. dummy.background.gameObject.SetActive(false);
  941. }
  942.  
  943. /// Password / Email -> Require confirmation
  944. if (field.name.ToLower().Contains("password"))
  945. {
  946. passwordConfirm = new AS_MySQLField(field);
  947. passwordConfirm.name = "Confirm Password";
  948. AS_InputField passwordInputField = CreateInputField(passwordConfirm);
  949. }
  950. else if (field.name.ToLower().Contains("email"))
  951. {
  952. emailConfirm = new AS_MySQLField(field);
  953. emailConfirm.name = "Confirm Email";
  954. AS_InputField passwordInputField = CreateInputField(emailConfirm);
  955. }
  956. }
  957. }
  958. #endregion
  959. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement