diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLDataStore.cs | 143 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/MySQLEstateData.cs | 386 | ||||
-rw-r--r-- | OpenSim/Data/MySQL/Resources/013_RegionStore.sql | 103 |
3 files changed, 492 insertions, 140 deletions
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Threading; | ||
34 | using libsecondlife; | ||
35 | using log4net; | ||
36 | using MySql.Data.MySqlClient; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.Environment.Interfaces; | ||
39 | using OpenSim.Region.Environment.Scenes; | ||
40 | |||
41 | namespace 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 @@ | |||
1 | begin; | ||
2 | |||
3 | drop table regionsettings; | ||
4 | |||
5 | CREATE 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 | |||
43 | CREATE TABLE `estate_managers` ( | ||
44 | `EstateID` int(10) unsigned NOT NULL, | ||
45 | `uuid` char(36) NOT NULL, | ||
46 | KEY `EstateID` (`EstateID`) | ||
47 | ) ENGINE=InnoDB; | ||
48 | |||
49 | CREATE TABLE `estate_groups` ( | ||
50 | `EstateID` int(10) unsigned NOT NULL, | ||
51 | `uuid` char(36) NOT NULL, | ||
52 | KEY `EstateID` (`EstateID`) | ||
53 | ) ENGINE=InnoDB; | ||
54 | |||
55 | CREATE TABLE `estate_users` ( | ||
56 | `EstateID` int(10) unsigned NOT NULL, | ||
57 | `uuid` char(36) NOT NULL, | ||
58 | KEY `EstateID` (`EstateID`) | ||
59 | ) ENGINE=InnoDB; | ||
60 | |||
61 | CREATE 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 | |||
70 | CREATE 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 | |||
95 | CREATE 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 | |||
102 | commit; | ||
103 | |||