Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.35 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using SmartLocalization;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.SceneManagement;
  8. using UnityEngine.UI;
  9.  
  10. public class ActivateWindow : MonoBehaviour
  11. {
  12. public static string URL_PREFIX = "org";
  13.  
  14. public InputField serialField;
  15. public InputField nameField;
  16. public InputField keyField;
  17. public Text errorText;
  18. public GameObject errorHolder;
  19. public GameObject errorWindow;
  20. public GameObject errorNameWindow;
  21. public GameObject updateWindow;
  22. private int errorCount = 0;
  23.  
  24. public Text dealerText;
  25.  
  26. //Debug section
  27. public InputField pointsDealey;
  28. public InputField sectorDealey;
  29. public InputField minSpeed;
  30.  
  31. public Dropdown deviceDropDown;
  32.  
  33. public ActivationUpperMenu menu;
  34.  
  35. public Text serialText;
  36.  
  37. public GameObject imeiErrorWindow;
  38.  
  39. public static ActivateWindow Instance;
  40.  
  41. void Awake()
  42. {
  43. Instance = this;
  44. if (PlayerPrefs.GetInt("NeedUpdate") == 1)
  45. {
  46. updateWindow.SetActive(true);
  47. }
  48. }
  49.  
  50. // Use this for initialization
  51. void Start()
  52. {
  53. string imei = "";
  54. string phone = "";
  55. #if !UNITY_EDITOR && UNITY_WSA_10_0
  56. UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
  57. string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  58. phone = phoneNumber[0];
  59. imei = phoneNumber[1];
  60. #elif !UNITY_EDITOR && UNITY_ANDROID
  61. AndroidJNI.AttachCurrentThread();
  62. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  63. {
  64. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  65. {
  66. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  67. }
  68. }
  69.  
  70. string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
  71. string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  72. phone = phoneNumber[0];
  73. imei = phoneNumber[1];
  74. #elif UNITY_STANDALONE
  75. imei = SystemInfo.graphicsDeviceVersion;
  76. phone = "CantFindPhoneNumber";
  77.  
  78. #endif
  79.  
  80. #if !UNITY_EDITOR
  81. if (string.IsNullOrEmpty(imei) || imei == "null")
  82. {
  83. imeiErrorWindow.SetActive(true);
  84. return;
  85. }
  86. #endif
  87. #if UNITY_STANDALONE
  88. Debug.Log(Application.dataPath);
  89. WinBluetoothController.Instance.RunBTConnector();
  90. #endif
  91. //PlayerPrefs.DeleteAll();
  92. serialText.text = "S/N: "+ PlayerPrefs.GetString("serial");
  93. Debug.Log(PlayerPrefs.GetString("serial"));
  94. int active = PlayerPrefs.GetInt("Active");
  95. if (PlayerPrefs.GetInt("Active") == 1)
  96. {
  97.  
  98. gameObject.SetActive(false);
  99. MainMenuController.Instance.CheckLauncher();
  100. MainMenuController.Instance.CheckOriginalDevice();
  101.  
  102. }
  103. else
  104. {
  105. GetAllMacs();
  106. }
  107. if (errorWindow.activeSelf)
  108. {
  109. gameObject.SetActive(false);
  110. }
  111. }
  112.  
  113. public void SetDemo()
  114. {
  115. PlayerPrefs.SetString("serial", "Demo");
  116. serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
  117.  
  118. PlayerPrefs.SetString("deviceId", "Demo");
  119. PlayerPrefs.SetInt("Active", 1);
  120. if (!SaveController.Instance.isInnerGPS)
  121. {
  122. PlayerPrefs.SetString("device", "Demo");
  123. PlayerPrefs.SetString("key", "Demo1");
  124. PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("OriginalDemo"));
  125. }
  126. else
  127. {
  128. PlayerPrefs.SetString("device", "Demo");
  129. PlayerPrefs.SetString("key", "Demo");
  130. PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("Original"));
  131. }
  132.  
  133. //PlayerPrefs.SetString("info", "Demo");
  134. PlayerPrefs.SetString("activationDate", DateTime.Now.ToShortDateString());
  135. PlayerPrefs.SetInt("VelestorDevice", 1);
  136. PlayerPrefs.SetFloat("startDevicedSquare", 1);
  137. PlayerPrefs.SetInt("startDevicedSquareCount", 1);
  138. PlayerPrefs.SetFloat("startDevicedSpeed", 1);
  139. MainMenuController.Instance.CheckOriginalDevice();
  140. MainMenuController.Instance.ChangeTexts();
  141. }
  142.  
  143. void StartCheck()
  144. {
  145. StartCoroutine(CheckActivated());
  146. }
  147.  
  148. void GetAllMacs()
  149. {
  150. #if !UNITY_EDITOR && UNITY_WSA_10_0
  151. UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
  152. string mac = bt.GetAllMacs().Result;
  153. ParseMacs(mac);
  154. #elif UNITY_ANDROID
  155. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  156. {
  157. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  158. {
  159. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  160. string mac = gpsActivityJavaClass.CallStatic<string>("GetAllMacs");
  161. if (string.IsNullOrEmpty(mac) && getMacsCount < 2)
  162. {
  163. getMacsCount++;
  164. GetAllMacs();
  165. }
  166. else
  167. {
  168. ParseMacs(mac);
  169. }
  170. }
  171. }
  172. #elif UNITY_STANDALONE
  173. deviceDropDown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Loading")));
  174. deviceDropDown.value = 0;
  175. deviceDropDown.RefreshShownValue();
  176. WinBluetoothController.Instance.RequestMacs();
  177. #endif
  178. }
  179. private int getMacsCount = 0;
  180. public List<string> Names;
  181. public List<string> Macs;
  182.  
  183. public void ParseMacs(string macs)
  184. {
  185. if (string.IsNullOrEmpty(macs))
  186. return;
  187.  
  188. deviceDropDown.options.Clear();
  189.  
  190. string[] temp = macs.Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
  191. for (int i = 0; i < temp.Length; i++)
  192. {
  193. string[] macTemp = temp[i].Split(new char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);
  194. Names.Add(macTemp[0]);
  195. Macs.Add(macTemp[1]);
  196. deviceDropDown.options.Add(new Dropdown.OptionData(macTemp[0]));
  197. }
  198. if (deviceDropDown.options.Count > 0)
  199. {
  200. deviceDropDown.value = 0;
  201. deviceDropDown.RefreshShownValue();
  202. }
  203. }
  204.  
  205. public void OnSendClick()
  206. {
  207.  
  208. errorHolder.SetActive(false);
  209. if (menu.isNewWork)
  210. {
  211. StartCoroutine(SendRequest());
  212. }
  213. else
  214. {
  215. if (string.IsNullOrEmpty(keyField.text))
  216. return;
  217.  
  218. #if !UNITY_EDITOR && UNITY_WSA_10_0
  219. StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, ""));
  220. #elif UNITY_ANDROID
  221. //AndroidJNI.AttachCurrentThread();
  222. StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, ""));
  223. #elif UNITY_STANDALONE
  224. StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, ""));
  225. #endif
  226.  
  227. }
  228. }
  229.  
  230. public void SendByMac(string mac)
  231. {
  232. if (!string.IsNullOrEmpty(mac))
  233. {
  234. StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, mac));
  235. }
  236. else
  237. {
  238. errorText.text = LanguageManager.Instance.GetTextValue("cantFindDeviceByName");
  239. StartCoroutine(ShowError());
  240. }
  241. }
  242.  
  243. private string GenerateSerial()
  244. {
  245. string serial = "";
  246. string[] parts = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  247. for (int i = 0; i < 8; i++)
  248. {
  249. serial += parts[UnityEngine.Random.Range(0, parts.Length)];
  250. }
  251. return serial+"00";
  252. }
  253.  
  254.  
  255. private IEnumerator GetDetailsMore()
  256. {
  257. WWW wwww = new WWW(url + "loxovnet.php?serial=" + serialField.text);
  258. while (!wwww.isDone)
  259. {
  260. yield return new WaitForEndOfFrame();
  261. }
  262. ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(wwww.text);
  263. if (!string.IsNullOrEmpty(model.error))
  264. {
  265. errorCount++;
  266. errorText.text = LanguageManager.Instance.GetTextValue("cantFindDevice");
  267. StartCoroutine(ShowError());
  268. if (errorCount >= 5)
  269. {
  270. ShowErrorWindow();
  271. }
  272. }
  273. else
  274. {
  275. if (model.active == 0)
  276. {
  277. errorText.text = LanguageManager.Instance.GetTextValue("deviceDeactivated");
  278. StartCoroutine(ShowError());
  279. }
  280. else
  281. {
  282. PlayerPrefs.SetString("deviceId", serialField.text);
  283. PlayerPrefs.SetInt("Active", 1);
  284. PlayerPrefs.SetString("mac", model.mac);
  285. PlayerPrefs.SetString("pin", model.pin);
  286. PlayerPrefs.SetString("device", model.name);
  287. PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
  288. PlayerPrefs.SetString("serial", serialField.text);
  289. PlayerPrefs.SetString("key", model.key);
  290.  
  291. PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
  292. PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
  293. PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
  294. PlayerPrefs.SetString("delader", model.dealer);
  295. PlayerPrefs.SetString("info", model.text);
  296. PlayerPrefs.SetString("activationDate", model.date);
  297.  
  298. PlayerPrefs.SetInt("control",model.control);
  299. PlayerPrefs.SetString("dealerContact", model.contact);
  300. PlayerPrefs.SetString("dealerEmail", model.email);
  301. PlayerPrefs.SetString("dealerAddress", model.address);
  302. PlayerPrefs.SetString("dealerTel", model.tel);
  303.  
  304. MainMenuController.Instance.ChangeTexts();
  305. pointsDealey.text = model.squareDelta.ToString();
  306. sectorDealey.text = model.squareCount.ToString();
  307. minSpeed.text = model.minSpeed.ToString();
  308. if (model.dealer.Length > 3)
  309. {
  310. dealerText.text = model.dealer;
  311. }
  312. else
  313. {
  314. if (!string.IsNullOrEmpty(model.tel))
  315. {
  316.  
  317. dealerText.text = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}",model.contact,model.email,model.address,model.tel);
  318. PlayerPrefs.SetString("delader", dealerText.text);
  319. MainMenuController.Instance.ChangeTexts();
  320. }
  321. }
  322.  
  323. Debug.Log(PlayerPrefs.GetString("serial"));
  324. serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
  325. gameObject.SetActive(false);
  326. CheckDevice(model);
  327. }
  328. }
  329. string deviceModel = "";
  330. string phone = "";
  331. string imei = "";
  332. #if !UNITY_EDITOR && UNITY_WSA_10_0
  333. UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
  334. string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  335. phone = phoneNumber[0];
  336. imei = phoneNumber[1];
  337. deviceModel = bt.friendlyName;
  338.  
  339. #elif UNITY_ANDROID
  340. AndroidJNI.AttachCurrentThread();
  341. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  342. {
  343. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  344. {
  345. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  346. }
  347. }
  348.  
  349. deviceModel = SystemInfo.deviceModel;
  350. string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
  351. string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  352. phone = phoneNumber[0];
  353. imei = phoneNumber[1];
  354. #elif UNITY_STANDALONE
  355. deviceModel = SystemInfo.deviceModel;
  356. imei = SystemInfo.graphicsDeviceVersion;
  357. phone = "CantFindPhoneNumber";
  358.  
  359. #endif
  360.  
  361.  
  362. string urll = "velestor."+ URL_PREFIX + "/insertLogin.php?serial=" + serialField.text + "&ip=123" + "&model=" + deviceModel + "&imei=" + imei +
  363. "&version=" + SystemInfo.operatingSystem + "&phone=" + phone + "&action=OK" + "&errorPin=-" + "&errorSerial=-";
  364. urll = urll.Replace("\r\n", "%0A");
  365. urll = urll.Replace(" ", "%20");
  366. urll = urll.Replace(" ", "%20");
  367. urll = urll.Replace("#", "%23");
  368. urll = urll.Replace(":", "%3A");
  369. WWW www = new WWW("http://" + urll);
  370. yield return www;
  371. }
  372.  
  373. public IEnumerator SendDevice(string serial, string name, string pin, string mac)
  374. {
  375. if (Names.Count >= deviceDropDown.value + 1)
  376. {
  377.  
  378. string url = "velestor." + URL_PREFIX + "/insertDevice.php?serial=" + serial + "&name=" + Names[deviceDropDown.value] + "&pin=" + pin +
  379. "&mac=" + Macs[deviceDropDown.value];
  380. url = url.Replace("\r\n", "%0A");
  381. url = url.Replace(" ", "%20");
  382. url = url.Replace(" ", "%20");
  383. url = url.Replace("#", "%23");
  384. url = url.Replace(":", "%3A");
  385. WWW www = new WWW("http://" + url);
  386. yield return www;
  387. if (!string.IsNullOrEmpty(www.error))
  388. {
  389. errorText.text = LanguageManager.Instance.GetTextValue("LostInternet");
  390. StartCoroutine(ShowError());
  391. }
  392. else
  393. {
  394.  
  395.  
  396. if (string.IsNullOrEmpty(www.error) && www.text.StartsWith("OK"))
  397. {
  398. string[] s = www.text.Split(new char[] { '|' });
  399. PlayerPrefs.SetString("deviceId", s[1]);
  400. PlayerPrefs.SetInt("Active", 1);
  401. PlayerPrefs.SetString("mac", mac);
  402. PlayerPrefs.SetString("pin", pin);
  403. PlayerPrefs.SetString("device", name);
  404. PlayerPrefs.SetString("deviceSpeed", "$PMTK300,100,0,0,0,0*2C");
  405. PlayerPrefs.SetString("serial", s[1]);
  406. PlayerPrefs.SetString("key", pin);
  407. serialField.text = PlayerPrefs.GetString("serial");
  408.  
  409.  
  410. //Invoke(StartGetDetails(),1);
  411. PlayerPrefs.SetFloat("startDevicedSquare", 1);
  412. PlayerPrefs.SetInt("startDevicedSquareCount", 1);
  413. PlayerPrefs.SetFloat("startDevicedSpeed", 1);
  414. PlayerPrefs.SetString("delader", "");
  415. MainMenuController.Instance.ChangeTexts();
  416. pointsDealey.text = "1";
  417. sectorDealey.text = "1";
  418. minSpeed.text = "1";
  419. dealerText.text = "";
  420. serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
  421. Debug.Log(PlayerPrefs.GetString("serial"));
  422. yield return StartCoroutine(GetDetailsMore());
  423. DownloadController.Instance.StartSendAnalitic(s[1], "123", "test", "test", "test", "OK");
  424. gameObject.SetActive(false);
  425.  
  426. CheckForBan.Instance.OnSuccessLogin();
  427.  
  428. }
  429. else if (string.IsNullOrEmpty(www.error) && www.text.StartsWith("Error pin"))
  430. {
  431. string[] s = www.text.Split(new char[] { '|' });
  432. DownloadController.Instance.StartSendAnalitic(s[1], "123", "test", "test", "test", "ERROR",
  433. keyField.text,
  434. keyField.text);
  435. errorText.text = LanguageManager.Instance.GetTextValue("deviceExist");
  436. StartCoroutine(ShowError());
  437.  
  438. errorCount++;
  439.  
  440. if (errorCount >= 5)
  441. {
  442. ShowErrorNameWindow();
  443. }
  444. }
  445. }
  446. }
  447. }
  448.  
  449. private void StartGetDetails()
  450. {
  451.  
  452. }
  453.  
  454. public void ShowErrorWindow()
  455. {
  456. var epochStart = new System.DateTime(1970, 1, 1, 8, 0, 0, System.DateTimeKind.Utc);
  457. var timestamp = (System.DateTime.UtcNow - epochStart).TotalSeconds;
  458. PlayerPrefs.SetInt("block", (int)timestamp);
  459. errorWindow.SetActive(true);
  460. gameObject.SetActive(false);
  461. }
  462.  
  463. public void ShowErrorNameWindow()
  464. {
  465.  
  466. var epochStart = new System.DateTime(1970, 1, 1, 8, 0, 0, System.DateTimeKind.Utc);
  467. var timestamp = (System.DateTime.UtcNow - epochStart).TotalSeconds;
  468. PlayerPrefs.SetInt("block", (int)timestamp);
  469. errorNameWindow.SetActive(true);
  470. gameObject.SetActive(false);
  471. }
  472.  
  473. public void OnExitClicked()
  474. {
  475. Application.Quit();
  476. }
  477.  
  478. private string url = "http://velestor." + URL_PREFIX + "/";
  479. private AndroidJavaObject gpsActivityJavaClass;
  480. private string GetEncodedString(string param)
  481. {
  482. param = param.Replace("\r\n", "%0A");
  483. param = param.Replace(" ", "%20");
  484. param = param.Replace(" ", "%20");
  485. param = param.Replace("#", "%23");
  486. param = param.Replace(":", "%3A");
  487. return param;
  488. }
  489. IEnumerator SendRequest()
  490. {
  491. string imei = "";
  492. string deviceModel = "";
  493. #if !UNITY_EDITOR && UNITY_WSA_10_0
  494. UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
  495. string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  496. imei = phoneNumber[1];
  497. deviceModel = bt.friendlyName;
  498.  
  499. #elif !UNITY_EDITOR && UNITY_ANDROID
  500. AndroidJNI.AttachCurrentThread();
  501. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  502. {
  503. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  504. {
  505. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  506. }
  507. }
  508. string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
  509. string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  510. imei = phoneNumber[1];
  511. deviceModel = SystemInfo.deviceModel;
  512. #elif UNITY_STANDALONE
  513. deviceModel = SystemInfo.deviceModel;
  514. imei = SystemInfo.graphicsDeviceVersion;
  515.  
  516. #endif
  517. string urll = url + "errorget.php?serial=" + serialField.text + "&key=" + keyField.text;
  518. if (serialField.text.Length <= 8)
  519. {
  520. if (string.IsNullOrEmpty(imei) || imei == "")
  521. {
  522.  
  523. }
  524. urll += "&imei=" + GetEncodedString(imei) + "&deviceModel=" + GetEncodedString(deviceModel);
  525. }
  526. WWW www = new WWW(urll);
  527. yield return www;
  528. if (!string.IsNullOrEmpty(www.error))
  529. {
  530. errorText.text = LanguageManager.Instance.GetTextValue("LostInternet");
  531. StartCoroutine(ShowError());
  532. }
  533. else
  534. {
  535. ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
  536. if (model == null || !string.IsNullOrEmpty(model.error))
  537. {
  538. errorCount++;
  539. errorText.text = LanguageManager.Instance.GetTextValue("cantFindDevice");
  540. StartCoroutine(ShowError());
  541. DownloadController.Instance.StartSendAnalitic(serialField.text, "123", "test", "test", "test", "ERROR",
  542. keyField.text, serialField.text);
  543. if (errorCount >= 5)
  544. {
  545.  
  546. ShowErrorWindow();
  547. }
  548. }
  549. else
  550. {
  551. if (model.active == 0)
  552. {
  553. errorText.text = LanguageManager.Instance.GetTextValue("deviceDeactivated");
  554. StartCoroutine(ShowError());
  555. }
  556. else
  557. {
  558. DownloadController.Instance.StartSendAnalitic(serialField.text, "123", "test", "test", "test", "OK");
  559. StartCoroutine(GetDetails());
  560. }
  561. }
  562. }
  563. }
  564.  
  565.  
  566. IEnumerator GetDetails()
  567. {
  568. WWW www = new WWW(url + "loxovnet.php?serial=" + serialField.text);
  569. yield return www;
  570. ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
  571. if (!string.IsNullOrEmpty(model.error))
  572. {
  573. errorCount++;
  574. errorText.text = LanguageManager.Instance.GetTextValue("cantFindDevice");
  575. StartCoroutine(ShowError());
  576. if (errorCount >= 5)
  577. {
  578. ShowErrorWindow();
  579. }
  580. }
  581. else
  582. {
  583. if (model.active == 0)
  584. {
  585. errorText.text = LanguageManager.Instance.GetTextValue("deviceDeactivated");
  586. StartCoroutine(ShowError());
  587. }
  588. else
  589. {
  590. PlayerPrefs.SetString("deviceId", serialField.text);
  591. PlayerPrefs.SetInt("Active", 1);
  592. PlayerPrefs.SetString("mac", model.mac);
  593. PlayerPrefs.SetString("pin", model.pin);
  594. PlayerPrefs.SetString("device", model.name);
  595. PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
  596. PlayerPrefs.SetString("serial", serialField.text);
  597. PlayerPrefs.SetString("key", keyField.text);
  598.  
  599. PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
  600. PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
  601. PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
  602. PlayerPrefs.SetString("delader", model.dealer);
  603. MainMenuController.Instance.ChangeTexts();
  604. PlayerPrefs.SetString("info", model.text);
  605. PlayerPrefs.SetString("activationDate", model.date);
  606.  
  607. PlayerPrefs.SetInt("control", model.control);
  608. PlayerPrefs.SetString("dealerContact", model.contact);
  609. PlayerPrefs.SetString("dealerEmail", model.email);
  610. PlayerPrefs.SetString("dealerAddress", model.address);
  611. PlayerPrefs.SetString("dealerTel", model.tel);
  612.  
  613.  
  614. pointsDealey.text = model.squareDelta.ToString();
  615. sectorDealey.text = model.squareCount.ToString();
  616. minSpeed.text = model.minSpeed.ToString();
  617. if (model.dealer.Length > 3)
  618. {
  619. dealerText.text = model.dealer;
  620. }
  621. else
  622. {
  623. if (!string.IsNullOrEmpty(model.tel))
  624. {
  625. dealerText.text = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", model.contact, model.email, model.address, model.tel);
  626. PlayerPrefs.SetString("delader", dealerText.text);
  627. MainMenuController.Instance.ChangeTexts();
  628. }
  629. }
  630. serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
  631. Debug.Log(PlayerPrefs.GetString("serial"));
  632. gameObject.SetActive(false);
  633. CheckDevice(model);
  634. CheckForBan.Instance.OnSuccessLogin();
  635. }
  636. }
  637. }
  638.  
  639. public void SetInfo(ActivationModel model)
  640. {
  641. PlayerPrefs.SetInt("Active", 1);
  642. PlayerPrefs.SetString("mac", model.mac);
  643. PlayerPrefs.SetString("pin", model.pin);
  644. PlayerPrefs.SetString("device", model.name);
  645. PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
  646. PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
  647. PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
  648. PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
  649. PlayerPrefs.SetString("delader", model.dealer);
  650. MainMenuController.Instance.ChangeTexts();
  651. PlayerPrefs.SetString("info", model.text);
  652. PlayerPrefs.SetString("activationDate", model.date);
  653.  
  654. PlayerPrefs.SetInt("control", model.control);
  655. PlayerPrefs.SetString("dealerContact", model.contact);
  656. PlayerPrefs.SetString("dealerEmail", model.email);
  657. PlayerPrefs.SetString("dealerAddress", model.address);
  658. PlayerPrefs.SetString("dealerTel", model.tel);
  659. serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
  660. pointsDealey.text = model.squareDelta.ToString();
  661. sectorDealey.text = model.squareCount.ToString();
  662. minSpeed.text = model.minSpeed.ToString();
  663. if (model.dealer.Length > 3)
  664. {
  665. dealerText.text = model.dealer;
  666. }
  667. else
  668. {
  669. if (!string.IsNullOrEmpty(model.tel))
  670. {
  671. dealerText.text = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", model.contact, model.email, model.address, model.tel);
  672. PlayerPrefs.SetString("delader", dealerText.text);
  673. MainMenuController.Instance.ChangeTexts();
  674. }
  675. }
  676. CheckDevice(model);
  677. }
  678.  
  679. private void CheckDevice(ActivationModel model)
  680. {
  681. if (model.serial.Length > 8 || model.pin == model.key)
  682. {
  683. PlayerPrefs.SetInt("VelestorDevice", 0);
  684. PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("Original"));
  685. MainMenuController.Instance.ChangeTexts();
  686. dealerText.text = LanguageManager.Instance.GetTextValue("Original");
  687. }
  688. else
  689. {
  690. PlayerPrefs.SetInt("VelestorDevice", 1);
  691. }
  692.  
  693. MainMenuController.Instance.CheckOriginalDevice();
  694.  
  695. }
  696.  
  697. IEnumerator CheckActivated()
  698. {
  699. string imei = "";
  700. string deviceModel = "";
  701. #if !UNITY_EDITOR && UNITY_WSA_10_0
  702. UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
  703. string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  704. imei = phoneNumber[1];
  705. deviceModel = bt.friendlyName;
  706.  
  707. #elif !UNITY_EDITOR && UNITY_ANDROID
  708. AndroidJNI.AttachCurrentThread();
  709. using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  710. {
  711. using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  712. {
  713. gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
  714. }
  715. }
  716. string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
  717. string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
  718. imei = phoneNumber[1];
  719. deviceModel = SystemInfo.deviceModel;
  720. #elif UNITY_STANDALONE
  721. deviceModel = SystemInfo.deviceModel;
  722. imei = SystemInfo.graphicsDeviceVersion;
  723.  
  724. #endif
  725. WWW www = new WWW(url + "errorget.php?serial=" + PlayerPrefs.GetString("serial") + "&key=" + PlayerPrefs.GetString("key") + "&imei=" + imei + "&deviceModel=" + GetEncodedString(deviceModel));
  726. yield return www;
  727. ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
  728. if (model.active == 0)
  729. {
  730. Debug.Log("NonActive");
  731. PlayerPrefs.SetInt("Active", 0);
  732. SceneManager.LoadScene("Menu");
  733. }
  734. else
  735. {
  736. Debug.Log("Active");
  737. gameObject.SetActive(false);
  738. }
  739. }
  740.  
  741. IEnumerator ShowError(string key = "")
  742. {
  743. errorHolder.SetActive(true);
  744. yield return new WaitForSeconds(1);
  745. }
  746.  
  747. public void HideError()
  748. {
  749. errorHolder.SetActive(false);
  750. }
  751. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement