/// <summary> /// Upload item data to buddies /// Will return false if still on cooldown, or item count is the same as before. /// (Will not update if adding one item, and removing another) /// </summary> /// <param name="data"></param> /// <returns></returns> public bool UploadBuddyData(SerializedPlayerItems data) { if (!string.IsNullOrEmpty(data.Items) && data.UserId > 0) { if (data.Items.Length != _lastBuddyUpdateLength) { _lastBuddyUpdateLength = data.Items.Length; string json = JsonConvert.SerializeObject(data); var compressedJson = GzipCompressionHandler.CompressAndConvertToBase64(json); var encodedCompressedJson = HttpUtility.UrlEncode(compressedJson); /*var uncompressedSize = Encoding.ASCII.GetByteCount(json); * var compressedSize = Encoding.ASCII.GetByteCount(compressedJson); * var compressedEncodedSize = Encoding.ASCII.GetByteCount(encodedCompressedJson); * * Logger.Debug($"Transmitting buddy items, {uncompressedSize} before compression, {compressedSize} after compression and {compressedEncodedSize} after URL encoding.");*/ var result = UploadBuddyData($"json={encodedCompressedJson}", UrlBuddyUpload); // Access denied, we'll need a new user id it seems. // Something must be wrong. if (result != null && result.Status == 401) { Properties.Settings.Default.BuddySyncUserIdV2 = 0; Properties.Settings.Default.Save(); CreateUserId(); } return(result != null && result.Success); } else { Logger.Info("Buddy items not updated, no new changes detected."); return(true); } } else { Logger.Info("Tried to upload buddy data, but either userid or items were null"); } return(false); }
/// <summary> /// Upload item data to buddies /// Will return false if still on cooldown, or item count is the same as before. /// (Will not update if adding one item, and removing another) /// </summary> /// <param name="data"></param> /// <returns></returns> public bool UploadBuddyData(SerializedPlayerItems data) { if (!string.IsNullOrEmpty(data.Items) && data.UserId > 0) { if (data.Items.Length != _lastBuddyUpdateLength) { _lastBuddyUpdateLength = data.Items.Length; string json = JsonConvert.SerializeObject(data); var compressedJson = GzipCompressionHandler.CompressAndConvertToBase64(json); var encodedCompressedJson = HttpUtility.UrlEncode(compressedJson); var result = UploadBuddyData($"json={encodedCompressedJson}", UrlBuddyUpload); // Access denied, we'll need a new user id it seems. // Something must be wrong. if (result != null && result.Status == 401) { _settings.GetPersistent().BuddySyncUserIdV2 = 0; CreateUserId(); } return(result != null && result.Success); } else { Logger.Info("Buddy items not updated, no new changes detected."); return(true); } } else { Logger.Info("Tried to upload buddy data, but either userid or items were null"); } return(false); }