Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using SmartLocalization;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class ActivateWindow : MonoBehaviour
- {
- public static string URL_PREFIX = "org";
- public InputField serialField;
- public InputField nameField;
- public InputField keyField;
- public Text errorText;
- public GameObject errorHolder;
- public GameObject errorWindow;
- public GameObject errorNameWindow;
- public GameObject updateWindow;
- private int errorCount = 0;
- public Text dealerText;
- //Debug section
- public InputField pointsDealey;
- public InputField sectorDealey;
- public InputField minSpeed;
- public Dropdown deviceDropDown;
- public ActivationUpperMenu menu;
- public Text serialText;
- public GameObject imeiErrorWindow;
- public static ActivateWindow Instance;
- void Awake()
- {
- Instance = this;
- if (PlayerPrefs.GetInt("NeedUpdate") == 1)
- {
- updateWindow.SetActive(true);
- }
- }
- // Use this for initialization
- void Start()
- {
- string imei = "";
- string phone = "";
- #if !UNITY_EDITOR && UNITY_WSA_10_0
- UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
- string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- phone = phoneNumber[0];
- imei = phoneNumber[1];
- #elif !UNITY_EDITOR && UNITY_ANDROID
- AndroidJNI.AttachCurrentThread();
- using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
- {
- gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
- }
- }
- string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
- string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- phone = phoneNumber[0];
- imei = phoneNumber[1];
- #elif UNITY_STANDALONE
- imei = SystemInfo.graphicsDeviceVersion;
- phone = "CantFindPhoneNumber";
- #endif
- #if !UNITY_EDITOR
- if (string.IsNullOrEmpty(imei) || imei == "null")
- {
- imeiErrorWindow.SetActive(true);
- return;
- }
- #endif
- #if UNITY_STANDALONE
- Debug.Log(Application.dataPath);
- WinBluetoothController.Instance.RunBTConnector();
- #endif
- //PlayerPrefs.DeleteAll();
- serialText.text = "S/N: "+ PlayerPrefs.GetString("serial");
- Debug.Log(PlayerPrefs.GetString("serial"));
- int active = PlayerPrefs.GetInt("Active");
- if (PlayerPrefs.GetInt("Active") == 1)
- {
- gameObject.SetActive(false);
- MainMenuController.Instance.CheckLauncher();
- MainMenuController.Instance.CheckOriginalDevice();
- }
- else
- {
- GetAllMacs();
- }
- if (errorWindow.activeSelf)
- {
- gameObject.SetActive(false);
- }
- }
- public void SetDemo()
- {
- PlayerPrefs.SetString("serial", "Demo");
- serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
- PlayerPrefs.SetString("deviceId", "Demo");
- PlayerPrefs.SetInt("Active", 1);
- if (!SaveController.Instance.isInnerGPS)
- {
- PlayerPrefs.SetString("device", "Demo");
- PlayerPrefs.SetString("key", "Demo1");
- PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("OriginalDemo"));
- }
- else
- {
- PlayerPrefs.SetString("device", "Demo");
- PlayerPrefs.SetString("key", "Demo");
- PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("Original"));
- }
- //PlayerPrefs.SetString("info", "Demo");
- PlayerPrefs.SetString("activationDate", DateTime.Now.ToShortDateString());
- PlayerPrefs.SetInt("VelestorDevice", 1);
- PlayerPrefs.SetFloat("startDevicedSquare", 1);
- PlayerPrefs.SetInt("startDevicedSquareCount", 1);
- PlayerPrefs.SetFloat("startDevicedSpeed", 1);
- MainMenuController.Instance.CheckOriginalDevice();
- MainMenuController.Instance.ChangeTexts();
- }
- void StartCheck()
- {
- StartCoroutine(CheckActivated());
- }
- void GetAllMacs()
- {
- #if !UNITY_EDITOR && UNITY_WSA_10_0
- UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
- string mac = bt.GetAllMacs().Result;
- ParseMacs(mac);
- #elif UNITY_ANDROID
- using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
- {
- gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
- string mac = gpsActivityJavaClass.CallStatic<string>("GetAllMacs");
- if (string.IsNullOrEmpty(mac) && getMacsCount < 2)
- {
- getMacsCount++;
- GetAllMacs();
- }
- else
- {
- ParseMacs(mac);
- }
- }
- }
- #elif UNITY_STANDALONE
- deviceDropDown.options.Add(new Dropdown.OptionData(LanguageManager.Instance.GetTextValue("Loading")));
- deviceDropDown.value = 0;
- deviceDropDown.RefreshShownValue();
- WinBluetoothController.Instance.RequestMacs();
- #endif
- }
- private int getMacsCount = 0;
- public List<string> Names;
- public List<string> Macs;
- public void ParseMacs(string macs)
- {
- if (string.IsNullOrEmpty(macs))
- return;
- deviceDropDown.options.Clear();
- string[] temp = macs.Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < temp.Length; i++)
- {
- string[] macTemp = temp[i].Split(new char[] { '|' }, System.StringSplitOptions.RemoveEmptyEntries);
- Names.Add(macTemp[0]);
- Macs.Add(macTemp[1]);
- deviceDropDown.options.Add(new Dropdown.OptionData(macTemp[0]));
- }
- if (deviceDropDown.options.Count > 0)
- {
- deviceDropDown.value = 0;
- deviceDropDown.RefreshShownValue();
- }
- }
- public void OnSendClick()
- {
- errorHolder.SetActive(false);
- if (menu.isNewWork)
- {
- StartCoroutine(SendRequest());
- }
- else
- {
- if (string.IsNullOrEmpty(keyField.text))
- return;
- #if !UNITY_EDITOR && UNITY_WSA_10_0
- StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, ""));
- #elif UNITY_ANDROID
- //AndroidJNI.AttachCurrentThread();
- StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, ""));
- #elif UNITY_STANDALONE
- StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, ""));
- #endif
- }
- }
- public void SendByMac(string mac)
- {
- if (!string.IsNullOrEmpty(mac))
- {
- StartCoroutine(SendDevice(GenerateSerial(), nameField.text, keyField.text, mac));
- }
- else
- {
- errorText.text = LanguageManager.Instance.GetTextValue("cantFindDeviceByName");
- StartCoroutine(ShowError());
- }
- }
- private string GenerateSerial()
- {
- string serial = "";
- string[] parts = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
- for (int i = 0; i < 8; i++)
- {
- serial += parts[UnityEngine.Random.Range(0, parts.Length)];
- }
- return serial+"00";
- }
- private IEnumerator GetDetailsMore()
- {
- WWW wwww = new WWW(url + "loxovnet.php?serial=" + serialField.text);
- while (!wwww.isDone)
- {
- yield return new WaitForEndOfFrame();
- }
- ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(wwww.text);
- if (!string.IsNullOrEmpty(model.error))
- {
- errorCount++;
- errorText.text = LanguageManager.Instance.GetTextValue("cantFindDevice");
- StartCoroutine(ShowError());
- if (errorCount >= 5)
- {
- ShowErrorWindow();
- }
- }
- else
- {
- if (model.active == 0)
- {
- errorText.text = LanguageManager.Instance.GetTextValue("deviceDeactivated");
- StartCoroutine(ShowError());
- }
- else
- {
- PlayerPrefs.SetString("deviceId", serialField.text);
- PlayerPrefs.SetInt("Active", 1);
- PlayerPrefs.SetString("mac", model.mac);
- PlayerPrefs.SetString("pin", model.pin);
- PlayerPrefs.SetString("device", model.name);
- PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
- PlayerPrefs.SetString("serial", serialField.text);
- PlayerPrefs.SetString("key", model.key);
- PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
- PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
- PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
- PlayerPrefs.SetString("delader", model.dealer);
- PlayerPrefs.SetString("info", model.text);
- PlayerPrefs.SetString("activationDate", model.date);
- PlayerPrefs.SetInt("control",model.control);
- PlayerPrefs.SetString("dealerContact", model.contact);
- PlayerPrefs.SetString("dealerEmail", model.email);
- PlayerPrefs.SetString("dealerAddress", model.address);
- PlayerPrefs.SetString("dealerTel", model.tel);
- MainMenuController.Instance.ChangeTexts();
- pointsDealey.text = model.squareDelta.ToString();
- sectorDealey.text = model.squareCount.ToString();
- minSpeed.text = model.minSpeed.ToString();
- if (model.dealer.Length > 3)
- {
- dealerText.text = model.dealer;
- }
- else
- {
- if (!string.IsNullOrEmpty(model.tel))
- {
- dealerText.text = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}",model.contact,model.email,model.address,model.tel);
- PlayerPrefs.SetString("delader", dealerText.text);
- MainMenuController.Instance.ChangeTexts();
- }
- }
- Debug.Log(PlayerPrefs.GetString("serial"));
- serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
- gameObject.SetActive(false);
- CheckDevice(model);
- }
- }
- string deviceModel = "";
- string phone = "";
- string imei = "";
- #if !UNITY_EDITOR && UNITY_WSA_10_0
- UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
- string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- phone = phoneNumber[0];
- imei = phoneNumber[1];
- deviceModel = bt.friendlyName;
- #elif UNITY_ANDROID
- AndroidJNI.AttachCurrentThread();
- using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
- {
- gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
- }
- }
- deviceModel = SystemInfo.deviceModel;
- string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
- string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- phone = phoneNumber[0];
- imei = phoneNumber[1];
- #elif UNITY_STANDALONE
- deviceModel = SystemInfo.deviceModel;
- imei = SystemInfo.graphicsDeviceVersion;
- phone = "CantFindPhoneNumber";
- #endif
- string urll = "velestor."+ URL_PREFIX + "/insertLogin.php?serial=" + serialField.text + "&ip=123" + "&model=" + deviceModel + "&imei=" + imei +
- "&version=" + SystemInfo.operatingSystem + "&phone=" + phone + "&action=OK" + "&errorPin=-" + "&errorSerial=-";
- urll = urll.Replace("\r\n", "%0A");
- urll = urll.Replace(" ", "%20");
- urll = urll.Replace(" ", "%20");
- urll = urll.Replace("#", "%23");
- urll = urll.Replace(":", "%3A");
- WWW www = new WWW("http://" + urll);
- yield return www;
- }
- public IEnumerator SendDevice(string serial, string name, string pin, string mac)
- {
- if (Names.Count >= deviceDropDown.value + 1)
- {
- string url = "velestor." + URL_PREFIX + "/insertDevice.php?serial=" + serial + "&name=" + Names[deviceDropDown.value] + "&pin=" + pin +
- "&mac=" + Macs[deviceDropDown.value];
- url = url.Replace("\r\n", "%0A");
- url = url.Replace(" ", "%20");
- url = url.Replace(" ", "%20");
- url = url.Replace("#", "%23");
- url = url.Replace(":", "%3A");
- WWW www = new WWW("http://" + url);
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- errorText.text = LanguageManager.Instance.GetTextValue("LostInternet");
- StartCoroutine(ShowError());
- }
- else
- {
- if (string.IsNullOrEmpty(www.error) && www.text.StartsWith("OK"))
- {
- string[] s = www.text.Split(new char[] { '|' });
- PlayerPrefs.SetString("deviceId", s[1]);
- PlayerPrefs.SetInt("Active", 1);
- PlayerPrefs.SetString("mac", mac);
- PlayerPrefs.SetString("pin", pin);
- PlayerPrefs.SetString("device", name);
- PlayerPrefs.SetString("deviceSpeed", "$PMTK300,100,0,0,0,0*2C");
- PlayerPrefs.SetString("serial", s[1]);
- PlayerPrefs.SetString("key", pin);
- serialField.text = PlayerPrefs.GetString("serial");
- //Invoke(StartGetDetails(),1);
- PlayerPrefs.SetFloat("startDevicedSquare", 1);
- PlayerPrefs.SetInt("startDevicedSquareCount", 1);
- PlayerPrefs.SetFloat("startDevicedSpeed", 1);
- PlayerPrefs.SetString("delader", "");
- MainMenuController.Instance.ChangeTexts();
- pointsDealey.text = "1";
- sectorDealey.text = "1";
- minSpeed.text = "1";
- dealerText.text = "";
- serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
- Debug.Log(PlayerPrefs.GetString("serial"));
- yield return StartCoroutine(GetDetailsMore());
- DownloadController.Instance.StartSendAnalitic(s[1], "123", "test", "test", "test", "OK");
- gameObject.SetActive(false);
- CheckForBan.Instance.OnSuccessLogin();
- }
- else if (string.IsNullOrEmpty(www.error) && www.text.StartsWith("Error pin"))
- {
- string[] s = www.text.Split(new char[] { '|' });
- DownloadController.Instance.StartSendAnalitic(s[1], "123", "test", "test", "test", "ERROR",
- keyField.text,
- keyField.text);
- errorText.text = LanguageManager.Instance.GetTextValue("deviceExist");
- StartCoroutine(ShowError());
- errorCount++;
- if (errorCount >= 5)
- {
- ShowErrorNameWindow();
- }
- }
- }
- }
- }
- private void StartGetDetails()
- {
- }
- public void ShowErrorWindow()
- {
- var epochStart = new System.DateTime(1970, 1, 1, 8, 0, 0, System.DateTimeKind.Utc);
- var timestamp = (System.DateTime.UtcNow - epochStart).TotalSeconds;
- PlayerPrefs.SetInt("block", (int)timestamp);
- errorWindow.SetActive(true);
- gameObject.SetActive(false);
- }
- public void ShowErrorNameWindow()
- {
- var epochStart = new System.DateTime(1970, 1, 1, 8, 0, 0, System.DateTimeKind.Utc);
- var timestamp = (System.DateTime.UtcNow - epochStart).TotalSeconds;
- PlayerPrefs.SetInt("block", (int)timestamp);
- errorNameWindow.SetActive(true);
- gameObject.SetActive(false);
- }
- public void OnExitClicked()
- {
- Application.Quit();
- }
- private string url = "http://velestor." + URL_PREFIX + "/";
- private AndroidJavaObject gpsActivityJavaClass;
- private string GetEncodedString(string param)
- {
- param = param.Replace("\r\n", "%0A");
- param = param.Replace(" ", "%20");
- param = param.Replace(" ", "%20");
- param = param.Replace("#", "%23");
- param = param.Replace(":", "%3A");
- return param;
- }
- IEnumerator SendRequest()
- {
- string imei = "";
- string deviceModel = "";
- #if !UNITY_EDITOR && UNITY_WSA_10_0
- UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
- string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- imei = phoneNumber[1];
- deviceModel = bt.friendlyName;
- #elif !UNITY_EDITOR && UNITY_ANDROID
- AndroidJNI.AttachCurrentThread();
- using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
- {
- gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
- }
- }
- string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
- string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- imei = phoneNumber[1];
- deviceModel = SystemInfo.deviceModel;
- #elif UNITY_STANDALONE
- deviceModel = SystemInfo.deviceModel;
- imei = SystemInfo.graphicsDeviceVersion;
- #endif
- string urll = url + "errorget.php?serial=" + serialField.text + "&key=" + keyField.text;
- if (serialField.text.Length <= 8)
- {
- if (string.IsNullOrEmpty(imei) || imei == "")
- {
- }
- urll += "&imei=" + GetEncodedString(imei) + "&deviceModel=" + GetEncodedString(deviceModel);
- }
- WWW www = new WWW(urll);
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- errorText.text = LanguageManager.Instance.GetTextValue("LostInternet");
- StartCoroutine(ShowError());
- }
- else
- {
- ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
- if (model == null || !string.IsNullOrEmpty(model.error))
- {
- errorCount++;
- errorText.text = LanguageManager.Instance.GetTextValue("cantFindDevice");
- StartCoroutine(ShowError());
- DownloadController.Instance.StartSendAnalitic(serialField.text, "123", "test", "test", "test", "ERROR",
- keyField.text, serialField.text);
- if (errorCount >= 5)
- {
- ShowErrorWindow();
- }
- }
- else
- {
- if (model.active == 0)
- {
- errorText.text = LanguageManager.Instance.GetTextValue("deviceDeactivated");
- StartCoroutine(ShowError());
- }
- else
- {
- DownloadController.Instance.StartSendAnalitic(serialField.text, "123", "test", "test", "test", "OK");
- StartCoroutine(GetDetails());
- }
- }
- }
- }
- IEnumerator GetDetails()
- {
- WWW www = new WWW(url + "loxovnet.php?serial=" + serialField.text);
- yield return www;
- ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
- if (!string.IsNullOrEmpty(model.error))
- {
- errorCount++;
- errorText.text = LanguageManager.Instance.GetTextValue("cantFindDevice");
- StartCoroutine(ShowError());
- if (errorCount >= 5)
- {
- ShowErrorWindow();
- }
- }
- else
- {
- if (model.active == 0)
- {
- errorText.text = LanguageManager.Instance.GetTextValue("deviceDeactivated");
- StartCoroutine(ShowError());
- }
- else
- {
- PlayerPrefs.SetString("deviceId", serialField.text);
- PlayerPrefs.SetInt("Active", 1);
- PlayerPrefs.SetString("mac", model.mac);
- PlayerPrefs.SetString("pin", model.pin);
- PlayerPrefs.SetString("device", model.name);
- PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
- PlayerPrefs.SetString("serial", serialField.text);
- PlayerPrefs.SetString("key", keyField.text);
- PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
- PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
- PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
- PlayerPrefs.SetString("delader", model.dealer);
- MainMenuController.Instance.ChangeTexts();
- PlayerPrefs.SetString("info", model.text);
- PlayerPrefs.SetString("activationDate", model.date);
- PlayerPrefs.SetInt("control", model.control);
- PlayerPrefs.SetString("dealerContact", model.contact);
- PlayerPrefs.SetString("dealerEmail", model.email);
- PlayerPrefs.SetString("dealerAddress", model.address);
- PlayerPrefs.SetString("dealerTel", model.tel);
- pointsDealey.text = model.squareDelta.ToString();
- sectorDealey.text = model.squareCount.ToString();
- minSpeed.text = model.minSpeed.ToString();
- if (model.dealer.Length > 3)
- {
- dealerText.text = model.dealer;
- }
- else
- {
- if (!string.IsNullOrEmpty(model.tel))
- {
- dealerText.text = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", model.contact, model.email, model.address, model.tel);
- PlayerPrefs.SetString("delader", dealerText.text);
- MainMenuController.Instance.ChangeTexts();
- }
- }
- serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
- Debug.Log(PlayerPrefs.GetString("serial"));
- gameObject.SetActive(false);
- CheckDevice(model);
- CheckForBan.Instance.OnSuccessLogin();
- }
- }
- }
- public void SetInfo(ActivationModel model)
- {
- PlayerPrefs.SetInt("Active", 1);
- PlayerPrefs.SetString("mac", model.mac);
- PlayerPrefs.SetString("pin", model.pin);
- PlayerPrefs.SetString("device", model.name);
- PlayerPrefs.SetString("deviceSpeed", model.deviceSpeed);
- PlayerPrefs.SetFloat("startDevicedSquare", model.squareDelta);
- PlayerPrefs.SetInt("startDevicedSquareCount", model.squareCount);
- PlayerPrefs.SetFloat("startDevicedSpeed", model.minSpeed);
- PlayerPrefs.SetString("delader", model.dealer);
- MainMenuController.Instance.ChangeTexts();
- PlayerPrefs.SetString("info", model.text);
- PlayerPrefs.SetString("activationDate", model.date);
- PlayerPrefs.SetInt("control", model.control);
- PlayerPrefs.SetString("dealerContact", model.contact);
- PlayerPrefs.SetString("dealerEmail", model.email);
- PlayerPrefs.SetString("dealerAddress", model.address);
- PlayerPrefs.SetString("dealerTel", model.tel);
- serialText.text = "S/N: " + PlayerPrefs.GetString("serial");
- pointsDealey.text = model.squareDelta.ToString();
- sectorDealey.text = model.squareCount.ToString();
- minSpeed.text = model.minSpeed.ToString();
- if (model.dealer.Length > 3)
- {
- dealerText.text = model.dealer;
- }
- else
- {
- if (!string.IsNullOrEmpty(model.tel))
- {
- dealerText.text = string.Format("{0}\r\n{1}\r\n{2}\r\n{3}", model.contact, model.email, model.address, model.tel);
- PlayerPrefs.SetString("delader", dealerText.text);
- MainMenuController.Instance.ChangeTexts();
- }
- }
- CheckDevice(model);
- }
- private void CheckDevice(ActivationModel model)
- {
- if (model.serial.Length > 8 || model.pin == model.key)
- {
- PlayerPrefs.SetInt("VelestorDevice", 0);
- PlayerPrefs.SetString("delader", LanguageManager.Instance.GetTextValue("Original"));
- MainMenuController.Instance.ChangeTexts();
- dealerText.text = LanguageManager.Instance.GetTextValue("Original");
- }
- else
- {
- PlayerPrefs.SetInt("VelestorDevice", 1);
- }
- MainMenuController.Instance.CheckOriginalDevice();
- }
- IEnumerator CheckActivated()
- {
- string imei = "";
- string deviceModel = "";
- #if !UNITY_EDITOR && UNITY_WSA_10_0
- UnityBluetoothLibrary.UnityBluetooth bt = new UnityBluetoothLibrary.UnityBluetooth();
- string[] phoneNumber = bt.Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- imei = phoneNumber[1];
- deviceModel = bt.friendlyName;
- #elif !UNITY_EDITOR && UNITY_ANDROID
- AndroidJNI.AttachCurrentThread();
- using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
- {
- using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
- {
- gpsActivityJavaClass = new AndroidJavaObject("com.velestor.tractor.GPSTest", currentActivity);
- }
- }
- string Phone = gpsActivityJavaClass.CallStatic<string>("GetPhone");
- string[] phoneNumber = Phone.Split(new string[] { "|" }, System.StringSplitOptions.None);
- imei = phoneNumber[1];
- deviceModel = SystemInfo.deviceModel;
- #elif UNITY_STANDALONE
- deviceModel = SystemInfo.deviceModel;
- imei = SystemInfo.graphicsDeviceVersion;
- #endif
- WWW www = new WWW(url + "errorget.php?serial=" + PlayerPrefs.GetString("serial") + "&key=" + PlayerPrefs.GetString("key") + "&imei=" + imei + "&deviceModel=" + GetEncodedString(deviceModel));
- yield return www;
- ActivationModel model = JsonConvert.DeserializeObject<ActivationModel>(www.text);
- if (model.active == 0)
- {
- Debug.Log("NonActive");
- PlayerPrefs.SetInt("Active", 0);
- SceneManager.LoadScene("Menu");
- }
- else
- {
- Debug.Log("Active");
- gameObject.SetActive(false);
- }
- }
- IEnumerator ShowError(string key = "")
- {
- errorHolder.SetActive(true);
- yield return new WaitForSeconds(1);
- }
- public void HideError()
- {
- errorHolder.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement