internal override void ForgetMe() { if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN)) { Logger.LogDebug("Already forgotten user " + UserID); return; } Logger.LogDebug("Forgetting user " + UserID); PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1); if (IsUploading) { return; } var advertisingId = PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID); var dictionary = new Dictionary <string, object>() { { "eventName", "ddnaForgetMe" }, { "eventTimestamp", GetCurrentTimestamp() }, { "eventUUID", Guid.NewGuid().ToString() }, { "sessionID", SessionID }, { "userID", UserID }, { "eventParams", new Dictionary <string, object>() { { "platform", Platform }, { "sdkVersion", Settings.SDK_VERSION }, { "ddnaAdvertisingId", advertisingId } } } }; if (string.IsNullOrEmpty(advertisingId)) { (dictionary["eventParams"] as Dictionary <string, object>) .Remove("ddnaAdvertisingId"); } string json; try { json = MiniJSON.Json.Serialize(dictionary); } catch (Exception e) { Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message); return; } var url = (HashSecret != null) ? DDNA.FormatURI( Settings.COLLECT_HASH_URL_PATTERN.Replace("/bulk", ""), CollectURL, EnvironmentKey, DDNA.GenerateHash(json, HashSecret)) : DDNA.FormatURI( Settings.COLLECT_URL_PATTERN.Replace("/bulk", ""), CollectURL, EnvironmentKey, null); HttpRequest request = new HttpRequest(url) { HTTPMethod = HttpRequest.HTTPMethodType.POST, HTTPBody = json }; request.setHeader("Content-Type", "application/json"); StartCoroutine(Send( request, () => { Logger.LogDebug("Forgot user " + UserID); PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1); })); }
internal IEnumerator Prefetch(Action onSuccess, Action <string> onError, params string[] urls) { if (urls == null || urls.Length == 0) { onSuccess(); yield break; } if (IsFull()) { Logger.LogInfo("Not attempting image pre-fetch - cache is already full"); onSuccess(); yield break; } var downloaded = 0; string error = null; var downloading = 0; var userMaxConcurrent = DDNA.Instance.Settings.MaxConcurrentImageCacheFetches; var maxConcurrent = userMaxConcurrent > 0 ? userMaxConcurrent : 5; foreach (var url in urls) { var name = GetName(url); if (IsFull()) { Logger.LogWarning("Did not attempt to download image message - Image Message cache is full"); downloaded++; } else if (!File.Exists(cache + name)) { yield return(new WaitUntil(() => downloading <= maxConcurrent)); downloading++; parent.StartCoroutine(Fetch( url, t => { var filePath = cache + GetName(url); File.Move(t, filePath); downloaded++; downloading--; }, e => { error = e; downloading--; })); } else { downloaded++; } } while (downloaded < urls.Length) { if (error != null) { onError(error); yield break; } else { yield return(null); } } onSuccess(); }
internal virtual bool Evaluate(GameEvent evnt) { if (limit != -1 && runs >= limit) { return(false); } if (evnt.Name != eventName) { return(false); } var parameters = evnt.parameters.AsDictionary(); var stack = new Stack <object>(); foreach (var token in condition) { if (token.ContainsKey("o")) { string op = (string)token["o"]; object right = stack.Pop(); object left = stack.Pop(); try { if (right is bool) { if (left is bool) { stack.Push(BOOLS[op]((bool)left, (bool)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is long) { if (left is int) { stack.Push(LONGS[op]((int)left, (long)right)); } else if (left is long) { stack.Push(LONGS[op]((long)left, (long)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is double) { if (left is float) { stack.Push(DOUBLES[op]((float)left, (double)right)); } else if (left is double) { stack.Push(DOUBLES[op]((double)left, (double)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is string) { if (left is string) { stack.Push(STRINGS[op]((string)left, (string)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is DateTime) { if (left is string) { stack.Push(DATES[op]( DateTime.ParseExact( (string)left, Settings.EVENT_TIMESTAMP_FORMAT, System.Globalization.CultureInfo.InvariantCulture), (DateTime)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else { Logger.LogWarning("Unexpected type for " + right); return(false); } } catch (KeyNotFoundException) { Logger.LogWarning(string.Format( "Failed to find operation {0} for {1} and {2}", op, left, right)); return(false); } catch (FormatException) { Logger.LogWarning("Failed converting parameter " + left + " to DateTime"); return(false); } } else if (token.ContainsKey("p")) { var param = (string)token["p"]; if (parameters.ContainsKey(param)) { stack.Push(parameters[param]); } else { Logger.LogWarning("Failed to find " + param + " in event params"); return(false); } } else if (token.ContainsKey("b")) { stack.Push((bool)token["b"]); } else if (token.ContainsKey("i")) { // ints are double precision in JSON stack.Push((long)token["i"]); } else if (token.ContainsKey("f")) { var value = token["f"]; // serialiser inserts a whole double as a long if (value is long) { stack.Push((double)(long)token["f"]); } else { // floats are double precision in JSON stack.Push((double)token["f"]); } } else if (token.ContainsKey("s")) { stack.Push((string)token["s"]); } else if (token.ContainsKey("t")) { try { stack.Push(DateTime.Parse((string)token["t"], null)); } catch (FormatException) { Logger.LogWarning("Failed converting " + token["t"] + " to DateTime"); return(false); } } else { stack.Push(token); } } var result = stack.Count == 0 || (stack.Pop() as bool? ?? false); if (result) { runs++; ddna.RecordEvent(new GameEvent("ddnaEventTriggeredAction") .AddParam("ddnaEventTriggeredCampaignID", campaignId) .AddParam("ddnaEventTriggeredCampaignPriority", priority) .AddParam("ddnaEventTriggeredVariantID", variantId) .AddParam("ddnaEventTriggeredActionType", GetAction()) .AddParam("ddnaEventTriggeredSessionCount", runs)); } return(result); }
private void HandleSessionConfigurationCallback(JSONObject response) { if (response.Count > 0) { var parameters = response["parameters"]; if (parameters != null && parameters is JSONObject) { object dpWhitelist = null; (parameters as JSONObject).TryGetValue("dpWhitelist", out dpWhitelist); if (dpWhitelist != null && dpWhitelist is List <object> ) { whitelistDps = new ReadOnlyCollection <string>( (dpWhitelist as List <object>) .Select(e => e as string) .ToList()); } object eventsWhitelist = null; (parameters as JSONObject).TryGetValue("eventsWhitelist", out eventsWhitelist); if (eventsWhitelist != null && eventsWhitelist is List <object> ) { whitelistEvents = new ReadOnlyCollection <string>( (eventsWhitelist as List <object>) .Select(e => e as string) .ToList()); } object triggers = null; (parameters as JSONObject).TryGetValue("triggers", out triggers); if (triggers != null && triggers is List <object> ) { eventTriggers = (triggers as List <object>) .Select((e, i) => { var t = new EventTrigger(this, i, e as JSONObject); // save persistent actions var p = t.GetResponse().GetOrDefault("parameters", new JSONObject()); if (p.GetOrDefault("ddnaIsPersistent", false)) { actionStore.Put(t, p); } return(t); }) .GroupBy(e => e.GetEventName()) .ToDictionary(e => e.Key, e => { var list = e.ToList(); list.Sort(); return(new ReadOnlyCollection <EventTrigger>(list)); }); } object imageCache = null; (parameters as JSONObject).TryGetValue("imageCache", out imageCache); if (imageCache != null && imageCache is List <object> ) { cacheImages = new ReadOnlyCollection <string>( (imageCache as List <object>) .Select(e => e as string) .ToList()); DownloadImageAssets(); } #if DDNA_SMARTADS SmartAds.Instance.RegisterForAdsInternal(response); #endif Logger.LogDebug("Session configured"); object cached = null; (parameters as JSONObject).TryGetValue("isCachedResponse", out cached); if (cached != null && cached is bool) { ddna.NotifyOnSessionConfigured(cached as bool? ?? false); } else { ddna.NotifyOnSessionConfigured(false); } } } else { Logger.LogWarning("Session configuration failed"); ddna.NotifyOnSessionConfigurationFailed(); } TriggerDefaultEvents(newPlayer); }
private IEnumerator EngageCoroutine(string decisionPoint, Dictionary <string, object> engageParams, Action <Dictionary <string, object> > callback) { Logger.LogDebug("Starting engagement for '" + decisionPoint + "'"); Dictionary <string, object> engageRequest = new Dictionary <string, object>() { { "userID", this.UserID }, { "decisionPoint", decisionPoint }, { "sessionID", this.SessionID }, { "version", Settings.ENGAGE_API_VERSION }, { "sdkVersion", Settings.SDK_VERSION }, { "platform", this.Platform }, { "timezoneOffset", Convert.ToInt32(ClientInfo.TimezoneOffset) } }; if (ClientInfo.Locale != null) { engageRequest.Add("locale", ClientInfo.Locale); } if (engageParams != null) { engageRequest.Add("parameters", engageParams); } string engageJSON = null; try { engageJSON = MiniJSON.Json.Serialize(engageRequest); } catch (Exception e) { Logger.LogWarning("Problem serialising engage request data: " + e.Message); yield break; } Action <string> requestCb = (response) => { bool cachedResponse = false; if (response != null) { Logger.LogDebug("Using live engagement: " + response); this.engageArchive[decisionPoint] = response; } else { if (this.engageArchive.Contains(decisionPoint)) { Logger.LogWarning("Engage request failed, using cached response."); cachedResponse = true; response = this.engageArchive[decisionPoint]; } else { Logger.LogWarning("Engage request failed"); } } Dictionary <string, object> result = MiniJSON.Json.Deserialize(response) as Dictionary <string, object>; if (cachedResponse) { result["isCachedResponse"] = cachedResponse; } if (callback != null) { callback(result); } }; yield return(StartCoroutine(EngageRequest(engageJSON, requestCb))); }
internal virtual bool Evaluate(GameEvent evnt) { if (evnt.Name != eventName) { return(false); } var parameters = evnt.parameters.AsDictionary(); var stack = new Stack <object>(); foreach (var token in condition) { if (token.ContainsKey("o")) { string op = (string)token["o"]; op = op.ToLower(); object right = stack.Pop(); object left = stack.Pop(); try{ if (right is bool) { if (left is bool) { stack.Push(BOOLS[op]((bool)left, (bool)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is long) { if (left is int) { stack.Push(LONGS[op]((int)left, (long)right)); } else if (left is long) { stack.Push(LONGS[op]((long)left, (long)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is double) { if (left is float) { stack.Push(DOUBLES[op]((float)left, (double)right)); } else if (left is double) { stack.Push(DOUBLES[op]((double)left, (double)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is string) { if (left is string) { stack.Push(STRINGS[op]((string)left, (string)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is DateTime) { if (left is string) { stack.Push(DATES[op]( DateTime.ParseExact( (string)left, Settings.EVENT_TIMESTAMP_FORMAT, System.Globalization.CultureInfo.InvariantCulture), (DateTime)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else { Logger.LogWarning("Unexpected type for " + right); return(false); } } catch (KeyNotFoundException) { Logger.LogWarning(string.Format( "Failed to find operation {0} for {1} and {2}", op, left, right)); return(false); } catch (FormatException) { Logger.LogWarning("Failed converting parameter " + left + " to DateTime"); return(false); } } else if (token.ContainsKey("p")) { var param = (string)token["p"]; if (parameters.ContainsKey(param)) { stack.Push(parameters[param]); } else { Logger.LogWarning("Failed to find " + param + " in event params"); return(false); } } else if (token.ContainsKey("b")) { stack.Push((bool)token["b"]); } else if (token.ContainsKey("i")) { // ints are double precision in JSON stack.Push((long)token["i"]); } else if (token.ContainsKey("f")) { var value = token["f"]; // serialiser inserts a whole double as a long if (value is long) { stack.Push((double)(long)token["f"]); } else { // floats are double precision in JSON stack.Push((double)token["f"]); } } else if (token.ContainsKey("s")) { stack.Push((string)token["s"]); } else if (token.ContainsKey("t")) { try{ stack.Push(DateTime.Parse((string)token["t"], null)); } catch (FormatException) { Logger.LogWarning("Failed converting " + token["t"] + " to DateTime"); return(false); } } else { stack.Push(token); } } var result = stack.Count == 0 || (stack.Pop() as bool? ?? false); if (result) { // Default to true if no conditions exist bool triggerConditionsReached = campaignTriggerConditions.Count == 0; // Only one condition needs to be true to flip conditions to true this.executionCountManager.incrementExecutionCount(this.variantId); foreach (TriggerCondition campaignTriggerCondition in campaignTriggerConditions) { if (campaignTriggerCondition.CanExecute()) { triggerConditionsReached = true; } } // If none reached return false if (!triggerConditionsReached) { return(false); } if (limit != -1 && runs >= limit) { return(false); } var eventTriggeredActionEvent = CreateEventTriggeredActionEvent(true); ddna.RecordEvent(eventTriggeredActionEvent); } return(result); }