From 2758bc81ad79c6110777ceb6cc714c7b40014359 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sat, 21 Jun 2008 06:50:38 +0000 Subject: [PATCH] * Persists region banlists across reboots for the sqlite datastore also now. --- .../Data/SQLite/Resources/002_RegionStore.sql | 10 +++ OpenSim/Data/SQLite/SQLiteRegionData.cs | 85 ++++++++++++++++++- OpenSim/Framework/RegionBanListItem.cs | 27 ++++++ 3 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 OpenSim/Data/SQLite/Resources/002_RegionStore.sql diff --git a/OpenSim/Data/SQLite/Resources/002_RegionStore.sql b/OpenSim/Data/SQLite/Resources/002_RegionStore.sql new file mode 100644 index 0000000000..c5c7c99455 --- /dev/null +++ b/OpenSim/Data/SQLite/Resources/002_RegionStore.sql @@ -0,0 +1,10 @@ +BEGIN TRANSACTION; + +CREATE TABLE regionban( + regionUUID varchar (255), + bannedUUID varchar (255), + bannedIp varchar (255), + bannedIpHostMask varchar (255) + ); + +COMMIT; \ No newline at end of file diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index ab4d283a02..8212691f8c 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs @@ -50,6 +50,7 @@ namespace OpenSim.Data.SQLite private const string terrainSelect = "select * from terrain limit 1"; private const string landSelect = "select * from land"; private const string landAccessListSelect = "select distinct * from landaccesslist"; + private const string regionbanListSelect = "select * from regionban"; private DataSet ds; private SqliteDataAdapter primDa; @@ -58,6 +59,7 @@ namespace OpenSim.Data.SQLite private SqliteDataAdapter terrainDa; private SqliteDataAdapter landDa; private SqliteDataAdapter landAccessListDa; + private SqliteDataAdapter regionBanListDa; private SqliteConnection m_conn; @@ -106,6 +108,9 @@ namespace OpenSim.Data.SQLite SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); + SqliteCommand regionBanListSelectCmd = new SqliteCommand(regionbanListSelect, m_conn); + regionBanListDa = new SqliteDataAdapter(regionBanListSelectCmd); + // This actually does the roll forward assembly stuff Assembly assem = GetType().Assembly; Migration m = new Migration(m_conn, assem, "RegionStore"); @@ -141,6 +146,10 @@ namespace OpenSim.Data.SQLite ds.Tables.Add(createLandAccessListTable()); setupLandAccessCommands(landAccessListDa, m_conn); + ds.Tables.Add(createRegionBanListTable()); + setupRegionBanCommands(regionBanListDa, m_conn); + + // WORKAROUND: This is a work around for sqlite on // windows, which gets really unhappy with blob columns // that have no sample data in them. At some point we @@ -180,6 +189,16 @@ namespace OpenSim.Data.SQLite { m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); } + + try + { + regionBanListDa.Fill(ds.Tables["regionban"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on regionban table"); + } + return; } } @@ -790,6 +809,17 @@ namespace OpenSim.Data.SQLite return landaccess; } + private static DataTable createRegionBanListTable() + { + DataTable regionbanlist = new DataTable("regionban"); + createCol(regionbanlist, "regionUUID", typeof(String)); + createCol(regionbanlist, "bannedUUID", typeof(String)); + createCol(regionbanlist, "bannedIp", typeof(String)); + createCol(regionbanlist, "bannedIpHostMask", typeof(String)); + + return regionbanlist; + } + /*********************************************************************** * * Convert between ADO.NET <=> OpenSim Objects @@ -1036,21 +1066,60 @@ namespace OpenSim.Data.SQLite return entry; } - + + public List LoadRegionBanList(LLUUID regionUUID) { List regionbanlist = new List(); + lock (ds) + { + DataTable regionban = ds.Tables["regionban"]; + string searchExp = "regionUUID = '" + regionUUID.ToString() + "'"; + DataRow[] rawbanlist = regionban.Select(searchExp); + foreach (DataRow rawbanrow in rawbanlist) + { + RegionBanListItem rbli = new RegionBanListItem(); + LLUUID tmpvalue = LLUUID.Zero; + + rbli.regionUUID = regionUUID; + + if (Helpers.TryParse((string)rawbanrow["bannedUUID"], out tmpvalue)) + rbli.bannedUUID = tmpvalue; + + rbli.bannedIP = (string)rawbanrow["bannedIp"]; + rbli.bannedIPHostMask = (string)rawbanrow["bannedIpHostMask"]; + regionbanlist.Add(rbli); + } + } return regionbanlist; } public void AddToRegionBanlist(RegionBanListItem item) { - + lock (ds) + { + using (SqliteCommand cmd = new SqliteCommand("insert into regionban (regionUUID, bannedUUID, bannedIp, bannedIpHostMask) values (:regionUUID,:bannedUUID,:bannedIp,:bannedIpHostMask)", m_conn)) + { + cmd.Parameters.Add(new SqliteParameter(":regionUUID", item.regionUUID.ToString())); + cmd.Parameters.Add(new SqliteParameter(":bannedUUID", item.bannedUUID.ToString())); + cmd.Parameters.Add(new SqliteParameter(":bannedIp", item.bannedIP)); + cmd.Parameters.Add(new SqliteParameter(":bannedIpHostMask", item.bannedIPHostMask)); + cmd.ExecuteNonQuery(); + } + } } public void RemoveFromRegionBanlist(RegionBanListItem item) { - + lock (ds) + { + using (SqliteCommand cmd = new SqliteCommand("delete from regionban where regionUUID=:regionUUID AND bannedUUID=:bannedUUID", m_conn)) + { + cmd.Parameters.Add(new SqliteParameter(":regionUUID", item.regionUUID.ToString())); + cmd.Parameters.Add(new SqliteParameter(":bannedUUID", item.bannedUUID.ToString())); + cmd.ExecuteNonQuery(); + } + } } private static Array serializeTerrain(double[,] val) @@ -1536,6 +1605,16 @@ namespace OpenSim.Data.SQLite da.InsertCommand.Connection = conn; } + private void setupRegionBanCommands(SqliteDataAdapter da, SqliteConnection conn) + { + da.InsertCommand = createInsertCommand("regionban", ds.Tables["regionban"]); + da.InsertCommand.Connection = conn; + + da.UpdateCommand = createUpdateCommand("regionban", "regionUUID=:regionUUID AND bannedUUID=:bannedUUID", ds.Tables["regionban"]); + da.UpdateCommand.Connection = conn; + } + + private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn) { da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]); diff --git a/OpenSim/Framework/RegionBanListItem.cs b/OpenSim/Framework/RegionBanListItem.cs index 60383fb323..edf6a224df 100644 --- a/OpenSim/Framework/RegionBanListItem.cs +++ b/OpenSim/Framework/RegionBanListItem.cs @@ -1,3 +1,30 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + using libsecondlife; using System; using System.Collections.Generic;