12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using Prime31;
- public class ServerGiftManager : MonoBehaviour {
- public enum RegistrationStates
- {
- New,
- Old,
- UpdateDone,
- SantaNameNotUnique,
- IdentificatorNotIsset,
- ContactsIsNotEnough,
- Error
- }
- [System.Serializable]
- public class CouponsList
- {
- [SerializeField]
- public CouponInfo[] Coupons;
- }
- public class GiftInfo
- {
- public static GiftInfo GetInfo()
- {
- return new GiftInfo(PlayerPrefs.GetString("GiftTokenInfo",""));
- }
- public static void Save(GiftInfo info)
- {
- PlayerPrefs.SetString("GiftTokenInfo",info.ToString());
- }
- public static void Consume()
- {
- PlayerPrefs.SetString("GiftTokenInfo", "");
- }
- public bool HasToken
- {
- get { return _lastTokenDate.Date == DateTime.Today && _token > 0; }
- }
- private DateTime _lastTokenDate;
- private int _token;
- public int Token
- {
- get
- {
- if (HasToken)
- {
- return _token;
- }
- return 0;
- }
- }
- public GiftInfo(string source)
- {
- _lastTokenDate = DateTime.MinValue;
- if (!String.IsNullOrEmpty(source))
- {
- var arr = source.Split(':');
- _lastTokenDate = DateTime.FromBinary(Int64.Parse(arr[0]));
- _token = Int32.Parse(arr[1]);
- }
- }
- public GiftInfo(int token)
- {
- _token = token;
- _lastTokenDate = DateTime.Now;
- }
- public override string ToString()
- {
- if (HasToken)
- {
- return String.Format("{0}:{1}",_lastTokenDate.Date.ToBinary(),_token);
- }
- return "";
- }
- }
- internal void SetAge(object text, Func<object, object> p)
- {
- throw new NotImplementedException();
- }
-
- private void Consume(string code, Action<bool> onDone)
- {
- StartCoroutine(ConsumeRoutine(code, onDone));
- }
- public IEnumerator ConsumeRoutine(string couponCode, Action<bool> onDone)
- {
- var www = new WWW(string.Format("{0}Coupon/ConsumeCoupon.php?identificator={1}&code={2}", GameConstants.SERVER_BASE_URL, DeviceID, couponCode));
- yield return www;
- if (string.IsNullOrEmpty(www.error) && www.text.Contains("consumed"))
- {
- //FlurryLogger.Instance.CouponConsumed();
- GetCouponsList(() =>
- {
- onDone(true);
- });
- }
- else
- {
- onDone(false);
- }
- }
- public void GetCouponsList(Action onDone = null)
- {
- StartCoroutine(GetCouponsListRoutine(onDone));
- }
- private IEnumerator GetCouponsListRoutine(Action onDone = null)
- {
- var www = new WWW(string.Format("{0}Coupon/GetCoupons.php?identificator={1}", GameConstants.SERVER_BASE_URL, DeviceID));
- yield return www; ;
- //Debug.LogError(www.text);
- if (string.IsNullOrEmpty(www.error) && !string.IsNullOrEmpty(www.text.Trim()))
- {
- try
- {
- var data = UnityEngine.JsonUtility.FromJson<CouponsList>(www.text.Trim());
- Coupons.Clear();
- Coupons.AddRange(data.Coupons);
- foreach (var info in Coupons)
- {
- info.GetTexture(null);
- }
- }
- catch (Exception ex)
- {
- Debug.LogException(ex);
- }
- }
- else
- {
- Coupons.Clear();
- }
- if (onDone != null)
- {
- onDone();
- }
- }
- public class CouponInfo
- {
- private static Dictionary<string, Texture2D> _texturesCache = new Dictionary<string, Texture2D>();
- [SerializeField]
- public string name;
- [SerializeField]
- public string imageUrl;
- [SerializeField]
- public string code;
- [SerializeField]
- public string expire;
- public void Consume(Action<bool> onDone)
- {
- ServerGiftManager.Instance.Consume(code, onDone);
- }
- public void GetTexture(Action<Texture2D> onDone)
- {
- if (_texturesCache.ContainsKey(imageUrl))
- {
- if (onDone != null)
- {
- onDone(_texturesCache[imageUrl]);
- }
- }
- else
- {
- Instance.StartCoroutine(Instance.LoadTexture(imageUrl, texture =>
- {
- if (texture)
- {
- if (!_texturesCache.ContainsKey(imageUrl))
- {
- _texturesCache.Add(imageUrl, texture);
- //Debug.LogError("TEXTURE LOADED: " + imageUrl);
- }
- }
- if (onDone != null)
- {
- onDone(texture);
- }
- }));
- }
- }
- }
- private IEnumerator LoadTexture(string url, Action<Texture2D> onDone)
- {
- var www = new WWW(url);
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- onDone(www.texture);
- }
- else
- {
- onDone(null);
- Debug.LogError(www.error + ":" + www.url);
- }
- }
- public static string ID;
- private static string DeviceID
- {
- get
- {
- return (SystemInfo.deviceUniqueIdentifier + ID);
- }
- }
- public bool PhoneProvided;// { get; private set; }
- public bool SantaNameProvided;// { get; private set; }
- public bool EmailProvided;// { get; private set; }
- [SerializeField]
- public List<CouponInfo> Coupons;
- public static ServerGiftManager Instance {
- get
- {
- if (!_instance)
- {
- _instance = new GameObject("_serverGiftManager").AddComponent<ServerGiftManager>();
- DontDestroyOnLoad(_instance.gameObject);
- }
- return _instance;
- }
- }
- private static ServerGiftManager _instance;
- public int LevelServer;
- public int GiftNum;
- void Awake ()
- {
- //PlayerPrefs.DeleteAll();
- //PlayerPrefs.SetInt("GetCoupon", 0);
- //PlayerPrefs.Save();
- if (PlayerPrefs.GetInt("Level") == 0)
- {
- PlayerPrefs.SetInt("Level", 1);
- }
-
- //PlayerPrefs.SetInt("FirstEnter", 0);
- ID = "v1_25";
- if (_instance && _instance != this)
- {
- Destroy(gameObject);
- return;
- }
- //ServerGiftManager.Instance.RegisterSantaName(Label.text, state =>
- //{
- // switch (state)
- // {
- // case ServerGiftManager.RegistrationStates.UpdateDone:
- // NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.Menu);
- // NGUITools.SetActive(this.transform.parent.gameObject, false);
- // Debug.Log("UpdateDone");
- // Label.text = "Nytt namm...";
- // //todo: handle - user info was updated (everything goes good)
- // break;
- // case ServerGiftManager.RegistrationStates.Old:
- // Debug.Log("Old");
- // //todo: handle - old user returns (everything goes good)
- // break;
- // case ServerGiftManager.RegistrationStates.SantaNameNotUnique:
- // UIMessage.LabelMessage.text = "Tyvärr är namnet redan upptaget";
- // UIMessage.GetComponent<ScreenBase>().Show();
- // Label.text = "Nytt namm...";
- // Debug.Log("SantaNameNotUnique");
- // //todo: handle - user should guess another name for santa (no data was updated!)
- // break;
- // case ServerGiftManager.RegistrationStates.IdentificatorNotIsset:
- // Debug.Log("IdentificatorNotIsset");
- // Label.text = "Nytt namm...";
- // //todo: handle - you must run base registration first! (no data was updated!)
- // break;
- // case ServerGiftManager.RegistrationStates.ContactsIsNotEnough:
- // Debug.Log("ContactsIsNotEnough");
- // Label.text = "Nytt namm...";
- // //todo: handle - santaName or phone or e-mail is empty (no data was updated!)
- // break;
- // case ServerGiftManager.RegistrationStates.Error:
- // UIMessage.LabelMessage.text = "Okänt fel";
- // UIMessage.GetComponent<ScreenBase>().Show();
- // Label.text = "Nytt namm...";
- // //todo: handle - unknown error happens - maybe internet connection errors (no data was updated!)
- // break;
- // }
- // Debug.LogWarning(state);
- //});
- }
- private static void TESTCALL()
- {
- ServerGiftManager.Instance.RequestTreeUpdate(meals =>
- {
- if (meals == -1)
- {
- //todo: server error, or wrong number filled
- }
- else
- {
- //todo: handle meals amount (everything goes good)
- }
- });
- ServerGiftManager.Instance.BaseRegistration((state, santaName) =>
- {
- switch (state)
- {
- case RegistrationStates.New:
- //todo: handle - user was registered from scratch (everything goes good)
- break;
- case RegistrationStates.Old:
- //todo: handle - old user returns (everything goes good)
- break;
- case RegistrationStates.Error:
- //todo: handle - unknown error happens - maybe internet connection errors (no data was updated!)
- break;
- }
- Debug.LogWarning(state + " " + santaName);
- });
- ServerGiftManager.Instance.FullRegistration("BestSanta", "+38 (063) 270-08-56", "m-snowy@mail.ru", state =>
- {
- switch (state)
- {
- case RegistrationStates.UpdateDone:
- //todo: handle - user info was updated (everything goes good)
- break;
- case RegistrationStates.Old:
- //todo: handle - old user returns (everything goes good)
- break;
- case RegistrationStates.SantaNameNotUnique:
- //todo: handle - user should guess another name for santa (no data was updated!)
- break;
- case RegistrationStates.IdentificatorNotIsset:
- //todo: handle - you must run base registration first! (no data was updated!)
- break;
- case RegistrationStates.ContactsIsNotEnough:
- //todo: handle - target field - santaName or phone or e-mail is empty (no data was updated!)
- break;
- case RegistrationStates.Error:
- //todo: handle - unknown error happens - maybe internet connection errors (no data was updated!)
- break;
- }
- Debug.LogWarning(state);
- });
- ServerGiftManager.Instance.GetGiftToken(info =>
- {
- if (info.HasToken)
- {
- //todo: handle - user achieve gift token - we can give coupon
- }
- else
- {
- //todo: handle - no token!
- }
- Debug.LogWarning(info.HasToken + " " + info.Token);
- });
- ServerGiftManager.Instance.ConsumeToken();
- //ServerGiftManager.Instance.SendCoupon((done, message,errorCode) =>
- //{
- // if (done)
- // {
- // //TODO coupon sent
- // }
- // else
- // {
- // switch (errorCode)
- // {
- // case 56:
- // //TODO handle error: deviceID is not registered
- // break;
- // case 57:
- // //TODO handle error: no deviceID
- // break;
- // case 58:
- // //TODO handle error: phone number does not provided
- // break;
- // case 59:
- // //TODO handle error: request error
- // break;
- // }
- // }
- //});
- }
- public void ConsumeToken()
- {
- GiftInfo.Consume();
- //FlurryLogger.Instance.CouponWon();
- }
- public void GetGiftToken(Action<GiftInfo> onDone)
- {
- //Debug.Log("GetGiftTokenRoutine");
- var info = GiftInfo.GetInfo();
- if (info.HasToken)
- {
- onDone(info);
- StartCoroutine(GetGiftTokenRoutine(info, onDone));
- }
- else
- {
- StartCoroutine(GetGiftTokenRoutine(info,onDone));
- }
- }
- static string remSkob(string input)
- {
- char[] arr = input.ToCharArray();
- char[] arr2 = new char[input.ToCharArray().Length];
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] == '{')
- {
-
- int k = i + 1;
- arr2[i] = '{';
- while (arr[k] != '}')
- {
- //arr[k] = '\0';
- arr2[k] = arr[k];
- k++;
- }
- arr2[k] = arr[k];
- }
- }
- string result = "";
- for (int i = 0; i < arr2.Length; i++)
- {
- if (arr2[i] != '\0')
- {
- result += arr2[i];
- }
- }
- return result;
- }
- public void GetCouponeInfo(Action onDone)
- {
- GiftNum = PlayerPrefs.GetInt("giftNum");
- if(GiftNum == 0)
- {
- return;
- }
- StartCoroutine(GetCouponeInfoRoutine(GiftNum, onDone));
- }
- private IEnumerator GetCouponeInfoRoutine(int giftNum, Action onDone)
- {
- WWW www = null;
- www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/GetGift.php?giftId={0}", giftNum));
- yield return www;
- var result = remSkob(www.text);
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone();
- }
- else
- {
- string res = "";
- var response = (JsonObject)Json.decode(www.text);
- //if (response == null)
- //{
- // res = result;
- //}
- //else
- //{
- // if (response != null)
- // {
- // res = response["response"] == null ? "" : response["response"].ToString().ToLower();
- // }
- //}
- var text = ((JsonObject)Json.decode(www.text))["text"].ToString();
- var url = ((JsonObject)Json.decode(www.text))["img"].ToString();
- NGUIMenuScript.Instance.LabelCoupone.text = text;
- WWW wwwTex = null;
- wwwTex = new WWW(url);
- yield return wwwTex;
- NGUIMenuScript.Instance.TextureCoupone.mainTexture = wwwTex.texture;
- onDone();
- Debug.LogError("INFO " + text + " " + url);
- yield return new WaitForSeconds(0.1f);
-
-
- }
- }
- private IEnumerator GetGiftTokenRoutine(GiftInfo def,Action<GiftInfo> onDone)
- {
- WWW www = null;
- if (InGameScriptCS.Instance.Level > 0 && InGameScriptCS.Instance.Level <= 2)
- {
- www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/GetGift.php?identificator={0}&lvl={1}", DeviceID, InGameScriptCS.Instance.Level));
- }
- else
- {
- www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/GetGift.php?id={0}", DeviceID));
- }
- yield return www;
- var result = remSkob(www.text);
- if (!string.IsNullOrEmpty(www.error))
- {
- StartCoroutine(GetGiftTokenRoutine(def, onDone));
- onDone(def);
- }
- else
- {
- string res = "";
- var response = (JsonObject)Json.decode(www.text);
- res = result;
- //if (response == null)
- //{
- // res = result;
- //}
- //else
- //{
- //if (response != null)
- //{
- // res = response["response"] == null ? "" : response["response"].ToString().ToLower();
- //}
- //}
- //Debug.Log(res);
- //Debug.Log(PlayerPrefs.GetInt("GetCoupon"));
- //Debug.Log(giftNum);
- //if (giftNum > 0)
- //{
- // Debug.Log(giftNum);
- // var newInfo = new GiftInfo(giftNum);
- // GiftInfo.Save(newInfo);
- // onDone(newInfo);
- //}
- //Debug.Log(res);
- try
- {
- if (res.Contains("giftNum"))
- {
- var respo = (JsonObject)Json.decode(res);
- res = "available";
- }
-
- }
- catch (Exception e)
- {
- Debug.LogError(e);
- }
- switch (res)
- {
- case "available":
- if (PlayerPrefs.GetInt("GetCoupon") == 0)
- {
- var token = Int32.Parse(((JsonObject)Json.decode(result))["giftNum"].ToString());
- GiftNum = token;
- PlayerPrefs.SetInt("giftNum", token);
- PlayerPrefs.Save();
- var newInfo = new GiftInfo(token);
- GiftInfo.Save(newInfo);
- onDone(newInfo);
- Debug.LogError("token");
- }
- yield return new WaitForSeconds(0.1f);
- break;
- case "day count error":
- //Debug.Log("Day Count error");
- var newInf = new GiftInfo(0);
- GiftInfo.Save(newInf);
- InGameScriptCS.Instance.GetComponent<ElementsGeneratorCS>().GetGift = false;
- onDone(newInf);
- yield return new WaitForSeconds(0.1f);
- break;
- default:
- //StartCoroutine(GetGiftTokenRoutine(def, onDone));
- yield return new WaitForSeconds(0.1f);
- break;
- }
-
-
- if (response==null)
- {
- yield return new WaitForSeconds(0.1f);
- }
- else
- {
- if (response.ContainsKey("lvl"))
- {
- StartCoroutine(GetGiftTokenRoutine(def, onDone));
- string lvl = response["lvl"] == null ? "" : response["lvl"].ToString();
- LevelServer = int.Parse(lvl);
- }
- }
-
- }
- }
- public void RequestTreeUpdate(Action<int> onDone)
- {
- StartCoroutine(RequestTreeUpdateRoutine(onDone));
- }
- private IEnumerator RequestTreeUpdateRoutine(Action<int> onDone)
- {
- var www = new WWW("https://game.gamatic.com/app_runner_is/meals.json");
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(-1);
- }
- else
- {
- var response = ((JsonObject)Json.decode(www.text))["meals"].ToString().ToLower();
- int result = 0;
- if (int.TryParse(response, out result))
- {
- onDone(result);
- }
- else
- {
- onDone(-1);
- }
- }
- }
- public void RequestWeeksUpdate(Action<string> onDone)
- {
- StartCoroutine(RequestWeekUpdateRoutine(onDone));
- }
- private IEnumerator RequestWeekUpdateRoutine(Action<string> onDone)
- {
- var www = new WWW("https://game.gamatic.com/app_runner_is/week.json");
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(www.error);
- }
- else
- {
- var response = www.text;
- int result = 0;
- if (!string.IsNullOrEmpty(www.text))
- {
- onDone(www.text);
- }
- else
- {
- onDone("Empty");
- }
- }
- }
- public void BaseRegistration(Action<RegistrationStates, string> onDone)
- {
- StartCoroutine(BaseRegistrationRoutine(onDone));
- }
- public IEnumerator BaseRegistrationRoutine(Action<RegistrationStates, string> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/Register.php?identificator={0}", WWW.EscapeURL(DeviceID)));
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(RegistrationStates.Error,"");
- }
- else
- {
- var response = (JsonObject)Json.decode(www.text);
- var answer = response["response"].ToString().ToLower();
- string santaName = response["name"] == null ? "" : response["name"].ToString();
- string setted = response["Isset"] == null ? "" : response["Isset"].ToString();
- SantaNameProvided = !string.IsNullOrEmpty(santaName);
- PhoneProvided = setted.Contains("P");
- EmailProvided = setted.Contains("M");
- switch (answer)
- {
- case "isset":
- onDone(RegistrationStates.Old, santaName);
- break;
- case "added":
- onDone(RegistrationStates.New, santaName);
- break;
- default:
- onDone(RegistrationStates.Error,"");
- break;
- }
- }
- }
- public void RegisterPhone(string phone, Action<RegistrationStates> onDone)
- {
- if (string.IsNullOrEmpty(phone))
- {
- onDone(RegistrationStates.ContactsIsNotEnough);
- return;
- }
- StartCoroutine(FullRegistrationRoutine("", phone.Trim(), "", onDone));
- }
- public void RegisterMail(string mail, Action<RegistrationStates> onDone)
- {
- if (string.IsNullOrEmpty(mail))
- {
- onDone(RegistrationStates.ContactsIsNotEnough);
- return;
- }
- StartCoroutine(FullRegistrationRoutine("", "", mail.Trim(), onDone));
- }
- public void RegisterSantaName(string santaName, Action<RegistrationStates> onDone)
- {
- if (string.IsNullOrEmpty(santaName))
- {
- onDone(RegistrationStates.ContactsIsNotEnough);
- return;
- }
- StartCoroutine(FullRegistrationRoutine(santaName.Trim(), "", "", onDone));
- }
- public void FullRegistration(string santaName, string phone, string email,Action<RegistrationStates> onDone)
- {
- if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(santaName))
- {
- onDone(RegistrationStates.ContactsIsNotEnough);
- return;
- }
- StartCoroutine(FullRegistrationRoutine(santaName,phone,email,onDone));
- }
- protected IEnumerator FullRegistrationRoutine(string santaName, string phone, string email, Action<RegistrationStates> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/Register.php?identificator={0}&name={1}&phone={2}&email={3}", WWW.EscapeURL(DeviceID), WWW.EscapeURL(santaName), WWW.EscapeURL(phone), WWW.EscapeURL(email)));
- yield return www;
- //Debug.Log(www.url);
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(RegistrationStates.Error);
- }
- else
- {
- var response = (JsonObject)Json.decode(www.text);
- var answer = response["response"].ToString().ToLower();
- if (string.IsNullOrEmpty(RegistrationManager.Instance.CurName))
- {
- SantaNameProvided = !string.IsNullOrEmpty(santaName);
- }
-
- string setted = response["Isset"] == null ? "" : response["Isset"].ToString();
- PhoneProvided = setted.Contains("P");
- EmailProvided = setted.Contains("M");
- switch (answer)
- {
- case "identificator not isset":
- onDone(RegistrationStates.IdentificatorNotIsset);
- break;
- case "update is succesfull":
- //Debug.Log((RegistrationManager.Instance == null) +" "+ santaName .ToString()+ " RegistrationManager.Instance is NULL!");
- if (RegistrationManager.Instance && !string.IsNullOrEmpty(santaName))
- {
- RegistrationManager.Instance.CurName = santaName;
- }
- else
- {
- Debug.Log("RegistrationManager.Instance is NULL!");
- }
-
- onDone(RegistrationStates.UpdateDone);
- break;
- case "isset":
- onDone(RegistrationStates.Old);
- break;
- case "namenotunique":
- onDone(RegistrationStates.SantaNameNotUnique);
- break;
- default:
- onDone(RegistrationStates.Error);
- break;
- }
- Debug.Log(answer);
- }
- }
- public void SetLevel(int lvl,Action<object> onDone)
- {
- if (lvl == 0)
- {
- return;
- }
- StartCoroutine(SendGetLevel(lvl, onDone));
- }
- private IEnumerator SendGetLevel(int lvl, Action<object> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/GetGift.php?identificator={0}&lvl={1}", WWW.EscapeURL(DeviceID), WWW.EscapeURL(lvl.ToString())));
- yield return www;
- Debug.Log(www.url);
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(RegistrationStates.Error);
- }
- else
- {
-
- //var answer = response["result"].ToString().ToLower();
- //Debug.Log(answer);
- //if (string.IsNullOrEmpty(RegistrationManager.Instance.CurName))
- //{
- // SantaNameProvided = !string.IsNullOrEmpty(santaName);
- //}
- //string setted = response["Isset"] == null ? "" : response["Isset"].ToString();
- //PhoneProvided = setted.Contains("P");
- //EmailProvided = setted.Contains("M");
- //switch (answer)
- //{
- //}
- //Debug.Log(answer);
- }
- }
- public void GetLevel( Action<object> onDone)
- {
-
- StartCoroutine(SendGetLevel(onDone));
- }
- public void GetGiftActive(string giftId, Action onDone)
- {
- StartCoroutine(SendGetGiftOnRoad(giftId, onDone));
- }
- private IEnumerator SendGetGiftOnRoad(string giftId, Action onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/GetGift.php?gift_id={0}", giftId));
- yield return www;
- Debug.Log(www.text);
- if (!string.IsNullOrEmpty(www.error))
- {
- //onDone(RegistrationStates.Error);
- Debug.LogError("error");
- }
- else
- {
- var response = (JsonObject)Json.decode(www.text);
- if (response.ContainsKey("success"))
- {
- Debug.LogError("success");
- }
- else if (response.ContainsKey("success"))
- {
- Debug.LogError("success");
- }
- onDone();
- }
- }
- private IEnumerator SendGetLevel(Action<object> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/GetGift.php?id={0}", WWW.EscapeURL(DeviceID)));
- yield return www;
- //Debug.Log(www.url);
- if (!string.IsNullOrEmpty(www.error))
- {
- //onDone(RegistrationStates.Error);
- }
- else
- {
- var response = (JsonObject)Json.decode(www.text);
- if (response.ContainsKey("lvl"))
- {
- string lvl = response["lvl"] == null ? "" : response["lvl"].ToString();
- //Debug.Log(lvl);
- if (!string.IsNullOrEmpty(lvl))
- {
- switch (lvl)
- {
- case "null":
- Debug.Log("null");
- break;
- }
- LevelServer = int.Parse(lvl);
- }
- else
- {
- LevelServer = 0;
- }
- }
- else
- {
- LevelServer = 0;
- }
- onDone(LevelServer);
- }
- }
- public void SendInviteMailToserv(string email, Action<object> onDone)
- {
- if (string.IsNullOrEmpty(email))
- {
- onDone(RegistrationStates.ContactsIsNotEnough);
- return;
- }
- StartCoroutine(SendInviteMail(email, onDone));
- }
- private IEnumerator SendInviteMail(string email, Action<object> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RegScripts/SendInvite.php?uid={0}&Mail={1}", WWW.EscapeURL(DeviceID), WWW.EscapeURL(email)));
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(RegistrationStates.Error);
- }
- else
- {
- var response = SimpleJSON.JSON.Parse(www.text)["Result"].ToString();
- onDone(response);
- Debug.Log(response);
- }
- }
- public void SendCoupon(string phone,Action<bool, string, int> onDone)
- {
- Debug.Log( " phone " + phone + " " + WWW.EscapeURL(DeviceID));
- StartCoroutine(SendCouponRoutine(phone,onDone));
- }
- protected IEnumerator SendCouponRoutine(string phone,Action<bool, string, int> onDone)
- {
-
- var linq = string.Format(
- "https://game.gamatic.com/app_runner_is/RegScripts/SendPhone.php?&phone={1}&identificator={0}",
- WWW.EscapeURL(DeviceID), phone);
- var www = new WWW(linq);
-
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(false, www.error,100);
- }
- else
- {
- bool done = false;
- var answer = ((JsonObject)Json.decode(www.text));
- if (answer.ToString().Contains("issued"))
- {
- LoginManager.Instance.BackMessageCoupone.SetActive(true);
- LoginManager.Instance.CouponNumberWronge.Show();
-
- }
- else if (answer.ToString().Contains("succesfull"))
- {
- done = true;
- }
- else
- {
- if (answer.ToString().Contains("succesfull"))
- {
- done = answer["status"].ToString().Equals("done");
- }
-
- }
- int errorCode = answer.ContainsKey("errorCode") ? int.Parse(answer["errorCode"].ToString()) : 0;
- string message = answer.ContainsKey("errorCode")? answer["errorDesc"].ToString():"";
- //bool done = answer["status"].ToString().Equals("done");
- onDone(done, message, errorCode);
- }
- }
- public void GetAgeAction(Action<object> onDone)
- {
- StartCoroutine(GetAge(onDone));
- }
- protected IEnumerator GetAge(Action<object> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RequestCheck.php?GetAge={0}&uid={1}", 1, WWW.EscapeURL(DeviceID)));
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(RegistrationStates.Error);
- }
- else
- {
- var response = www.text;
- if (response == 1.ToString())
- {
- LoginManager.Instance.Age = true;
- }
-
- onDone(response);
- }
- }
- public void SetAgeAction(Action<object> onDone)
- {
- Debug.Log(DeviceID);
- StartCoroutine(SetAge(onDone));
- }
- protected IEnumerator SetAge(Action<object> onDone)
- {
- var www = new WWW(string.Format("https://game.gamatic.com/app_runner_is/RequestCheck.php?SetAge={0}&uid={1}",1, WWW.EscapeURL(DeviceID)));
- yield return www;
- if (!string.IsNullOrEmpty(www.error))
- {
- onDone(RegistrationStates.Error);
- }
- else
- {
- var response = www.text;
- onDone(response);
- }
- }
- }
|