aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
authorMelanie Thielker2008-07-18 02:40:47 +0000
committerMelanie Thielker2008-07-18 02:40:47 +0000
commit263633e274082135b21b8183b92280b768d18883 (patch)
treef6104eef3633a8b454a4e8ac09d15182970c6bae /OpenSim/Data
parentadded region port number to output of "show regions" command (diff)
downloadopensim-SC_OLD-263633e274082135b21b8183b92280b768d18883.zip
opensim-SC_OLD-263633e274082135b21b8183b92280b768d18883.tar.gz
opensim-SC_OLD-263633e274082135b21b8183b92280b768d18883.tar.bz2
opensim-SC_OLD-263633e274082135b21b8183b92280b768d18883.tar.xz
Patch #9151
Makes the estate dialog fully functional. Implements all client facing functionality. Moves estate data from estate_settings.xml, which is used to provide defaults, to the region data store. Creates one estate for each region, and places the region in it. Converts all region bans to estate bans.
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLDataStore.cs8
-rw-r--r--OpenSim/Data/MySQL/MySQLDataStore.cs143
-rw-r--r--OpenSim/Data/MySQL/MySQLEstateData.cs386
-rw-r--r--OpenSim/Data/MySQL/Resources/013_RegionStore.sql103
-rw-r--r--OpenSim/Data/NHibernate/NHibernateRegionData.cs8
-rw-r--r--OpenSim/Data/Null/NullDataStore.cs16
-rw-r--r--OpenSim/Data/SQLite/Resources/006_RegionStore.sql92
-rw-r--r--OpenSim/Data/SQLite/SQLiteEstateData.cs333
-rw-r--r--OpenSim/Data/SQLite/SQLiteRegionData.cs114
9 files changed, 925 insertions, 278 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLDataStore.cs b/OpenSim/Data/MSSQL/MSSQLDataStore.cs
index 46e4107..c7d034f 100644
--- a/OpenSim/Data/MSSQL/MSSQLDataStore.cs
+++ b/OpenSim/Data/MSSQL/MSSQLDataStore.cs
@@ -548,9 +548,9 @@ namespace OpenSim.Data.MSSQL
548 /// </summary> 548 /// </summary>
549 /// <param name="regionUUID">the region UUID</param> 549 /// <param name="regionUUID">the region UUID</param>
550 /// <returns>the banlist list</returns> 550 /// <returns>the banlist list</returns>
551 public List<RegionBanListItem> LoadRegionBanList(LLUUID regionUUID) 551 public List<EstateBan> LoadRegionBanList(LLUUID regionUUID)
552 { 552 {
553 List<RegionBanListItem> regionbanlist = new List<RegionBanListItem>(); 553 List<EstateBan> regionbanlist = new List<EstateBan>();
554 return regionbanlist; 554 return regionbanlist;
555 } 555 }
556 556
@@ -558,7 +558,7 @@ namespace OpenSim.Data.MSSQL
558 /// STUB, add an item into region banlist 558 /// STUB, add an item into region banlist
559 /// </summary> 559 /// </summary>
560 /// <param name="item">the item</param> 560 /// <param name="item">the item</param>
561 public void AddToRegionBanlist(RegionBanListItem item) 561 public void AddToRegionBanlist(EstateBan item)
562 { 562 {
563 563
564 } 564 }
@@ -567,7 +567,7 @@ namespace OpenSim.Data.MSSQL
567 /// STUB, remove an item from region banlist 567 /// STUB, remove an item from region banlist
568 /// </summary> 568 /// </summary>
569 /// <param name="item"></param> 569 /// <param name="item"></param>
570 public void RemoveFromRegionBanlist(RegionBanListItem item) 570 public void RemoveFromRegionBanlist(EstateBan item)
571 { 571 {
572 572
573 } 573 }
diff --git a/OpenSim/Data/MySQL/MySQLDataStore.cs b/OpenSim/Data/MySQL/MySQLDataStore.cs
index 254e526..25956d5 100644
--- a/OpenSim/Data/MySQL/MySQLDataStore.cs
+++ b/OpenSim/Data/MySQL/MySQLDataStore.cs
@@ -53,7 +53,6 @@ namespace OpenSim.Data.MySQL
53 private const string m_terrainSelect = "select * from terrain limit 1"; 53 private const string m_terrainSelect = "select * from terrain limit 1";
54 private const string m_landSelect = "select * from land"; 54 private const string m_landSelect = "select * from land";
55 private const string m_landAccessListSelect = "select * from landaccesslist"; 55 private const string m_landAccessListSelect = "select * from landaccesslist";
56 private const string m_regionBanListSelect = "select * from regionban";
57 private const string m_regionSettingsSelect = "select * from regionsettings"; 56 private const string m_regionSettingsSelect = "select * from regionsettings";
58 private const string m_waitTimeoutSelect = "select @@wait_timeout"; 57 private const string m_waitTimeoutSelect = "select @@wait_timeout";
59 58
@@ -83,7 +82,6 @@ namespace OpenSim.Data.MySQL
83 private MySqlDataAdapter m_terrainDataAdapter; 82 private MySqlDataAdapter m_terrainDataAdapter;
84 private MySqlDataAdapter m_landDataAdapter; 83 private MySqlDataAdapter m_landDataAdapter;
85 private MySqlDataAdapter m_landAccessListDataAdapter; 84 private MySqlDataAdapter m_landAccessListDataAdapter;
86 private MySqlDataAdapter m_regionBanListDataAdapter;
87 private MySqlDataAdapter m_regionSettingsDataAdapter; 85 private MySqlDataAdapter m_regionSettingsDataAdapter;
88 86
89 private DataTable m_primTable; 87 private DataTable m_primTable;
@@ -92,7 +90,6 @@ namespace OpenSim.Data.MySQL
92 private DataTable m_terrainTable; 90 private DataTable m_terrainTable;
93 private DataTable m_landTable; 91 private DataTable m_landTable;
94 private DataTable m_landAccessListTable; 92 private DataTable m_landAccessListTable;
95 private DataTable m_regionBanListTable;
96 private DataTable m_regionSettingsTable; 93 private DataTable m_regionSettingsTable;
97 94
98 /// <value>Temporary attribute while this is experimental</value> 95 /// <value>Temporary attribute while this is experimental</value>
@@ -150,9 +147,6 @@ namespace OpenSim.Data.MySQL
150 MySqlCommand landAccessListSelectCmd = new MySqlCommand(m_landAccessListSelect, m_connection); 147 MySqlCommand landAccessListSelectCmd = new MySqlCommand(m_landAccessListSelect, m_connection);
151 m_landAccessListDataAdapter = new MySqlDataAdapter(landAccessListSelectCmd); 148 m_landAccessListDataAdapter = new MySqlDataAdapter(landAccessListSelectCmd);
152 149
153 MySqlCommand regionBanListSelectCmd = new MySqlCommand(m_regionBanListSelect, m_connection);
154 m_regionBanListDataAdapter = new MySqlDataAdapter(regionBanListSelectCmd);
155
156 MySqlCommand regionSettingsSelectCmd = new MySqlCommand(m_regionSettingsSelect, m_connection); 150 MySqlCommand regionSettingsSelectCmd = new MySqlCommand(m_regionSettingsSelect, m_connection);
157 m_regionSettingsDataAdapter = new MySqlDataAdapter(regionSettingsSelectCmd); 151 m_regionSettingsDataAdapter = new MySqlDataAdapter(regionSettingsSelectCmd);
158 152
@@ -192,11 +186,6 @@ namespace OpenSim.Data.MySQL
192 setupLandAccessCommands(m_landAccessListDataAdapter, m_connection); 186 setupLandAccessCommands(m_landAccessListDataAdapter, m_connection);
193 m_landAccessListDataAdapter.Fill(m_landAccessListTable); 187 m_landAccessListDataAdapter.Fill(m_landAccessListTable);
194 188
195 m_regionBanListTable = createRegionBanTable();
196 m_dataSet.Tables.Add(m_regionBanListTable);
197 SetupRegionBanCommands(m_regionBanListDataAdapter, m_connection);
198 m_regionBanListDataAdapter.Fill(m_regionBanListTable);
199
200 m_regionSettingsTable = createRegionSettingsTable(); 189 m_regionSettingsTable = createRegionSettingsTable();
201 m_dataSet.Tables.Add(m_regionSettingsTable); 190 m_dataSet.Tables.Add(m_regionSettingsTable);
202 SetupRegionSettingsCommands(m_regionSettingsDataAdapter, m_connection); 191 SetupRegionSettingsCommands(m_regionSettingsDataAdapter, m_connection);
@@ -774,99 +763,6 @@ namespace OpenSim.Data.MySQL
774 } 763 }
775 764
776 /// <summary> 765 /// <summary>
777 /// Load (fetch?) a region banlist
778 /// </summary>
779 /// <param name="regionUUID">The region UUID</param>
780 /// <returns>The Region banlist</returns>
781 public List<RegionBanListItem> LoadRegionBanList(LLUUID regionUUID)
782 {
783 List<RegionBanListItem> regionbanlist = new List<RegionBanListItem>();
784 lock (m_dataSet)
785 {
786 CheckConnection();
787 DataTable regionban = m_regionBanListTable;
788 string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
789 DataRow[] rawbanlist = regionban.Select(searchExp);
790 foreach (DataRow rawbanrow in rawbanlist)
791 {
792 RegionBanListItem rbli = new RegionBanListItem();
793 LLUUID tmpvalue = LLUUID.Zero;
794
795 rbli.regionUUID = regionUUID;
796
797 if (Helpers.TryParse((string)rawbanrow["bannedUUID"], out tmpvalue))
798 rbli.bannedUUID = tmpvalue;
799
800 rbli.bannedIP = (string)rawbanrow["bannedIp"];
801 rbli.bannedIPHostMask = (string)rawbanrow["bannedIpHostMask"];
802 regionbanlist.Add(rbli);
803 }
804 return regionbanlist;
805 }
806 }
807
808 /// <summary>
809 /// Add an item to region banlist
810 /// </summary>
811 /// <param name="item">The item</param>
812 public void AddToRegionBanlist(RegionBanListItem item)
813 {
814 lock (m_dataSet)
815 {
816 CheckConnection();
817 DataTable regionban = m_regionBanListTable;
818 string searchExp = "regionUUID = '" + item.regionUUID.ToString() + "' AND bannedUUID = '" + item.bannedUUID.ToString() + "'";
819 DataRow[] rawbanlist = regionban.Select(searchExp);
820 if (rawbanlist.Length == 0)
821 {
822 DataRow regionbanrow = regionban.NewRow();
823 regionbanrow["regionUUID"] = item.regionUUID.ToString();
824 regionbanrow["bannedUUID"] = item.bannedUUID.ToString();
825 regionbanrow["bannedIp"] = item.bannedIP.ToString();
826 regionbanrow["bannedIpHostMask"] = item.bannedIPHostMask.ToString();
827 regionban.Rows.Add(regionbanrow);
828 }
829 Commit();
830 }
831 }
832
833 /// <summary>
834 /// Remove an item from region banlist
835 /// </summary>
836 /// <param name="item">The item</param>
837 public void RemoveFromRegionBanlist(RegionBanListItem item)
838 {
839 lock (m_dataSet)
840 {
841 CheckConnection();
842 DataTable regionban = m_regionBanListTable;
843 string searchExp = "regionUUID = '" + item.regionUUID.ToString() + "' AND bannedUUID = '" + item.bannedUUID.ToString() + "'";
844 DataRow[] rawbanlist = regionban.Select(searchExp);
845 if (rawbanlist.Length > 0)
846 {
847 foreach (DataRow rbli in rawbanlist)
848 {
849 regionban.Rows.Remove(rbli);
850 }
851 }
852 Commit();
853 }
854
855 using
856 (
857 MySqlCommand cmd =
858 new MySqlCommand("delete from regionban where regionUUID = ?regionUUID AND bannedUUID = ?bannedUUID", m_connection)
859 )
860 {
861 cmd.Parameters.Add(new MySqlParameter("?regionUUID", item.regionUUID.ToString()));
862 cmd.Parameters.Add(new MySqlParameter("?bannedUUID", item.bannedUUID.ToString()));
863 CheckConnection();
864 cmd.ExecuteNonQuery();
865 }
866
867 }
868
869 /// <summary>
870 /// 766 ///
871 /// </summary> 767 /// </summary>
872 /// <param name="regionUUID"></param> 768 /// <param name="regionUUID"></param>
@@ -918,7 +814,6 @@ namespace OpenSim.Data.MySQL
918 m_terrainDataAdapter.Update(m_terrainTable); 814 m_terrainDataAdapter.Update(m_terrainTable);
919 m_landDataAdapter.Update(m_landTable); 815 m_landDataAdapter.Update(m_landTable);
920 m_landAccessListDataAdapter.Update(m_landAccessListTable); 816 m_landAccessListDataAdapter.Update(m_landAccessListTable);
921 m_regionBanListDataAdapter.Update(m_regionBanListTable);
922 m_regionSettingsDataAdapter.Update(m_regionSettingsTable); 817 m_regionSettingsDataAdapter.Update(m_regionSettingsTable);
923 818
924 m_dataSet.AcceptChanges(); 819 m_dataSet.AcceptChanges();
@@ -1006,6 +901,7 @@ namespace OpenSim.Data.MySQL
1006 createCol(regionsettings, "terrain_raise_limit", typeof (Double)); 901 createCol(regionsettings, "terrain_raise_limit", typeof (Double));
1007 createCol(regionsettings, "terrain_lower_limit", typeof (Double)); 902 createCol(regionsettings, "terrain_lower_limit", typeof (Double));
1008 createCol(regionsettings, "use_estate_sun", typeof (Int32)); 903 createCol(regionsettings, "use_estate_sun", typeof (Int32));
904 createCol(regionsettings, "sandbox", typeof (Int32));
1009 createCol(regionsettings, "fixed_sun", typeof (Int32)); 905 createCol(regionsettings, "fixed_sun", typeof (Int32));
1010 createCol(regionsettings, "sun_position", typeof (Double)); 906 createCol(regionsettings, "sun_position", typeof (Double));
1011 createCol(regionsettings, "covenant", typeof(String)); 907 createCol(regionsettings, "covenant", typeof(String));
@@ -1016,21 +912,6 @@ namespace OpenSim.Data.MySQL
1016 } 912 }
1017 913
1018 /// <summary> 914 /// <summary>
1019 /// Create the "regionban" table
1020 /// </summary>
1021 /// <returns></returns>
1022 private static DataTable createRegionBanTable()
1023 {
1024 DataTable regionban = new DataTable("regionban");
1025 createCol(regionban, "regionUUID", typeof(String));
1026 createCol(regionban, "bannedUUID", typeof(String));
1027 createCol(regionban, "bannedIp", typeof(String));
1028 createCol(regionban, "bannedIpHostMask", typeof(String));
1029 return regionban;
1030
1031 }
1032
1033 /// <summary>
1034 /// Create the "prims" table 915 /// Create the "prims" table
1035 /// </summary> 916 /// </summary>
1036 /// <returns></returns> 917 /// <returns></returns>
@@ -1417,6 +1298,7 @@ namespace OpenSim.Data.MySQL
1417 newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]); 1298 newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
1418 newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]); 1299 newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
1419 newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]); 1300 newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
1301 newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
1420 newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]); 1302 newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
1421 newSettings.SunPosition = Convert.ToDouble(row["sun_position"]); 1303 newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
1422 newSettings.Covenant = new LLUUID((String) row["covenant"]); 1304 newSettings.Covenant = new LLUUID((String) row["covenant"]);
@@ -1676,6 +1558,7 @@ namespace OpenSim.Data.MySQL
1676 row["terrain_raise_limit"] = settings.TerrainRaiseLimit; 1558 row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
1677 row["terrain_lower_limit"] = settings.TerrainLowerLimit; 1559 row["terrain_lower_limit"] = settings.TerrainLowerLimit;
1678 row["use_estate_sun"] = settings.UseEstateSun; 1560 row["use_estate_sun"] = settings.UseEstateSun;
1561 row["sandbox"] = settings.Sandbox;
1679 row["fixed_sun"] = settings.FixedSun; 1562 row["fixed_sun"] = settings.FixedSun;
1680 row["sun_position"] = settings.SunPosition; 1563 row["sun_position"] = settings.SunPosition;
1681 row["covenant"] = settings.Covenant.ToString(); 1564 row["covenant"] = settings.Covenant.ToString();
@@ -2143,26 +2026,6 @@ namespace OpenSim.Data.MySQL
2143 /// </summary> 2026 /// </summary>
2144 /// <param name="da"></param> 2027 /// <param name="da"></param>
2145 /// <param name="conn"></param> 2028 /// <param name="conn"></param>
2146 private void SetupRegionBanCommands(MySqlDataAdapter da, MySqlConnection conn)
2147 {
2148 da.InsertCommand = createInsertCommand("regionban", m_regionBanListTable);
2149 da.InsertCommand.Connection = conn;
2150
2151 da.UpdateCommand = createUpdateCommand("regionban", "regionUUID = ?regionUUID AND bannedUUID = ?bannedUUID", m_regionBanListTable);
2152 da.UpdateCommand.Connection = conn;
2153
2154 MySqlCommand delete = new MySqlCommand("delete from regionban where regionUUID = ?regionUUID AND bannedUUID = ?bannedUUID");
2155 delete.Parameters.Add(createMySqlParameter("regionUUID", typeof(String)));
2156 delete.Parameters.Add(createMySqlParameter("bannedUUID", typeof(String)));
2157 delete.Connection = conn;
2158 da.DeleteCommand = delete;
2159 }
2160
2161 /// <summary>
2162 ///
2163 /// </summary>
2164 /// <param name="da"></param>
2165 /// <param name="conn"></param>
2166 private void SetupTerrainCommands(MySqlDataAdapter da, MySqlConnection conn) 2029 private void SetupTerrainCommands(MySqlDataAdapter da, MySqlConnection conn)
2167 { 2030 {
2168 da.InsertCommand = createInsertCommand("terrain", m_dataSet.Tables["terrain"]); 2031 da.InsertCommand = createInsertCommand("terrain", m_dataSet.Tables["terrain"]);
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs
new file mode 100644
index 0000000..eeff31b
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLEstateData.cs
@@ -0,0 +1,386 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.IO;
32using System.Reflection;
33using System.Threading;
34using libsecondlife;
35using log4net;
36using MySql.Data.MySqlClient;
37using OpenSim.Framework;
38using OpenSim.Region.Environment.Interfaces;
39using OpenSim.Region.Environment.Scenes;
40
41namespace OpenSim.Data.MySQL
42{
43 public class MySQLEstateStore : IEstateDataStore
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private const string m_waitTimeoutSelect = "select @@wait_timeout";
49
50 private MySqlConnection m_connection;
51 private string m_connectionString;
52 private long m_waitTimeout;
53 private long m_waitTimeoutLeeway = 60 * TimeSpan.TicksPerSecond;
54 private long m_lastConnectionUse;
55
56 private FieldInfo[] m_Fields;
57 private Dictionary<string, FieldInfo> m_FieldMap =
58 new Dictionary<string, FieldInfo>();
59
60 public void Initialise(string connectionString)
61 {
62 m_connectionString = connectionString;
63
64 m_log.Info("[ESTATE DB]: MySql - connecting: "+m_connectionString);
65
66 m_connection = new MySqlConnection(m_connectionString);
67 m_connection.Open();
68
69 GetWaitTimeout();
70
71 Assembly assem = GetType().Assembly;
72 Migration m = new Migration(m_connection, assem, "EstateStore");
73 m.Update();
74
75 Type t = typeof(EstateSettings);
76 m_Fields = t.GetFields(BindingFlags.NonPublic |
77 BindingFlags.Instance |
78 BindingFlags.DeclaredOnly);
79
80 foreach (FieldInfo f in m_Fields)
81 if(f.Name.Substring(0, 2) == "m_")
82 m_FieldMap[f.Name.Substring(2)] = f;
83 }
84
85 private string[] FieldList
86 {
87 get { return new List<string>(m_FieldMap.Keys).ToArray(); }
88 }
89
90 protected void GetWaitTimeout()
91 {
92 MySqlCommand cmd = new MySqlCommand(m_waitTimeoutSelect,
93 m_connection);
94
95 using (MySqlDataReader dbReader =
96 cmd.ExecuteReader(CommandBehavior.SingleRow))
97 {
98 if (dbReader.Read())
99 {
100 m_waitTimeout
101 = Convert.ToInt32(dbReader["@@wait_timeout"]) *
102 TimeSpan.TicksPerSecond + m_waitTimeoutLeeway;
103 }
104
105 dbReader.Close();
106 cmd.Dispose();
107 }
108
109 m_lastConnectionUse = System.DateTime.Now.Ticks;
110
111 m_log.DebugFormat(
112 "[REGION DB]: Connection wait timeout {0} seconds",
113 m_waitTimeout / TimeSpan.TicksPerSecond);
114 }
115
116 protected void CheckConnection()
117 {
118 long timeNow = System.DateTime.Now.Ticks;
119 if (timeNow - m_lastConnectionUse > m_waitTimeout ||
120 m_connection.State != ConnectionState.Open)
121 {
122 m_log.DebugFormat("[REGION DB]: Database connection has gone away - reconnecting");
123
124 lock (m_connection)
125 {
126 m_connection.Close();
127 m_connection = new MySqlConnection(m_connectionString);
128 m_connection.Open();
129 }
130 }
131
132 m_lastConnectionUse = timeNow;
133 }
134
135 public EstateSettings LoadEstateSettings(LLUUID regionID)
136 {
137 EstateSettings es = new EstateSettings();
138
139 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = ?RegionID";
140
141 CheckConnection();
142
143 MySqlCommand cmd = m_connection.CreateCommand();
144
145 cmd.CommandText = sql;
146 cmd.Parameters.Add("?RegionID", regionID.ToString());
147
148 IDataReader r = cmd.ExecuteReader();
149
150 if(r.Read())
151 {
152 foreach (string name in FieldList)
153 {
154 if(m_FieldMap[name].GetValue(es) is bool)
155 {
156 int v = Convert.ToInt32(r[name]);
157 if(v != 0)
158 m_FieldMap[name].SetValue(es, true);
159 else
160 m_FieldMap[name].SetValue(es, false);
161 }
162 else
163 {
164 m_FieldMap[name].SetValue(es, r[name]);
165 }
166 }
167 r.Close();
168 }
169 else
170 {
171 // Migration case
172 //
173 r.Close();
174
175 List<string> names = new List<string>(FieldList);
176
177 names.Remove("EstateID");
178
179 sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( ?"+String.Join(", ?", names.ToArray())+")";
180
181 cmd.CommandText = sql;
182 cmd.Parameters.Clear();
183
184 foreach (string name in FieldList)
185 {
186 if(m_FieldMap[name].GetValue(es) is bool)
187 {
188 if((bool)m_FieldMap[name].GetValue(es))
189 cmd.Parameters.Add("?"+name, "1");
190 else
191 cmd.Parameters.Add("?"+name, "0");
192 }
193 else
194 {
195 cmd.Parameters.Add("?"+name, m_FieldMap[name].GetValue(es).ToString());
196 }
197 }
198
199 cmd.ExecuteNonQuery();
200
201 cmd.CommandText = "select LAST_INSERT_ID() as id";
202 cmd.Parameters.Clear();
203
204 r = cmd.ExecuteReader();
205
206 r.Read();
207
208 es.EstateID = Convert.ToUInt32(r["id"]);
209
210 r.Close();
211
212 cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)";
213 cmd.Parameters.Add("?RegionID", regionID.ToString());
214 cmd.Parameters.Add("?EstateID", es.EstateID.ToString());
215
216 // This will throw on dupe key
217 try
218 {
219 cmd.ExecuteNonQuery();
220 }
221 catch (Exception)
222 {
223 }
224
225 // Munge and transfer the ban list
226 //
227 cmd.Parameters.Clear();
228 cmd.CommandText = "insert into estateban select "+es.EstateID.ToString()+", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = ?UUID";
229 cmd.Parameters.Add("?UUID", regionID.ToString());
230
231 try
232 {
233 cmd.ExecuteNonQuery();
234 }
235 catch (Exception)
236 {
237 }
238 }
239
240 LoadBanList(es);
241
242 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
243 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
244 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
245 return es;
246 }
247
248 public void StoreEstateSettings(EstateSettings es)
249 {
250 string sql = "replace into estate_settings ("+String.Join(",", FieldList)+") values ( ?"+String.Join(", ?", FieldList)+")";
251
252 CheckConnection();
253
254 MySqlCommand cmd = m_connection.CreateCommand();
255
256 cmd.CommandText = sql;
257
258 foreach (string name in FieldList)
259 {
260 if(m_FieldMap[name].GetValue(es) is bool)
261 {
262 if((bool)m_FieldMap[name].GetValue(es))
263 cmd.Parameters.Add("?"+name, "1");
264 else
265 cmd.Parameters.Add("?"+name, "0");
266 }
267 else
268 {
269 cmd.Parameters.Add("?"+name, m_FieldMap[name].GetValue(es).ToString());
270 }
271 }
272
273 cmd.ExecuteNonQuery();
274
275 SaveBanList(es);
276 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
277 SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
278 SaveUUIDList(es.EstateID, "estate_groups", es.EstateGroups);
279 }
280
281 private void LoadBanList(EstateSettings es)
282 {
283 es.ClearBans();
284
285 CheckConnection();
286
287 MySqlCommand cmd = m_connection.CreateCommand();
288
289 cmd.CommandText = "select bannedUUID from estateban where EstateID = ?EstateID";
290 cmd.Parameters.Add("?EstateID", es.EstateID);
291
292 IDataReader r = cmd.ExecuteReader();
293
294 while(r.Read())
295 {
296 EstateBan eb = new EstateBan();
297
298 LLUUID uuid = new LLUUID();
299 LLUUID.TryParse(r["bannedUUID"].ToString(), out uuid);
300
301 eb.bannedUUID = uuid;
302 eb.bannedIP = "0.0.0.0";
303 eb.bannedIPHostMask = "0.0.0.0";
304 es.AddBan(eb);
305 }
306 r.Close();
307 }
308
309 private void SaveBanList(EstateSettings es)
310 {
311 CheckConnection();
312
313 MySqlCommand cmd = m_connection.CreateCommand();
314
315 cmd.CommandText = "delete from estateban where EstateID = ?EstateID";
316 cmd.Parameters.Add("?EstateID", es.EstateID.ToString());
317
318 cmd.ExecuteNonQuery();
319
320 cmd.Parameters.Clear();
321
322 cmd.CommandText = "insert into estateban (EstateID, bannedUUID) values ( ?EstateID, ?bannedUUID )";
323
324 foreach(EstateBan b in es.EstateBans)
325 {
326 cmd.Parameters.Add("?EstateID", es.EstateID.ToString());
327 cmd.Parameters.Add("?bannedUUID", b.bannedUUID.ToString());
328
329 cmd.ExecuteNonQuery();
330 cmd.Parameters.Clear();
331 }
332 }
333
334 void SaveUUIDList(uint EstateID, string table, LLUUID[] data)
335 {
336 CheckConnection();
337
338 MySqlCommand cmd = m_connection.CreateCommand();
339
340 cmd.CommandText = "delete from "+table+" where EstateID = ?EstateID";
341 cmd.Parameters.Add("?EstateID", EstateID.ToString());
342
343 cmd.ExecuteNonQuery();
344
345 cmd.Parameters.Clear();
346
347 cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( ?EstateID, ?uuid )";
348
349 foreach(LLUUID uuid in data)
350 {
351 cmd.Parameters.Add("?EstateID", EstateID.ToString());
352 cmd.Parameters.Add("?uuid", uuid.ToString());
353
354 cmd.ExecuteNonQuery();
355 cmd.Parameters.Clear();
356 }
357 }
358
359 LLUUID[] LoadUUIDList(uint EstateID, string table)
360 {
361 List<LLUUID> uuids = new List<LLUUID>();
362
363 CheckConnection();
364
365 MySqlCommand cmd = m_connection.CreateCommand();
366
367 cmd.CommandText = "select uuid from "+table+" where EstateID = ?EstateID";
368 cmd.Parameters.Add("?EstateID", EstateID);
369
370 IDataReader r = cmd.ExecuteReader();
371
372 while(r.Read())
373 {
374 EstateBan eb = new EstateBan();
375
376 LLUUID uuid = new LLUUID();
377 LLUUID.TryParse(r["uuid"].ToString(), out uuid);
378
379 uuids.Add(uuid);
380 }
381 r.Close();
382
383 return uuids.ToArray();
384 }
385 }
386}
diff --git a/OpenSim/Data/MySQL/Resources/013_RegionStore.sql b/OpenSim/Data/MySQL/Resources/013_RegionStore.sql
new file mode 100644
index 0000000..a6bd30d
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/013_RegionStore.sql
@@ -0,0 +1,103 @@
1begin;
2
3drop table regionsettings;
4
5CREATE TABLE `regionsettings` (
6 `regionUUID` char(36) NOT NULL,
7 `block_terraform` int(11) NOT NULL,
8 `block_fly` int(11) NOT NULL,
9 `allow_damage` int(11) NOT NULL,
10 `restrict_pushing` int(11) NOT NULL,
11 `allow_land_resell` int(11) NOT NULL,
12 `allow_land_join_divide` int(11) NOT NULL,
13 `block_show_in_search` int(11) NOT NULL,
14 `agent_limit` int(11) NOT NULL,
15 `object_bonus` float NOT NULL,
16 `maturity` int(11) NOT NULL,
17 `disable_scripts` int(11) NOT NULL,
18 `disable_collisions` int(11) NOT NULL,
19 `disable_physics` int(11) NOT NULL,
20 `terrain_texture_1` char(36) NOT NULL,
21 `terrain_texture_2` char(36) NOT NULL,
22 `terrain_texture_3` char(36) NOT NULL,
23 `terrain_texture_4` char(36) NOT NULL,
24 `elevation_1_nw` float NOT NULL,
25 `elevation_2_nw` float NOT NULL,
26 `elevation_1_ne` float NOT NULL,
27 `elevation_2_ne` float NOT NULL,
28 `elevation_1_se` float NOT NULL,
29 `elevation_2_se` float NOT NULL,
30 `elevation_1_sw` float NOT NULL,
31 `elevation_2_sw` float NOT NULL,
32 `water_height` float NOT NULL,
33 `terrain_raise_limit` float NOT NULL,
34 `terrain_lower_limit` float NOT NULL,
35 `use_estate_sun` int(11) NOT NULL,
36 `fixed_sun` int(11) NOT NULL,
37 `sun_position` float NOT NULL,
38 `covenant` char(36) default NULL,
39 `Sandbox` tinyint(4) NOT NULL,
40 PRIMARY KEY (`regionUUID`)
41) ENGINE=InnoDB;
42
43CREATE TABLE `estate_managers` (
44 `EstateID` int(10) unsigned NOT NULL,
45 `uuid` char(36) NOT NULL,
46 KEY `EstateID` (`EstateID`)
47) ENGINE=InnoDB;
48
49CREATE TABLE `estate_groups` (
50 `EstateID` int(10) unsigned NOT NULL,
51 `uuid` char(36) NOT NULL,
52 KEY `EstateID` (`EstateID`)
53) ENGINE=InnoDB;
54
55CREATE TABLE `estate_users` (
56 `EstateID` int(10) unsigned NOT NULL,
57 `uuid` char(36) NOT NULL,
58 KEY `EstateID` (`EstateID`)
59) ENGINE=InnoDB;
60
61CREATE TABLE `estateban` (
62 `EstateID` int(10) unsigned NOT NULL,
63 `bannedUUID` varchar(36) NOT NULL,
64 `bannedIp` varchar(16) NOT NULL,
65 `bannedIpHostMask` varchar(16) NOT NULL,
66 `bannedNameMask` varchar(64) default NULL,
67 KEY `estateban_EstateID` (`EstateID`)
68) ENGINE=InnoDB;
69
70CREATE TABLE `estate_settings` (
71 `EstateID` int(10) unsigned NOT NULL auto_increment,
72 `EstateName` varchar(64) default NULL,
73 `AbuseEmailToEstateOwner` tinyint(4) NOT NULL,
74 `DenyAnonymous` tinyint(4) NOT NULL,
75 `ResetHomeOnTeleport` tinyint(4) NOT NULL,
76 `FixedSun` tinyint(4) NOT NULL,
77 `DenyTransacted` tinyint(4) NOT NULL,
78 `BlockDwell` tinyint(4) NOT NULL,
79 `DenyIdentified` tinyint(4) NOT NULL,
80 `AllowVoice` tinyint(4) NOT NULL,
81 `UseGlobalTime` tinyint(4) NOT NULL,
82 `PricePerMeter` int(11) NOT NULL,
83 `TaxFree` tinyint(4) NOT NULL,
84 `AllowDirectTeleport` tinyint(4) NOT NULL,
85 `RedirectGridX` int(11) NOT NULL,
86 `RedirectGridY` int(11) NOT NULL,
87 `ParentEstateID` int(10) unsigned NOT NULL,
88 `SunPosition` double NOT NULL,
89 `EstateSkipScripts` tinyint(4) NOT NULL,
90 `BillableFactor` float NOT NULL,
91 `PublicAccess` tinyint(4) NOT NULL,
92 PRIMARY KEY (`EstateID`)
93) ENGINE=InnoDB AUTO_INCREMENT=100;
94
95CREATE TABLE `estate_map` (
96 `RegionID` char(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
97 `EstateID` int(11) NOT NULL,
98 PRIMARY KEY (`RegionID`),
99 KEY `EstateID` (`EstateID`)
100) ENGINE=InnoDB;
101
102commit;
103
diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
index 9dee95c..2014e24 100644
--- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
@@ -349,9 +349,9 @@ namespace OpenSim.Data.NHibernate
349 /// </summary> 349 /// </summary>
350 /// <param name="regionUUID">the region UUID</param> 350 /// <param name="regionUUID">the region UUID</param>
351 /// <returns>The banlist</returns> 351 /// <returns>The banlist</returns>
352 public List<RegionBanListItem> LoadRegionBanList(LLUUID regionUUID) 352 public List<EstateBan> LoadRegionBanList(LLUUID regionUUID)
353 { 353 {
354 List<RegionBanListItem> regionbanlist = new List<RegionBanListItem>(); 354 List<EstateBan> regionbanlist = new List<EstateBan>();
355 355
356 return regionbanlist; 356 return regionbanlist;
357 } 357 }
@@ -360,7 +360,7 @@ namespace OpenSim.Data.NHibernate
360 /// Add en entry into region banlist 360 /// Add en entry into region banlist
361 /// </summary> 361 /// </summary>
362 /// <param name="item"></param> 362 /// <param name="item"></param>
363 public void AddToRegionBanlist(RegionBanListItem item) 363 public void AddToRegionBanlist(EstateBan item)
364 { 364 {
365 365
366 } 366 }
@@ -369,7 +369,7 @@ namespace OpenSim.Data.NHibernate
369 /// remove an entry from the region banlist 369 /// remove an entry from the region banlist
370 /// </summary> 370 /// </summary>
371 /// <param name="item"></param> 371 /// <param name="item"></param>
372 public void RemoveFromRegionBanlist(RegionBanListItem item) 372 public void RemoveFromRegionBanlist(EstateBan item)
373 { 373 {
374 374
375 } 375 }
diff --git a/OpenSim/Data/Null/NullDataStore.cs b/OpenSim/Data/Null/NullDataStore.cs
index 422c0c6..e244a5e 100644
--- a/OpenSim/Data/Null/NullDataStore.cs
+++ b/OpenSim/Data/Null/NullDataStore.cs
@@ -92,22 +92,6 @@ namespace OpenSim.Data.Null
92 return new List<LandData>(); 92 return new List<LandData>();
93 } 93 }
94 94
95 public List<RegionBanListItem> LoadRegionBanList(LLUUID regionUUID)
96 {
97 List<RegionBanListItem> regionbanlist = new List<RegionBanListItem>();
98 return regionbanlist;
99 }
100
101 public void AddToRegionBanlist(RegionBanListItem item)
102 {
103
104 }
105
106 public void RemoveFromRegionBanlist(RegionBanListItem item)
107 {
108
109 }
110
111 public void Shutdown() 95 public void Shutdown()
112 { 96 {
113 } 97 }
diff --git a/OpenSim/Data/SQLite/Resources/006_RegionStore.sql b/OpenSim/Data/SQLite/Resources/006_RegionStore.sql
new file mode 100644
index 0000000..025f1a9
--- /dev/null
+++ b/OpenSim/Data/SQLite/Resources/006_RegionStore.sql
@@ -0,0 +1,92 @@
1CREATE TABLE `estate_groups` (
2 `EstateID` int(10) NOT NULL,
3 `uuid` char(36) NOT NULL
4);
5CREATE TABLE `estate_managers` (
6 `EstateID` int(10) NOT NULL,
7 `uuid` char(36) NOT NULL
8);
9CREATE TABLE `estate_map` (
10 `RegionID` char(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
11 `EstateID` int(11) NOT NULL
12);
13CREATE TABLE `estate_settings` (
14 `EstateID` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
15 `EstateName` varchar(64) default NULL,
16 `AbuseEmailToEstateOwner` tinyint(4) NOT NULL,
17 `DenyAnonymous` tinyint(4) NOT NULL,
18 `ResetHomeOnTeleport` tinyint(4) NOT NULL,
19 `FixedSun` tinyint(4) NOT NULL,
20 `DenyTransacted` tinyint(4) NOT NULL,
21 `BlockDwell` tinyint(4) NOT NULL,
22 `DenyIdentified` tinyint(4) NOT NULL,
23 `AllowVoice` tinyint(4) NOT NULL,
24 `UseGlobalTime` tinyint(4) NOT NULL,
25 `PricePerMeter` int(11) NOT NULL,
26 `TaxFree` tinyint(4) NOT NULL,
27 `AllowDirectTeleport` tinyint(4) NOT NULL,
28 `RedirectGridX` int(11) NOT NULL,
29 `RedirectGridY` int(11) NOT NULL,
30 `ParentEstateID` int(10) NOT NULL,
31 `SunPosition` double NOT NULL,
32 `EstateSkipScripts` tinyint(4) NOT NULL,
33 `BillableFactor` float NOT NULL,
34 `PublicAccess` tinyint(4) NOT NULL
35);
36insert into `estate_settings` (`EstateID`,`EstateName`,`AbuseEmailToEstateOwner`,`DenyAnonymous`,`ResetHomeOnTeleport`,`FixedSun`,`DenyTransacted`,`BlockDwell`,`DenyIdentified`,`AllowVoice`,`UseGlobalTime`,`PricePerMeter`,`TaxFree`,`AllowDirectTeleport`,`RedirectGridX`,`RedirectGridY`,`ParentEstateID`,`SunPosition`,`PublicAccess`,`EstateSkipScripts`,`BillableFactor`) values ( 99, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
37delete from `estate_settings`;
38CREATE TABLE `estate_users` (
39 `EstateID` int(10) NOT NULL,
40 `uuid` char(36) NOT NULL
41);
42CREATE TABLE `estateban` (
43 `EstateID` int(10) NOT NULL,
44 `bannedUUID` varchar(36) NOT NULL,
45 `bannedIp` varchar(16) NOT NULL,
46 `bannedIpHostMask` varchar(16) NOT NULL,
47 `bannedNameMask` varchar(64) default NULL
48);
49drop table if exists `regionsettings`;
50CREATE TABLE `regionsettings` (
51 `regionUUID` char(36) NOT NULL,
52 `block_terraform` int(11) NOT NULL,
53 `block_fly` int(11) NOT NULL,
54 `allow_damage` int(11) NOT NULL,
55 `restrict_pushing` int(11) NOT NULL,
56 `allow_land_resell` int(11) NOT NULL,
57 `allow_land_join_divide` int(11) NOT NULL,
58 `block_show_in_search` int(11) NOT NULL,
59 `agent_limit` int(11) NOT NULL,
60 `object_bonus` float NOT NULL,
61 `maturity` int(11) NOT NULL,
62 `disable_scripts` int(11) NOT NULL,
63 `disable_collisions` int(11) NOT NULL,
64 `disable_physics` int(11) NOT NULL,
65 `terrain_texture_1` char(36) NOT NULL,
66 `terrain_texture_2` char(36) NOT NULL,
67 `terrain_texture_3` char(36) NOT NULL,
68 `terrain_texture_4` char(36) NOT NULL,
69 `elevation_1_nw` float NOT NULL,
70 `elevation_2_nw` float NOT NULL,
71 `elevation_1_ne` float NOT NULL,
72 `elevation_2_ne` float NOT NULL,
73 `elevation_1_se` float NOT NULL,
74 `elevation_2_se` float NOT NULL,
75 `elevation_1_sw` float NOT NULL,
76 `elevation_2_sw` float NOT NULL,
77 `water_height` float NOT NULL,
78 `terrain_raise_limit` float NOT NULL,
79 `terrain_lower_limit` float NOT NULL,
80 `use_estate_sun` int(11) NOT NULL,
81 `fixed_sun` int(11) NOT NULL,
82 `sun_position` float NOT NULL,
83 `covenant` char(36) default NULL,
84 `Sandbox` tinyint(4) NOT NULL,
85 PRIMARY KEY (`regionUUID`)
86);
87CREATE INDEX `estate_ban_estate_id` on `estateban`(`EstateID`);
88CREATE INDEX `estate_groups_estate_id` on `estate_groups`(`EstateID`);
89CREATE INDEX `estate_managers_estate_id` on `estate_managers`(`EstateID`);
90CREATE INDEX `estate_map_estate_id` on `estate_map`(`EstateID`);
91CREATE UNIQUE INDEX `estate_map_region)id` on `estate_map`(`RegionID`);
92CREATE INDEX `estate_users_estate_id` on `estate_users`(`EstateID`);
diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs
new file mode 100644
index 0000000..2d046f2
--- /dev/null
+++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs
@@ -0,0 +1,333 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.IO;
32using System.Reflection;
33using System.Threading;
34using libsecondlife;
35using Mono.Data.SqliteClient;
36using log4net;
37using OpenSim.Framework;
38using OpenSim.Region.Environment.Interfaces;
39using OpenSim.Region.Environment.Scenes;
40
41namespace OpenSim.Data.MySQL
42{
43 public class MySQLEstateStore : IEstateDataStore
44 {
45 private static readonly ILog m_log =
46 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 private SqliteConnection m_connection;
49 private string m_connectionString;
50
51 private FieldInfo[] m_Fields;
52 private Dictionary<string, FieldInfo> m_FieldMap =
53 new Dictionary<string, FieldInfo>();
54
55 public void Initialise(string connectionString)
56 {
57 m_connectionString = connectionString;
58
59 m_log.Info("[ESTATE DB]: Sqlite - connecting: "+m_connectionString);
60
61 m_connection = new SqliteConnection(m_connectionString);
62 m_connection.Open();
63
64 Assembly assem = GetType().Assembly;
65 Migration m = new Migration(m_connection, assem, "EstateStore");
66 m.Update();
67
68 m_connection.Close();
69 m_connection.Open();
70
71 Type t = typeof(EstateSettings);
72 m_Fields = t.GetFields(BindingFlags.NonPublic |
73 BindingFlags.Instance |
74 BindingFlags.DeclaredOnly);
75
76 foreach (FieldInfo f in m_Fields)
77 if(f.Name.Substring(0, 2) == "m_")
78 m_FieldMap[f.Name.Substring(2)] = f;
79 }
80
81 private string[] FieldList
82 {
83 get { return new List<string>(m_FieldMap.Keys).ToArray(); }
84 }
85
86 public EstateSettings LoadEstateSettings(LLUUID regionID)
87 {
88 EstateSettings es = new EstateSettings();
89
90 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = @RegionID";
91
92 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
93
94 cmd.CommandText = sql;
95 cmd.Parameters.Add("@RegionID", regionID.ToString());
96
97 IDataReader r = cmd.ExecuteReader();
98
99 if(r.Read())
100 {
101 foreach (string name in FieldList)
102 {
103 if(m_FieldMap[name].GetValue(es) is bool)
104 {
105 int v = Convert.ToInt32(r[name]);
106 if(v != 0)
107 m_FieldMap[name].SetValue(es, true);
108 else
109 m_FieldMap[name].SetValue(es, false);
110 }
111 else
112 {
113 m_FieldMap[name].SetValue(es, Convert.ChangeType(r[name], m_FieldMap[name].FieldType));
114 }
115 }
116 r.Close();
117 }
118 else
119 {
120 // Migration case
121 //
122 r.Close();
123
124 List<string> names = new List<string>(FieldList);
125
126 names.Remove("EstateID");
127
128 sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( @"+String.Join(", @", names.ToArray())+")";
129
130 cmd.CommandText = sql;
131 cmd.Parameters.Clear();
132
133 foreach (string name in FieldList)
134 {
135 if(m_FieldMap[name].GetValue(es) is bool)
136 {
137 if((bool)m_FieldMap[name].GetValue(es))
138 cmd.Parameters.Add("@"+name, "1");
139 else
140 cmd.Parameters.Add("@"+name, "0");
141 }
142 else
143 {
144 cmd.Parameters.Add("@"+name, m_FieldMap[name].GetValue(es).ToString());
145 }
146 }
147
148 cmd.ExecuteNonQuery();
149
150 cmd.CommandText = "select LAST_INSERT_ROWID() as id";
151 cmd.Parameters.Clear();
152
153 r = cmd.ExecuteReader();
154
155 r.Read();
156
157 es.EstateID = Convert.ToUInt32(r["id"]);
158
159 r.Close();
160
161 cmd.CommandText = "insert into estate_map values (@RegionID, @EstateID)";
162 cmd.Parameters.Add("@RegionID", regionID.ToString());
163 cmd.Parameters.Add("@EstateID", es.EstateID.ToString());
164
165 // This will throw on dupe key
166 try
167 {
168 cmd.ExecuteNonQuery();
169 }
170 catch (Exception)
171 {
172 }
173
174 // Munge and transfer the ban list
175 //
176 cmd.Parameters.Clear();
177 cmd.CommandText = "insert into estateban select "+es.EstateID.ToString()+", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = @UUID";
178 cmd.Parameters.Add("@UUID", regionID.ToString());
179
180 try
181 {
182 cmd.ExecuteNonQuery();
183 }
184 catch (Exception)
185 {
186 }
187 }
188
189 LoadBanList(es);
190
191 es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers");
192 es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users");
193 es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups");
194 return es;
195 }
196
197 public void StoreEstateSettings(EstateSettings es)
198 {
199 List<string> fields = new List<string>(FieldList);
200 fields.Remove("EstateID");
201
202 List<string> terms = new List<string>();
203
204 foreach (string f in fields)
205 terms.Add(f+" = @"+f);
206
207 string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = @EstateID";
208
209 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
210
211 cmd.CommandText = sql;
212
213 foreach (string name in FieldList)
214 {
215 if(m_FieldMap[name].GetValue(es) is bool)
216 {
217 if((bool)m_FieldMap[name].GetValue(es))
218 cmd.Parameters.Add("@"+name, "1");
219 else
220 cmd.Parameters.Add("@"+name, "0");
221 }
222 else
223 {
224 cmd.Parameters.Add("@"+name, m_FieldMap[name].GetValue(es).ToString());
225 }
226 }
227
228 cmd.ExecuteNonQuery();
229
230 SaveBanList(es);
231 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
232 SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess);
233 SaveUUIDList(es.EstateID, "estate_groups", es.EstateGroups);
234 }
235
236 private void LoadBanList(EstateSettings es)
237 {
238 es.ClearBans();
239
240 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
241
242 cmd.CommandText = "select bannedUUID from estateban where EstateID = @EstateID";
243 cmd.Parameters.Add("@EstateID", es.EstateID);
244
245 IDataReader r = cmd.ExecuteReader();
246
247 while(r.Read())
248 {
249 EstateBan eb = new EstateBan();
250
251 LLUUID uuid = new LLUUID();
252 LLUUID.TryParse(r["bannedUUID"].ToString(), out uuid);
253
254 eb.bannedUUID = uuid;
255 eb.bannedIP = "0.0.0.0";
256 eb.bannedIPHostMask = "0.0.0.0";
257 es.AddBan(eb);
258 }
259 r.Close();
260 }
261
262 private void SaveBanList(EstateSettings es)
263 {
264 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
265
266 cmd.CommandText = "delete from estateban where EstateID = @EstateID";
267 cmd.Parameters.Add("@EstateID", es.EstateID.ToString());
268
269 cmd.ExecuteNonQuery();
270
271 cmd.Parameters.Clear();
272
273 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( @EstateID, @bannedUUID, '', '', '' )";
274
275 foreach(EstateBan b in es.EstateBans)
276 {
277 cmd.Parameters.Add("@EstateID", es.EstateID.ToString());
278 cmd.Parameters.Add("@bannedUUID", b.bannedUUID.ToString());
279
280 cmd.ExecuteNonQuery();
281 cmd.Parameters.Clear();
282 }
283 }
284
285 void SaveUUIDList(uint EstateID, string table, LLUUID[] data)
286 {
287 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
288
289 cmd.CommandText = "delete from "+table+" where EstateID = @EstateID";
290 cmd.Parameters.Add("@EstateID", EstateID.ToString());
291
292 cmd.ExecuteNonQuery();
293
294 cmd.Parameters.Clear();
295
296 cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( @EstateID, @uuid )";
297
298 foreach(LLUUID uuid in data)
299 {
300 cmd.Parameters.Add("@EstateID", EstateID.ToString());
301 cmd.Parameters.Add("@uuid", uuid.ToString());
302
303 cmd.ExecuteNonQuery();
304 cmd.Parameters.Clear();
305 }
306 }
307
308 LLUUID[] LoadUUIDList(uint EstateID, string table)
309 {
310 List<LLUUID> uuids = new List<LLUUID>();
311
312 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
313
314 cmd.CommandText = "select uuid from "+table+" where EstateID = @EstateID";
315 cmd.Parameters.Add("@EstateID", EstateID);
316
317 IDataReader r = cmd.ExecuteReader();
318
319 while(r.Read())
320 {
321 EstateBan eb = new EstateBan();
322
323 LLUUID uuid = new LLUUID();
324 LLUUID.TryParse(r["uuid"].ToString(), out uuid);
325
326 uuids.Add(uuid);
327 }
328 r.Close();
329
330 return uuids.ToArray();
331 }
332 }
333}
diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs
index 0e67fb9..4e87e0d 100644
--- a/OpenSim/Data/SQLite/SQLiteRegionData.cs
+++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs
@@ -62,7 +62,6 @@ namespace OpenSim.Data.SQLite
62 private SqliteDataAdapter terrainDa; 62 private SqliteDataAdapter terrainDa;
63 private SqliteDataAdapter landDa; 63 private SqliteDataAdapter landDa;
64 private SqliteDataAdapter landAccessListDa; 64 private SqliteDataAdapter landAccessListDa;
65 private SqliteDataAdapter regionBanListDa;
66 65
67 private SqliteConnection m_conn; 66 private SqliteConnection m_conn;
68 67
@@ -119,9 +118,6 @@ namespace OpenSim.Data.SQLite
119 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); 118 SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
120 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); 119 landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
121 120
122 SqliteCommand regionBanListSelectCmd = new SqliteCommand(regionbanListSelect, m_conn);
123 regionBanListDa = new SqliteDataAdapter(regionBanListSelectCmd);
124
125 // This actually does the roll forward assembly stuff 121 // This actually does the roll forward assembly stuff
126 Assembly assem = GetType().Assembly; 122 Assembly assem = GetType().Assembly;
127 Migration m = new Migration(m_conn, assem, "RegionStore"); 123 Migration m = new Migration(m_conn, assem, "RegionStore");
@@ -157,10 +153,6 @@ namespace OpenSim.Data.SQLite
157 ds.Tables.Add(createLandAccessListTable()); 153 ds.Tables.Add(createLandAccessListTable());
158 setupLandAccessCommands(landAccessListDa, m_conn); 154 setupLandAccessCommands(landAccessListDa, m_conn);
159 155
160 ds.Tables.Add(createRegionBanListTable());
161 setupRegionBanCommands(regionBanListDa, m_conn);
162
163
164 // WORKAROUND: This is a work around for sqlite on 156 // WORKAROUND: This is a work around for sqlite on
165 // windows, which gets really unhappy with blob columns 157 // windows, which gets really unhappy with blob columns
166 // that have no sample data in them. At some point we 158 // that have no sample data in them. At some point we
@@ -201,15 +193,6 @@ namespace OpenSim.Data.SQLite
201 m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); 193 m_log.Info("[REGION DB]: Caught fill error on landaccesslist table");
202 } 194 }
203 195
204 try
205 {
206 regionBanListDa.Fill(ds.Tables["regionban"]);
207 }
208 catch (Exception)
209 {
210 m_log.Info("[REGION DB]: Caught fill error on regionban table");
211 }
212
213 return; 196 return;
214 } 197 }
215 } 198 }
@@ -900,21 +883,6 @@ namespace OpenSim.Data.SQLite
900 return landaccess; 883 return landaccess;
901 } 884 }
902 885
903 /// <summary>
904 /// create "regionban" table
905 /// </summary>
906 /// <returns>regionban datatable</returns>
907 private static DataTable createRegionBanListTable()
908 {
909 DataTable regionbanlist = new DataTable("regionban");
910 createCol(regionbanlist, "regionUUID", typeof(String));
911 createCol(regionbanlist, "bannedUUID", typeof(String));
912 createCol(regionbanlist, "bannedIp", typeof(String));
913 createCol(regionbanlist, "bannedIpHostMask", typeof(String));
914
915 return regionbanlist;
916 }
917
918 /*********************************************************************** 886 /***********************************************************************
919 * 887 *
920 * Convert between ADO.NET <=> OpenSim Objects 888 * Convert between ADO.NET <=> OpenSim Objects
@@ -1178,74 +1146,6 @@ namespace OpenSim.Data.SQLite
1178 return entry; 1146 return entry;
1179 } 1147 }
1180 1148
1181
1182 /// <summary>
1183 /// Load a region banlist
1184 /// </summary>
1185 /// <param name="regionUUID">the region UUID</param>
1186 /// <returns>The banlist</returns>
1187 public List<RegionBanListItem> LoadRegionBanList(LLUUID regionUUID)
1188 {
1189 List<RegionBanListItem> regionbanlist = new List<RegionBanListItem>();
1190 lock (ds)
1191 {
1192 DataTable regionban = ds.Tables["regionban"];
1193 string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
1194 DataRow[] rawbanlist = regionban.Select(searchExp);
1195 foreach (DataRow rawbanrow in rawbanlist)
1196 {
1197 RegionBanListItem rbli = new RegionBanListItem();
1198 LLUUID tmpvalue = LLUUID.Zero;
1199
1200 rbli.regionUUID = regionUUID;
1201
1202 if (Helpers.TryParse((string)rawbanrow["bannedUUID"], out tmpvalue))
1203 rbli.bannedUUID = tmpvalue;
1204
1205 rbli.bannedIP = (string)rawbanrow["bannedIp"];
1206 rbli.bannedIPHostMask = (string)rawbanrow["bannedIpHostMask"];
1207 regionbanlist.Add(rbli);
1208 }
1209 }
1210 return regionbanlist;
1211 }
1212
1213 /// <summary>
1214 /// Add en entry into region banlist
1215 /// </summary>
1216 /// <param name="item"></param>
1217 public void AddToRegionBanlist(RegionBanListItem item)
1218 {
1219 lock (ds)
1220 {
1221 using (SqliteCommand cmd = new SqliteCommand("insert into regionban (regionUUID, bannedUUID, bannedIp, bannedIpHostMask) values (:regionUUID,:bannedUUID,:bannedIp,:bannedIpHostMask)", m_conn))
1222 {
1223 cmd.Parameters.Add(new SqliteParameter(":regionUUID", item.regionUUID.ToString()));
1224 cmd.Parameters.Add(new SqliteParameter(":bannedUUID", item.bannedUUID.ToString()));
1225 cmd.Parameters.Add(new SqliteParameter(":bannedIp", item.bannedIP));
1226 cmd.Parameters.Add(new SqliteParameter(":bannedIpHostMask", item.bannedIPHostMask));
1227 cmd.ExecuteNonQuery();
1228 }
1229 }
1230 }
1231
1232 /// <summary>
1233 /// remove an entry from the region banlist
1234 /// </summary>
1235 /// <param name="item"></param>
1236 public void RemoveFromRegionBanlist(RegionBanListItem item)
1237 {
1238 lock (ds)
1239 {
1240 using (SqliteCommand cmd = new SqliteCommand("delete from regionban where regionUUID=:regionUUID AND bannedUUID=:bannedUUID", m_conn))
1241 {
1242 cmd.Parameters.Add(new SqliteParameter(":regionUUID", item.regionUUID.ToString()));
1243 cmd.Parameters.Add(new SqliteParameter(":bannedUUID", item.bannedUUID.ToString()));
1244 cmd.ExecuteNonQuery();
1245 }
1246 }
1247 }
1248
1249 /// <summary> 1149 /// <summary>
1250 /// 1150 ///
1251 /// </summary> 1151 /// </summary>
@@ -1827,20 +1727,6 @@ namespace OpenSim.Data.SQLite
1827 /// </summary> 1727 /// </summary>
1828 /// <param name="da"></param> 1728 /// <param name="da"></param>
1829 /// <param name="conn"></param> 1729 /// <param name="conn"></param>
1830 private void setupRegionBanCommands(SqliteDataAdapter da, SqliteConnection conn)
1831 {
1832 da.InsertCommand = createInsertCommand("regionban", ds.Tables["regionban"]);
1833 da.InsertCommand.Connection = conn;
1834
1835 da.UpdateCommand = createUpdateCommand("regionban", "regionUUID=:regionUUID AND bannedUUID=:bannedUUID", ds.Tables["regionban"]);
1836 da.UpdateCommand.Connection = conn;
1837 }
1838
1839 /// <summary>
1840 ///
1841 /// </summary>
1842 /// <param name="da"></param>
1843 /// <param name="conn"></param>
1844 private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn) 1730 private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
1845 { 1731 {
1846 da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]); 1732 da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);