12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108 |
- /*
- * 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 OpenSimulator 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 System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Reflection;
- using System.Text;
- using log4net;
- using MySql.Data.MySqlClient;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes;
- namespace OpenSim.Data.MySQL
- {
- /// <summary>
- /// A MySQL Interface for the Region Server
- /// </summary>
- public class MySQLSimulationData : ISimulationDataStore
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- private static string LogHeader = "[REGION DB MYSQL]";
- private string m_connectionString;
- /// <summary>
- /// This lock was being used to serialize database operations when the connection was shared, but this has
- /// been unnecessary for a long time after we switched to using MySQL's underlying connection pooling instead.
- /// FIXME: However, the locks remain in many places since they are effectively providing a level of
- /// transactionality. This should be replaced by more efficient database transactions which would not require
- /// unrelated operations to block each other or unrelated operations on the same tables from blocking each
- /// other.
- /// </summary>
- private object m_dbLock = new object();
- protected virtual Assembly Assembly
- {
- get { return GetType().Assembly; }
- }
- public MySQLSimulationData()
- {
- }
- public MySQLSimulationData(string connectionString)
- {
- Initialise(connectionString);
- }
- public virtual void Initialise(string connectionString)
- {
- m_connectionString = connectionString;
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- // Apply new Migrations
- //
- Migration m = new Migration(dbcon, Assembly, "RegionStore");
- m.Update();
- dbcon.Close();
- }
- }
- private IDataReader ExecuteReader(MySqlCommand c)
- {
- IDataReader r = null;
- try
- {
- r = c.ExecuteReader();
- }
- catch (Exception e)
- {
- m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e);
- throw;
- }
- return r;
- }
- private void ExecuteNonQuery(MySqlCommand c)
- {
- try
- {
- c.ExecuteNonQuery();
- }
- catch (Exception e)
- {
- m_log.Error("[REGION DB]: MySQL error in ExecuteNonQuery: " + e.Message);
- throw;
- }
- }
- public void Dispose() {}
- public virtual void StoreObject(SceneObjectGroup obj, UUID regionUUID)
- {
- uint flags = obj.RootPart.GetEffectiveObjectFlags();
- // Eligibility check
- //
- if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
- return;
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- foreach (SceneObjectPart prim in obj.Parts)
- {
- cmd.Parameters.Clear();
- cmd.CommandText = "replace into prims (" +
- "UUID, CreationDate, " +
- "Name, Text, Description, " +
- "SitName, TouchName, ObjectFlags, " +
- "OwnerMask, NextOwnerMask, GroupMask, " +
- "EveryoneMask, BaseMask, " +
- "PositionX, PositionY, PositionZ, " +
- "GroupPositionX, GroupPositionY, GroupPositionZ, " +
- "VelocityX, VelocityY, VelocityZ, " +
- "AngularVelocityX, AngularVelocityY, AngularVelocityZ, " +
- "AccelerationX, AccelerationY, AccelerationZ, " +
- "standtargetx, standtargety, standtargetz, " +
- "RotationX, RotationY, RotationZ, RotationW, " +
- "SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, " +
- "SitTargetOrientW, SitTargetOrientX, " +
- "SitTargetOrientY, SitTargetOrientZ, " +
- "RegionUUID, CreatorID, " +
- "OwnerID, GroupID, " +
- "LastOwnerID, RezzerID, SceneGroupID, " +
- "PayPrice, PayButton1, " +
- "PayButton2, PayButton3, " +
- "PayButton4, LoopedSound, " +
- "LoopedSoundGain, TextureAnimation, " +
- "CameraEyeOffsetX, CameraEyeOffsetY, " +
- "CameraEyeOffsetZ, CameraAtOffsetX, " +
- "CameraAtOffsetY, CameraAtOffsetZ, " +
- "ForceMouselook, ScriptAccessPin, " +
- "AllowedDrop, DieAtEdge, " +
- "SalePrice, SaleType, " +
- "ColorR, ColorG, ColorB, ColorA, " +
- "ParticleSystem, ClickAction, Material, " +
- "CollisionSound, CollisionSoundVolume, " +
- "PassTouches, " +
- "PassCollisions, " +
- "LinkNumber, MediaURL, KeyframeMotion, AttachedPosX, " +
- "AttachedPosY, AttachedPosZ, " +
- "PhysicsShapeType, Density, GravityModifier, " +
- "Friction, Restitution, Vehicle, PhysInertia, DynAttrs, " +
- "RotationAxisLocks, sopanims, sitactrange, pseudocrc" +
- ") values (" + "?UUID, " +
- "?CreationDate, ?Name, ?Text, " +
- "?Description, ?SitName, ?TouchName, " +
- "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
- "?GroupMask, ?EveryoneMask, ?BaseMask, " +
- "?PositionX, ?PositionY, ?PositionZ, " +
- "?GroupPositionX, ?GroupPositionY, ?GroupPositionZ, " +
- "?VelocityX, ?VelocityY, ?VelocityZ, "+
- "?AngularVelocityX, ?AngularVelocityY, ?AngularVelocityZ, " +
- "?AccelerationX, ?AccelerationY, ?AccelerationZ, " +
- "?standtargetx, ?standtargety, ?standtargetz, " +
- "?RotationX, ?RotationY, ?RotationZ, " +
- "?RotationW, ?SitTargetOffsetX, " +
- "?SitTargetOffsetY, ?SitTargetOffsetZ, " +
- "?SitTargetOrientW, ?SitTargetOrientX, " +
- "?SitTargetOrientY, ?SitTargetOrientZ, " +
- "?RegionUUID, ?CreatorID, ?OwnerID, " +
- "?GroupID, ?LastOwnerID, ?RezzerID, ?SceneGroupID, " +
- "?PayPrice, ?PayButton1, ?PayButton2, " +
- "?PayButton3, ?PayButton4, ?LoopedSound, " +
- "?LoopedSoundGain, ?TextureAnimation, " +
- "?CameraEyeOffsetX, ?CameraEyeOffsetY, " +
- "?CameraEyeOffsetZ, ?CameraAtOffsetX, " +
- "?CameraAtOffsetY, ?CameraAtOffsetZ, " +
- "?ForceMouselook, ?ScriptAccessPin, " +
- "?AllowedDrop, ?DieAtEdge, ?SalePrice, " +
- "?SaleType, ?ColorR, ?ColorG, " +
- "?ColorB, ?ColorA, ?ParticleSystem, " +
- "?ClickAction, ?Material, ?CollisionSound, " +
- "?CollisionSoundVolume, ?PassTouches, ?PassCollisions, " +
- "?LinkNumber, ?MediaURL, ?KeyframeMotion, ?AttachedPosX, " +
- "?AttachedPosY, ?AttachedPosZ, " +
- "?PhysicsShapeType, ?Density, ?GravityModifier, " +
- "?Friction, ?Restitution, ?Vehicle, ?PhysInertia, ?DynAttrs," +
- "?RotationAxisLocks, ?sopanims, ?sitactrange, ?pseudocrc)";
- FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
- ExecuteNonQuery(cmd);
- cmd.Parameters.Clear();
- cmd.CommandText = "replace into primshapes (" +
- "UUID, Shape, ScaleX, ScaleY, " +
- "ScaleZ, PCode, PathBegin, PathEnd, " +
- "PathScaleX, PathScaleY, PathShearX, " +
- "PathShearY, PathSkew, PathCurve, " +
- "PathRadiusOffset, PathRevolutions, " +
- "PathTaperX, PathTaperY, PathTwist, " +
- "PathTwistBegin, ProfileBegin, ProfileEnd, " +
- "ProfileCurve, ProfileHollow, Texture, " +
- "ExtraParams, State, LastAttachPoint, Media) " +
- "values (?UUID, " +
- "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, " +
- "?PCode, ?PathBegin, ?PathEnd, " +
- "?PathScaleX, ?PathScaleY, " +
- "?PathShearX, ?PathShearY, " +
- "?PathSkew, ?PathCurve, ?PathRadiusOffset, " +
- "?PathRevolutions, ?PathTaperX, " +
- "?PathTaperY, ?PathTwist, " +
- "?PathTwistBegin, ?ProfileBegin, " +
- "?ProfileEnd, ?ProfileCurve, " +
- "?ProfileHollow, ?Texture, ?ExtraParams, " +
- "?State, ?LastAttachPoint, ?Media)";
- FillShapeCommand(cmd, prim);
- ExecuteNonQuery(cmd);
- }
- }
- dbcon.Close();
- }
- }
- }
- public virtual void RemoveObject(UUID obj, UUID regionUUID)
- {
- // m_log.DebugFormat("[REGION DB]: Deleting scene object {0} from {1} in database", obj, regionUUID);
- List<string> uuids = new List<string>();
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID";
- cmd.Parameters.AddWithValue("UUID", obj.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- uuids.Add(reader["UUID"].ToString());
- }
- if(uuids.Count == 0)
- {
- dbcon.Close();
- return;
- }
- // delete the main prims
- cmd.CommandText = "delete from prims where SceneGroupID= ?UUID";
- ExecuteNonQuery(cmd);
- cmd.Parameters.Clear();
- string sqlparams;
- if (uuids.Count > 1)
- {
- StringBuilder sb = new StringBuilder(uuids.Count * 39 + 5);
- sb.Append("IN (");
- for(int i = 0; i < uuids.Count - 1; ++i )
- {
- sb.Append("'");
- sb.Append(uuids[i]);
- sb.Append("',");
- }
- sb.Append("'");
- sb.Append(uuids[uuids.Count - 1]);
- sb.Append("')");
- sqlparams = sb.ToString();
- }
- else
- sqlparams = "='" + uuids[0] + "'";
- cmd.CommandText = "delete from primshapes where UUID " + sqlparams;
- ExecuteNonQuery(cmd);
- cmd.CommandText = "delete from primitems where primID " + sqlparams;
- ExecuteNonQuery(cmd);
- dbcon.Close();
- }
- }
- }
- }
- public virtual List<SceneObjectGroup> LoadObjects(UUID regionID)
- {
- const int ROWS_PER_QUERY = 5000;
- Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>(ROWS_PER_QUERY);
- Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
- int count = 0;
- #region Prim Loading
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText =
- "SELECT * FROM prims LEFT JOIN primshapes ON prims.UUID = primshapes.UUID WHERE RegionUUID = ?RegionUUID";
- cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- cmd.CommandTimeout = 3600;
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- SceneObjectPart prim = BuildPrim(reader);
- if (reader["Shape"] is DBNull)
- prim.Shape = PrimitiveBaseShape.Default;
- else
- prim.Shape = BuildShape(reader);
- UUID parentID = DBGuid.FromDB(reader["SceneGroupID"].ToString());
- if (parentID != prim.UUID)
- prim.ParentUUID = parentID;
- prims[prim.UUID] = prim;
- ++count;
- if (count % ROWS_PER_QUERY == 0)
- m_log.Debug("[REGION DB]: Loaded " + count + " prims...");
- }
- }
- }
- dbcon.Close();
- }
- }
- #endregion Prim Loading
- #region SceneObjectGroup Creation
- // Create all of the SOGs from the root prims first
- foreach (SceneObjectPart prim in prims.Values)
- {
- if (prim.ParentUUID == UUID.Zero)
- {
- objects[prim.UUID] = new SceneObjectGroup(prim);
- }
- }
- // Add all of the children objects to the SOGs
- foreach (SceneObjectPart prim in prims.Values)
- {
- SceneObjectGroup sog;
- if (prim.UUID != prim.ParentUUID)
- {
- if (objects.TryGetValue(prim.ParentUUID, out sog))
- {
- int originalLinkNum = prim.LinkNum;
- sog.AddPart(prim);
- // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
- // We override that here
- if (originalLinkNum != 0)
- prim.LinkNum = originalLinkNum;
- }
- else
- {
- m_log.WarnFormat(
- "[REGION DB]: Database contains an orphan child prim {0} {1} in region {2} pointing to missing parent {3}. This prim will not be loaded.",
- prim.Name, prim.UUID, regionID, prim.ParentUUID);
- }
- }
- }
- #endregion SceneObjectGroup Creation
- m_log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
- #region Prim Inventory Loading
- // Instead of attempting to LoadItems on every prim,
- // most of which probably have no items... get a
- // list from DB of all prims which have items and
- // LoadItems only on those
- List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand itemCmd = dbcon.CreateCommand())
- {
- itemCmd.CommandText = "SELECT DISTINCT primID FROM primitems";
- using (IDataReader itemReader = ExecuteReader(itemCmd))
- {
- while (itemReader.Read())
- {
- if (!(itemReader["primID"] is DBNull))
- {
- UUID primID = DBGuid.FromDB(itemReader["primID"].ToString());
- if (prims.ContainsKey(primID))
- primsWithInventory.Add(prims[primID]);
- }
- }
- }
- }
- dbcon.Close();
- }
- }
- foreach (SceneObjectPart prim in primsWithInventory)
- {
- LoadItems(prim);
- }
- #endregion Prim Inventory Loading
- m_log.DebugFormat("[REGION DB]: Loaded inventory from {0} objects", primsWithInventory.Count);
- return new List<SceneObjectGroup>(objects.Values);
- }
- /// <summary>
- /// Load in a prim's persisted inventory.
- /// </summary>
- /// <param name="prim">The prim</param>
- private void LoadItems(SceneObjectPart prim)
- {
- lock (m_dbLock)
- {
- List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select * from primitems where PrimID = ?PrimID";
- cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- TaskInventoryItem item = BuildItem(reader);
- item.ParentID = prim.UUID; // Values in database are often wrong
- inventory.Add(item);
- }
- }
- }
- dbcon.Close();
- }
- prim.Inventory.RestoreInventoryItems(inventory);
- }
- }
- // Legacy entry point for when terrain was always a 256x256 hieghtmap
- public void StoreTerrain(double[,] ter, UUID regionID)
- {
- StoreTerrain(new TerrainData(ter), regionID);
- }
- public void StoreTerrain(TerrainData terrData, UUID regionID)
- {
- Util.FireAndForget(delegate(object x)
- {
- m_log.Info("[REGION DB]: Storing terrain");
- int terrainDBRevision;
- Array terrainDBblob;
- terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
- cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- using (MySqlCommand cmd2 = dbcon.CreateCommand())
- {
- try
- {
- cmd2.CommandText = "insert into terrain (RegionUUID, " +
- "Revision, Heightfield) values (?RegionUUID, " +
- "?Revision, ?Heightfield)";
- cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- cmd2.Parameters.AddWithValue("Revision", terrainDBRevision);
- cmd2.Parameters.AddWithValue("Heightfield", terrainDBblob);
- ExecuteNonQuery(cmd);
- ExecuteNonQuery(cmd2);
- }
- catch (Exception e)
- {
- m_log.ErrorFormat(e.ToString());
- }
- }
- }
- dbcon.Close();
- }
- }
- });
- }
- public void StoreBakedTerrain(TerrainData terrData, UUID regionID)
- {
- Util.FireAndForget(delegate(object x)
- {
- m_log.Info("[REGION DB]: Storing Baked terrain");
- int terrainDBRevision;
- Array terrainDBblob;
- terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from bakedterrain where RegionUUID = ?RegionUUID";
- cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- using (MySqlCommand cmd2 = dbcon.CreateCommand())
- {
- try
- {
- cmd2.CommandText = "insert into bakedterrain (RegionUUID, " +
- "Revision, Heightfield) values (?RegionUUID, " +
- "?Revision, ?Heightfield)";
- cmd2.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- cmd2.Parameters.AddWithValue("Revision", terrainDBRevision);
- cmd2.Parameters.AddWithValue("Heightfield", terrainDBblob);
- ExecuteNonQuery(cmd);
- ExecuteNonQuery(cmd2);
- }
- catch (Exception e)
- {
- m_log.ErrorFormat(e.ToString());
- }
- }
- }
- dbcon.Close();
- }
- }
- });
- }
- // Legacy region loading
- public virtual double[,] LoadTerrain(UUID regionID)
- {
- double[,] ret = null;
- TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
- if (terrData != null)
- ret = terrData.GetDoubles();
- return ret;
- }
- // Returns 'null' if region not found
- public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
- {
- TerrainData terrData = null;
- byte[] blob = null;
- int rev = 0;
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
- "from terrain where RegionUUID = ?RegionUUID " +
- "order by Revision desc limit 1";
- cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- rev = Convert.ToInt32(reader["Revision"]);
- if ((reader["Heightfield"] != DBNull.Value))
- {
- blob = (byte[])reader["Heightfield"];
- }
- }
- }
- }
- dbcon.Close();
- }
- }
- if(blob != null)
- terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
- return terrData;
- }
- public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
- {
- TerrainData terrData = null;
- byte[] blob = null;
- int rev = 0;
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
- "from bakedterrain where RegionUUID = ?RegionUUID ";
- cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- rev = Convert.ToInt32(reader["Revision"]);
- if ((reader["Heightfield"] != DBNull.Value))
- {
- blob = (byte[])reader["Heightfield"];
- }
- }
- }
- }
- dbcon.Close();
- }
- }
- if(blob != null)
- terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
- return terrData;
- }
- public virtual void RemoveLandObject(UUID globalID)
- {
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from land where UUID = ?UUID";
- cmd.Parameters.AddWithValue("UUID", globalID.ToString());
- ExecuteNonQuery(cmd);
- }
- dbcon.Close();
- }
- }
- }
- public virtual void StoreLandObject(ILandObject parcel)
- {
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "replace into land (UUID, RegionUUID, " +
- "LocalLandID, Bitmap, Name, Description, " +
- "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
- "Category, ClaimDate, ClaimPrice, GroupUUID, " +
- "SalePrice, LandStatus, LandFlags, LandingType, " +
- "MediaAutoScale, MediaTextureUUID, MediaURL, " +
- "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
- "UserLocationX, UserLocationY, UserLocationZ, " +
- "UserLookAtX, UserLookAtY, UserLookAtZ, " +
- "AuthbuyerID, OtherCleanTime, Dwell, MediaType, MediaDescription, " +
- "MediaSize, MediaLoop, ObscureMusic, ObscureMedia, " +
- "SeeAVs, AnyAVSounds, GroupAVSounds, environment) values (" +
- "?UUID, ?RegionUUID, " +
- "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
- "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
- "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
- "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
- "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
- "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
- "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
- "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
- "?AuthbuyerID, ?OtherCleanTime, ?Dwell, ?MediaType, ?MediaDescription, "+
- "CONCAT(?MediaWidth, ',', ?MediaHeight), ?MediaLoop, ?ObscureMusic, ?ObscureMedia, " +
- "?SeeAVs, ?AnyAVSounds, ?GroupAVSounds, ?environment)";
- FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
- ExecuteNonQuery(cmd);
- cmd.CommandText = "delete from landaccesslist where LandUUID = ?UUID";
- ExecuteNonQuery(cmd);
- cmd.Parameters.Clear();
- cmd.CommandText = "insert into landaccesslist (LandUUID, " +
- "AccessUUID, Flags, Expires) values (?LandUUID, ?AccessUUID, " +
- "?Flags, ?Expires)";
- foreach (LandAccessEntry entry in parcel.LandData.ParcelAccessList)
- {
- FillLandAccessCommand(cmd, entry, parcel.LandData.GlobalID);
- ExecuteNonQuery(cmd);
- cmd.Parameters.Clear();
- }
- }
- dbcon.Close();
- }
- }
- }
- public virtual RegionSettings LoadRegionSettings(UUID regionUUID)
- {
- RegionSettings rs = null;
- bool needStore = false;
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
- cmd.Parameters.AddWithValue("regionUUID", regionUUID);
- using (IDataReader reader = ExecuteReader(cmd))
- {
- if (reader.Read())
- {
- rs = BuildRegionSettings(reader);
- rs.OnSave += StoreRegionSettings;
- }
- else
- {
- rs = new RegionSettings();
- rs.RegionUUID = regionUUID;
- rs.OnSave += StoreRegionSettings;
- needStore = true;
- }
- }
- }
- dbcon.Close();
- }
- }
- if(needStore)
- StoreRegionSettings(rs);
- LoadSpawnPoints(rs);
- return rs;
- }
- #region RegionEnvironmentSettings
- public string LoadRegionEnvironmentSettings(UUID regionUUID)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- string command = "select * from `regionenvironment` where region_id = ?region_id";
- using (MySqlCommand cmd = new MySqlCommand(command))
- {
- cmd.Connection = dbcon;
- cmd.Parameters.AddWithValue("?region_id", regionUUID.ToString());
- using(IDataReader result = ExecuteReader(cmd))
- {
- if(!result.Read())
- {
- dbcon.Close();
- return String.Empty;
- }
- else
- {
- string ret = Convert.ToString(result["llsd_settings"]);
- dbcon.Close();
- return ret;
- }
- }
- }
- }
- }
- public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "REPLACE INTO `regionenvironment` (`region_id`, `llsd_settings`) VALUES (?region_id, ?llsd_settings)";
- cmd.Parameters.AddWithValue("region_id", regionUUID);
- cmd.Parameters.AddWithValue("llsd_settings", settings);
- ExecuteNonQuery(cmd);
- }
- dbcon.Close();
- }
- }
- public void RemoveRegionEnvironmentSettings(UUID regionUUID)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from `regionenvironment` where region_id = ?region_id";
- cmd.Parameters.AddWithValue("?region_id", regionUUID.ToString());
- ExecuteNonQuery(cmd);
- }
- dbcon.Close();
- }
- }
- #endregion
- public virtual void StoreRegionSettings(RegionSettings rs)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "replace into regionsettings (regionUUID, " +
- "block_terraform, block_fly, allow_damage, " +
- "restrict_pushing, allow_land_resell, " +
- "allow_land_join_divide, block_show_in_search, " +
- "agent_limit, object_bonus, maturity, " +
- "disable_scripts, disable_collisions, " +
- "disable_physics, terrain_texture_1, " +
- "terrain_texture_2, terrain_texture_3, " +
- "terrain_texture_4, elevation_1_nw, " +
- "elevation_2_nw, elevation_1_ne, " +
- "elevation_2_ne, elevation_1_se, " +
- "elevation_2_se, elevation_1_sw, " +
- "elevation_2_sw, water_height, " +
- "terrain_raise_limit, terrain_lower_limit, " +
- "use_estate_sun, fixed_sun, sun_position, " +
- "covenant, covenant_datetime, Sandbox, sunvectorx, sunvectory, " +
- "sunvectorz, loaded_creation_datetime, " +
- "loaded_creation_id, map_tile_ID, block_search, casino, " +
- "TelehubObject, parcel_tile_ID, cacheID) " +
- "values (?RegionUUID, ?BlockTerraform, " +
- "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
- "?AllowLandResell, ?AllowLandJoinDivide, " +
- "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
- "?Maturity, ?DisableScripts, ?DisableCollisions, " +
- "?DisablePhysics, ?TerrainTexture1, " +
- "?TerrainTexture2, ?TerrainTexture3, " +
- "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
- "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
- "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
- "?WaterHeight, ?TerrainRaiseLimit, " +
- "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
- "?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " +
- "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
- "?LoadedCreationDateTime, ?LoadedCreationID, " +
- "?TerrainImageID, ?block_search, ?casino, " +
- "?TelehubObject, ?ParcelImageID, ?cacheID)";
- FillRegionSettingsCommand(cmd, rs);
- ExecuteNonQuery(cmd);
- }
- dbcon.Close();
- SaveSpawnPoints(rs);
- }
- }
- public virtual List<LandData> LoadLandObjects(UUID regionUUID)
- {
- List<LandData> landData = new List<LandData>();
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
- cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- LandData newLand = BuildLandData(reader);
- landData.Add(newLand);
- }
- }
- }
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- foreach (LandData land in landData)
- {
- cmd.Parameters.Clear();
- cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
- cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- land.ParcelAccessList.Add(BuildLandAccessData(reader));
- }
- }
- }
- }
- dbcon.Close();
- }
- }
- return landData;
- }
- public void Shutdown()
- {
- }
- private SceneObjectPart BuildPrim(IDataReader row)
- {
- SceneObjectPart prim = new SceneObjectPart();
- // depending on the MySQL connector version, CHAR(36) may be already converted to Guid!
- prim.UUID = DBGuid.FromDB(row["UUID"]);
- prim.CreatorIdentification = (string)row["CreatorID"];
- prim.OwnerID = DBGuid.FromDB(row["OwnerID"]);
- prim.GroupID = DBGuid.FromDB(row["GroupID"]);
- prim.LastOwnerID = DBGuid.FromDB(row["LastOwnerID"]);
- if (row["RezzerID"] != DBNull.Value)
- prim.RezzerID = DBGuid.FromDB(row["RezzerID"]);
- else
- prim.RezzerID = UUID.Zero;
- // explicit conversion of integers is required, which sort
- // of sucks. No idea if there is a shortcut here or not.
- try {
- prim.CreationDate = (int)row["CreationDate"];
- }
- catch (Exception e)
- {
- m_log.ErrorFormat("[MYSQL DB]: Invalid CreationDate cast to integer: prim UUID was {0}, date was {1}, exception was {2}", row["UUID"].ToString(), row["CreationDate"].ToString(), e.ToString());
- }
- if (row["Name"] != DBNull.Value)
- prim.Name = (string)row["Name"];
- else
- prim.Name = String.Empty;
- // Various text fields
- prim.Text = (string)row["Text"];
- prim.Color = Color.FromArgb((int)row["ColorA"],
- (int)row["ColorR"],
- (int)row["ColorG"],
- (int)row["ColorB"]);
- prim.Description = (string)row["Description"];
- prim.SitName = (string)row["SitName"];
- prim.TouchName = (string)row["TouchName"];
- // Permissions
- prim.Flags = (PrimFlags)(int)row["ObjectFlags"];
- prim.OwnerMask = (uint)(int)row["OwnerMask"];
- prim.NextOwnerMask = (uint)(int)row["NextOwnerMask"];
- prim.GroupMask = (uint)(int)row["GroupMask"];
- prim.EveryoneMask = (uint)(int)row["EveryoneMask"];
- prim.BaseMask = (uint)(int)row["BaseMask"];
- // Vectors
- prim.OffsetPosition = new Vector3(
- (float)row["PositionX"],
- (float)row["PositionY"],
- (float)row["PositionZ"]
- );
- prim.GroupPosition = new Vector3(
- (float)row["GroupPositionX"],
- (float)row["GroupPositionY"],
- (float)row["GroupPositionZ"]
- );
- prim.Velocity = new Vector3(
- (float)row["VelocityX"],
- (float)row["VelocityY"],
- (float)row["VelocityZ"]
- );
- prim.AngularVelocity = new Vector3(
- (float)row["AngularVelocityX"],
- (float)row["AngularVelocityY"],
- (float)row["AngularVelocityZ"]
- );
- prim.Acceleration = new Vector3(
- (float)row["AccelerationX"],
- (float)row["AccelerationY"],
- (float)row["AccelerationZ"]
- );
- // quaternions
- prim.RotationOffset = new Quaternion(
- (float)row["RotationX"],
- (float)row["RotationY"],
- (float)row["RotationZ"],
- (float)row["RotationW"]
- );
- prim.SitTargetPositionLL = new Vector3(
- (float)row["SitTargetOffsetX"],
- (float)row["SitTargetOffsetY"],
- (float)row["SitTargetOffsetZ"]
- );
- prim.SitTargetOrientationLL = new Quaternion(
- (float)row["SitTargetOrientX"],
- (float)row["SitTargetOrientY"],
- (float)row["SitTargetOrientZ"],
- (float)row["SitTargetOrientW"]
- );
- prim.StandOffset = new Vector3(
- (float)row["standtargetx"],
- (float)row["standtargety"],
- (float)row["standtargetz"]
- );
- prim.SitActiveRange = (float)row["sitactrange"];
- prim.PayPrice[0] = (int)row["PayPrice"];
- prim.PayPrice[1] = (int)row["PayButton1"];
- prim.PayPrice[2] = (int)row["PayButton2"];
- prim.PayPrice[3] = (int)row["PayButton3"];
- prim.PayPrice[4] = (int)row["PayButton4"];
- prim.Sound = DBGuid.FromDB(row["LoopedSound"].ToString());
- prim.SoundGain = (float)row["LoopedSoundGain"];
- if (prim.Sound != UUID.Zero)
- prim.SoundFlags = 1; // If it's persisted at all, it's looped
- else
- prim.SoundFlags = 0;
- if (!(row["TextureAnimation"] is DBNull))
- prim.TextureAnimation = (byte[])row["TextureAnimation"];
- if (!(row["ParticleSystem"] is DBNull))
- prim.ParticleSystem = (byte[])row["ParticleSystem"];
- prim.SetCameraEyeOffset(new Vector3(
- (float)row["CameraEyeOffsetX"],
- (float)row["CameraEyeOffsetY"],
- (float)row["CameraEyeOffsetZ"]
- ));
- prim.SetCameraAtOffset(new Vector3(
- (float)row["CameraAtOffsetX"],
- (float)row["CameraAtOffsetY"],
- (float)row["CameraAtOffsetZ"]
- ));
- prim.SetForceMouselook((sbyte)row["ForceMouselook"] != 0);
- prim.ScriptAccessPin = (int)row["ScriptAccessPin"];
- prim.AllowedDrop = ((sbyte)row["AllowedDrop"] != 0);
- prim.DIE_AT_EDGE = ((sbyte)row["DieAtEdge"] != 0);
- prim.SalePrice = (int)row["SalePrice"];
- prim.ObjectSaleType = unchecked((byte)(sbyte)row["SaleType"]);
- prim.Material = unchecked((byte)(sbyte)row["Material"]);
- if (!(row["ClickAction"] is DBNull))
- prim.ClickAction = unchecked((byte)(sbyte)row["ClickAction"]);
- prim.CollisionSound = DBGuid.FromDB(row["CollisionSound"]);
- prim.CollisionSoundVolume = (float)(double)row["CollisionSoundVolume"];
- prim.PassTouches = ((sbyte)row["PassTouches"] != 0);
- prim.PassCollisions = ((sbyte)row["PassCollisions"] != 0);
- prim.LinkNum = (int)row["LinkNumber"];
- if (!(row["MediaURL"] is System.DBNull))
- prim.MediaUrl = (string)row["MediaURL"];
- if (!(row["AttachedPosX"] is System.DBNull))
- {
- prim.AttachedPos = new Vector3(
- (float)row["AttachedPosX"],
- (float)row["AttachedPosY"],
- (float)row["AttachedPosZ"]
- );
- }
- if (!(row["DynAttrs"] is System.DBNull))
- prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
- else
- prim.DynAttrs = null;
- if (!(row["KeyframeMotion"] is DBNull))
- {
- Byte[] data = (byte[])row["KeyframeMotion"];
- if (data.Length > 0)
- prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
- else
- prim.KeyframeMotion = null;
- }
- else
- {
- prim.KeyframeMotion = null;
- }
- prim.PhysicsShapeType = (byte)Convert.ToInt32(row["PhysicsShapeType"].ToString());
- prim.Density = (float)row["Density"];
- prim.GravityModifier = (float)row["GravityModifier"];
- prim.Friction = (float)row["Friction"];
- prim.Restitution = (float)row["Restitution"];
- prim.RotationAxisLocks = (byte)Convert.ToInt32(row["RotationAxisLocks"].ToString());
- SOPVehicle vehicle = null;
- if (row["Vehicle"].ToString() != String.Empty)
- {
- vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
- if (vehicle != null)
- prim.VehicleParams = vehicle;
- }
- PhysicsInertiaData pdata = null;
- if (row["PhysInertia"].ToString() != String.Empty)
- pdata = PhysicsInertiaData.FromXml2(row["PhysInertia"].ToString());
- prim.PhysicsInertia = pdata;
- if (!(row["sopanims"] is DBNull))
- {
- Byte[] data = (byte[])row["sopanims"];
- if (data.Length > 0)
- prim.DeSerializeAnimations(data);
- else
- prim.Animations = null;
- }
- else
- {
- prim.Animations = null;
- }
- prim.SitActiveRange = (float)row["sitactrange"];
- int pseudocrc = (int)row["pseudocrc"];
- if(pseudocrc != 0)
- prim.PseudoCRC = pseudocrc;
- return prim;
- }
- /// <summary>
- /// Build a prim inventory item from the persisted data.
- /// </summary>
- /// <param name="row"></param>
- /// <returns></returns>
- private static TaskInventoryItem BuildItem(IDataReader row)
- {
- try
- {
- TaskInventoryItem taskItem = new TaskInventoryItem();
- taskItem.ItemID = DBGuid.FromDB(row["itemID"]);
- taskItem.ParentPartID = DBGuid.FromDB(row["primID"]);
- taskItem.AssetID = DBGuid.FromDB(row["assetID"]);
- taskItem.ParentID = DBGuid.FromDB(row["parentFolderID"]);
- taskItem.InvType = Convert.ToInt32(row["invType"]);
- taskItem.Type = Convert.ToInt32(row["assetType"]);
- taskItem.Name = (String)row["name"];
- taskItem.Description = (String)row["description"];
- taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
- taskItem.CreatorIdentification = (String)row["creatorID"];
- taskItem.OwnerID = DBGuid.FromDB(row["ownerID"]);
- taskItem.LastOwnerID = DBGuid.FromDB(row["lastOwnerID"]);
- taskItem.GroupID = DBGuid.FromDB(row["groupID"]);
- taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
- taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
- taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
- taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
- taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
- taskItem.Flags = Convert.ToUInt32(row["flags"]);
- return taskItem;
- }
- catch
- {
- m_log.ErrorFormat("[MYSQL DB]: Error reading task inventory: itemID was {0}, primID was {1}", row["itemID"].ToString(), row["primID"].ToString());
- throw;
- }
- }
- private static RegionSettings BuildRegionSettings(IDataReader row)
- {
- RegionSettings newSettings = new RegionSettings();
- newSettings.RegionUUID = DBGuid.FromDB(row["regionUUID"]);
- newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
- newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
- newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
- newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
- newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
- newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
- newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
- newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
- newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
- newSettings.Maturity = Convert.ToInt32(row["maturity"]);
- newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
- newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
- newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
- newSettings.TerrainTexture1 = DBGuid.FromDB(row["terrain_texture_1"]);
- newSettings.TerrainTexture2 = DBGuid.FromDB(row["terrain_texture_2"]);
- newSettings.TerrainTexture3 = DBGuid.FromDB(row["terrain_texture_3"]);
- newSettings.TerrainTexture4 = DBGuid.FromDB(row["terrain_texture_4"]);
- newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
- newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
- newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
- newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
- newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
- newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
- newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
- newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
- newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
- newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
- newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
- newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
- newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]);
- newSettings.SunVector = new Vector3 (
- Convert.ToSingle(row["sunvectorx"]),
- Convert.ToSingle(row["sunvectory"]),
- Convert.ToSingle(row["sunvectorz"])
- );
- newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
- newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
- newSettings.Covenant = DBGuid.FromDB(row["covenant"]);
- newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
- newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
- if (row["loaded_creation_id"] is DBNull)
- newSettings.LoadedCreationID = "";
- else
- newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
- newSettings.TerrainImageID = DBGuid.FromDB(row["map_tile_ID"]);
- newSettings.ParcelImageID = DBGuid.FromDB(row["parcel_tile_ID"]);
- newSettings.TelehubObject = DBGuid.FromDB(row["TelehubObject"]);
- newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]);
- newSettings.Casino = Convert.ToBoolean(row["casino"]);
- if (!(row["cacheID"] is DBNull))
- newSettings.CacheID = DBGuid.FromDB(row["cacheID"]);
- return newSettings;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <returns></returns>
- private static LandData BuildLandData(IDataReader row)
- {
- LandData newData = new LandData();
- newData.GlobalID = DBGuid.FromDB(row["UUID"]);
- newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
- // Bitmap is a byte[512]
- newData.Bitmap = (Byte[]) row["Bitmap"];
- newData.Name = (String) row["Name"];
- newData.Description = (String) row["Description"];
- newData.OwnerID = DBGuid.FromDB(row["OwnerUUID"]);
- newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
- newData.Area = Convert.ToInt32(row["Area"]);
- newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
- newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
- //Enum libsecondlife.Parcel.ParcelCategory
- newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
- newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
- newData.GroupID = DBGuid.FromDB(row["GroupUUID"]);
- newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
- newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
- //Enum. libsecondlife.Parcel.ParcelStatus
- newData.Flags = Convert.ToUInt32(row["LandFlags"]);
- newData.LandingType = Convert.ToByte(row["LandingType"]);
- newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
- newData.MediaID = DBGuid.FromDB(row["MediaTextureUUID"]);
- newData.MediaURL = (String) row["MediaURL"];
- newData.MusicURL = (String) row["MusicURL"];
- newData.PassHours = Convert.ToSingle(row["PassHours"]);
- newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
- UUID authedbuyer = UUID.Zero;
- UUID snapshotID = UUID.Zero;
- UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
- UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
- newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
- newData.Dwell = Convert.ToSingle(row["Dwell"]);
- newData.AuthBuyerID = authedbuyer;
- newData.SnapshotID = snapshotID;
- try
- {
- newData.UserLocation =
- new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
- Convert.ToSingle(row["UserLocationZ"]));
- newData.UserLookAt =
- new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
- Convert.ToSingle(row["UserLookAtZ"]));
- }
- catch (InvalidCastException)
- {
- newData.UserLocation = Vector3.Zero;
- newData.UserLookAt = Vector3.Zero;
- m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
- }
- newData.MediaDescription = (string) row["MediaDescription"];
- newData.MediaType = (string) row["MediaType"];
- newData.MediaWidth = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[0]);
- newData.MediaHeight = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[1]);
- newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
- newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
- newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
- newData.ParcelAccessList = new List<LandAccessEntry>();
- if (!(row["SeeAVs"] is System.DBNull))
- newData.SeeAVs = Convert.ToInt32(row["SeeAVs"]) != 0 ? true : false;
- if (!(row["AnyAVSounds"] is System.DBNull))
- newData.AnyAVSounds = Convert.ToInt32(row["AnyAVSounds"]) != 0 ? true : false;
- if (!(row["GroupAVSounds"] is System.DBNull))
- newData.GroupAVSounds = Convert.ToInt32(row["GroupAVSounds"]) != 0 ? true : false;
- if (row["environment"] is DBNull)
- {
- newData.Environment = null;
- newData.EnvironmentVersion = -1;
- }
- else
- {
- string env = (string)row["environment"];
- if(string.IsNullOrEmpty(env))
- {
- newData.Environment = null;
- newData.EnvironmentVersion = -1;
- }
- else
- {
- try
- {
- ViewerEnvironment VEnv = ViewerEnvironment.FromOSDString(env);
- newData.Environment = VEnv;
- newData.EnvironmentVersion = VEnv.version;
- }
- catch
- {
- newData.Environment = null;
- newData.EnvironmentVersion = -1;
- }
- }
- }
- return newData;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <returns></returns>
- private static LandAccessEntry BuildLandAccessData(IDataReader row)
- {
- LandAccessEntry entry = new LandAccessEntry();
- entry.AgentID = DBGuid.FromDB(row["AccessUUID"]);
- entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
- entry.Expires = Convert.ToInt32(row["Expires"]);
- return entry;
- }
- /// <summary>
- /// Fill the prim command with prim values
- /// </summary>
- /// <param name="row"></param>
- /// <param name="prim"></param>
- /// <param name="sceneGroupID"></param>
- /// <param name="regionUUID"></param>
- private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
- {
- cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
- cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
- cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
- cmd.Parameters.AddWithValue("Name", prim.Name);
- cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
- // the UUID of the root part for this SceneObjectGroup
- // various text fields
- cmd.Parameters.AddWithValue("Text", prim.Text);
- cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
- cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
- cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
- cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
- cmd.Parameters.AddWithValue("Description", prim.Description);
- cmd.Parameters.AddWithValue("SitName", prim.SitName);
- cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
- // permissions
- cmd.Parameters.AddWithValue("ObjectFlags", (uint)prim.Flags);
- cmd.Parameters.AddWithValue("CreatorID", prim.CreatorIdentification.ToString());
- cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
- cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
- cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
- cmd.Parameters.AddWithValue("RezzerID", prim.RezzerID.ToString());
- cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
- cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
- cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
- cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
- cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
- // vectors
- cmd.Parameters.AddWithValue("PositionX", prim.OffsetPosition.X);
- cmd.Parameters.AddWithValue("PositionY", prim.OffsetPosition.Y);
- cmd.Parameters.AddWithValue("PositionZ", prim.OffsetPosition.Z);
- cmd.Parameters.AddWithValue("GroupPositionX", prim.GroupPosition.X);
- cmd.Parameters.AddWithValue("GroupPositionY", prim.GroupPosition.Y);
- cmd.Parameters.AddWithValue("GroupPositionZ", prim.GroupPosition.Z);
- cmd.Parameters.AddWithValue("VelocityX", prim.Velocity.X);
- cmd.Parameters.AddWithValue("VelocityY", prim.Velocity.Y);
- cmd.Parameters.AddWithValue("VelocityZ", prim.Velocity.Z);
- cmd.Parameters.AddWithValue("AngularVelocityX", prim.AngularVelocity.X);
- cmd.Parameters.AddWithValue("AngularVelocityY", prim.AngularVelocity.Y);
- cmd.Parameters.AddWithValue("AngularVelocityZ", prim.AngularVelocity.Z);
- cmd.Parameters.AddWithValue("AccelerationX", prim.Acceleration.X);
- cmd.Parameters.AddWithValue("AccelerationY", prim.Acceleration.Y);
- cmd.Parameters.AddWithValue("AccelerationZ", prim.Acceleration.Z);
- cmd.Parameters.AddWithValue("standtargetx", prim.StandOffset.X);
- cmd.Parameters.AddWithValue("standtargety", prim.StandOffset.Y);
- cmd.Parameters.AddWithValue("standtargetz", prim.StandOffset.Z);
- // quaternions
- cmd.Parameters.AddWithValue("RotationX", prim.RotationOffset.X);
- cmd.Parameters.AddWithValue("RotationY", prim.RotationOffset.Y);
- cmd.Parameters.AddWithValue("RotationZ", prim.RotationOffset.Z);
- cmd.Parameters.AddWithValue("RotationW", prim.RotationOffset.W);
- // Sit target
- Vector3 sitTargetPos = prim.SitTargetPositionLL;
- cmd.Parameters.AddWithValue("SitTargetOffsetX", sitTargetPos.X);
- cmd.Parameters.AddWithValue("SitTargetOffsetY", sitTargetPos.Y);
- cmd.Parameters.AddWithValue("SitTargetOffsetZ", sitTargetPos.Z);
- Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
- cmd.Parameters.AddWithValue("SitTargetOrientW", sitTargetOrient.W);
- cmd.Parameters.AddWithValue("SitTargetOrientX", sitTargetOrient.X);
- cmd.Parameters.AddWithValue("SitTargetOrientY", sitTargetOrient.Y);
- cmd.Parameters.AddWithValue("SitTargetOrientZ", sitTargetOrient.Z);
- cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
- cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
- cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
- cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
- cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
- if ((prim.SoundFlags & 1) != 0) // Looped
- {
- cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
- cmd.Parameters.AddWithValue("LoopedSoundGain", (float)prim.SoundGain);
- }
- else
- {
- cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
- cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
- }
- cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
- cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
- cmd.Parameters.AddWithValue("CameraEyeOffsetX", prim.GetCameraEyeOffset().X);
- cmd.Parameters.AddWithValue("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y);
- cmd.Parameters.AddWithValue("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z);
- cmd.Parameters.AddWithValue("CameraAtOffsetX", prim.GetCameraAtOffset().X);
- cmd.Parameters.AddWithValue("CameraAtOffsetY", prim.GetCameraAtOffset().Y);
- cmd.Parameters.AddWithValue("CameraAtOffsetZ", prim.GetCameraAtOffset().Z);
- if (prim.GetForceMouselook())
- cmd.Parameters.AddWithValue("ForceMouselook", 1);
- else
- cmd.Parameters.AddWithValue("ForceMouselook", 0);
- cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
- if (prim.AllowedDrop)
- cmd.Parameters.AddWithValue("AllowedDrop", 1);
- else
- cmd.Parameters.AddWithValue("AllowedDrop", 0);
- if (prim.DIE_AT_EDGE)
- cmd.Parameters.AddWithValue("DieAtEdge", 1);
- else
- cmd.Parameters.AddWithValue("DieAtEdge", 0);
- cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
- cmd.Parameters.AddWithValue("SaleType", unchecked((sbyte)(prim.ObjectSaleType)));
- byte clickAction = prim.ClickAction;
- cmd.Parameters.AddWithValue("ClickAction", unchecked((sbyte)(clickAction)));
- cmd.Parameters.AddWithValue("Material", unchecked((sbyte)(prim.Material)));
- cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
- cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
- if (prim.PassTouches)
- cmd.Parameters.AddWithValue("PassTouches", 1);
- else
- cmd.Parameters.AddWithValue("PassTouches", 0);
- if (prim.PassCollisions)
- cmd.Parameters.AddWithValue("PassCollisions", 1);
- else
- cmd.Parameters.AddWithValue("PassCollisions", 0);
- cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
- cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
- if (prim.AttachedPos != null)
- {
- cmd.Parameters.AddWithValue("AttachedPosX", prim.AttachedPos.X);
- cmd.Parameters.AddWithValue("AttachedPosY", prim.AttachedPos.Y);
- cmd.Parameters.AddWithValue("AttachedPosZ", prim.AttachedPos.Z);
- }
- if (prim.KeyframeMotion != null)
- cmd.Parameters.AddWithValue("KeyframeMotion", prim.KeyframeMotion.Serialize());
- else
- cmd.Parameters.AddWithValue("KeyframeMotion", new Byte[0]);
- if (prim.PhysicsInertia != null)
- cmd.Parameters.AddWithValue("PhysInertia", prim.PhysicsInertia.ToXml2());
- else
- cmd.Parameters.AddWithValue("PhysInertia", String.Empty);
- if (prim.VehicleParams != null)
- cmd.Parameters.AddWithValue("Vehicle", prim.VehicleParams.ToXml2());
- else
- cmd.Parameters.AddWithValue("Vehicle", String.Empty);
- if (prim.DynAttrs != null && prim.DynAttrs.CountNamespaces > 0)
- cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml());
- else
- cmd.Parameters.AddWithValue("DynAttrs", null);
- cmd.Parameters.AddWithValue("PhysicsShapeType", prim.PhysicsShapeType);
- cmd.Parameters.AddWithValue("Density", prim.Density);
- cmd.Parameters.AddWithValue("GravityModifier", prim.GravityModifier);
- cmd.Parameters.AddWithValue("Friction", prim.Friction);
- cmd.Parameters.AddWithValue("Restitution", prim.Restitution);
- cmd.Parameters.AddWithValue("RotationAxisLocks", prim.RotationAxisLocks);
- if (prim.Animations!= null)
- cmd.Parameters.AddWithValue("sopanims", prim.SerializeAnimations());
- else
- cmd.Parameters.AddWithValue("sopanims", null);
- cmd.Parameters.AddWithValue("sitactrange", prim.SitActiveRange);
- cmd.Parameters.AddWithValue("pseudocrc", prim.PseudoCRC);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <param name="taskItem"></param>
- private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
- {
- cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
- cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
- cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
- cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
- cmd.Parameters.AddWithValue("invType", taskItem.InvType);
- cmd.Parameters.AddWithValue("assetType", taskItem.Type);
- cmd.Parameters.AddWithValue("name", taskItem.Name);
- cmd.Parameters.AddWithValue("description", taskItem.Description);
- cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
- cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorIdentification);
- cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
- cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
- cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
- cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
- cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
- cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
- cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
- cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
- cmd.Parameters.AddWithValue("flags", taskItem.Flags);
- }
- /// <summary>
- ///
- /// </summary>
- private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
- {
- cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
- cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
- cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
- cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
- cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
- cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
- cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
- cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
- cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
- cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
- cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
- cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
- cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
- cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
- cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
- cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
- cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
- cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
- cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
- cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
- cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
- cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
- cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
- cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
- cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
- cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
- cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
- cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
- cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
- cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
- cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
- cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
- cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
- cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
- cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
- cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
- cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
- cmd.Parameters.AddWithValue("CovenantChangedDateTime", settings.CovenantChangedDateTime);
- cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
- cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
- cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
- cmd.Parameters.AddWithValue("block_search", settings.GodBlockSearch);
- cmd.Parameters.AddWithValue("casino", settings.Casino);
- cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID);
- cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject);
- cmd.Parameters.AddWithValue("cacheID", settings.CacheID);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <param name="land"></param>
- /// <param name="regionUUID"></param>
- private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
- {
- cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
- cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
- cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
- // Bitmap is a byte[512]
- cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
- cmd.Parameters.AddWithValue("Name", land.Name);
- cmd.Parameters.AddWithValue("Description", land.Description);
- cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
- cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
- cmd.Parameters.AddWithValue("Area", land.Area);
- cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
- cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
- cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
- cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
- cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
- cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
- cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
- cmd.Parameters.AddWithValue("LandFlags", land.Flags);
- cmd.Parameters.AddWithValue("LandingType", land.LandingType);
- cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
- cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
- cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
- cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
- cmd.Parameters.AddWithValue("PassHours", land.PassHours);
- cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
- cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
- cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
- cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
- cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
- cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
- cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
- cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
- cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
- cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
- cmd.Parameters.AddWithValue("Dwell", land.Dwell);
- cmd.Parameters.AddWithValue("MediaDescription", land.MediaDescription);
- cmd.Parameters.AddWithValue("MediaType", land.MediaType);
- cmd.Parameters.AddWithValue("MediaWidth", land.MediaWidth);
- cmd.Parameters.AddWithValue("MediaHeight", land.MediaHeight);
- cmd.Parameters.AddWithValue("MediaLoop", land.MediaLoop);
- cmd.Parameters.AddWithValue("ObscureMusic", land.ObscureMusic);
- cmd.Parameters.AddWithValue("ObscureMedia", land.ObscureMedia);
- cmd.Parameters.AddWithValue("SeeAVs", land.SeeAVs ? 1 : 0);
- cmd.Parameters.AddWithValue("AnyAVSounds", land.AnyAVSounds ? 1 : 0);
- cmd.Parameters.AddWithValue("GroupAVSounds", land.GroupAVSounds ? 1 : 0);
- if (land.Environment == null)
- cmd.Parameters.AddWithValue("environment", "");
- else
- {
- try
- {
- cmd.Parameters.AddWithValue("environment", ViewerEnvironment.ToOSDString(land.Environment));
- }
- catch
- {
- cmd.Parameters.AddWithValue("environment", "");
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <param name="entry"></param>
- /// <param name="parcelID"></param>
- private static void FillLandAccessCommand(MySqlCommand cmd, LandAccessEntry entry, UUID parcelID)
- {
- cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
- cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
- cmd.Parameters.AddWithValue("Flags", entry.Flags);
- cmd.Parameters.AddWithValue("Expires", entry.Expires.ToString());
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <returns></returns>
- private PrimitiveBaseShape BuildShape(IDataReader row)
- {
- PrimitiveBaseShape s = new PrimitiveBaseShape();
- s.Scale = new Vector3(
- (float)(double)row["ScaleX"],
- (float)(double)row["ScaleY"],
- (float)(double)row["ScaleZ"]
- );
- // paths
- s.PCode = (byte)(int)row["PCode"];
- s.PathBegin = (ushort)(int)row["PathBegin"];
- s.PathEnd = (ushort)(int)row["PathEnd"];
- s.PathScaleX = (byte)(int)row["PathScaleX"];
- s.PathScaleY = (byte)(int)row["PathScaleY"];
- s.PathShearX = (byte)(int)row["PathShearX"];
- s.PathShearY = (byte)(int)row["PathShearY"];
- s.PathSkew = (sbyte)(int)row["PathSkew"];
- s.PathCurve = (byte)(int)row["PathCurve"];
- s.PathRadiusOffset = (sbyte)(int)row["PathRadiusOffset"];
- s.PathRevolutions = (byte)(int)row["PathRevolutions"];
- s.PathTaperX = (sbyte)(int)row["PathTaperX"];
- s.PathTaperY = (sbyte)(int)row["PathTaperY"];
- s.PathTwist = (sbyte)(int)row["PathTwist"];
- s.PathTwistBegin = (sbyte)(int)row["PathTwistBegin"];
- // profile
- s.ProfileBegin = (ushort)(int)row["ProfileBegin"];
- s.ProfileEnd = (ushort)(int)row["ProfileEnd"];
- s.ProfileCurve = (byte)(int)row["ProfileCurve"];
- s.ProfileHollow = (ushort)(int)row["ProfileHollow"];
- s.TextureEntry = (byte[])row["Texture"];
- s.ExtraParams = (byte[])row["ExtraParams"];
- s.State = (byte)(int)row["State"];
- s.LastAttachPoint = (byte)(int)row["LastAttachPoint"];
- if (!(row["Media"] is System.DBNull))
- s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
- return s;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="row"></param>
- /// <param name="prim"></param>
- private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
- {
- PrimitiveBaseShape s = prim.Shape;
- cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
- // shape is an enum
- cmd.Parameters.AddWithValue("Shape", 0);
- // vectors
- cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
- cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
- cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
- // paths
- cmd.Parameters.AddWithValue("PCode", s.PCode);
- cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
- cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
- cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
- cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
- cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
- cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
- cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
- cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
- cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
- cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
- cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
- cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
- cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
- cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
- // profile
- cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
- cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
- cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
- cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
- cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
- cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
- cmd.Parameters.AddWithValue("State", s.State);
- cmd.Parameters.AddWithValue("LastAttachPoint", s.LastAttachPoint);
- cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml());
- }
- public virtual void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
- {
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from primitems where primID = ?PrimID";
- cmd.Parameters.AddWithValue("primID", primID.ToString());
- ExecuteNonQuery(cmd);
- if (items.Count == 0)
- {
- dbcon.Close();
- return;
- }
- cmd.Parameters.Clear();
- cmd.CommandText = "insert into primitems (" +
- "invType, assetType, name, " +
- "description, creationDate, nextPermissions, " +
- "currentPermissions, basePermissions, " +
- "everyonePermissions, groupPermissions, " +
- "flags, itemID, primID, assetID, " +
- "parentFolderID, creatorID, ownerID, " +
- "groupID, lastOwnerID) values (?invType, " +
- "?assetType, ?name, ?description, " +
- "?creationDate, ?nextPermissions, " +
- "?currentPermissions, ?basePermissions, " +
- "?everyonePermissions, ?groupPermissions, " +
- "?flags, ?itemID, ?primID, ?assetID, " +
- "?parentFolderID, ?creatorID, ?ownerID, " +
- "?groupID, ?lastOwnerID)";
- foreach (TaskInventoryItem item in items)
- {
- cmd.Parameters.Clear();
- FillItemCommand(cmd, item);
- ExecuteNonQuery(cmd);
- }
- }
- dbcon.Close();
- }
- }
- }
- public UUID[] GetObjectIDs(UUID regionID)
- {
- List<UUID> uuids = new List<UUID>();
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select UUID from prims where RegionUUID = ?RegionUUID and SceneGroupID = UUID";
- cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
- using (IDataReader reader = ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- UUID id = new UUID(reader["UUID"].ToString());
- uuids.Add(id);
- }
- }
- }
- dbcon.Close();
- }
- }
- return uuids.ToArray();
- }
- private void LoadSpawnPoints(RegionSettings rs)
- {
- rs.ClearSpawnPoints();
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select Yaw, Pitch, Distance from spawn_points where RegionID = ?RegionID";
- cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString());
- using (IDataReader r = cmd.ExecuteReader())
- {
- while (r.Read())
- {
- SpawnPoint sp = new SpawnPoint();
- sp.Yaw = (float)r["Yaw"];
- sp.Pitch = (float)r["Pitch"];
- sp.Distance = (float)r["Distance"];
- rs.AddSpawnPoint(sp);
- }
- }
- }
- dbcon.Close();
- }
- }
- }
- private void SaveSpawnPoints(RegionSettings rs)
- {
- lock (m_dbLock)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from spawn_points where RegionID = ?RegionID";
- cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString());
- cmd.ExecuteNonQuery();
- cmd.Parameters.Clear();
- cmd.CommandText = "insert into spawn_points (RegionID, Yaw, Pitch, Distance) values ( ?RegionID, ?Yaw, ?Pitch, ?Distance)";
- foreach (SpawnPoint p in rs.SpawnPoints())
- {
- cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString());
- cmd.Parameters.AddWithValue("?Yaw", p.Yaw);
- cmd.Parameters.AddWithValue("?Pitch", p.Pitch);
- cmd.Parameters.AddWithValue("?Distance", p.Distance);
- cmd.ExecuteNonQuery();
- cmd.Parameters.Clear();
- }
- }
- dbcon.Close();
- }
- }
- }
- public void SaveExtra(UUID regionID, string name, string val)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "replace into regionextra values (?RegionID, ?Name, ?value)";
- cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
- cmd.Parameters.AddWithValue("?Name", name);
- cmd.Parameters.AddWithValue("?value", val);
- cmd.ExecuteNonQuery();
- }
- dbcon.Close();
- }
- }
- public void RemoveExtra(UUID regionID, string name)
- {
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "delete from regionextra where RegionID=?RegionID and Name=?Name";
- cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
- cmd.Parameters.AddWithValue("?Name", name);
- cmd.ExecuteNonQuery();
- }
- dbcon.Close();
- }
- }
- public Dictionary<string, string> GetExtra(UUID regionID)
- {
- Dictionary<string, string> ret = new Dictionary<string, string>();
- using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
- {
- dbcon.Open();
- using (MySqlCommand cmd = dbcon.CreateCommand())
- {
- cmd.CommandText = "select * from regionextra where RegionID=?RegionID";
- cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
- using (IDataReader r = cmd.ExecuteReader())
- {
- while (r.Read())
- {
- ret[r["Name"].ToString()] = r["value"].ToString();
- }
- }
- }
- dbcon.Close();
- }
- return ret;
- }
- }
- }
|