aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/PGSQL
diff options
context:
space:
mode:
authorTomDataworks2016-01-10 09:59:45 -0500
committerUbitUmarov2016-01-10 18:05:08 +0000
commit905dec5d23f13a3c65e333a2a8b51241248a7709 (patch)
tree4cbf541db0df257af1ce9de83c122a078907fe90 /OpenSim/Data/PGSQL
parent add npc create option OS_NPC_OBJECT_GROUP. with it the npc will be created w... (diff)
downloadopensim-SC-905dec5d23f13a3c65e333a2a8b51241248a7709.zip
opensim-SC-905dec5d23f13a3c65e333a2a8b51241248a7709.tar.gz
opensim-SC-905dec5d23f13a3c65e333a2a8b51241248a7709.tar.bz2
opensim-SC-905dec5d23f13a3c65e333a2a8b51241248a7709.tar.xz
Fix region data range selection in the PGSQL backend.
Signed-off-by: UbitUmarov <ajlduarte@sapo.pt>
Diffstat (limited to 'OpenSim/Data/PGSQL')
-rw-r--r--OpenSim/Data/PGSQL/PGSQLRegionData.cs64
1 files changed, 53 insertions, 11 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLRegionData.cs b/OpenSim/Data/PGSQL/PGSQLRegionData.cs
index b3076f0..a7da013 100644
--- a/OpenSim/Data/PGSQL/PGSQLRegionData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLRegionData.cs
@@ -118,24 +118,46 @@ namespace OpenSim.Data.PGSQL
118 118
119 public RegionData Get(int posX, int posY, UUID scopeID) 119 public RegionData Get(int posX, int posY, UUID scopeID)
120 { 120 {
121 string sql = "select * from "+m_Realm+" where \"locX\" = :posX and \"locY\" = :posY"; 121 // extend database search for maximum region size area
122 string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY";
122 if (scopeID != UUID.Zero) 123 if (scopeID != UUID.Zero)
123 sql += " and \"ScopeID\" = :scopeID"; 124 sql += " and \"ScopeID\" = :scopeID";
124 125
126 int startX = posX - (int)Constants.MaximumRegionSize;
127 int startY = posY - (int)Constants.MaximumRegionSize;
128 int endX = posX;
129 int endY = posY;
130
131 List<RegionData> ret;
125 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) 132 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString))
126 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) 133 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
127 { 134 {
128 cmd.Parameters.Add(m_database.CreateParameter("posX", posX)); 135 cmd.Parameters.Add(m_database.CreateParameter("startX", startX));
129 cmd.Parameters.Add(m_database.CreateParameter("posY", posY)); 136 cmd.Parameters.Add(m_database.CreateParameter("startY", startY));
137 cmd.Parameters.Add(m_database.CreateParameter("endX", endX));
138 cmd.Parameters.Add(m_database.CreateParameter("endY", endY));
130 if (scopeID != UUID.Zero) 139 if (scopeID != UUID.Zero)
131 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); 140 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID));
132 conn.Open(); 141 conn.Open();
133 List<RegionData> ret = RunCommand(cmd); 142 ret = RunCommand(cmd);
134 if (ret.Count == 0) 143 }
135 return null;
136 144
137 return ret[0]; 145 if (ret.Count == 0)
146 return null;
147
148 // Find the first that contains pos
149 RegionData rg = null;
150 foreach (RegionData r in ret)
151 {
152 if (posX >= r.posX && posX < r.posX + r.sizeX
153 && posY >= r.posY && posY < r.posY + r.sizeY)
154 {
155 rg = r;
156 break;
157 }
138 } 158 }
159
160 return rg;
139 } 161 }
140 162
141 public RegionData Get(UUID regionID, UUID scopeID) 163 public RegionData Get(UUID regionID, UUID scopeID)
@@ -160,21 +182,41 @@ namespace OpenSim.Data.PGSQL
160 182
161 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID) 183 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
162 { 184 {
185 // extend database search for maximum region size area
163 string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY"; 186 string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY";
164 if (scopeID != UUID.Zero) 187 if (scopeID != UUID.Zero)
165 sql += " and \"ScopeID\" = :scopeID"; 188 sql += " and \"ScopeID\" = :scopeID";
166 189
190 int qstartX = startX - (int)Constants.MaximumRegionSize;
191 int qstartY = startY - (int)Constants.MaximumRegionSize;
192
193 List<RegionData> dbret;
167 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) 194 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString))
168 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) 195 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
169 { 196 {
170 cmd.Parameters.Add(m_database.CreateParameter("startX", startX)); 197 cmd.Parameters.Add(m_database.CreateParameter("startX", qstartX));
171 cmd.Parameters.Add(m_database.CreateParameter("startY", startY)); 198 cmd.Parameters.Add(m_database.CreateParameter("startY", qstartY));
172 cmd.Parameters.Add(m_database.CreateParameter("endX", endX)); 199 cmd.Parameters.Add(m_database.CreateParameter("endX", endX));
173 cmd.Parameters.Add(m_database.CreateParameter("endY", endY)); 200 cmd.Parameters.Add(m_database.CreateParameter("endY", endY));
174 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); 201 if (scopeID != UUID.Zero)
202 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID));
175 conn.Open(); 203 conn.Open();
176 return RunCommand(cmd); 204
205 dbret = RunCommand(cmd);
206 }
207
208 List<RegionData> ret = new List<RegionData>();
209
210 if(dbret.Count == 0)
211 return ret;
212
213 foreach (RegionData r in dbret)
214 {
215 if (r.posX + r.sizeX > startX && r.posX <= endX
216 && r.posY + r.sizeX > startY && r.posY <= endY)
217 ret.Add(r);
177 } 218 }
219 return ret;
178 } 220 }
179 221
180 public List<RegionData> RunCommand(NpgsqlCommand cmd) 222 public List<RegionData> RunCommand(NpgsqlCommand cmd)