Allow registering regions whose names are equivalent under LIKE but not truly equal

user_profiles
Oren Hurvitz 2012-12-16 09:48:37 +02:00 committed by Justin Clark-Casey (justincc)
parent 1a6694b264
commit 1b826b4877
3 changed files with 19 additions and 8 deletions

View File

@ -2102,5 +2102,16 @@ namespace OpenSim.Framework
return firstName + "." + lastName + " " + "@" + uri.Authority; return firstName + "." + lastName + " " + "@" + uri.Authority;
} }
#endregion #endregion
/// <summary>
/// Escapes the special characters used in "LIKE".
/// </summary>
/// <remarks>
/// For example: EscapeForLike("foo_bar%baz") = "foo\_bar\%baz"
/// </remarks>
public static string EscapeForLike(string str)
{
return str.Replace("_", "\\_").Replace("%", "\\%");
}
} }
} }

View File

@ -185,15 +185,15 @@ namespace OpenSim.Services.GridService
if (!m_AllowDuplicateNames) if (!m_AllowDuplicateNames)
{ {
List<RegionData> dupe = m_Database.Get(regionInfos.RegionName, scopeID); List<RegionData> dupe = m_Database.Get(Util.EscapeForLike(regionInfos.RegionName), scopeID);
if (dupe != null && dupe.Count > 0) if (dupe != null && dupe.Count > 0)
{ {
foreach (RegionData d in dupe) foreach (RegionData d in dupe)
{ {
if (d.RegionID != regionInfos.RegionID) if (d.RegionID != regionInfos.RegionID)
{ {
m_log.WarnFormat("[GRID SERVICE]: Region {0} tried to register duplicate name with ID {1}.", m_log.WarnFormat("[GRID SERVICE]: Region tried to register using a duplicate name. New region: {0} ({1}), existing region: {2} ({3}).",
regionInfos.RegionName, regionInfos.RegionID); regionInfos.RegionName, regionInfos.RegionID, d.RegionName, d.RegionID);
return "Duplicate region name"; return "Duplicate region name";
} }
} }
@ -359,7 +359,7 @@ namespace OpenSim.Services.GridService
public GridRegion GetRegionByName(UUID scopeID, string name) public GridRegion GetRegionByName(UUID scopeID, string name)
{ {
List<RegionData> rdatas = m_Database.Get(name, scopeID); List<RegionData> rdatas = m_Database.Get(Util.EscapeForLike(name), scopeID);
if ((rdatas != null) && (rdatas.Count > 0)) if ((rdatas != null) && (rdatas.Count > 0))
return RegionData2RegionInfo(rdatas[0]); // get the first return RegionData2RegionInfo(rdatas[0]); // get the first
@ -377,7 +377,7 @@ namespace OpenSim.Services.GridService
{ {
// m_log.DebugFormat("[GRID SERVICE]: GetRegionsByName {0}", name); // m_log.DebugFormat("[GRID SERVICE]: GetRegionsByName {0}", name);
List<RegionData> rdatas = m_Database.Get(name + "%", scopeID); List<RegionData> rdatas = m_Database.Get(Util.EscapeForLike(name) + "%", scopeID);
int count = 0; int count = 0;
List<GridRegion> rinfos = new List<GridRegion>(); List<GridRegion> rinfos = new List<GridRegion>();
@ -586,7 +586,7 @@ namespace OpenSim.Services.GridService
string regionName = cmd[3]; string regionName = cmd[3];
List<RegionData> regions = m_Database.Get(regionName, UUID.Zero); List<RegionData> regions = m_Database.Get(Util.EscapeForLike(regionName), UUID.Zero);
if (regions == null || regions.Count < 1) if (regions == null || regions.Count < 1)
{ {
MainConsole.Instance.Output("No region with name {0} found", regionName); MainConsole.Instance.Output("No region with name {0} found", regionName);
@ -716,7 +716,7 @@ namespace OpenSim.Services.GridService
return; return;
} }
List<RegionData> regions = m_Database.Get(cmd[3], UUID.Zero); List<RegionData> regions = m_Database.Get(Util.EscapeForLike(cmd[3]), UUID.Zero);
if (regions == null || regions.Count < 1) if (regions == null || regions.Count < 1)
{ {
MainConsole.Instance.Output("Region not found"); MainConsole.Instance.Output("Region not found");

View File

@ -387,7 +387,7 @@ namespace OpenSim.Services.GridService
m_log.DebugFormat("[HYPERGRID LINKER]: Request to unlink {0}", mapName); m_log.DebugFormat("[HYPERGRID LINKER]: Request to unlink {0}", mapName);
GridRegion regInfo = null; GridRegion regInfo = null;
List<RegionData> regions = m_Database.Get(mapName, m_ScopeID); List<RegionData> regions = m_Database.Get(Util.EscapeForLike(mapName), m_ScopeID);
if (regions != null && regions.Count > 0) if (regions != null && regions.Count > 0)
{ {
OpenSim.Framework.RegionFlags rflags = (OpenSim.Framework.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]); OpenSim.Framework.RegionFlags rflags = (OpenSim.Framework.RegionFlags)Convert.ToInt32(regions[0].Data["flags"]);