From 2ff9ea3f8038653135c284cc0c93d88690db9a22 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 1 Jun 2014 10:06:26 -0700 Subject: Fixed a few things pertaining to interfacing with the estate service. Specifically, StoreEstateSettings was not being used anywhere; instead EstatSetting.Save was being called, but that method is a trigger to the DB-layer code directly, which, besides being wrong, was making it impossible to replace the service with a remote connector. Also added more packing/unpacking code. --- OpenSim/Framework/EstateSettings.cs | 101 +++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/EstateSettings.cs') diff --git a/OpenSim/Framework/EstateSettings.cs b/OpenSim/Framework/EstateSettings.cs index dd3e195..328fca4 100644 --- a/OpenSim/Framework/EstateSettings.cs +++ b/OpenSim/Framework/EstateSettings.cs @@ -418,17 +418,106 @@ namespace OpenSim.Framework Dictionary map = new Dictionary(); PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo p in properties) - map[p.Name] = p.GetValue(this, null); - + { + // EstateBans is a complex type, let's treat it as special + if (p.Name == "EstateBans") + continue; + + object value = p.GetValue(this, null); + if (value != null) + { + if (p.PropertyType.IsArray) // of UUIDs + { + if (((Array)value).Length > 0) + { + string[] args = new string[((Array)value).Length]; + int index = 0; + foreach (object o in (Array)value) + args[index++] = o.ToString(); + map[p.Name] = String.Join(",", args); + } + } + else // simple types + map[p.Name] = value; + } + } + + // EstateBans are special + Dictionary bans = new Dictionary(); + int i = 0; + foreach (EstateBan ban in EstateBans) + bans["ban" + i++] = ban.ToMap(); + map["EstateBans"] = bans; return map; } - public EstateSettings(Dictionary map) + /// + /// For debugging + /// + /// + public override string ToString() { - PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); - foreach (PropertyInfo p in properties) - p.SetValue(this, map[p.Name], null); + Dictionary map = ToMap(); + String result = String.Empty; + + foreach (KeyValuePair kvp in map) + { + if (kvp.Key == "EstateBans") + { + result += "EstateBans:" + Environment.NewLine; + foreach (KeyValuePair ban in (Dictionary)kvp.Value) + result += ban.Value.ToString(); + } + else + result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value.ToString(), Environment.NewLine); + } + return result; + } + + public EstateSettings(Dictionary map) + { + foreach (KeyValuePair kvp in map) + { + PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance); + if (p == null) + continue; + + // EstateBans is a complex type, let's treat it as special + if (p.Name == "EstateBans") + continue; + + if (p.PropertyType.IsArray) + { + string[] elements = ((string)map[p.Name]).Split(new char[] { ',' }); + UUID[] uuids = new UUID[elements.Length]; + int i = 0; + foreach (string e in elements) + uuids[i++] = new UUID(e); + p.SetValue(this, uuids, null); + } + else + { + object value = p.GetValue(this, null); + if (value is String) + p.SetValue(this, map[p.Name], null); + else if (value is UInt32) + p.SetValue(this, UInt32.Parse((string)map[p.Name]), null); + else if (value is Boolean) + p.SetValue(this, Boolean.Parse((string)map[p.Name]), null); + else if (value is UUID) + p.SetValue(this, UUID.Parse((string)map[p.Name]), null); + } + } + + // EstateBans are special + var banData = ((Dictionary)map["EstateBans"]).Values; + EstateBan[] bans = new EstateBan[banData.Count]; + int b = 0; + foreach (Dictionary ban in banData) + bans[b++] = new EstateBan(ban); + PropertyInfo bansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance); + bansProperty.SetValue(this, bans, null); } } } -- cgit v1.1