public static bool SetSecureAreaData(string plusCode, string key, byte[] value, string password, double?expiration = null) { var db = new PraxisContext(); byte[] encryptedValue = EncryptValue(value, password, out byte[] IVs); var row = db.AreaGameData.FirstOrDefault(p => p.PlusCode == plusCode && p.DataKey == key); if (row == null) { row = new DbTables.AreaGameData(); row.DataKey = key; row.PlusCode = plusCode; row.GeoAreaIndex = Converters.GeoAreaToPolygon(OpenLocationCode.DecodeValid(plusCode.ToUpper())); db.AreaGameData.Add(row); } if (expiration.HasValue) { row.Expiration = DateTime.Now.AddSeconds(expiration.Value); } else { row.Expiration = null; } row.DataValue = encryptedValue; row.IvData = IVs; return(db.SaveChanges() == 1); }
public static bool SetAreaData(string plusCode, string key, string value, double?expiration = null) { var db = new PraxisContext(); if (db.PlayerData.Any(p => p.DeviceID == key || p.DeviceID == value)) { return(false); } var row = db.AreaGameData.FirstOrDefault(p => p.PlusCode == plusCode && p.DataKey == key); if (row == null) { row = new DbTables.AreaGameData(); row.DataKey = key; row.PlusCode = plusCode; row.GeoAreaIndex = Converters.GeoAreaToPolygon(OpenLocationCode.DecodeValid(plusCode.ToUpper())); db.AreaGameData.Add(row); } if (expiration.HasValue) { row.Expiration = DateTime.Now.AddSeconds(expiration.Value); } else { row.Expiration = null; } row.IvData = null; row.DataValue = value.ToByteArrayUTF8(); return(db.SaveChanges() == 1); }